Pārlūkot izejas kodu

新增获取手机号方法

shish 1 gadu atpakaļ
vecāks
revīzija
3e302f6315
1 mainītis faili ar 38 papildinājumiem un 0 dzēšanām
  1. 38 0
      app-hd/controllers/AuthController.php

+ 38 - 0
app-hd/controllers/AuthController.php

@@ -30,6 +30,44 @@ use yii\helpers\Json;
 class AuthController extends PublicController
 {
 
+    //获取手机号 ssh 20250217
+    public function actionGetMobile()
+    {
+        $post = Yii::$app->request->post();
+        $iv = $post['iv'];
+        $encryptedData = $post['encryptedData'];
+        $merchant = WxOpenService::getWxMiniBase();
+        $appId = $merchant['miniAppId'];
+        $miniOpenId = $post['miniOpenId'] ?? '';
+        if (empty($miniOpenId)) {
+            util::success(['hasNoOpenId' => 1], '登录失败,没有miniOpenId');
+        }
+        $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
+        $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        if (empty($sessionKey)) {
+            Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
+            //noticeUtil::push($cacheKey . " 登录失败!!sessionKey空的", '15280215347');
+            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]);
+            //noticeUtil::push($cacheKey . " 登录失败!!!!sessionKey异常", '15280215347');
+            util::success(['hasNoOpenId' => 1], '登录失败...');
+        }
+        $arr = Json::decode($result);
+        $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
+        if (empty($phoneNumber)) {
+            Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
+            //noticeUtil::push($cacheKey . " 登录失败了!获取手机号失败", '15280215347');
+            util::success(['hasNoOpenId' => 1], '登录失败了哦');
+        }
+        util::success(['mobile' => $phoneNumber]);
+    }
+
     //微信手机号一键登录 ssh 20210121
     public function actionWxMobileLogin()
     {