Browse Source

取消授权

liuzejian 1 year ago
parent
commit
3f60cafa47

BIN
app/1228789.jpg


BIN
app/images.png


+ 4 - 0
modules/Channel/Http/Controllers/WechatOpenPlatformController.php

@@ -89,6 +89,10 @@ class WechatOpenPlatformController extends CatchController
             myLog('authorCommand')->info('handleAuthorized', ['message' => $message]);
             return $next($message);
         });
+        $server->handleUnauthorized(function($message, \Closure $next) {
+            WechatOpenPlatformService::handleUnauthorized($message);
+            return $next($message);
+        });
 
         return $server->serve();
     }

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

@@ -3,6 +3,7 @@
 namespace Modules\Channel\Services\WechatOpenPlatform;
 
 use EasyWeChat\OpenPlatform\Application;
+use EasyWeChat\OpenPlatform\Message;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Modules\Common\Errors\Errors;
@@ -58,4 +59,18 @@ class WechatOpenPlatformService
         $app->setCache(Cache::store('redis'));
         return $app;
     }
+
+    /**
+     * 取消授权
+     * @param Message $message
+     */
+    public static function handleUnauthorized($message) {
+        $component_appid = $message['AppId'];
+        $authorizer_appid = $message['AuthorizerAppid'];
+        DB::table('wechat_authorization_infos')
+            ->where([
+                'component_appid' => $component_appid,
+                'authorizer_appid' => $authorizer_appid,
+            ])->delete();
+    }
 }