Browse Source

回复测试

zqwang 1 year ago
parent
commit
1cef72b872

+ 2 - 2
modules/Channel/Http/Controllers/WechatOpenPlatformController.php

@@ -128,7 +128,6 @@ class WechatOpenPlatformController extends CatchController
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         myLog("wx-xiaoxi")->info('-------开始处理---'.get_date());
         $server = $app->getServer();
-
         $message = $server->getDecryptedMessage();
         myLog("wx-xiaoxi")->info([
             'authorizer_appid' => $authorizer_appid,
@@ -136,7 +135,8 @@ class WechatOpenPlatformController extends CatchController
             'param' => $request->all(),
             'msg' => $message,
         ]);
-
+        $refreshToken = WechatOpenPlatformService::getRefreshToken($authorizer_appid,$component_appid);
+        $server = $app->getOfficialAccountWithRefreshToken($authorizer_appid, $refreshToken)->getServer();
         $server->addMessageListener('text', function($message) {
             myLog("wx-xiaoxi")->info('----文本消息---');
             if ($message->Content == "pk"){

+ 17 - 0
modules/Channel/Services/WechatOpenPlatform/WechatOpenPlatformService.php

@@ -73,4 +73,21 @@ class WechatOpenPlatformService
                 'authorizer_appid' => $authorizer_appid,
             ])->delete();
     }
+
+    /**
+     *  获取公众号的refreshToken
+     * name: getRefreshToken
+     * @param $authorizer_appid
+     * @param $component_appid
+     * date 2023/07/07 10:16
+     */
+    public static function getRefreshToken($authorizer_appid, $component_appid)
+    {
+        return  DB::table('wechat_authorization_infos')
+        ->where([
+            'component_appid' => $component_appid,
+            'authorizer_appid' => $authorizer_appid,
+            'is_enabled'  =>  1,
+        ])->value('authorizer_refresh_token');
+    }
 }