$channelId]; $requestUri .= http_build_query($params); # 获取响应数据 $accessToken = ''; $response = HttpService::httpGet($requestUri); $responseData = json_decode($response, true); if(isset($responseData['code']) && $responseData['code'] == 0) { $accessToken = $responseData['data'] ?? ''; if(empty($accessToken) && $retry <5) { $retry++; return self::login($channelId, $retry); } if(!empty($accessToken)) RedisModel::set(MaiBuService::MAI_BU_ACCESS_TOKEN_RDS . $channelId, $accessToken); RedisModel::expire(MaiBuService::MAI_BU_ACCESS_TOKEN_RDS . $channelId, 86300*2); } else { // 获取失败,发起重试 if($retry < 5) { $retry++; return self::login($channelId, $retry); } } if(empty($accessToken)) { // EmailQueue::rPush('迈步Token获取失败', json_encode([ // 'channelId' => $channelId, // 'response' => $responseData // ], 256), ['xiaohua.hou@kuxuan-inc.com'], '迈步Token获取失败'); Log::logError('迈步Token获取失败', [ 'label' => $channelId, 'retry' => $retry ], 'MaiBuAccessToken'); return false; } return $accessToken; } /** * 获取剧列表 * */ public static function getContentList( $partnerId, $pageIndex, $pageSize, $token, $finishState=-1, $state=-1, $appId=null, $contentName=null, $feeType=null ) { $requestUri = config('maiBu.get_content_list'); $params = [ 'partnerId' => $partnerId, 'pageIndex' => $pageIndex, 'pageSize' => $pageSize ]; # appid if(!is_null($appId)) $params['appId'] = $appId; # 内容名称 if(!is_null($contentName)) $params['contentName'] = $contentName; # 完结状态 if(!is_null($finishState)) $params['finishState'] = $finishState; # 收费类型 if(!is_null($feeType)) $params['feeType'] = $feeType; # 剧上下架状态 if(!is_null($state)) $params['state'] = $state; $requestUri .= http_build_query($params); $header = ['authorization:' . $token]; # 获取响应数据 $response = HttpService::httpGet($requestUri, $header); $responseData = json_decode($response, true); return $responseData; } /** * 获取剧集列表 * */ public static function getSectionList($contentId, $pageIndex, $pageSize, $token) { $requestUri = config('maiBu.get_section_list'); $params = [ 'contentId' => $contentId, 'pageIndex' => $pageIndex, 'pageSize' => $pageSize ]; $requestUri .= http_build_query($params); $header = ['authorization:' . $token]; # 获取响应数据 $response = HttpService::httpGet($requestUri, $header); $responseData = json_decode($response, true); return $responseData; } /** * 创建推广链接 * */ public static function savePromotion( $partnerId, $appId, $name, $contentId, $sectionId, $forceSubscribe=null, $forceSubscribeSectionId=null, $type=null ) { $token = self::getAccessToken($partnerId); $requestUri = config('maiBu.save_promotion'); $params = [ 'partnerId' => $partnerId, 'appId' => $appId, 'name' => $name, 'contentId' =>$contentId, 'sectionId' => $sectionId ]; # 是否强关 if(!is_null($forceSubscribe)) $params['forceSubscribe'] = $forceSubscribe; # 强关章节ID if(!is_null($forceSubscribeSectionId)) $params['forceSubscribeSectionId'] = $forceSubscribeSectionId; # 链接类型 if(!is_null($type)) $params['type'] = $type; $requestUri .= http_build_query($params); $header = ['authorization:' . $token]; # 获取响应数据 $response = HttpService::httpGet($requestUri, $header); $responseData = json_decode($response, true); return $responseData; } /** * 获取应用列表 * */ public static function getAppList($partnerId, $pageIndex, $pageSize, $token) { $requestUri = config('maiBu.get_app_list'); $params = [ 'partnerId' => $partnerId, 'pageIndex' => $pageIndex, 'pageSize' => $pageSize ]; $requestUri .= http_build_query($params); $header = ['authorization:' . $token]; # 获取响应数据 $response = HttpService::httpGet($requestUri, $header); $responseData = json_decode($response, true); return $responseData; } public static function getPromotionList($token, $partnerId, $appId, $beginDate, $endDate, $type, $pageIndex, $pageSize, $lastMinId, $retry = 0) { $requestUri = config('maiBu.get_promotion_list'); $params = [ 'partnerId' => $partnerId, 'appId' => $appId, 'beginDate' => $beginDate, 'endDate' => $endDate, 'type' => $type, 'pageIndex' => $pageIndex, 'pageSize' => $pageSize, 'lastMinId' => $lastMinId ]; $requestUri .= http_build_query($params); $header = ['authorization:' . $token]; # 获取响应数据 $response = HttpService::httpGet($requestUri, $header); $responseData = json_decode($response, true); Log::logInfo('获取公众号推文数据', [ 'params' => [ 'partnerId' => $partnerId, 'appId' => $appId, 'beginDate' => $beginDate, 'endDate' => $endDate, 'type' => $type, 'pageIndex' => $pageIndex, 'pageSize' => $pageSize, 'lastMinId' => $lastMinId, 'retry' => $retry ], 'response' => $responseData ], 'maibuApi'); $code = $responseData['code'] ?? 1; if($code) { $retry++; if($retry < 2) { sleep(1); return self::getPromotionList($token, $partnerId, $appId, $beginDate, $endDate, $type, $pageIndex, $pageSize, $lastMinId, $retry); } } return $responseData; } public static function getOrderPayType($payType) { $payTypeArr= [ 0 => 6, // 微信小程序支付 1 => 7, // 微信_APP支付 2 => 8, // 微信_H5支付 3 => 5, // 支付宝_APP支付 4 => 9, // 微信快手支付 5 => 10,// 微信抖音支付 6 => 11,// 苹果_APP支付 7 => 12,// H5微信内支付 8 => 13,// 华为APP支付 9 => 14,// 百度百度小程序支付 10=> 1, // 微信_小程序虚拟支付 ]; return $payTypeArr[$payType] ?? 0; } }