123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/10/21
- * Time: 14:29
- */
- namespace App\Service;
- use App\Log;
- class JiaShuService
- {
- /*
- * 创建推广链接
- * */
- public static function savePromotion(
- $apiKey, $customerId, $appId, $videoId, $dramaSort, $remark
- )
- {
- $requestUri = config('jiashu.save_promotion');
- $paramsArr['app_id'] = $appId;
- $paramsArr['customer_id'] = $customerId;
- $paramsArr['drama_sort'] = $dramaSort;
- $paramsArr['only_url'] = 1;
- $paramsArr['remark'] = $remark;
- $paramsArr['timestamp'] = time();
- $paramsArr['video_id'] = $videoId;
- # 生成签名
- $params = self::createSign($apiKey, $paramsArr);
- $response = HttpService::httpPost($requestUri, $params);
- $responseData = json_decode($response, 1);
- Log::logInfo('创建推广链接', [
- 'params' => [
- 'api_key' => $apiKey,
- 'customer_id' => $customerId,
- 'app_id' => $appId,
- 'video_id' => $videoId,
- 'drama_sort' => $dramaSort,
- 'remark' => $remark
- ],
- 'response' => $responseData
- ], 'jiashuApi');
- sleep(1);
- return $responseData;
- }
- /*
- * 获取剧列表
- * */
- public static function getContentList(
- $apiKey, $customerId, $page = null, $appId
- )
- {
- $requestUri = config('jiashu.get_content_list');
- $paramsArr['app_id'] = $appId;
- $paramsArr['customer_id'] = $customerId;
- if(!is_null($page)) $paramsArr['page'] = $page;
- $paramsArr['timestamp'] = time();
- $params = self::createSign($apiKey, $paramsArr);
- $requestUri .= http_build_query($params);
- # 获取响应数据
- $response = HttpService::httpGet($requestUri);
- $responseData = json_decode($response, true);
- Log::logInfo('获取短剧列表', [
- 'params' => [
- 'api_key' => $apiKey,
- 'customer_id' => $customerId,
- 'app_id' => $appId,
- 'page' => $page,
- ],
- 'response' => $responseData
- ], 'jiashuApi');
- return $responseData;
- }
- /*
- * 获取剧集列表
- * */
- public static function getSectionList($apiKey, $customerId, $appId, $videoId)
- {
- $requestUri = config('jiashu.get_section_list');
- $paramsArr['app_id'] = $appId;
- $paramsArr['customer_id'] = $customerId;
- $paramsArr['timestamp'] = time();
- $paramsArr['video_id'] = $videoId;
- $params = self::createSign($apiKey, $paramsArr);
- $requestUri .= http_build_query($params);
- # 获取响应数据
- $response = HttpService::httpGet($requestUri);
- $responseData = json_decode($response, true);
- Log::logInfo('获取剧集列表', [
- 'params' => [
- 'api_key' => $apiKey,
- 'customer_id' => $customerId,
- 'app_id' => $appId,
- 'video_id' => $videoId,
- ],
- 'response' => $responseData
- ], 'jiashuApi');
- return $responseData;
- }
- /*
- * 获取应用列表
- * */
- public static function getAppList($apiKey, $customerId)
- {
- $requestUri = config('jiashu.get_app_list');
- $paramsArr['customer_id'] = $customerId;
- $paramsArr['timestamp'] = time();
- $params = self::createSign($apiKey, $paramsArr);
- # 获取响应数据
- $response = HttpService::httpPost($requestUri, $params);
- $responseData = json_decode($response, true);
- Log::logInfo('获取产品列表', [
- 'params' => [
- 'api_key' => $apiKey,
- 'customer_id' => $customerId,
- ],
- 'response' => $responseData
- ], 'jiashuApi');
- return $responseData;
- }
- public static function createSign($apiKey, $paramsArr)
- {
- $params = [];
- foreach($paramsArr as $k=> $v) {
- $params[] = $k.'='.$v;
- }
- sort($params);
- $string = implode('&', $params);
- $sign = md5($apiKey.$string);
- $paramsArr['sign'] = $sign;
- return $paramsArr;
- }
- # 获取推广链接
- public static function getArticle($apiKey, $customerId, $appId, $article, $retry = 0)
- {
- $requestUri = config('jiashu.get_article');
- $paramsArr['app_id'] = $appId;
- $paramsArr['article'] = $article;
- $paramsArr['customer_id'] = $customerId;
- $paramsArr['timestamp'] = time();
- $params = self::createSign($apiKey, $paramsArr);
- $requestUri .= http_build_query($params);
- # 获取响应数据
- $response = HttpService::httpGet($requestUri);
- $responseData = json_decode($response, true);
- Log::logInfo('获取推广链接', [
- 'params' => [
- 'api_key' => $apiKey,
- 'customer_id' => $customerId,
- 'app_id' => $appId,
- 'article' => $article,
- 'retry' => $retry
- ],
- 'response' => $responseData
- ], 'jiashuApi');
- $code = $responseData['code'] ?? 1;
- if($code) {
- $retry++;
- if($retry < 2) {
- sleep(1);
- return self::getArticle($apiKey, $customerId, $appId, $article, $retry);
- }
- }
- return $responseData;
- }
- public static function getArticleList($apiKey, $customerId, $appId, $statTime, $endTime, $retry = 0)
- {
- $requestUri = config('jiashu.get_article_data');
- $paramsArr['app_id'] = $appId;
- $paramsArr['customer_id'] = $customerId;
- $paramsArr['end_time'] = $endTime;
- $paramsArr['start_time'] = $statTime;
- $paramsArr['timestamp'] = time();
- $params = self::createSign($apiKey, $paramsArr);
- $requestUri .= http_build_query($params);
- # 获取响应数据
- $response = HttpService::httpGet($requestUri);
- $responseData = json_decode($response, true);
- Log::logInfo('获取公众号推文数据', [
- 'params' => [
- 'api_key' => $apiKey,
- 'customer_id' => $customerId,
- 'app_id' => $appId,
- 'start_time' => $statTime,
- 'end_time' => $endTime,
- 'retry' => $retry
- ],
- 'response' => $responseData
- ], 'jiashuApi');
- $code = $responseData['code'] ?? 1;
- if($code) {
- $retry++;
- if($retry < 2) {
- sleep(1);
- return self::getArticleList($apiKey, $customerId, $appId, $statTime, $endTime, $retry);
- }
- }
- return $responseData;
- }
- }
|