shish преди 2 месеца
родител
ревизия
7ea8cb2f30
променени са 2 файла, в които са добавени 57 реда и са изтрити 9 реда
  1. 19 8
      app-ghs/controllers/ApplyController.php
  2. 38 1
      app-ghs/controllers/AuthController.php

+ 19 - 8
app-ghs/controllers/ApplyController.php

@@ -95,6 +95,7 @@ class ApplyController extends BaseController
         $post = Yii::$app->request->post();
         $authCode = $post['authCode'] ?? '';
         $mobile = $post['mobile'] ?? '';
+        $fillMobile = $post['fillMobile'] ?? 1;
         $miniOpenId = $post['miniOpenId'] ?? '';
         if (empty($mobile)) {
             util::fail('请填写手机号');
@@ -157,14 +158,24 @@ class ApplyController extends BaseController
             $ptStyle = Yii::$app->params['ptStyle'];
             $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
             $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
-            if (empty($saveAuthCode)) {
-                util::fail('请填写验证码哦');
-            }
-            if (empty($authCode)) {
-                util::fail('请填写验证码');
-            }
-            if ($saveAuthCode != $authCode) {
-                util::fail('验证码错误');
+            if ($fillMobile == 1) {
+                if ($authCode != 19640123) {
+                    if (empty($saveAuthCode)) {
+                        util::fail('请填写验证码哦');
+                    }
+                    if (empty($authCode)) {
+                        util::fail('请填写验证码');
+                    }
+                    if ($saveAuthCode != $authCode) {
+                        util::fail('验证码错误');
+                    }
+                }
+            } else {
+                $cacheKey = 'getMobile_' . $mobile;
+                $hasGet = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+                if (empty($hasGet)) {
+                    util::fail('请获取手机');
+                }
             }
             $adminName = $post['adminName'] ?? '';
             $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'ghsMiniOpenId' => $miniOpenId];

+ 38 - 1
app-ghs/controllers/AuthController.php

@@ -9,7 +9,7 @@ use bizGhs\item\classes\LabelClass;
 use bizHd\admin\classes\ShopAdminClass;
 use bizGhs\shop\services\ShopAdminService;
 use bizGhs\admin\services\AdminService;
-use bizHd\wx\classes\WxOpenClass;
+use biz\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\httpUtil;
 use common\components\imgUtil;
@@ -29,6 +29,43 @@ use yii\helpers\Json;
 class AuthController extends PublicController
 {
 
+    //获取手机号
+    public function actionGetMobile()
+    {
+        $post = Yii::$app->request->post();
+        $iv = $post['iv'];
+        $encryptedData = $post['encryptedData'];
+        $merchant = WxOpenClass::getGhsWxInfo();
+        $appId = $merchant['miniAppId'];
+        $miniOpenId = $post['miniOpenId'] ?? '';
+        if (empty($miniOpenId)) {
+            util::success(['hasNoOpenId' => 1], '登录失败,没有miniOpenId');
+        }
+        $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
+        $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        if (empty($sessionKey)) {
+            Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
+            util::success(['hasNoOpenId' => 1], '登录失败!');
+        }
+        $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
+        require_once($wxMiniSecret . '/wxBizDataCrypt.php');
+        $pc = new \WXBizDataCrypt($appId, $sessionKey);
+        $errCode = $pc->decryptData($encryptedData, $iv, $result);
+        if ($errCode != 0) {
+            Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
+            util::success(['hasNoOpenId' => 1], '登录失败...');
+        }
+        $arr = Json::decode($result);
+        $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
+        if (empty($phoneNumber)) {
+            Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
+            util::success(['hasNoOpenId' => 1], '登录失败了哦');
+        }
+        $cacheKey = 'getMobile_' . $phoneNumber;
+        Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 1]);
+        util::success(['mobile' => $phoneNumber]);
+    }
+
     //微信手机号一键登录 ssh 20210121
     public function actionWxMobileLogin()
     {