Просмотр исходного кода

Merge branch 'liuzj-1000975-dev' into test

liuzejian 1 год назад
Родитель
Сommit
0438283731

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

@@ -35,6 +35,15 @@ class WechatOpenPlatformController extends CatchController
 
     public function auth(Request $request, $component_appid, $user_id) {
         $auth_code = $request->input('auth_code');
+        $auth_user = DB::table('users')
+            ->where([
+                'id' => $user_id, 'deleted_at' => 0, 'status' => 1
+            ])
+            ->where('pid', '<>', 0)
+            ->select('pid', 'id')->first();
+        if(!$auth_user) {
+            CommonBusinessException::throwError(Errors::OPENPLATFORM_OPTIMIZER_INFO_ERROR);
+        }
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         $client = $app->getClient();
@@ -44,12 +53,12 @@ class WechatOpenPlatformController extends CatchController
         ]);
         $authorizer_appid = $response['authorization_info']['authorizer_appid'];
         $authorizer_refresh_token = $response['authorization_info']['authorizer_refresh_token'];
-        $currentUser = $this->getCurrentUser();
+
         WechatAuthorizationInfo::updateOrCreate([
             'authorizer_appid' => $authorizer_appid,
             'component_appid' => $component_appid,
             'user_id' => $user_id,
-            'puser_id' => $currentUser->id,
+            'puser_id' => $auth_user->pid,
         ], [
             'authorizer_refresh_token' => $authorizer_refresh_token
         ]);
@@ -64,22 +73,14 @@ class WechatOpenPlatformController extends CatchController
      */
     public function authorCommand(Request $request, $component_appid) {
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
-        myLog('authorCommand')->info('start:'. $component_appid);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
-        $app->setCache(Cache::store('redis'));
-        $server = $app->getServer();
-
-        $server->handleVerifyTicketRefreshed(function($message, \Closure $next) {
-            myLog('authorCommand')->info('handleVerifyTicketRefreshed', ['message' => $message]);
-            return $next($message);
-        });
 
+        $server = $app->getServer();
 
         $server->handleAuthorized(function($message, \Closure $next) {
             myLog('authorCommand')->info('handleAuthorized', ['message' => $message]);
             return $next($message);
         });
-        myLog('authorCommand')->info('end00000');
 
         return $server->serve();
     }

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

@@ -3,6 +3,7 @@
 namespace Modules\Channel\Services\WechatOpenPlatform;
 
 use EasyWeChat\OpenPlatform\Application;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Modules\Common\Errors\Errors;
 use Modules\Common\Exceptions\CommonBusinessException;
@@ -53,6 +54,8 @@ class WechatOpenPlatformService
                 'retry' => true, // 使用默认重试配置
             ],
         ];
-        return new Application($config);
+        $app = new Application($config);
+        $app->setCache(Cache::store('redis'));
+        return $app;
     }
 }

+ 3 - 3
modules/Channel/routes/route.php

@@ -54,10 +54,10 @@ Route::prefix('channel')->group(function () {
      * 第三方开放平台
      */
     Route::prefix('openPlatform')->group(function(){
-        Route::get('auth/{component_appid}/{user_id}', [WechatOpenPlatformController::class, 'auth'])->middleware(['roleCheck:company']);
+        Route::get('auth/{component_appid}/{user_id}', [WechatOpenPlatformController::class, 'auth'])->withoutMiddleware(config('catch.route.middlewares'));
         Route::get('preauth', [WechatOpenPlatformController::class, 'preauth'])->middleware(['roleCheck:company']);
-        Route::post('authorCommand/{component_appid}', [WechatOpenPlatformController::class, 'authorCommand'])->withoutMiddleware(config('catch.route.middlewares'));;
-        Route::post('infoCommand/{authorizer_appid}/{component_appid}', [WechatOpenPlatformController::class, 'infoCommand'])->withoutMiddleware(config('catch.route.middlewares'));;
+        Route::post('authorCommand/{component_appid}', [WechatOpenPlatformController::class, 'authorCommand'])->withoutMiddleware(config('catch.route.middlewares'));
+        Route::post('infoCommand/{authorizer_appid}/{component_appid}', [WechatOpenPlatformController::class, 'infoCommand'])->withoutMiddleware(config('catch.route.middlewares'));
     });
 });
 

+ 1 - 0
modules/Common/Errors/Errors.php

@@ -36,4 +36,5 @@ class Errors
     public const  MINIPROGRAM_OWNER_ACCOUNT_ROLE_ERROR= [5000501, '所分配的账号不是投放公司账号'];
     public const  GET_WECHAT_MEDIA_LINK_ERROR = [500304, '获取短剧播放链接失败'];
     public const  OPENPLATFORM_COMPANY_INFO_NOT_EXISTS= [5000601, '公司没有对应的开放平台信息'];
+    public const  OPENPLATFORM_OPTIMIZER_INFO_ERROR= [5000602, '优化师信息有误'];
 }