龙空技术网

PHP源码之京东联盟API接口,转链查询订单推广位

伊可泳衣 66

前言:

如今姐妹们对“php订单系统源码”大概比较注意,我们都想要知道一些“php订单系统源码”的相关文章。那么小编在网摘上搜集了一些对于“php订单系统源码””的相关知识,希望兄弟们能喜欢,姐妹们一起来学习一下吧!

PHP源码之京东联盟API接口,转链查询订单推广位

1、class源码,注意替换AppKey和appsecret

JdClient.php

<?phpclass JdClient{        public $AppKey = '你的AppKey';        public $AppSecret = '你的appsecret';        public $url = ';;        /* 成员变量 */          var $date;          var $Name;                    var $RequestUrl;                    var $HeadArray;                            /* 成员函数 */        function SetDate($Array){                $this->data = json_encode($Array);        }        function SetApiName($Name){                $this->ApiName = $Name;        }        function SetRequestUrl($url){                $this->RequestUrl = $url;        }        function SetHeaderArray($HeadArray){                $this->HeadArray = $HeadArray;        }        function curl_get(){                // 创建一个新cURL资源                $ch = curl_init();                // echo 'crul中调用的url:'.$this->RequestUrl;echo PHP_EOL;                // 设置URL和相应的选项                curl_setopt($ch, CURLOPT_URL, $this->RequestUrl);                //设置头文件的信息作为数据流输出                curl_setopt($ch, CURLOPT_HEADER, 0);                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置成 1 的时候,页面是没有输出内容的                curl_setopt($ch,CURLOPT_HTTPHEADER,$this->HeadArray);                /**禁止证书验证防止curl输出空白**/                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//禁止 cURL 验证对等证书                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//是否检测服务器的域名与证书上的是否一致                // 抓取URL并把它传递给浏览器                $res = curl_exec($ch);                               // 关闭cURL资源,并且释放系统资源                curl_close($ch);                return $res;        }       }//工具商获取推广链接class jd_union_open_promotion_byunionid_get extends JdClient{        var $materialId;//推广物料url        var $unionId;        var $positionId;                       private $private = 'Private';               function SetMaterialId($string){                $this->materialId = urlencode($string);        }        function SetUnionId($string){                $this->unionId = $string;        }        function SetPositionId($string){                $this->positionId = $string;        }        function GetResult(){                // echo 'GetResult中的materialId:'.$this->materialId;echo PHP_EOL;                $Array['businessParam'] = array(                        "materialId"=>$this->materialId,                        "unionId"=>$this->unionId,                        "positionId"=>$this->positionId                        );                $Array['apiName'] = 'jd.union.open.promotion.byunionid.get';                $Array['appKey'] = $this->AppKey;                $Array['appSecret'] = $this->AppSecret;                $data = json_encode($Array,JSON_UNESCAPED_SLASHES);                $request_url = $this->url.urlencode($data);                $header_array = array("referer:;);                               // $GoodsList = curl_get($request_url, $header_array);                $a = new JdClient();                $a->SetRequestUrl($request_url);                $a->SetHeaderArray($header_array);                $GoodsList = $a->curl_get();                $GoodsList = json_decode($GoodsList);//json_decode() 将json格式的数据转换为对象,数组,转换为数组要加true                $tgurl=json_decode(json_decode($GoodsList->data->result)->jd_union_open_promotion_byunionid_get_responce->getResult)->data->shortURL;                return $tgurl;        }}//订单行查询接口class jd_union_open_order_row_query extends JdClient{        var $pageIndex;//推广物料url        var $pageSize;        var $type;        var $startTime;        var $endTime;        var $key;                       private $private = 'Private';               function SetPageIndex($string){                $this->pageIndex = urlencode($string);        }        function SetPageSize($string){                $this->pageSize = $string;        }        function SetType($string){                $this->type = $string;        }        function SetStartTime($string){                $this->startTime = rawurlencode($string);        }        function SetEndTime($string){                $this->endTime = rawurlencode($string);        }        function SetKey($string){                $this->key = $string;        }        function GetResult(){                // echo 'GetResult中的materialId:'.$this->materialId;echo PHP_EOL;                $Array['businessParam'] = array(                        "pageIndex"=>$this->pageIndex,                        "pageSize"=>$this->pageSize,                        "type"=>$this->type,                        "startTime"=>$this->startTime,                        "endTime"=>$this->endTime,                        "key"=>$this->key                        );                $Array['apiName'] = 'jd.union.open.order.row.query';                $Array['appKey'] = $this->AppKey;                $Array['appSecret'] = $this->AppSecret;                $data = json_encode($Array,JSON_UNESCAPED_SLASHES);                $request_url = $this->url.urlencode($data);                $header_array = array("referer:;);                               // $GoodsList = curl_get($request_url, $header_array);                $a = new JdClient();                $a->SetRequestUrl($request_url);                $a->SetHeaderArray($header_array);                $GoodsList = $a->curl_get();                $GoodsList = json_decode($GoodsList);//json_decode() 将json格式的数据转换为对象,数组,转换为数组要加true                $tgurl=json_decode(json_decode($GoodsList->data->result)->jd_union_open_order_row_query_responce->queryResult)->data;                return $tgurl;//array的json        }}//查询推广位class jd_union_open_position_query extends JdClient{        var $unionId;//推广物料url        var $key;        var $unionType;//3:私域推广位,上限5000个,不在联盟后台展示,无对应 PID;4:联盟后台推广位,上限500个,会在推客联盟后台展示,可用于内容平台推广        var $pageIndex;        var $pageSize;                       private $private = 'Private';               function SetUnionId($string){                $this->unionId = $string;        }        function SetKey($string){                $this->key = $string;        }        function SetUnionType($string){                $this->unionType = $string;        }        function SetPageIndex($string){                $this->pageIndex = $string;        }        function SetPageSize($string){                $this->pageSize = $string;        }        function GetResult(){                // echo 'GetResult中的materialId:'.$this->materialId;echo PHP_EOL;                $Array['businessParam'] = array(                        "unionId"=>$this->unionId,                        "key"=>$this->key,                        "unionType"=>$this->unionType,                        "pageIndex"=>$this->pageIndex,                        "pageSize"=>$this->pageSize                        );                $Array['apiName'] = 'jd.union.open.position.query';                $Array['appKey'] = $this->AppKey;                $Array['appSecret'] = $this->AppSecret;                $data = json_encode($Array,JSON_UNESCAPED_SLASHES);                $request_url = $this->url.urlencode($data);                $header_array = array("referer:;);                               // $GoodsList = curl_get($request_url, $header_array);                $a = new JdClient();                $a->SetRequestUrl($request_url);                $a->SetHeaderArray($header_array);                $GoodsList = $a->curl_get();                $GoodsList = json_decode($GoodsList);//json_decode() 将json格式的数据转换为对象,数组,转换为数组要加true                $tgurl=json_decode(json_decode($GoodsList->data->result)->jd_union_open_position_query_responce->queryResult)->data->result;                return $tgurl;//array的json        }}
2、转链demo
<?phpinclude('./class/JdClient.php');$c = new jd_union_open_promotion_byunionid_get();$c->SetMaterialId(';);$c->SetUnionId('你的联盟ID');$c->SetPositionId('推广位ID');$resp = $c->GetResult();echo $resp;
3、订单查询demo
<?phpinclude('./class/JdClient.php');$c = new jd_union_open_order_row_query();$c->SetPageIndex('1');//页数$c->SetPageSize('500');//一页多少数量$c->SetType('1');//1下单时间$c->SetStartTime('2021-06-28 22:00:00');$c->SetEndTime('2021-06-28 23:00:00');$c->SetKey('推客的授权key');$resp = $c->GetResult();echo "<pre>";print_r($resp);echo "<pre>";
4、查询推广位demo
<?phpinclude('./class/JdClient.php');$c = new jd_union_open_position_query();$c->SetUnionId('联盟ID');$c->SetKey('<span style="color: rgb(96, 98, 102); font-family: -apple-system-font, " helvetica="" neue",="" sans-serif;="" background-color:="" rgb(245,="" 247,="" 250);"="">推客的授权key</span>');$c->SetUnionType('4');$c->SetPageIndex('1');$c->SetPageSize('100');$resp = $c->GetResult();echo "<pre>";print_r($resp);echo "<pre>";

标签: #php订单系统源码 #php订单源码