hrjy 2 лет назад
Родитель
Сommit
d610dbb726

+ 62 - 17
app/api/controller/AuthController.php

@@ -129,9 +129,27 @@ class AuthController
     {
         list($phone, $type, $key, $code) = UtilService::postMore([['phone', 0], ['type', ''], ['key', ''], ['code', '']], $request, true);
 
-        $keyName = 'sms.key.' . $key;
-        $nowKey = 'sms.' . date('YmdHi');
+        $temp = function ($item) {
+            switch ($item) {
+                case "register":
+                    return 'REGISTER';
+                case "login":
+                    return 'LOGIN';
+                case "reset":
+                    return 'RESET';
+                case "reset_2":
+                    return 'RESET_2';
+                case "trade":
+                    return 'TRADE';
+                default:
+                    return 'DEFAULT';
+            }
+        };
 
+
+//        $keyName = 'sms.key.' . $key;
+        $nowKey = 'sms.' . date('YmdHi');
+//
 //        if (!Cache::has($keyName))
 //            return app('json')->make(401, '发送验证码失败');
 //
@@ -149,7 +167,6 @@ class AuthController
             if ($total > Config::get('sms.maxMinuteCount', 20))
                 return app('json')->success('已发送');
         }
-
         try {
             validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]);
         } catch (ValidateException $e) {
@@ -162,25 +179,53 @@ class AuthController
         $defaultMaxIpCount = Config::get('sms.maxIpCount', 50);
         $maxPhoneCount = Config::get('sms.stores.' . $default . '.maxPhoneCount', $defaultMaxPhoneCount);
         $maxIpCount = Config::get('sms.stores.' . $default . '.maxIpCount', $defaultMaxIpCount);
-        if (SmsRecord::where('phone', $phone)->where('add_ip', $request->ip())->whereDay('add_time')->count() >= $maxPhoneCount) {
-            return app('json')->fail('您今日发送得短信次数已经达到上限');
-        }
+//        if (SmsRecord::where('phone', $phone)->where('add_ip', $request->ip())->whereDay('add_time')->count() >= $maxPhoneCount) {
+//            return app('json')->fail('您今日发送得短信次数已经达到上限');
+//        }
         if (SmsRecord::where('add_ip', $request->ip())->whereDay('add_time')->count() >= $maxIpCount) {
             return app('json')->fail('此IP今日发送次数已经达到上限');
         }
         $time = 60;
-        if (CacheService::get('code_' . $phone))
-            return app('json')->fail($time . '秒内有效');
+//        if (CacheService::get('code_' . $phone))
+//            return app('json')->fail($time . '秒内有效');
         $code = rand(100000, 999999);
         $data['code'] = $code;
-        $res = ShortLetterRepositories::send(true, $phone, $data, 'VERIFICATION_CODE');
+        $res = self::NewSmsSend($phone, $data, $temp($type));
+//        $res = ShortLetterRepositories::send(true, $phone, $data, 'VERIFICATION_CODE');
         if ($res !== true)
             return app('json')->fail('短信平台验证码发送失败' . $res);
         CacheService::set('code_' . $phone, $code, $time);
-        Cache::set($keyName, $num + 1, 300);
-        Cache::set($nowKey, $total, 61);
+//        Cache::set($keyName, $num + 1, 300);
+//        Cache::set($nowKey, $total, 61);
+
+        return app('json')->success('短信验证发送成功');
+    }
 
-        return app('json')->success('发送成功');
+    /**
+     * 发送短信
+     * @param string $phone 手机号码
+     * @param array $data 模板替换内容
+     * @param string $template 模板编号
+     * @return bool|string
+     * @throws DataNotFoundException
+     * @throws ModelNotFoundException
+     */
+    public static function NewSmsSend(string $phone, array $data, string $template)
+    {
+        try {
+            $res = ZjSMSServerService::send($phone, $data);
+//            var_dump($res);
+//            exit;
+            if ($res['status'] != '200') {
+                return $res['msg'];
+            } else {
+                SmsRecord::sendRecord($phone, $data['code'], $template, '');
+            }
+            return true;
+        } catch (Exception $exception) {
+//            Log::info($exception->getMessage());
+            return $exception->getMessage();
+        }
     }
 
     /**
@@ -197,11 +242,11 @@ class AuthController
             return app('json')->fail($e->getError());
         }
         $verifyCode = CacheService::get('code_' . $account);
-//        if (!$verifyCode)
-//            return app('json')->fail('请先获取验证码');
-//        $verifyCode = substr($verifyCode, 0, 6);
-//        if ($verifyCode != $captcha)
-//            return app('json')->fail('验证码错误');
+        if (!$verifyCode)
+            return app('json')->fail('请先获取验证码');
+        $verifyCode = substr($verifyCode, 0, 6);
+        if ($verifyCode != $captcha)
+            return app('json')->fail('验证码错误');
         if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16)
             return app('json')->fail('密码必须是在6到16位之间');
         if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码');

+ 85 - 0
app/api/controller/ZjSMSServerService.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace app\api\controller;
+
+use crmeb\services\HttpService;
+use think\facade\Db;
+
+/**
+ * 短信服务
+ * Class SMSService
+ * @package crmeb\services
+ */
+class ZjSMSServerService
+{
+    private static $userid = '15889';
+    private static $username = "yflkj";
+    private static $passwd = 'yfl831**';
+    //验证码
+    const VERIFICATION_CODE = 518076;
+    //支付成功
+    const PAY_SUCCESS_CODE = 520268;
+    //发货提醒
+    const DELIVER_GOODS_CODE = 520269;
+    //确认收货提醒
+    const TAKE_DELIVERY_CODE = 520271;
+    //管理员下单提醒
+    const ADMIN_PLACE_ORDER_CODE = 520272;
+    //管理员退货提醒
+    const ADMIN_RETURN_GOODS_CODE = 520274;
+    //管理员支付成功提醒
+    const ADMIN_PAY_SUCCESS_CODE = 520273;
+    //管理员确认收货
+    const ADMIN_TAKE_DELIVERY_CODE = 520422;
+
+    /**
+     * get: 发送短信验证码
+     * path: sendSmsCode
+     * method: sendSmsCode
+     * param: phone - {string} 手机号
+     */
+    public static function send($phone, array $param, $template = "VERIFICATION_CODE")
+    {
+        $code = $param['code'];
+        $target = "http://sms.izjun.cn/v2sms.aspx";
+        $company = sys_config('site_name', '', true);
+//        $company = "星拼乐";
+        switch ($template) {
+            case 'PAY_SUCCESS_CODE':
+                break;
+            case 'DELIVER_GOODS_CODE':
+                break;
+            case  'TAKE_DELIVERY_CODE':
+                break;
+            case 'ADMIN_PLACE_ORDER_CODE':
+                break;
+            case 'ADMIN_RETURN_GOODS_CODE':
+                break;
+            case 'ADMIN_PAY_SUCCESS_CODE':
+                break;
+            case 'ADMIN_TAKE_DELIVERY_CODE':
+                break;
+            default:
+                $content = sprintf('【%s】您的验证码为:%d 。验证码有效期为%d分钟,请尽快填写!', $company, $code, 5);
+        }
+        $time = date("YmdHis", time());
+        $data = [
+            'action' => 'send',
+            'userid' => self::$userid,
+            'timestamp' => $time,
+            'sign' => md5(self::$username . self::$passwd . $time),
+            'mobile' => $phone,
+            'content' => $content,
+            'sendTime' => '',
+            'extno' => '',
+            'rt' => 'json',
+        ];
+        $gets = json_decode(HttpService::postRequest($target, $data), true);
+        if ($gets) {
+            return ['status' => 200, 'msg' => '短信发送成功'];
+
+        } else {
+            return ['status' => 400, 'msg' => '发送失败'];
+        }
+    }
+}

+ 7 - 2
app/register/view/index/index.html

@@ -28,6 +28,10 @@
         <div class="username">登录密码</div>
         <input class="input-box" id="loginPass" type="password" name="loginPass" placeholder="请输入登录密码">
     </div>
+    <div class="login-box">
+        <div class="username">支付密码</div>
+        <input class="input-box" id="payment_pas" type="password" name="loginPass" placeholder="请输入支付密码">
+    </div>
     <div class="login-box">
         <div class="username">邀请码</div>
         <input class="input-box" id="invitation" type="text" disabled="disabled" name="invitation" placeholder="请输入邀请码">
@@ -52,6 +56,7 @@
         var loginPass = document.getElementById("loginPass").value;
         var code = document.getElementById("code").value;
         var invitation = document.getElementById("invitation").value;
+        var payment_pas = document.getElementById("payment_pas").value;
         if (phone == '') {
             window.alert("请输入账号");
             return false;
@@ -71,7 +76,7 @@
         $.ajax({
             type: "post",
             url: "http://sxg.frp.liuniu946.com/api/register",
-            data: {account: phone, captcha: code, password: loginPass, spread: invitation},
+            data: {account: phone, captcha: code, password: loginPass, spread: invitation,payment_pas:payment_pas},
             dataType: "json",
             success: function (data) {
                 window.alert(data.msg);
@@ -111,7 +116,7 @@
         }
         $.ajax({
             type: "post",
-            url: "http://store.duolio.cn/api/register/verify",
+            url: "http://sxg.frp.liuniu946.com/api/register/verify",
             data: {phone: phone, type: 'register'},
             dataType: "json",
             success: function (data) {