Sfoglia il codice sorgente

短视频同步到微信

liuzejian 2 anni fa
parent
commit
23e3a6b906

+ 3 - 0
app/Jobs/Video/WechatCheck.php

@@ -9,6 +9,9 @@ use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
 
+/**
+ * 剧目提审,真实处理逻辑在 duanju_crontab_script 项目
+ */
 class WechatCheck implements ShouldQueue
 {
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

+ 3 - 17
modules/Video/Services/WechatCheckSyncService.php

@@ -19,25 +19,11 @@ class WechatCheckSyncService
      * @throws \GuzzleHttp\Exception\GuzzleException
      */
     public static function pullupload($item, $accessToken) {
-        $client = new Client(['timeout' => 3]);
-        $httpResult = $client->post('https://api.weixin.qq.com/wxa/sec/vod/pullupload?access_token='.$accessToken, [
+        $url = 'https://api.weixin.qq.com/wxa/sec/vod/pullupload?access_token='.$accessToken;
+        $parsedContent = self::postWechat($url, [
             'media_name' => $item->media_name,
             'media_url' => $item->video_url
         ]);
-
-        $httpStatus = $httpResult->getStatusCode();
-        if(200 != $httpStatus) {
-            CommonBusinessException::throwError(Errors::REQUEST_HTTP_STATUS_ERROR);
-        }
-        $httpContent = $httpResult->getBody()->getContents();
-        $parsedContent = \json_decode($httpContent, true);
-        if(0 != ($parsedContent['errcode'] ?? 0)) {
-            myLog('WechatCheckSync')->error('拉取上传异常', [
-                'series_id' => $item->id,
-                'errMsg' => $httpContent
-            ]);
-            CommonBusinessException::throwError(Errors::REQUEST_HTTP_STATUS_ERROR);
-        }
         return $parsedContent['task_id'];
     }
 
@@ -109,7 +95,7 @@ class WechatCheckSyncService
                 'data' => $data,
                 'errMsg' => $httpContent
             ]);
-            CommonBusinessException::throwError(Errors::REQUEST_HTTP_STATUS_ERROR);
+            CommonBusinessException::throwError(Errors::REQUEST_CODE_STATUS_ERROR);
         }
 
         return $parsedContent;

+ 5 - 0
modules/Video/routes/route.php

@@ -6,6 +6,7 @@ use Modules\System\Http\Controllers\NoticeTypesController;
 use Modules\Video\Http\Controllers\EpisodeController;
 use Modules\Video\Http\Controllers\VideoCategoryController;
 use Modules\Video\Http\Controllers\VideoController;
+use Modules\Video\Http\Controllers\VideoSeriesWechatCheckController;
 use Modules\Video\Http\Controllers\WechatCheckController;
 
 Route::prefix('videoStock')->group(function () {
@@ -24,6 +25,10 @@ Route::prefix('videoStock')->group(function () {
         Route::post('add', [WechatCheckController::class, 'add']);
         Route::get('list', [WechatCheckController::class, 'list']);
         Route::post('delete', [WechatCheckController::class, 'delete']);
+        Route::prefix('videoSeries')->group(function(){
+            Route::post('syncWechat', [VideoSeriesWechatCheckController::class, 'syncWechat']);
+        });
     });
+
 });
 

+ 22 - 0
tests/Video/Http/Controllers/VideoSeriesWechatCheckControllerTest.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace Tests\Video\Http\Controllers;
+
+use Modules\Video\Http\Controllers\VideoSeriesWechatCheckController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class VideoSeriesWechatCheckControllerTest extends UsedTestCase
+{
+
+    public function testSyncWechat()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/videoStock/wechatCheck/videoSeries/syncWechat', [
+            'series_ids' => [81,82,83,84,85],
+        ]);
+        $res->dump();
+        $this->dumpJson($res);
+    }
+}