Esempio n. 1
0
 public static function send($tpl, $phonenum, $smsvalue)
 {
     header('content-type:text/html;charset=utf-8');
     $sendUrl = 'http://v.juhe.cn/sms/send';
     //短信接口的URL
     $smsConf = array();
     $smsConf['key'] = '##';
     //您申请的APPKEY
     $smsConf['mobile'] = $phonenum;
     //接受短信的用户手机号码
     switch ($tpl) {
         case 'code':
             //验证码
             $smsConf['tpl_id'] = 00;
             //您申请的短信模板ID,根据实际情况修改
             $smsConf['tpl_value'] = '#name#=' . $phonenum . '&#code#=' . $smsvalue;
             //您设置的模板变量,根据实际情况修改
             break;
         case 'succ':
             //通过
             $smsConf['tpl_id'] = 1111;
             $arr = explode("&&&", $smsvalue);
             $smsConf['tpl_value'] = '#app#=' . $arr[0] . '&#code#=' . $arr[1];
             break;
         case 'fail':
             //拒绝
             $smsConf['tpl_id'] = 2222;
             $smsConf['tpl_value'] = '#app#=' . $smsvalue;
             break;
     }
     $content = Sms::juhecurl($sendUrl, $smsConf, 1);
     //请求发送短信
     if ($content) {
         $result = json_decode($content, true);
         $error_code = $result['error_code'];
         if ($error_code == 0) {
             //状态为0,说明短信发送成功
             //echo "短信发送成功,短信ID:".$result['result']['sid'];exit;
             return 1;
         } else {
             //状态非0,说明失败
             //echo  "短信发送失败(".$error_code."):".$result['reason'];exit;
             return -2;
         }
     } else {
         //返回内容异常,以下可根据业务逻辑自行修改
         //echo "请求发送短信失败";
         return -1;
     }
 }