腾讯广告线索平台(广点通拉取线索信息) 发表于 2020-04-14 | 更新于: 2023-02-09 | 分类于 学习 字数统计: 673 | 阅读时长 ≈ 3 前言:本文章记录腾讯广告数据拉取,这个和飞鱼的接口基本上就是大同小异,原腾讯线索平台对接文档。使用方法:将在后台获取的密钥和token替换到相应的位置,按自己的需要修改插入方法即可。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143<?php/** * User: 牧马人 * DateTime: 2020-04-14 12:16 * Desc:广点通拉取线索信息 */namespace Home\Controller;use Common\CommonEvent\HomeController;use Common\CommonEvent\AjaxCommon;header("Content-Type: text/html;charset=utf-8");class GdtController extends HomeController{ //广点通请求地址 private $host = 'https://leads.qq.com/api/mv1'; private $pull_route = '/leads/list'; //获取几分钟前的数据 private $minute = 5; //第*页 private $page = 1; //每页*获取条数据 private $page_size = 50; /** * User: 牧马人 * DateTime: 2019/11/7 9:28 * Desc:运行入口 */ public function run(){ $this->azw(); } /** * User: 牧马人 * DateTime: 2020-04-14 9:29 * Desc:账号为azw的配置 */ private function azw(){ //广点通token $token = '**************'; //广点通secret $secret = '**************'; //开始时间 $start_time = time()-60*$this->minute; //结束时间 $end_time = time(); //第几页 $page = $this->page; //每页显示多少数据 $page_size = $this->page_size; $signature = $this->base64($token,$secret); $output = $this->curl($page,$page_size,$start_time,$end_time,$signature); if ($output['code']==0){ $this->insertdata($output['data']['list']); } } /** * User: 牧马人 * DateTime: 2020-04-14 9:29 * Desc:签名加密 * @param string $token * @param string $secret * @return string */ private function base64($token='',$secret=''){ $token = $token; //⼴告主线索平台token $secret = $secret; //⼴告主线索平台⽣成的接⼝密钥 $timestamp = time(); //即当前的秒级时间戳 $signature = base64_encode($token . "," . $timestamp . "," .sha1($token.".".$timestamp.".".$secret)); return $signature; } /** * User: 牧马人 * DateTime: 2020-04-14 9:30 * Desc:进行curl请求,并将获取到的数据进行数组转换 * @param $page * @param $page_size * @param $start_time * @param $end_time * @param $signature * @return mixed */ private function curl($page,$page_size,$start_time,$end_time,$signature){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->host.$this->pull_route. '?page='.$page.'&page_size='.$page_size. '&start_time='.$start_time.'&end_time='.$end_time); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-Signature:'.$signature, 'Accept:application/json', 'Content-Type:application/json', )); $output = curl_exec($ch); curl_close($ch); return json_decode($output,true); } /** * User: 牧马人 * DateTime: 2020-04-14 9:30 * Desc:插入到数据库 * @param $data */ private function insertdata($data){ $ajaxModel = new AjaxCommon(); foreach ($data as $value){ //尝试获取城市id $city = M('Cities')->where("name='".$value['tel_location']."' and level = 1")->getField('cityid'); if (!$city){ $province = 3; $city = 978; }else{ //如果获取到城市id,再请求获取到省份id $province = M('Cities')->where("name='".$value['tel_location']."' and level = 1")->getField('parentid'); } $array['province'] = $province; //省id $array['city'] = $city; //市id $array['name'] = $value['leads_name']; //客户名称 $array['mobilephone'] = $value['leads_tel'];//客户手机号码 $array['isBuried'] = 2; //提交方式 $array['furniture'] = 0; //所选的家具 $array['original_time'] = strtotime($value['leads_create_time']); $res = $ajaxModel->tenderSave(array(),'add',0,array(),1,$array); if ($res['state']!='success'){ continue; } //添加utm if ($res['bid']&&$res['cid']){ $data['utm'] = $value['adgroup_name']; $data['dateline'] = time(); $data['id'] = $res['cid']; $data['idtype'] = 'zhaobiao'; $utmRet = M('Utm')->add($data); if (!$utmRet){ continue; } } } }} Share