|
|
@@ -6,6 +6,12 @@ use app\common\controller\Api;
|
|
|
use app\common\library\Sms as Smslib;
|
|
|
use app\common\model\User;
|
|
|
use think\Hook;
|
|
|
+use fast\Random;
|
|
|
+use Exception;
|
|
|
+use think\Cache;
|
|
|
+use think\exception\PDOException;
|
|
|
+use think\exception\ValidateException;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 手机短信接口
|
|
|
@@ -101,4 +107,59 @@ class Sms extends Api
|
|
|
$this->error(__('验证码不正确'));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送短信验证码
|
|
|
+ *
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string $phone 手机号
|
|
|
+ * @param string $scene 事件名称
|
|
|
+ * @param string $countryCode 区号
|
|
|
+ * @param string $len 验证码长度
|
|
|
+ */
|
|
|
+ public function sendCodeSMS($phone, $scene = 'verify',$countryCode = '86', $len = '')
|
|
|
+ {
|
|
|
+
|
|
|
+ $key = $countryCode.$scene . ':' . $phone;
|
|
|
+ $code = Random::numeric($len);
|
|
|
+ //$content = $content == '' ? sprintf(SMSTemplates($scene,$countryCode),$code) : sprintf($content,$code);
|
|
|
+ //$phone = $countryCode . $phone;
|
|
|
+ $phone = '+' . $countryCode . $phone;//拼接国际区号
|
|
|
+ try {
|
|
|
+ $url1 = "https://uni.apistd.com";
|
|
|
+ $query = [
|
|
|
+ 'action' => 'sms.message.send',
|
|
|
+ 'accessKeyId' => 'SGnbSrqzJikDxx4PuU83kD9oTTmv7o34unZ2bPX8FqsgCrQkp'
|
|
|
+ ];
|
|
|
+ $url = $url1.'/?'.http_build_query($query);
|
|
|
+ $data = [
|
|
|
+ 'signature'=>'AEXBTC',
|
|
|
+ 'to'=>$phone,
|
|
|
+ //'content'=>$content,
|
|
|
+ 'templateId' => 'd33f1f90',
|
|
|
+ 'templateData' => ['code' => $code]
|
|
|
+ ];
|
|
|
+ $result = xcurl($url,$data);
|
|
|
+ $result = json_decode($result, true);
|
|
|
+ // var_dump($result);
|
|
|
+
|
|
|
+ // if($result['code'] == 0){
|
|
|
+ // $result = 1;
|
|
|
+ // }else {
|
|
|
+ // $result = 0;
|
|
|
+ // }
|
|
|
+ } catch (ValidateException|PDOException|Exception $e){
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result['code'] == 0){
|
|
|
+ Cache::set($key, $code,300);
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ return $result['message'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|