1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\service\byte_dance;
- use GuzzleHttp\Client;
- use traits\think\Instance;
- class OceanEngineService{
- use Instance;
- protected $query=[];
- protected $addon=[];
- public function __construct($query)
- {
- $this->query=$query;
- }
- /**
- * @param array $query
- */
- public static function setQuery(array $query)
- {
- return self::instance($query);
- }
- /**
- * @param array $addon
- */
- public function setAddon(array $addon)
- {
- $this->addon = $addon;
- return $this;
- }
- public function form(){
- $this->conversion('form');
- }
- protected function conversion($evenType){
- if(empty($this->query['clickid'])){
- return false;
- }
- $p=$this->client()->post('https://analytics.oceanengine.com/api/v2/conversion',[
- 'json'=>[
- 'event_type'=>$evenType,
- 'context'=>[
- 'ad'=>[
- 'callback'=>$this->query['clickid'],
- ]
- ],
- 'timestamp'=>time()*1000,
- ]
- ]);
- $result=json_decode($p->getBody()->getContents(),true);
- $codeArr=[
- 0=>'成功',
- 10=>'服务暂时不可用,请稍后重试',
- 100=>'无效的请求,请求数据解析失败',
- 101=>'鉴权认证失败, 数据会被丢弃',
- 102=>'参数:event_type无效',
- 103=>'参数:callback无效',
- 107=>'鉴权认证失败,请修正签名,当前状态下本次回传不受影响',
- ];
- user_log('oceanEngineService',[
- 'query'=>$this->query,
- 'addon'=>$this->addon,
- 'response'=>$result,
- 'code_text'=>$codeArr[$result['code']??-1]??null
- ]);
- return $result;
- }
- public function shopping(){
- $this->conversion('shopping');
- }
- protected function client(){
- return new Client();
- }
- }
|