sapi.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  3. class sapi
  4. {
  5. private $url = 'https://sapi.ads.oppomobile.com/v1/clue/sendData';
  6. private $ownerId = '1000178033';
  7. private $API_ID = 'cbbf0a225cd44cba81b9b6e093ded0a2';
  8. private $APIKEY = '0d10124566ff41c393c0c418a3ae147a';
  9. private function create_token()
  10. {
  11. $time = time();
  12. $sign = sha1($this->API_ID .$this->APIKEY . $time);
  13. return base64_encode($this->ownerId. ','. $this->API_ID. ',' .$time. ',' . $sign);
  14. }
  15. public function send($body)
  16. {
  17. $params['pageId'] = $body['pageId'];
  18. $params['ownerId'] = $this->ownerId;
  19. $params['ip'] = $_SERVER['REMOTE_ADDR'];
  20. $params['tid'] = $body['tid'];
  21. $params['lbid'] = $body['lbid'];
  22. $params['transformType'] = 101;
  23. $token = $this->create_token();
  24. $header = [
  25. 'Content-Type: application/json',
  26. "Authorization:Bearer {$token}"
  27. ];
  28. $params = json_encode($params);
  29. Log::record("sapi send json data {$params}", Log::ERR);
  30. $resp = http_post_data($this->url, $params, $header, $net_errno);
  31. if (empty($resp)) {
  32. Log::record("sapi send neterr {$net_errno}", Log::ERR);
  33. return false;
  34. } else {
  35. Log::record($resp, Log::DEBUG);
  36. $resp = json_decode($resp, true);
  37. if ($resp['code'] === 0) {
  38. return true;
  39. } else {
  40. Log::record("sapi send err {$resp['msg']}", Log::ERR);
  41. return false;
  42. }
  43. }
  44. }
  45. }