Niushop修改短信

发布时间 2023-09-05 19:51:13作者: 79524795

Niushop改短信教程

1.打开控制器

https://www.****.com//api/login/mobileCode
https://www.****.com//api/register/mobileCode

2.新增代码

点击查看代码
  public function dxb($tel,$code){
        
        $statusStr = array(
        "0" => "1",// "短信发送成功",
        "-1" => "参数不全",
        "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
        "30" => "密码错误",
        "40" => "账号不存在",
        "41" => "余额不足",
        "42" => "帐户已过期",
        "43" => "IP地址限制",
        "50" => "内容含有敏感词"
        );
        $smsapi = "http://api.smsbao.com/";
        // $user = "*****"; //短信平台帐号
        // $pass = md5("*****"); //短信平台密码
        
    
        
        $content="【海外优选】您的验证码是".$code.",如非本人操作,请忽略本短信";//要发送的短信内容
        $phone = $tel;//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
    
    
        return $statusStr[$result];

    }

3.修改代码

点击查看代码
      $code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);// 生成4位随机数,左侧补0
        // $message_model = new Message();
        // $res = $message_model->sendMessage(
        //     [ "mobile" => $mobile, "support_type" => [ 'sms' ], "code" => $code, "keywords" => "LOGIN_CODE" ]
        // );
        
            $a=$this->dxb($mobile,$code);
        
        
    
         // if ($res[ "code" ] >= 0) {
        if ($a == 1) {
            //将验证码存入缓存
            $key = 'login_mobile_code_' . md5(uniqid(null, true));
            Cache::tag("login_mobile_code")->set($key, [ 'mobile' => $mobile, 'code' => $code ], 600);
            return $this->response($this->success([ "key" => $key ]));
        } else {
            return $this->response($res);
        }

即可