|
@@ -0,0 +1,51 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace General\Services\ChargeReport;
|
|
|
+
|
|
|
+use App\Consts\BaseConst;
|
|
|
+use Exception;
|
|
|
+use General\Helpers\CommonHelper;
|
|
|
+use General\Models\ChargeReport\BaiDuAdAccount;
|
|
|
+use GuzzleHttp\Client;
|
|
|
+
|
|
|
+
|
|
|
+ * 通知上报
|
|
|
+ */
|
|
|
+class NotifyReport
|
|
|
+{
|
|
|
+
|
|
|
+ * 百度账号上报路径
|
|
|
+ */
|
|
|
+ protected $baidu_account_path = 'api/report/baidu/token';
|
|
|
+
|
|
|
+
|
|
|
+ * 百度账号上报
|
|
|
+ */
|
|
|
+ public function baiDuAdAccountReport(BaiDuAdAccount $model)
|
|
|
+ {
|
|
|
+ $this->report($this->baidu_account_path, [
|
|
|
+ 'source' => 'zsy',
|
|
|
+ 'adid' => $model->id,
|
|
|
+ 'token' => $model->token,
|
|
|
+ 'is_enabled' => $model->is_enabled,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function report(string $path, array $query_params)
|
|
|
+ {
|
|
|
+ $client = new Client(['timeout' => 3]);
|
|
|
+ $query_params['sign'] = CommonHelper::sign($query_params, BaseConst::TIKTOK_KEY);
|
|
|
+ try {
|
|
|
+ $response = $client->post(env('TRACK_API_DOMAIN') . '/' . $path, ['form_params' => $query_params]);
|
|
|
+ if ($response->getStatusCode() == 200) {
|
|
|
+ $result = $response->getBody()->getContents();
|
|
|
+ myLog('track_api')->info($result);
|
|
|
+ return json_decode($result, true);
|
|
|
+ } else {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ myLog('track_api')->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|