Example #1
0
 /**
 	@todo 发送验证码
 	@param $to string 发送目标
 	@param $captcha string 要发送的字符串
 	@access static public
 	@return 
 		{
 		    "data": {
 		        "availableNumber": "",//该号码当天可用(剩余)发送验证码次数。不返回则表示不限制发送次数
 		        "code": "1234"//传入的验证码
 		    },
 		    "message": "成功",//错误信息描述
 		    "result": 1000,//返回的结果
 		    "transId": "c5a484f3-8705-4cfe-af6f-2e6885c4c9ef"//请求流水号,本次请求对应的唯一ID
 		}
 */
 public static function _send($to)
 {
     session_start();
     $captcha = Sys::genCaptcha();
     $_SESSION['captcha'] = $captcha;
     $ch = curl_init();
     $url = sprintf('http://apis.baidu.com/baidu_communication/sms_verification_code/smsverifycode?phone=%s&content=%s', $to, $captcha);
     $header = array('apikey: ' . C('API_SMS_KEY'));
     // 添加apikey到header
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // 执行HTTP请求
     curl_setopt($ch, CURLOPT_URL, $url);
     $res = curl_exec($ch);
     $ret = json_decode($res, true);
     //此处待定,无法根据返回值判断是否发送成功
     if ($ret['result'] == 1000) {
         return true;
     }
     return false;
 }