赞
踩
首先找到接口文档地址:https://newdocs.toponad.com/docs/dukFyc
登录到topon后台之后,点击右上角账号管理,进入到此页面就能看到相应的key,拿到参数就可以开始对接了,这里我们需要根据自己的需要列出指定的维度,返回数据的指标,我们可以全部返回,则填入all,其他参数根据文档填写即可
然后是请求头,文档有写接口鉴权说明,这里自己列出代码,给大家参考:
public function get_data($date) { $contentArr = [ 'startdate' => (int)date('Ymd', strtotime($date)), 'enddate' => (int)date('Ymd', strtotime($date)), 'group_by' => ["date", "app", "placement", "adformat", "network_firm_id"], 'metric' => ["all"], 'start' => 0, 'limit' => 1000 ]; $reqUrl = self::serverHost . "/v2/fullreport"; $response = json_decode($this->doRequest("POST", $contentArr, self::Api_Key, $reqUrl), true); $data = $response['records'] ?? []; if (empty($data)) { return ['code' => 101, 'msg' => 'no data!']; } ....业务逻辑开始 } function doRequest($httpMethod, array $contentArr, $publisherKey, $reqUrl) { $time = time() * 1000; $headerArr = [ 'X-Up-Key' => $publisherKey, 'X-Up-Timestamp' => $time, ]; $headerStr = ''; foreach ($headerArr as $key => $value) { if (empty($headerStr)) { $headerStr = "$key:$value"; } else { $headerStr = "$headerStr\n$key:$value"; } } if ($httpMethod == "GET") { $reqUrl = $reqUrl . "?" . http_build_query($contentArr); $contentStr = ""; } else { $contentStr = json_encode($contentArr); } $contentMD5 = strtoupper(md5($contentStr)); $contentType = 'application/json'; $relativePath = parse_url($reqUrl)["path"]; $signStr = $httpMethod . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $headerStr . "\n" . $relativePath; $headerArr['X-Up-Signature'] = strtoupper(md5($signStr));; $headerArr['Content-Type'] = $contentType; return $this->execCurl($httpMethod, $reqUrl, $contentStr, $headerArr); } function execCurl($httpMethod, $reqUrl, $contentStr, array $headerArr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $reqUrl); if ($httpMethod == 'GET') { curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_HTTPGET, true); } elseif ($httpMethod == 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $contentStr); } else { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod); curl_setopt($ch, CURLOPT_POSTFIELDS, $contentStr); } $finalHeaderArr = []; foreach ($headerArr as $key => $value) { $finalHeaderArr[] = $key . ":" . $value; } curl_setopt($ch, CURLOPT_HTTPHEADER, $finalHeaderArr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $response = curl_exec($ch); curl_close($ch); return $response; }
代码将指定的参数换成自己的参数之后,即可直接使用,拿到对应的返回数据之后再根据我们自己的业务需求去做,希望能对你有所帮助。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。