Browse Source

登录方法

shish 4 năm trước cách đây
mục cha
commit
84dcbcc5aa
1 tập tin đã thay đổi với 77 bổ sung0 xóa
  1. 77 0
      app-hd/controllers/AuthController.php

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

@@ -29,6 +29,83 @@ use yii\helpers\Json;
 class AuthController extends PublicController
 {
 
+    //微信手机号一键登录 shish 20210121
+    public function actionWxMobileLogin()
+    {
+        $post = Yii::$app->request->post();
+        $iv = $post['iv'];
+        $encryptedData = $post['encryptedData'];
+        $merchant = WxOpenService::getWxMiniBase();
+        $appId = $merchant['miniAppId'];
+        $miniOpenId = $post['miniOpenId'] ?? '';
+        if (empty($miniOpenId)) {
+            util::fail('登录失败...');
+        }
+        $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
+        $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        if (empty($sessionKey)) {
+            util::fail('登录失败了哦');
+        }
+        $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
+        require_once($wxMiniSecret . '/wxBizDataCrypt.php');
+        $pc = new \WXBizDataCrypt($appId, $sessionKey);
+        $errCode = $pc->decryptData($encryptedData, $iv, $result);
+        if ($errCode != 0) {
+            util::fail('登录失败..');
+        }
+        $arr = Json::decode($result);
+        $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
+        if (empty($phoneNumber)) {
+            util::fail('登录失败了');
+        }
+        $admin = AdminService::getByCondition(['mobile' => $phoneNumber, 'style' => AdminClass::STYLE_HD]);
+        if (empty($admin)) {
+            util::fail('请先注册');
+        }
+        $openShop = $admin['openShop'] ?? 1;
+        $currentShopId = $admin['currentShopId'] ?? 0;
+        if (empty($currentShopId)) {
+            if ($openShop == 2) {
+                util::fail('审核中');
+            }
+            util::fail('请先注册');
+        }
+        $adminId = $admin['id'];
+        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'shopId' => $currentShopId, 'delStatus' => 0], true);
+        if (empty($shopAdmin)) {
+            util::fail('没有权限操作');
+        }
+        if ($shopAdmin->status == 0) {
+            util::fail("您的账号已冻结");
+        }
+        $shopId = $shopAdmin->shopId ?? 0;
+        if (empty($shopId)) {
+            util::fail('您不是管理员');
+        }
+        $token = jwt::getNewToken($adminId);
+        $shopAdmin->lastLogin = date("Y-m-d H:i:s");
+        $shopAdmin->save();
+        $shopAdminId = $shopAdmin->id ?? 0;
+        //是否有切换门店的权限
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $prefix = imgUtil::getPrefix();
+        $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
+        $admin['avatar'] = $avatar;
+        $showDemo = 1;
+        $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
+        //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
+        util::success([
+            'token' => $token,
+            'admin' => $admin,
+            'shopId' => $currentShopId,
+            'shopAdminId' => $shopAdminId,
+            'switchShop' => $switchShop,
+            'showDemo' => $showDemo,
+            //有小程序新版本提示更新
+            'update' => $remind,
+        ]);
+    }
+
     //app登陆 shish 20211219
     public function actionAppLogin()
     {