Explorar el Código

Merge branch 'liuzj-weixin-tishen-dev' into test

# Conflicts:
#	tests/UsedTestCase.php
liuzejian hace 1 año
padre
commit
a929560f1a

BIN
app/1228789.jpg


+ 0 - 62
app/Console/Commands/Video/WechatCheckGetTask.php

@@ -1,62 +0,0 @@
-<?php
-
-namespace App\Console\Commands\Video;
-
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
-use Modules\Video\Services\WechatCheckSyncService;
-
-class WechatCheckGetTask extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'Video:WechatCheckGetTask {--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 = WechatCheckSyncService::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),
-                                ]);
-                        }
-                    }
-                }
-            });
-    }
-}

BIN
app/images.png


+ 2 - 3
modules/Channel/Http/Controllers/AdvertiserController.php

@@ -74,9 +74,8 @@ class AdvertiserController extends CatchController
         $username = $request->input('username');
         $userContext = $this->getUserContext(null);
         $res =   DB::table('users')
-            ->join('user_has_miniprograms', 'users.id', 'user_has_miniprograms.uid')
+            ->leftJoin('user_has_miniprograms', 'users.id', 'user_has_miniprograms.uid')
             ->where([
-                'user_has_miniprograms.is_enabled' => 1,
                 'users.deleted_at' => 0,
             ])->where('users.pid', '<>', 0)
             ->when($userContext['loginUserRoles']->contains('company'), function ($query) use($userContext){
@@ -95,7 +94,7 @@ class AdvertiserController extends CatchController
             ->select(
                 'users.id', 'users.username', 'users.email', 'users.status', 'users.remark',
                 DB::raw("from_unixtime(users.created_at) as created_at"),
-                DB::raw("group_concat(distinct user_has_miniprograms.miniprogram_id separator ',') as miniProgramIds"),
+                DB::raw("group_concat(distinct if(user_has_miniprograms.is_enabled = 1, user_has_miniprograms.miniprogram_id, null)  separator ',') as miniProgramIds"),
                 DB::raw("NULL as miniPrograms")
             )->groupBy('users.id')
             ->orderBy('users.id','desc')

+ 4 - 3
modules/Common/Errors/Errors.php

@@ -30,8 +30,9 @@ class Errors
     public const  TIXIAN_ONLY_ONCE_EVERY_DAY = [500204, '每天只能提现一次'];
     public const  OPERATION_FIRST_PAGE_LIST_NOT_EXISTS = [500301, '首页列表配置项不存在'];
     public const  VIDEO_SERIES_NOT_EXISTS = [500302, '剧集不存在'];
-    public const REQUEST_HTTP_STATUS_ERROR = [500401, '请求上游接口返回http状态码有误'];
-    public const REQUEST_CODE_STATUS_ERROR = [500402, '请求上游接口返回code状态码有误'];
-    public const SYNC_WECHAT_NOT_OK = [500302, '剧集没有成功同步到微信'];
+    public const  REQUEST_HTTP_STATUS_ERROR = [500401, '请求上游接口返回http状态码有误'];
+    public const  REQUEST_CODE_STATUS_ERROR = [500402, '请求上游接口返回code状态码有误'];
+    public const  SYNC_WECHAT_NOT_OK = [500303, '剧集没有成功同步到微信'];
     public const  MINIPROGRAM_OWNER_ACCOUNT_ROLE_ERROR= [5000501, '所分配的账号不是投放公司账号'];
+    public const  GET_WECHAT_MEDIA_LINK_ERROR = [500304, '获取短剧播放链接失败'];
 }

+ 61 - 0
modules/Common/Support/Http/HttpRequest.php

@@ -0,0 +1,61 @@
+<?php
+namespace Modules\Common\Support\Http;
+
+use GuzzleHttp\Client;
+
+class HttpRequest
+{
+
+    /**
+     * 发送post请求
+     * @param $url 请求地址
+     * @param $accessToken 请求access_token
+     * @param $postMessage 请求体
+     * @return array
+     */
+    public static function simplePost($url, $postMessage) {
+        $client = new Client(['timeout' => 10]);
+        try {
+            $res = $client->post(
+                $url,
+                [
+                    'json' => $postMessage
+                ]);
+            $httpStatusCode = $res->getStatusCode();
+            $httpContent = $res->getBody()->getContents();
+            $parsedContent = json_decode($httpContent, true);
+            if (200 == $httpStatusCode) {
+                return $parsedContent;
+            }
+        } catch (\Exception $exception) {
+            myLog('HttpRequest')->error('请求失败:', [
+                'url' => $url,
+                'json' => $postMessage,
+                'exceptionMessage' => $exception->getMessage(),
+            ]);
+        }
+        return false;
+    }
+
+    public static function simpleGet($url, $query) {
+        $client = new Client(['timeout' => 10]);
+        try {
+            $response = $client->get($url, [
+                'query' => $query
+            ]);
+            $httpStatusCode = $response->getStatusCode();
+            $httpContent = $response->getBody()->getContents();
+            $parsedContent = json_decode($httpContent, true);
+            if (200 == $httpStatusCode)  {
+                return $parsedContent;
+            }
+        } catch (\Exception $exception) {
+            myLog('HttpRequest')->error('请求失败:', [
+                'url' => $url,
+                'query' => $query,
+                'exceptionMessage' => $exception->getMessage(),
+            ]);
+        }
+        return false;
+    }
+}

+ 13 - 0
modules/Common/Support/Http/WechatURL.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace Modules\Common\Support\Http;
+
+class WechatURL
+{
+    // 短剧拉取上传
+    public const vod_pullupload = 'https://api.weixin.qq.com/wxa/sec/vod/pullupload?access_token=';
+    // 短剧拉取任务查询
+    public const vod_gettask = 'https://api.weixin.qq.com/wxa/sec/vod/gettask?access_token=';
+    // 获取短剧播放链接
+    public const vod_getmedialink = 'https://api.weixin.qq.com/wxa/sec/vod/getmedialink?access_token=';
+}

+ 18 - 1
modules/Video/Http/Controllers/EpisodeController.php

@@ -30,9 +30,22 @@ class EpisodeController extends CatchController
             ->where([
                 'video_id' => $request->integer('video_id'),
                 'is_enabled' => 1
-            ])->select('series_name', 'series_sequence', 'video_key', 'duration')
+            ])->select('series_name', 'series_sequence', 'video_key', 'duration', 'id', 'video_id')
             ->orderBy('series_sequence', 'asc')
             ->paginate($request->integer('limit', 15));
+        /**
+         * 增加微信审核状态
+         */
+        $wechatCheckStatus = null;
+        if($request->input('need_wechat_status', 0)) {
+            $serieIds = $videoSeries->pluck('id');
+            $wechatCheckStatus = DB::table('video_series_wechat_check')
+                ->whereIn('series_id', $serieIds)
+                ->where('is_enabled', 1)
+                ->select('series_id', 'check_status')
+                ->get()->keyBy('series_id');
+        }
+        $wechatCheckStatusMap = config('video.wechat.checkStatus');
         foreach ($videoSeries as $series) {
             $series->series_name = sprintf('第%s集', $series->series_sequence);
             $series->is_charge = $series->series_sequence >= $video->charge_sequence;
@@ -40,6 +53,10 @@ class EpisodeController extends CatchController
             $series->public_video_url = config('common.qiniu.publicVideoLinkDomain') . DIRECTORY_SEPARATOR . $series->video_key;
             $series->download_video_url = QiniuTokenService::getPrivateSourceDownloadUrl(config('common.qiniu.sourceVideoLinkDomain') . DIRECTORY_SEPARATOR .
                 $series->video_key.'?attname='.urlencode($series->series_name).'.mp4');
+            $wechat_check_status = $wechatCheckStatus[$series->id]->check_status ?? 0;
+            $series->wechat_check_status = $wechat_check_status;
+            $series->wechat_check_status_str = $wechatCheckStatusMap[$wechat_check_status] ?? '';
+
         }
 
         return $videoSeries;

+ 37 - 4
modules/Video/Http/Controllers/VideoSeriesWechatCheckController.php

@@ -28,7 +28,8 @@ class VideoSeriesWechatCheckController extends CatchController
             ->join('videos', 'video_series.video_id', 'videos.id')
             ->whereIn('video_series.id', $series_ids)
             ->where(['video_series.is_enabled' => 1])
-            ->select('videos.name', 'video_series.series_sequence','video_series.id', 'video_series.video_key')
+            ->select('video_series.video_id', 'videos.name', 'video_series.series_sequence',
+                'video_series.id', 'video_series.video_key')
             ->get();
         if(collect($series_ids)->count() != $series->count()) {
             CommonBusinessException::throwError(Errors::VIDEO_SERIES_NOT_EXISTS);
@@ -39,7 +40,11 @@ class VideoSeriesWechatCheckController extends CatchController
         foreach ($series as $item) {
             $item->video_url = config('common.qiniu.publicVideoLinkDomain') . DIRECTORY_SEPARATOR . $item->video_key;
             $item->media_name = sprintf('%s - 第%s集', $item->name, $item->series_sequence);
-            $taskId = WechatCheckSyncService::pullupload($item, $accessToken);
+            $parsedContent = WechatCheckSyncService::pullupload($item, $accessToken);
+            if(false === $parsedContent || (0 != ($parsedContent['errcode'] ?? 0))) {
+                CommonBusinessException::throwError(Errors::SYNC_WECHAT_NOT_OK);
+            }
+            $taskId = $parsedContent['task_id'];
             DB::table('video_series_wechat_check')
                 ->where(['series_id' => $item->id, 'is_enabled' => 1])
                 ->update(['is_enabled' => 0, 'updated_at' => $now]);
@@ -47,7 +52,8 @@ class VideoSeriesWechatCheckController extends CatchController
                 ->insert([
                     'series_id' => $item->id,
                     'sync_task_id' => $taskId, 'appid' => $appid,
-                    'created_at' => $now, 'updated_at' => $now
+                    'created_at' => $now, 'updated_at' => $now,
+                    'video_id' => $item->video_id,
                 ]);
         }
 
@@ -55,7 +61,7 @@ class VideoSeriesWechatCheckController extends CatchController
     }
 
     /**
-     * 获取微信那边的剧集播放链接
+     * 获取微信的剧集播放链接
      * @param Request $request
      * @return mixed
      * @throws \Illuminate\Validation\ValidationException
@@ -73,8 +79,35 @@ class VideoSeriesWechatCheckController extends CatchController
         }
 
         $medialinkInfo = WechatCheckSyncService::getMedialinkInfo($seriesId);
+        if(false === $medialinkInfo) {
+            CommonBusinessException::throwError(Errors::GET_WECHAT_MEDIA_LINK_ERROR);
+        }
         $link = $medialinkInfo['mp4_url'];
         Redis::setex($redisKey, 6000, $link);
         return $link;
     }
+
+    public function listEvidence(Request $request) {
+        $this->validate($request, [
+            'series_id' => 'required'
+        ]);
+        $info = DB::table('video_series_wechat_check')
+            ->where([
+                'series_id' => $request->input('series_id'),
+                'is_enabled' => 1
+            ])->orderBy('id', 'desc')
+            ->select('evidence_material_id_list', 'appid')->first();
+        if($info) {
+            $evidence_material_id_lists = \json_decode($info->evidence_material_id_list, true);
+            $accessToken = WechatMiniprogramService::getDuanjuCheckAccessToken($info->appid);
+
+        }
+    }
+
+    public function test(Request $request) {
+        foreach (['1228789.jpg', 'images.png'] as $i) {
+            $res = file_get_contents(app_path($i));
+            echo $res;
+        }
+    }
 }

+ 30 - 6
modules/Video/Http/Controllers/WechatCheckController.php

@@ -7,6 +7,7 @@ use Catch\Base\CatchController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
+use Modules\Manage\Services\WechatMiniprogramService;
 
 /**
  * 微信提审
@@ -24,11 +25,14 @@ class WechatCheckController extends CatchController
             'producer' => 'required|string|max:256',
             'playwright' => 'required|string|max:256',
             'production_license_img' => 'required|url',
-            'authorized_img' => 'required|url'
+            'authorized_img' => 'required|url',
+            'registration_number' => 'required'
         ]);
 
         $data = $request->all();
+        $appid = WechatMiniprogramService::getDuanjuCheckAppid();
         $data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
+        $data['appid'] = $appid;
         DB::table('video_wechat_check')
             ->insert($data);
 
@@ -39,7 +43,26 @@ class WechatCheckController extends CatchController
      * 修改
      * @param Request $request
      */
-    public function update(Request $request) {}
+    public function update(Request $request) {
+        $this->validate($request, [
+            'id'=>'required',
+            'producer' => 'required|string|max:256',
+            'playwright' => 'required|string|max:256',
+            'production_license_img' => 'required|url',
+            'authorized_img' => 'required|url',
+            'registration_number' => 'required'
+        ]);
+
+        $data = $request->all();
+        $data['updated_at'] = date('Y-m-d H:i:s');
+        unset($data['id']);
+        DB::table('video_wechat_check')
+            ->where('id', $request->input('id'))
+            ->where('is_enabled', 1)
+            ->whereIn('status', [0,4])
+            ->update($data);
+        return 'ok';
+    }
 
     /**
      * 删除
@@ -48,6 +71,7 @@ class WechatCheckController extends CatchController
     public function delete(Request $request) {
         $this->validate($request, ['id' => 'required']);
         DB::table('video_wechat_check')
+            ->whereIn('status', [0,4])
             ->where([
                 'id' => $request->input('id'),
                 'is_enabled' => 1,
@@ -66,12 +90,12 @@ class WechatCheckController extends CatchController
         $videoId = $request->input('video_id');
         $producer = $request->input('producer');
         $playwright = $request->input('playwright');
-        $status = $request->input('status',0);
+        $status = $request->input('status',[0]);
 
         return DB::table('video_wechat_check as check')
             ->join('videos', 'videos.id', 'check.video_id')
+            ->whereIn('check.status', $status)
             ->where([
-                'check.status' => $status,
                 'check.is_enabled' => 1,
             ])->when($videoId, function ($query, $videoId) {
                 return $query->where('check.video_id', $videoId);
@@ -82,9 +106,9 @@ class WechatCheckController extends CatchController
             })->select('check.id', 'videos.name', 'videos.note', 'videos.total_episode_num',
                 'videos.cover_image','check.status','check.producer',
             'check.playwright', 'check.production_license_img', 'check.authorized_img', 'check.apply_at',
-            'check.check_at', 'check.check_reason')
+            'check.check_at', 'check.check_reason', 'check.registration_number')
             ->orderBy('check.id','desc')
-            ->paginate($request->input('limit', 10));
+            ->paginate($request->input('limit', 20));
 
     }
 

+ 10 - 47
modules/Video/Services/WechatCheckSyncService.php

@@ -6,6 +6,8 @@ use GuzzleHttp\Client;
 use Illuminate\Support\Facades\DB;
 use Modules\Common\Errors\Errors;
 use Modules\Common\Exceptions\CommonBusinessException;
+use Modules\Common\Support\Http\HttpRequest;
+use Modules\Common\Support\Http\WechatURL;
 use Modules\Manage\Services\WechatMiniprogramService;
 
 
@@ -19,12 +21,10 @@ class WechatCheckSyncService
      * @throws \GuzzleHttp\Exception\GuzzleException
      */
     public static function pullupload($item, $accessToken) {
-        $url = 'https://api.weixin.qq.com/wxa/sec/vod/pullupload?access_token='.$accessToken;
-        $parsedContent = self::postWechat($url, [
+        return HttpRequest::simplePost(WechatURL::vod_pullupload. $accessToken, [
             'media_name' => $item->media_name,
             'media_url' => $item->video_url
         ]);
-        return $parsedContent['task_id'];
     }
 
     /**
@@ -34,6 +34,7 @@ class WechatCheckSyncService
      * @throws \GuzzleHttp\Exception\GuzzleException
      */
     public static function getMedialinkInfo($seriesId) {
+        return ['mp4_url' => 'http://www.baidu.com'];
         $syncInfo = DB::table('video_series_wechat_check')
             ->where([
                 'series_id'=> $seriesId,
@@ -46,58 +47,20 @@ class WechatCheckSyncService
         }
         $mediaId = $syncInfo->media_id;
         $accessToken = WechatMiniprogramService::getDuanjuCheckAccessToken($syncInfo->appid);
-        $url = 'https://api.weixin.qq.com/wxa/sec/vod/getmedialink?access_token='.$accessToken;
 
-        $parsedContent = self::postWechat($url, [
+        return HttpRequest::simplePost(WechatURL::vod_getmedialink. $accessToken, [
             'media_id' => $mediaId,
             't' => time() + 7200,
         ]);
-        return $parsedContent['media_info'];
     }
 
+    /**
+     * 短剧播放链接保存的rediskey
+     * @param $seriesId
+     * @return string
+     */
     public static function getWechatMediaLinkRedisKey($seriesId) {
         return 'wechat.medialink.'.$seriesId;
     }
 
-    public static function getTask($syncInfo) {
-        try {
-            $accessToken = WechatMiniprogramService::getDuanjuCheckAccessToken($syncInfo->appid);
-            $url = 'https://api.weixin.qq.com/wxa/sec/vod/gettask?access_token='.$accessToken;
-            $parsedContent = self::postWechat($url, [
-                'task_id' => $syncInfo->sync_task_id
-            ]);
-            return $parsedContent['task_info'];
-        } catch (\Exception $exception) {
-            return [];
-        }
-
-    }
-
-    /**
-     *  post 请求微信上游
-     * @param $url
-     * @param $data
-     * @throws \GuzzleHttp\Exception\GuzzleException
-     */
-    public static function postWechat($url, $data) {
-        $client = new Client(['timeout' => 3]);
-        $httpResult = $client->post($url, $data);
-
-        $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('请求微信异常', [
-                'url' => $url,
-                'data' => $data,
-                'errMsg' => $httpContent
-            ]);
-            CommonBusinessException::throwError(Errors::REQUEST_CODE_STATUS_ERROR);
-        }
-
-        return $parsedContent;
-    }
 }

+ 10 - 0
modules/Video/config/wechat.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'checkStatus' => [
+        '0' =>  '',
+        '1' => '审核中',
+        '2' => '审核驳回',
+        '3' => '审核通过'
+    ],
+];

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

@@ -23,8 +23,11 @@ Route::prefix('videoStock')->group(function () {
         Route::post('add', [WechatCheckController::class, 'add']);
         Route::get('list', [WechatCheckController::class, 'list']);
         Route::post('delete', [WechatCheckController::class, 'delete']);
+        Route::post('update', [WechatCheckController::class, 'update']);
         Route::prefix('videoSeries')->group(function(){
             Route::post('syncWechat', [VideoSeriesWechatCheckController::class, 'syncWechat']);
+            Route::post('medialink', [VideoSeriesWechatCheckController::class, 'medialink']);
+            Route::get('test', [VideoSeriesWechatCheckController::class, 'test'])->withoutMiddleware(config('catch.route.middlewares'));
         });
     });
 

+ 0 - 1
tests/Channel/Http/Controllers/AdvertiserControllerTest.php

@@ -31,7 +31,6 @@ class AdvertiserControllerTest extends UsedTestCase
         ])->json('get','http://localhost/api/channel/advertiser/listAdvertiser?'.http_build_query([
 //                'email' => 'aa1@test.com',
 //                'miniProgramId' => 3,
-            'username' => 'aa'
             ]));
         $res->dump();
     }

+ 1 - 1
tests/UsedTestCase.php

@@ -13,7 +13,7 @@ abstract class UsedTestCase extends BaseTestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $tokenInfo = $this->post('http://localhost/api/login', [
-//            'email' => 'catch@admin.com',
+            'email' => 'catch@admin.com',
             'remember' => false,
             'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',

+ 3 - 3
tests/Video/Http/Controllers/EpisodeControllerTest.php

@@ -14,10 +14,10 @@ class EpisodeControllerTest extends UsedTestCase
         $res = $this->withHeaders([
             'Authorization' => 'Bearer '. $this->token,
         ])->json('get','http://localhost/api/videoStock/episode/downloadList', [
-            'video_id' => 3
+            'video_id' => 3,
+            'need_wechat_status' => 1
         ]);
-//        $this->dumpJson($res);
-        $res->dump();
+        $this->dumpJson($res);
     }
 
     public function testAdd()

+ 9 - 1
tests/Video/Http/Controllers/VideoSeriesWechatCheckControllerTest.php

@@ -16,7 +16,15 @@ class VideoSeriesWechatCheckControllerTest extends UsedTestCase
         ])->json('post','http://localhost/api/videoStock/wechatCheck/videoSeries/syncWechat', [
             'series_ids' => [81,82,83,84,85],
         ]);
-        $res->dump();
+        $this->dumpJson($res);
+    }
+    public function testmedialink()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/videoStock/wechatCheck/videoSeries/medialink', [
+            'series_id' => 81,
+        ]);
         $this->dumpJson($res);
     }
 }

+ 1 - 1
tests/Video/Http/Controllers/WechatCheckControllerTest.php

@@ -32,6 +32,6 @@ class WechatCheckControllerTest extends UsedTestCase
             'producer' => 'zzz',
             'playwright' =>  'xxxx',
         ]);
-        $res->dump();
+        $this->dumpJson($res);
     }
 }