|
@@ -0,0 +1,71 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace General\Services\Report;
|
|
|
|
+
|
|
|
|
+use General\Models\Report\BaiDuAdAccount;
|
|
|
|
+use General\Models\Report\ReportUserBindRecord;
|
|
|
|
+use GuzzleHttp\Client;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 百度数据上报
|
|
|
|
+ */
|
|
|
|
+class BaiduReport extends BaseReport
|
|
|
|
+{
|
|
|
|
+ public function __construct()
|
|
|
|
+ {
|
|
|
|
+ $this->charge_event_type = 19;
|
|
|
|
+ $this->register_event_type = 3;
|
|
|
|
+ $this->report_url = 'https://ocpc.baidu.com/ocpcapi/api/uploadConvertData';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function findToken(int $adid)
|
|
|
|
+ {
|
|
|
|
+ return BaiDuAdAccount::find($adid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
|
|
|
|
+ {
|
|
|
|
+ return [
|
|
|
|
+ 'token' => $this->findToken($user->adid),
|
|
|
|
+ 'conversionTypes' => [
|
|
|
|
+ 'logidUrl' => $user->link,
|
|
|
|
+ 'newType' => $this->charge_event_type,
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function getRegisterQueryParams(ReportUserBindRecord $user): array
|
|
|
|
+ {
|
|
|
|
+ return [
|
|
|
|
+ 'token' => $this->findToken($user->adid),
|
|
|
|
+ 'conversionTypes' => [
|
|
|
|
+ 'logidUrl' => $user->link,
|
|
|
|
+ 'newType' => $this->register_event_type,
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function report(array $query_params)
|
|
|
|
+ {
|
|
|
|
+ $result = false;
|
|
|
|
+ $content = '';
|
|
|
|
+ try {
|
|
|
|
+ $client = new Client(['timeout' => 4]);
|
|
|
|
+ $response = $client->post($this->report_url, ['json' => $query_params]);
|
|
|
|
+ $content = $response->getBody()->getContents();
|
|
|
|
+ $status_code = $response->getStatusCode();
|
|
|
|
+ if ($status_code == 200) {
|
|
|
|
+ $result = true;
|
|
|
|
+ } else {
|
|
|
|
+ $result = false;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
+ myLog('baidu_report')->error($e->getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ return [
|
|
|
|
+ 'result' => $result,
|
|
|
|
+ 'content' => $content,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|