liugc 9 месяцев назад
Родитель
Сommit
6246d737b9

+ 3 - 2
app/common/service/wechat/WeChatOaService.php

@@ -83,9 +83,10 @@ class WeChatOaService
      */
     public function getOpenIdByCode(string $code)
     {
-        $config = WeChatConfigService::getOaConfig();
+        //$config = WeChatConfigService::getOaConfig();
+        //https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx071ff3ce31f3ed51&secret=201d02189998b9098b886447b14e6d74&code=051aXSGa1Ny90K04QMFa1WCNG62aXSGT&grant_type=authorization_code
         $url = 'https://api.weixin.qq.com/sns/oauth2/access_token';
-        $url .= '?appid=' . $config['app_id'] . '&secret=' . $config['secret'] . '&code=' . $code;
+        $url .= '?appid=wx071ff3ce31f3ed51&secret=201d02189998b9098b886447b14e6d74&code=' . $code;
         $url .= '&grant_type=authorization_code';
         $requests = Requests::get($url);
         return json_decode($requests->body, true);

+ 16 - 1
app/workerapi/controller/LoginController.php

@@ -38,7 +38,7 @@ use think\facade\Log;
 class LoginController extends BaseApiController
 {
 
-    public array $notNeedLogin = ['register', 'account', 'logout','testWeChat','getCredentialName','passedInterview','getRegisterId','mobile','customerPhone'];
+    public array $notNeedLogin = ['register', 'account', 'logout','testWeChat','getCredentialName','passedInterview','getRegisterId','mobile','customerPhone','getOpenIdByCode'];
 
 
     /**
@@ -196,4 +196,19 @@ class LoginController extends BaseApiController
         $result = DictData::where(['type_value' => 'customer_support'])->column('value', 'name');
         return $this->data($result);
     }
+
+
+    /**
+     * 获取微信用户openid信息
+     */
+    public function getOpenIdByCode()
+    {
+        $code = $this->request->get('code');
+        $res = \app\api\logic\LoginLogic::getOpenIdByCode(['code'=>$code]);
+        if (false === $res) {
+            return $this->fail(LoginLogic::getError());
+        }
+        return $this->success('', $res);
+    }
+
 }