|
@@ -0,0 +1,126 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Jobs\Video;
|
|
|
|
+
|
|
|
|
+use App\Service\Miniprogram\Wechat\AccessTokenService;
|
|
|
|
+use App\Service\Util\Support\Http\WechatURL;
|
|
|
|
+use App\Service\Util\Support\Trace\TraceContext;
|
|
|
|
+use App\Service\Util\Support\Http\HttpRequestService;
|
|
|
|
+use Illuminate\Bus\Queueable;
|
|
|
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
+use Illuminate\Queue\SerializesModels;
|
|
|
|
+use Illuminate\Support\Arr;
|
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
+
|
|
|
|
+class WechatCheck implements ShouldQueue
|
|
|
|
+{
|
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
+
|
|
|
|
+ private $info;
|
|
|
|
+ /**
|
|
|
|
+ * Create a new job instance.
|
|
|
|
+ */
|
|
|
|
+ public function __construct($info)
|
|
|
|
+ {
|
|
|
|
+ $this->info = $info;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Execute the job.
|
|
|
|
+ */
|
|
|
|
+ public function handle(): void
|
|
|
|
+ {
|
|
|
|
+ myLog('WechatCheck')->info('开始处理微信提审', [
|
|
|
|
+ 'info' => $this->info
|
|
|
|
+ ]);
|
|
|
|
+ $traceContext = TraceContext::newFromParent($this->info['traceInfo']);
|
|
|
|
+
|
|
|
|
+ $id = $this->info['id'];
|
|
|
|
+ $record = DB::table('video_wechat_check')
|
|
|
|
+ ->join('videos', 'videos.id', 'video_wechat_check.video_id')
|
|
|
|
+ ->where(['video_wechat_check.id' => $id,
|
|
|
|
+ 'video_wechat_check.is_enabled' => 1, 'video_wechat_check.status' => 5])
|
|
|
|
+ ->select('video_wechat_check.*', 'videos.name as video_name', 'videos.cover_image as video_cover_image')
|
|
|
|
+ ->first();
|
|
|
|
+ if(!$record) {
|
|
|
|
+ myLog('WechatCheck')->info('当前状态不支持提审', [
|
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
|
+ ]);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ $appid = $record->appid ?: config('wechat.duanju.masterAppid');
|
|
|
|
+ $accessToken = Redis::get(AccessTokenService::getAccessTokenRedisKey($appid));
|
|
|
|
+ $medias = DB::table('video_series_wechat_check')
|
|
|
|
+ ->where('video_id', $record->video_id)
|
|
|
|
+ ->where(['sync_status' => 4, 'is_enabled' => 1])
|
|
|
|
+ ->where('media_id', '<>', 0)
|
|
|
|
+ ->get();
|
|
|
|
+ $cover_material_id = $this->getMaterialId($record->video_cover_image, $accessToken);
|
|
|
|
+ $authorized_material_id = $this->getMaterialId($record->authorized_img, $accessToken);
|
|
|
|
+ if(!($cover_material_id && $authorized_material_id)) {
|
|
|
|
+ myLog('WechatCheck')->error('上传短剧封面和授权材料到临时素材失败, 请重新提审', [
|
|
|
|
+ 'appid' => $appid,
|
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
|
+ ]);
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ $postData = [
|
|
|
|
+ 'name' => $record->video_name,
|
|
|
|
+ 'media_count' => $medias->count(),
|
|
|
|
+ 'media_id_list' => $medias->pluck('media_id')->toArray(),
|
|
|
|
+ 'producer' => $record->producer,
|
|
|
|
+ 'cover_material_id' =>$cover_material_id,
|
|
|
|
+ 'authorized_material_id' => $authorized_material_id,
|
|
|
|
+ 'registration_number' => $record->registration_number,
|
|
|
|
+ ];
|
|
|
|
+ if($record->drama_id) {
|
|
|
|
+ $postData['drama_id'] = $record->drama_id;
|
|
|
|
+ }
|
|
|
|
+ $result = HttpRequestService::simplePost(WechatURL::vod_auditdrama . $accessToken, $postData);
|
|
|
|
+ if(false === $result || (0 != ($result['errcode'] ?? 0)) || (! ($result['drama_id'] ?? ''))) {
|
|
|
|
+ myLog('WechatCheck')->error('提审请求失败', [
|
|
|
|
+ 'appid' => $appid,
|
|
|
|
+ 'post' => $postData,
|
|
|
|
+ 'result' => $result,
|
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
|
+ ]);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ $drama_id = $result['drama_id'];
|
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
|
+ DB::table('video_wechat_check')
|
|
|
|
+ ->where('id', $record->id)
|
|
|
|
+ ->update([
|
|
|
|
+ 'status' =>1,
|
|
|
|
+ 'apply_at' => $now,
|
|
|
|
+ 'drama_id' => $drama_id,
|
|
|
|
+ 'updated_at' => $now,
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 上传临时图片素材
|
|
|
|
+ * @param string $url 图片http地址
|
|
|
|
+ * @param string $accessToken
|
|
|
|
+ * @return string media_id
|
|
|
|
+ */
|
|
|
|
+ public function getMaterialId($url, $accessToken){
|
|
|
|
+ $result = HttpRequestService::post(WechatURL::media_upload. $accessToken, [
|
|
|
|
+ 'multipart' => [
|
|
|
|
+ [
|
|
|
|
+ 'name' => 'type',
|
|
|
|
+ 'contents' => 'image',
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'name' => 'media',
|
|
|
|
+ 'contents' => file_get_contents($url),
|
|
|
|
+ 'filename' => Arr::last(explode('/', $url)),
|
|
|
|
+ ]
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ return $result['media_id'] ?? '';
|
|
|
|
+ }
|
|
|
|
+}
|