report($this->report_url, [ 'event_type' => $this->purchase_roi_event_type, 'context' => [ 'ad' => [ 'callback' => $user->callback ] ], 'timestamp' => time() ]); } /** * 付费上报 */ public function reportCharge($user, $amount=0) { return $this->report($this->report_url, [ 'event_type' => $this->charge_event_type, 'context' => [ 'ad' => [ 'callback' => $user->callback ] ], 'timestamp' => time() ]); } /** * 注册上报 */ public function reportRegister(DouyinUser $user) { return $this->report($this->report_url, [ 'event_type' => $this->register_event_type, 'context' => [ 'ad' => [ 'callback' => $user->callback ] ], 'timestamp' => time() ]); } /** * 次日留存上报 */ public function reportRentention() { return $this->report($this->report_url, [ 'event_type' => $this->rentention_event_type, 'context' => [ 'ad' => [ 'callback' => $this->user->callback ] ], 'timestamp' => time() ]); } public function reportAddDesktop() { return []; } /** * 激活上报 */ public function reportActive($user) { return $this->report($this->report_url, [ 'event_type' => $this->active_event_type, 'context' => [ 'ad' => [ 'callback' => $user->callback ] ], 'timestamp' => time() ]); } /** * 数据上报 */ public function report(string $url, array $query_params) { $result = false; $content = ''; try { myLog('tiktok_event_report')->info('report_param_event_tiktok:' . json_encode($query_params)); $client = new Client(['timeout' => 4]); $response = $client->request('post', $url, ['json' => $query_params]); $content = $response->getBody()->getContents(); myLog('tiktok_event_report')->info('report_result_event_tiktok:' . json_encode($content, true)); $status_code = $response->getStatusCode(); if ($status_code == 200) { $result = true; } else { $result = false; } } catch (Exception $e) { myLog('tiktok_event_report')->error('event_tiktok_ept:' . json_encode($query_params) . ' ept:' . $e->getMessage()); } finally { $query_params['report_url'] = $url; return [ 'result' => $result, 'content' => $content, 'query_params' => $query_params, ]; } } }