123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-06-11
- * Time: 13:36
- */
-
- namespace api\js\controller;
-
-
- use Aliyun\DySDKLite\SignatureHelper;
- use api\js\model\UserModel;
- use cmf\controller\RestBaseController;
- use think\Db;
- //use Aliyun\DySDKLite\SignatureHelper;
- class VerificationCodeController extends RestBaseController
- {
- /**
- * 发送验证码
- */
- public function getVerificationCode()
- {
- $mobile = $this->request->param('mobile');
- $type = $this->request->param('type',1);
- $status = $this->request->param('status',1);
- if(!cmf_check_mobile($mobile)){
- $this->error('手机号不正确!');
- }
- $params = array ();
- $alisms = cmf_get_option('alisms');
- if($type == 1){
- if($status == 1){
- $where['user_type'] = 2;
- }
- if($status == 2){
- $where['user_type'] = 3;
- }
- $where['mobile'] = $mobile;
- $user_id = UserModel::name('user')->where($where)->value('id');
- if($user_id){
- $this->error('手机号已注册!');
- }
- $params["TemplateCode"] = $alisms['mb_id'];
- }else if($type == 2){
- $user_id = UserModel::name('user')->where('mobile',$mobile)->value('id');
- if(!$user_id){
- $this->error('手机号未注册!');
- }
- $params["TemplateCode"] = $alisms['edit_mb_id'];
- }else{
- $params["TemplateCode"] = $alisms['mb_id'];
- }
-
-
- $code = cmf_get_verification_code($mobile);
- if (empty($code)) {
- $this->error('验证码发送过多,明天再试');
- }
- cmf_verification_code_log($mobile, $code, time()+5*60);
- $param = ['mobile' => $mobile, 'code' => $code];
- $result = hook_one("send_mobile_verification_code", $param);
- if ($result !== false && !empty($result['error'])) {
- $this->error($result['message']);
- }
-
-
-
- $security = false;
- $accessKeyId = $alisms['access_key_id'];
- $accessKeySecret = $alisms['access_key_secret'];;
- $params["PhoneNumbers"] = $mobile;
- $params["SignName"] = $alisms['sms_qm'];
-
- $params['TemplateParam'] = Array (
- "code" => $code,
- );
- // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
- if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
- $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
- }
- // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
- $helper = new SignatureHelper();
- // 此处可能会抛出异常,注意catch
- $content = $helper->request(
- $accessKeyId,
- $accessKeySecret,
- "dysmsapi.aliyuncs.com",
- array_merge($params, array(
- "RegionId" => "cn-hangzhou",
- "Action" => "SendSms",
- "Version" => "2017-05-25",
- )),
- $security
- );
- if($content->Message == 'OK' && $content->Code == 'OK'){
- $this->success('验证已发送'.$mobile.'注意查收');
- }else{
- $this->error($content->Message);
- }
- }
-
- }
|