Browse Source

fix: 小程序支付参数,自动登录调整日志

joe 4 năm trước cách đây
mục cha
commit
06056b53b6

+ 8 - 7
app/api/controller/wechat/AuthController.php

@@ -53,18 +53,19 @@ class AuthController
         list($code) = UtilService::postMore([
             ['code', ''],
         ], $request, true);
-        Log::debug(__FUNCTION__ . " param code: $code");
+        // Log::debug(__FUNCTION__ . " param code: $code");
         try {
             $json2sess = MiniProgramService::getUserInfo($code);
             // $sess_key = $json2sess['session_key'] ?? '';
             $openId = $json2sess['openid'] ?? '';
             $unionid = $json2sess['unionid'] ?? '';
-            Log::debug("openid=$openId, unionid=$unionid");
+            // Log::debug("openid=$openId, unionid=$unionid");
             // find by unionid
             if ($unionid != '' ) {
                 $uid = WechatUser::where(['unionid' => $unionid])
                     ->where('user_type', 'routine')->value('uid');
-            } else if ($openId != '') {
+            } 
+            if (!$uid && $openId != '') {
                 $uid = WechatUser::where(['routine_openid' => $openId])->where('user_type', 'routine')->value('uid');
             }
             Log::debug("uid=$uid");
@@ -91,7 +92,7 @@ class AuthController
             if (!$token) {
                 return app('json')->fail('获取用户访问token失败!');
             }
-            Log::debug("token=" . $token->token);
+            // Log::debug("token=" . $token->token);
             // 缓存 session_key
             $cache_key = md5(time() . $code);
             Cache::set('eb_api_code_' . $cache_key, $json2sess, SECONDS_OF_ONEDAY);
@@ -196,7 +197,7 @@ class AuthController
             ['cache_key', ''],
             ['login_type', '']
         ], $request, true);
-        Log::debug("code=$code, post_cache_key=$post_cache_key, login_type=$login_type");
+        // Log::debug("code=$code, post_cache_key=$post_cache_key, login_type=$login_type");
         $session_key = Cache::get('eb_api_code_' . $post_cache_key);
         if (!$code && !$session_key)
             return app('json')->fail('授权失败,参数有误');
@@ -211,7 +212,7 @@ class AuthController
                     errmsg	string	错误信息
                  */
                 $userInfoWx = MiniProgramService::getUserInfo($code);
-                Log::debug('userinfo=' . json_encode($userInfoWx));
+                // Log::debug('userinfo=' . json_encode($userInfoWx));
                 $session_key = $userInfoWx['session_key'];
                 $cache_key = md5(time() . $code);
                 Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
@@ -229,7 +230,7 @@ class AuthController
         try {
             //解密获取用户信息
             $userInfo = MiniProgramService::encryptor($session_key, $data['iv'], $data['encryptedData']);
-            Log::debug('userinfo=' . json_encode($userInfo));
+            // Log::debug('userinfo=' . json_encode($userInfo));
         } catch (\Exception $e) {
             if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
         }

+ 3 - 3
crmeb/services/MiniProgramService.php

@@ -27,8 +27,8 @@ class MiniProgramService
             'site_url', 
             'routine_appId', 
             'routine_appsecret',
-            'wechat_token',
-            'wechat_encodingaeskey',
+            // 'wechat_token',
+            // 'wechat_encodingaeskey',
         ]);
         $payment = SystemConfigService::more([
             'pay_routine_appid',
@@ -46,7 +46,7 @@ class MiniProgramService
             'aes_key' => isset($wechat['wechat_encodingaeskey']) ? trim($wechat['wechat_encodingaeskey']) : ''
         ];
         $config['payment'] = [
-            'app_id' => isset($wechat['pay_routine_appid']) ? trim($wechat['pay_routine_appid']) : '',
+            'app_id' => isset($payment['pay_routine_appid']) ? trim($payment['pay_routine_appid']) : '',
             'merchant_id' => trim($payment['pay_routine_mchid']),
             'key' => trim($payment['pay_routine_key']),
             'cert_path' => realpath('.' . $payment['pay_routine_client_cert']),