Explorar el Código

同步短剧提审的分集信息

liuzejian hace 1 año
padre
commit
4e18517c30

+ 3 - 2
app/Console/Commands/Miniprogram/WechatAccessToken.php

@@ -48,9 +48,10 @@ class WechatAccessToken extends Command
             }
 
             $accessTokenInfo = AccessTokenService::getAccessToken($miniprogram->appid, $miniprogram->appsecret);
-            if(false === $accessTokenInfo) {
-                myLog('wechat-miniprogram')->info('刷新小程序accessToken失败', [
+            if(false === $accessTokenInfo || (0 != ($accessTokenInfo['errcode'] ?? 0))) {
+                myLog('WechatAccessToken')->info('刷新小程序accessToken失败', [
                     'appid' => $miniprogram->appid,
+                    'result' => $accessTokenInfo,
                 ]);
                 continue;
             }

+ 87 - 0
app/Console/Commands/Video/WechatCheck/GetTaskInfo.php

@@ -0,0 +1,87 @@
+<?php
+
+namespace App\Console\Commands\Video\WechatCheck;
+
+use App\Service\Miniprogram\Wechat\AccessTokenService;
+use App\Service\Util\Support\Http\HttpRequestService;
+use App\Service\Util\Support\Http\WechatURL;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Redis;
+use Modules\Common\Support\Http\HttpRequest;
+use Modules\Manage\Services\WechatMiniprogramService;
+use Modules\Video\Services\WechatCheckSyncService;
+
+class GetTaskInfo extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'WechatCheck:GetTaskInfo {--task_ids= : 英文逗号分割的任务id}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '查询短剧同步到微信的任务状态';
+
+    /**
+     * Execute the console command.
+     */
+    public function handle(): void
+    {
+        $task_ids = $this->option('task_ids');
+        $taskIdArr = null;
+        if($task_ids) {
+            $taskIdArr = explode(',', trim($task_ids, ','));
+        }
+        DB::table('video_series_wechat_check')
+            ->whereIn('sync_status', [1,2])
+            ->where('sync_task_id', '<>', '')
+            ->where('is_enabled', 1)
+            ->when($taskIdArr, function ($query, $taskIdArr) {
+                return $query->whereIn('task_id', $taskIdArr);
+            })->orderBy('id', 'asc')
+            ->chunk(100, function ($items) {
+                $now = date('Y-m-d H:i:s');
+                foreach ($items as $item) {
+                    $taskInfo = $this->getTask($item);
+                    if($taskInfo && 1 == $taskInfo['task_type']) {
+                        if(in_array($taskInfo['status'], [3,4])) {
+                            DB::table('video_series_wechat_check')
+                                ->where(['id' => $item->id])
+                                ->update([
+                                    'status' => $taskInfo['status'],
+                                    'remark' => $taskInfo['errmsg'] ?? '',
+                                    'media_id' => $taskInfo['media_id'] ?? '',
+                                    'updated_at' => $now,
+                                    'sync_task_info' => \json_encode($taskInfo),
+                                ]);
+                        }
+                    }
+                }
+            });
+    }
+
+    private function getTask($syncInfo) {
+        $appid = $syncInfo->appid ?: config('wechat.duanju.masterAppid');
+        $accessToken = Redis::get(AccessTokenService::getAccessTokenRedisKey($appid));
+        $parsedContent = HttpRequestService::simplePost(WechatURL::vod_gettask . $accessToken, [
+            'task_id' => $syncInfo->sync_task_id
+        ]);
+        if(false === $parsedContent || (0 != $parsedContent['errcode'] ?? 0)) {
+            return $parsedContent['task_info'];
+        } else {
+            myLog('GetTaskInfo')->error('拉取上传短剧任务查询失败', [
+                'task_id' => $syncInfo->sync_task_id,
+                'appid' => $appid,
+                'result' => $parsedContent,
+            ]);
+            return [];
+        }
+
+    }
+}

+ 92 - 0
app/Console/Commands/Video/WechatCheck/SyncMediaInfo.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Console\Commands\Video\WechatCheck;
+
+use App\Service\Miniprogram\Wechat\AccessTokenService;
+use App\Service\Util\Support\Http\HttpRequestService;
+use App\Service\Util\Support\Http\WechatURL;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Redis;
+use Predis\Command\Traits\DB;
+
+class SyncMediaInfo extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'WechatCheck:SyncMediaInfo {--video_ids= : videos.id}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '获取短剧分集详细信息';
+
+    /**
+     * Execute the console command.
+     */
+    public function handle()
+    {
+        $video_ids = $this->option('video_ids');
+        $videoIds = [];
+        if($video_ids) {
+            $videoIds = explode(',', $video_ids);
+        }
+
+        DB::table('video_wechat_check')
+            ->where('status', '<>', 0)
+            ->where('is_enabled', 1)
+            ->where('drama_id', '<>', 0)
+            ->when($videoIds, function ($query, $videoIds) {
+                return $query->whereIn('video_id', $videoIds);
+            })->select('video_id', 'id', 'drama_id', 'appid')
+            ->orderBy('id')
+            ->chunk(10, function ($items) {
+                foreach ($items as $item) {
+                    $this->syncInfo($item);
+                }
+            });
+    }
+
+    public function syncInfo($item) {
+        $appid = $item->appid ?: config('wechat.duanju.masterAppid');
+        $accessToken = Redis::get(AccessTokenService::getAccessTokenRedisKey($appid));
+        $offset = 0;
+        while (true) {
+            $parsedContent = HttpRequestService::simplePost(WechatURL::vod_listmedia . $accessToken, [
+                'drama_id' => $item->drama_id,
+                'limit' => 100,
+                'offset' => $offset
+            ]);
+            $offset += 100;
+            if(false === $parsedContent || (0 != $parsedContent['errcode'] ?? 0)) {
+                myLog('SyncMediaInfo')->error('拉取短剧分集信息失败', [
+                    'appid' => $appid,
+                    'video_id' => $item->video_id, 'drama_id' => $item->drama_id,
+                ]);
+                break;
+            }
+
+            $media_info_list = $parsedContent['media_info_list'];
+            $now = date('Y-m-d H:i:s');
+            foreach ($media_info_list as $media_info) {
+                $audit_detail = $media_info['audit_detail'];
+                $media_id = $media_info['media_id'];
+                DB::table('video_series_wechat_check')
+                    ->where(['video_id' => $item->video_id, 'is_enabled' => 1, 'media_id' => $media_id])
+                    ->update([
+                        'check_status' => $audit_detail['status'],
+                        'check_at' => date('Y-m-d H:i:s', $audit_detail['audit_time']),
+                        'check_reason' => $audit_detail['check_reason'],
+                        'evidence_material_id_list' => \json_encode($audit_detail['evidence_material_id_list']),
+                        'updated_at' => $now,
+                    ]);
+            }
+
+        }
+
+    }
+}

+ 8 - 0
app/Console/Kernel.php

@@ -23,6 +23,14 @@ class Kernel extends ConsoleKernel
          * 同步短剧剧目信息
          */
         $schedule->command('WechatCheck:SyncDramaInfo')->daily();
+        /**
+         * 同步短剧分集信息
+         */
+        $schedule->command('WechatCheck:SyncMediaInfo')->hourly();
+        /**
+         * 检查短剧剧目拉取任务
+         */
+        $schedule->command('WechatCheck:GetTaskInfo')->everyTenMinutes();
     }
 
     /**

+ 4 - 3
app/Service/Util/Support/Http/HttpRequestService.php

@@ -28,9 +28,9 @@ class HttpRequestService
                 return $parsedContent;
             }
         } catch (\Exception $exception) {
-            myLog('RequestWechat')->error('请求上游失败:', [
+            myLog('HttpRequest')->error('请求上游失败:', [
                 'url' => $url,
-                'json' => $postMessage,
+                'postJson' => $postMessage,
                 'exceptionMessage' => $exception->getMessage(),
             ]);
         }
@@ -48,8 +48,9 @@ class HttpRequestService
                 return $parsedContent;
             }
         } catch (\Exception $exception) {
-            myLog('RequestWechat')->error('请求上游失败:', [
+            myLog('HttpRequest')->error('请求上游失败:', [
                 'url' => $url,
+                'postOptions' => $options,
                 'exceptionMessage' => $exception->getMessage(),
             ]);
         }

+ 4 - 0
app/Service/Util/Support/Http/WechatURL.php

@@ -12,4 +12,8 @@ class WechatURL
     public const vod_auditdrama = 'https://api.weixin.qq.com/wxa/sec/vod/auditdrama?access_token=';
     // 新增临时素材
     public const media_upload = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=';
+    // 媒资上传-查询任务
+    public const vod_gettask = 'https://api.weixin.qq.com/wxa/sec/vod/gettask?access_token=';
+    // 获取媒资列表
+    public const vod_listmedia = 'https://api.weixin.qq.com/wxa/sec/vod/listmedia?access_token=';
 }