Browse Source

feat:用户端-微信-获取JSAPI配置

刘学玺 4 months ago
parent
commit
c2411f27be
1 changed files with 8 additions and 8 deletions
  1. 8 8
      app/Services/Client/WechatService.php

+ 8 - 8
app/Services/Client/WechatService.php

@@ -84,7 +84,7 @@ class WechatService
             }
 
             // 执行登录
-            return $this->accountService->wxLogin($user->getId(), $userInfo);
+            return $this->accountService->wxLogin($user->openid, $userInfo);
         } catch (BusinessException $e) {
             throw $e;
         } catch (\Exception $e) {
@@ -109,7 +109,7 @@ class WechatService
         } catch (\Exception $e) {
             Log::error('缓存微信授权state失败', [
                 'state' => $state,
-                'error' => $e->getMessage()
+                'error' => $e->getMessage(),
             ]);
             throw new BusinessException('系统错误,请稍后重试');
         }
@@ -125,7 +125,7 @@ class WechatService
         try {
             $states = Cache::get('wechat_auth_states', []);
 
-            if (!isset($states[$state])) {
+            if (! isset($states[$state])) {
                 Log::warning('微信授权state无效', ['state' => $state]);
                 throw new BusinessException('授权已过期,请重新授权');
             }
@@ -138,7 +138,7 @@ class WechatService
         } catch (\Exception $e) {
             Log::error('验证微信授权state失败', [
                 'state' => $state,
-                'error' => $e->getMessage()
+                'error' => $e->getMessage(),
             ]);
             throw new BusinessException('系统错误,请稍后重试');
         }
@@ -149,7 +149,7 @@ class WechatService
      */
     protected function generateState(): string
     {
-        return md5(uniqid((string)mt_rand(), true));
+        return md5(uniqid((string) mt_rand(), true));
     }
 
     /**
@@ -204,7 +204,7 @@ class WechatService
 
     protected function getAuthStateKey(string $state): string
     {
-        return config('wechat.auth.cache_prefix') . $state;
+        return config('wechat.auth.cache_prefix').$state;
     }
 
     /**
@@ -227,14 +227,14 @@ class WechatService
                 'downloadImage',
                 'getLocation',
                 'openLocation',
-                'scanQRCode'
+                'scanQRCode',
             ];
 
             return $this->app->getUtils()->buildJsSdkConfig($url, $apis);
         } catch (\Throwable $e) {
             \Log::error('获取JSAPI配置失败', [
                 'url' => $url,
-                'error' => $e->getMessage()
+                'error' => $e->getMessage(),
             ]);
             throw new BusinessException('获取JSAPI配置失败,请稍后重试');
         }