Kirin 3 tahun lalu
induk
melakukan
bb06d0497f

+ 44 - 22
app/api/controller/AuthController.php

@@ -173,7 +173,7 @@ class AuthController
             return app('json')->fail($time . '秒内有效');
         $code = rand(100000, 999999);
         $data['code'] = $code;
-        $res = ShortLetterRepositories::send(true, $phone, $data, 'VERIFICATION_CODE');
+        $res = ShortLetterRepositories::NewSmsSend($phone, $data, 'VERIFICATION_CODE');
         if ($res !== true)
             return app('json')->fail('短信平台验证码发送失败' . $res);
         CacheService::set('code_' . $phone, $code, $time);
@@ -196,12 +196,12 @@ class AuthController
         } catch (ValidateException $e) {
             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('验证码错误');
+        $verifyCode = CacheService::get('code_' . $account);
+        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('密码太过简单,请输入较为复杂的密码');
@@ -372,23 +372,45 @@ class AuthController
         $verifyCode = substr($verifyCode, 0, 6);
         if ($verifyCode != $captcha)
             return app('json')->fail('验证码错误');
-
-        $userInfo = User::where('uid', $request->uid())->find();
-        $userPhone = $userInfo->phone;
-        if (!$userInfo) return app('json')->fail('用户不存在');
-        if ($userInfo->phone) return app('json')->fail('您的账号已经绑定过手机号码!');
-        if (User::where('phone', $phone)->where('user_type', '<>', 'h5')->count())
-            return app('json')->success('此手机已经绑定,无法多次绑定!');
-        if (User::where('account', $phone)->where('phone', $phone)->where('user_type', 'h5')->find()) {
-            if (!$step) return app('json')->success('H5已有账号是否绑定此账号上', ['is_bind' => 1]);
-            $userInfo->phone = $phone;
+        $userInfo = User::where('account', $phone)->find();
+        if ($userInfo) {
+            //直接绑定到老帐号
+//            var_dump($request->uid());
+            $wechat = WechatUser::where('uid', $userInfo['uid'])->find();
+            if ($wechat['openid'] || $wechat['unionid'] || $wechat['routine_openid']) {
+                if (!$userInfo) return app('json')->fail('该手机或邮箱已绑定微信账号');
+            } else {
+                $now = WechatUser::where('uid', $request->uid())->find()->toArray();
+                unset($now['site_id']);
+                unset($now['uid']);
+                unset($now['add_time']);
+                unset($now['stair']);
+                unset($now['second']);
+                unset($now['order_stair']);
+                unset($now['order_second']);
+                unset($now['now_money']);
+                unset($now['user_type']);
+                WechatUser::where('uid', $userInfo['uid'])->update($now);
+                WechatUser::where('uid', $request->uid())->delete();
+                User::where('uid', $request->uid())->delete();
+                $request->tokenData()->delete();
+                return app('json')->success('绑定成功,请重新登录');
+            }
         } else {
+            //账号的H5信息设置上
+            $userInfo = User::where('uid', $request->uid())->find();
+            $userPhone = $userInfo->account;
+            if (!$userInfo) return app('json')->fail('用户不存在');
+            if ($userInfo->account == $userInfo->email || $userInfo->account == $userInfo->phone) return app('json')->fail('您的账号已经绑定过手机号码或邮箱!');
             $userInfo->account = $phone;
-            $userInfo->phone = $phone;
+            if (mobile_check($phone))
+                $userInfo->phone = $phone;
+            else
+                $userInfo->email = $phone;
+            if ($userInfo->save() || $userPhone == $phone)
+                return app('json')->success('绑定成功');
+            else
+                return app('json')->fail('绑定失败');
         }
-        if ($userInfo->save() || $userPhone == $phone)
-            return app('json')->success('绑定成功');
-        else
-            return app('json')->fail('绑定失败');
     }
 }

+ 20 - 0
crmeb/repositories/ShortLetterRepositories.php

@@ -5,6 +5,8 @@ namespace crmeb\repositories;
 
 use app\admin\model\sms\SmsRecord;
 use crmeb\services\sms\Sms;
+use crmeb\services\ZjSMSServerService;
+use think\Exception;
 use think\facade\Log;
 
 /**
@@ -46,4 +48,22 @@ class ShortLetterRepositories
             return false;
         }
     }
+
+    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();
+        }
+    }
 }

+ 84 - 0
crmeb/services/ZjSMSServerService.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace crmeb\services;
+
+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');
+        $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' => '发送失败'];
+        }
+    }
+}