Browse Source

自定义信息回复匹配关键词修复

zqwang 1 year ago
parent
commit
53d303dd3e

+ 20 - 11
modules/Channel/Http/Controllers/WechatOpenPlatformController.php

@@ -34,7 +34,8 @@ class WechatOpenPlatformController extends CatchController
      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
      */
      */
-    public function preauth(Request $request) {
+    public function preauth(Request $request)
+    {
         $this->validate($request, [
         $this->validate($request, [
             'user_id' => 'required'
             'user_id' => 'required'
         ]);
         ]);
@@ -42,7 +43,7 @@ class WechatOpenPlatformController extends CatchController
         $componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid($currentUser->id);
         $componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid($currentUser->id);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         $user_id = $request->input('user_id');
         $user_id = $request->input('user_id');
-        $url = $app->getPreAuthorizationUrl(sprintf('%s/api/channel/openPlatform/auth/%s/%s',config('app.url'), $componentInfo->app_id, $user_id), []);
+        $url = $app->getPreAuthorizationUrl(sprintf('%s/api/channel/openPlatform/auth/%s/%s', config('app.url'), $componentInfo->app_id, $user_id), []);
         return $url;
         return $url;
     }
     }
 
 
@@ -58,7 +59,8 @@ class WechatOpenPlatformController extends CatchController
      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
      */
      */
-    public function auth(Request $request, $component_appid, $user_id) {
+    public function auth(Request $request, $component_appid, $user_id)
+    {
         $auth_code = $request->input('auth_code');
         $auth_code = $request->input('auth_code');
         $auth_user = DB::table('users')
         $auth_user = DB::table('users')
             ->where([
             ->where([
@@ -66,7 +68,7 @@ class WechatOpenPlatformController extends CatchController
             ])
             ])
             ->where('pid', '<>', 0)
             ->where('pid', '<>', 0)
             ->select('pid', 'id')->first();
             ->select('pid', 'id')->first();
-        if(!$auth_user) {
+        if (!$auth_user) {
             CommonBusinessException::throwError(Errors::OPENPLATFORM_OPTIMIZER_INFO_ERROR);
             CommonBusinessException::throwError(Errors::OPENPLATFORM_OPTIMIZER_INFO_ERROR);
         }
         }
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
@@ -84,11 +86,13 @@ class WechatOpenPlatformController extends CatchController
         ])->update([
         ])->update([
             'is_enabled' => 0,
             'is_enabled' => 0,
         ]);
         ]);
-        WechatAuthorizationInfo::create([
+        WechatAuthorizationInfo::updateOrCreate([
             'authorizer_appid' => $authorizer_appid,
             'authorizer_appid' => $authorizer_appid,
             'component_appid' => $component_appid,
             'component_appid' => $component_appid,
             'user_id' => $user_id,
             'user_id' => $user_id,
             'puser_id' => $auth_user->pid,
             'puser_id' => $auth_user->pid,
+        ], [
+            'is_enabled' => 1,
             'authorizer_refresh_token' => $authorizer_refresh_token,
             'authorizer_refresh_token' => $authorizer_refresh_token,
             'nick_name' => $gzhBaseInfo['authorizer_info']['nick_name'],
             'nick_name' => $gzhBaseInfo['authorizer_info']['nick_name'],
         ]);
         ]);
@@ -101,7 +105,8 @@ class WechatOpenPlatformController extends CatchController
      * @param Request $request
      * @param Request $request
      * @param $component_appid
      * @param $component_appid
      */
      */
-    public function authorCommand(Request $request, $component_appid) {
+    public function authorCommand(Request $request, $component_appid)
+    {
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
 
 
@@ -117,7 +122,8 @@ class WechatOpenPlatformController extends CatchController
         return $server->serve();
         return $server->serve();
     }
     }
 
 
-    public function infoCommand(Request $request, $authorizer_appid, $component_appid) {
+    public function infoCommand(Request $request, $authorizer_appid, $component_appid)
+    {
 
 
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $openPlatform = WechatOpenPlatformService::buildApplication($componentInfo);
         $openPlatform = WechatOpenPlatformService::buildApplication($componentInfo);
@@ -130,13 +136,16 @@ class WechatOpenPlatformController extends CatchController
             'param' => $request->all(),
             'param' => $request->all(),
             'msg' => $message,
             'msg' => $message,
         ]);
         ]);
-        $refreshToken = WechatOpenPlatformService::getRefreshToken($authorizer_appid,$component_appid);
-        $app = $openPlatform->officialAccount($authorizer_appid, $refreshToken);
-        $app->server->push(function ($message) use($authorizer_appid,$component_appid) {
+        $appInfo = WechatOpenPlatformService::getRefreshToken($authorizer_appid,$component_appid);
+        $wechatAppId = getProp($appInfo,'id');
+
+        $app = $openPlatform->officialAccount($authorizer_appid, getProp($appInfo,'authorizer_refresh_token'));
+        unset($appInfo);
+        $app->server->push(function ($message) use($app,$wechatAppId) {
             myLog("wx-xiaoxi")->info("----文本消息---");
             myLog("wx-xiaoxi")->info("----文本消息---");
             myLog("wx-xiaoxi")->info("体消息:");
             myLog("wx-xiaoxi")->info("体消息:");
             myLog("wx-xiaoxi")->info($message);
             myLog("wx-xiaoxi")->info($message);
-            return WechatCommonService::handleMessage($authorizer_appid,$message);
+            return WechatCommonService::handleMessage($app,$wechatAppId ,$message);
         });
         });
 
 
         myLog("wx-xiaoxi")->info('-------结束处理---'.get_date());
         myLog("wx-xiaoxi")->info('-------结束处理---'.get_date());

+ 1 - 1
modules/Channel/Services/WechatOpenPlatform/WechatOpenPlatformService.php

@@ -87,6 +87,6 @@ class WechatOpenPlatformService
             'component_appid' => $component_appid,
             'component_appid' => $component_appid,
             'authorizer_appid' => $authorizer_appid,
             'authorizer_appid' => $authorizer_appid,
             'is_enabled'  =>  1,
             'is_enabled'  =>  1,
-        ])->value('authorizer_refresh_token');
+        ])->select('authorizer_refresh_token','id')->first();
     }
     }
 }
 }