12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace General\Services\Report;
- use General\Models\Report\ReportUserBindRecord;
- use App\Consts\BaseConst;
- use GuzzleHttp\Client;
- use Illuminate\Support\Collection;
- /**
- * 喜马拉雅数据上报
- */
- class QappXimalayaReport {
- public static function reportCharge(ReportUserBindRecord $user) :array
- {
- try{
- $path = $user->link . '&event_type=2';
- myLog('ximalaya-charge-buchuan')->info('充值回传:开始浅层转化目标[event_type=2],uid='. $user->uid);
- $requestResult = self::sendRequest($path);
- if($requestResult['result']) {
- $deepPath = $user->link. '&deep_event_type=1';
- myLog('ximalaya-charge-buchuan')->info('充值回传:开始深层转化目标[deep_event_type=1],uid='. $user->uid);
- $deepRequestResult = self::sendRequest($deepPath);
- return [
- 'result' => $deepRequestResult->get('result', false),
- 'content' => '',
- 'query_params' => ['path' => $path, 'deep_path' => $deepPath],
- ];
- }
- return [
- 'result' => $requestResult->get('result', false),
- 'content' => '',
- 'query_params' => ['path' => $path],
- ];
- }catch (\Exception $exception) {
- myLog('ximalaya-charge-buchuan')->error('回传充值出现异常:'. $exception->getMessage(), $exception->getTrace());
- return [
- 'result' => false,
- 'content' => '回传充值出现异常',
- 'query_params' => []
- ];
- }
- }
- private function sendRequest($path) :Collection{
- myLog('ximalaya-charge-buchuan')->info('请求喜马拉雅服务器的参数:', [
- 'path' => $path,
- ]);
- $httpClient = new Client(['timeout' => 4]);
- $httpResponse = $httpClient->get($path);
- $result = ($httpResponse->getStatusCode() == 200);
- $content = $httpResponse->getBody()->getContents();
- $resultType = (\json_decode($content, true))['type'] ?? '';
- $result = $result && ('success' == strtolower($resultType));
- myLog('ximalaya-charge-buchuan')->info('请求喜马拉雅服务器的结果:', [
- 'request_url' => $path,
- 'reponse_status' => $httpResponse->getStatusCode(),
- 'response_content' => $content,
- 'result' => $result,
- ]);
- return collect(compact('result', 'content'));
- }
- }
|