Quellcode durchsuchen

Merge branch 'wx-kw' into feature-wechat

zqwang vor 1 Jahr
Ursprung
Commit
1da84c74b8

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

@@ -123,12 +123,29 @@ class WechatOpenPlatformController extends CatchController
     }
 
     public function infoCommand(Request $request, $authorizer_appid, $component_appid) {
-        myLog("wx-xiaoxi")->info(['authorizer_appid' => $authorizer_appid,'component_appid' => $component_appid,'param' => $request->all()]);
+
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
-
+        myLog("wx-xiaoxi")->info('-------开始处理---'.get_date());
         $server = $app->getServer();
+        $message = $server->getDecryptedMessage();
+        myLog("wx-xiaoxi")->info([
+            'authorizer_appid' => $authorizer_appid,
+            'component_appid' => $component_appid,
+            '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"){
+                return  $message->FromUserName;
+            }
+        });
 
+        $server->addEventListener('subscribe', function() {  });
+        myLog("wx-xiaoxi")->info('-------结束处理---'.get_date());
         return $server->serve();
     }
 }

+ 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');
+    }
 }