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

PHP源码 京东联盟API接口,转链+cha询订单,cha询推广位@TOC

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

JdClient.php

<?php
class JdClient{
        public $AppKey = '你的AppKey';
        public $AppSecret = '你的appsecret';
        public $url = 'https://api.m.jd.com/api?functionId=unionOpenMngApiDemo&appid=unionpc&body=';
        /* 成员变量 */
          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:https://union.jd.com/");               
                // $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:https://union.jd.com/");               
                // $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:https://union.jd.com/");               
                // $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

<?php
include('./class/JdClient.php');
$c = new jd_union_open_promotion_byunionid_get();
$c->SetMaterialId('https://u.jd.com/G85ARu9');
$c->SetUnionId('你的联盟ID');
$c->SetPositionId('推广位ID');
$resp = $c->GetResult();
echo $resp;

3、订单查询demo

<?php
include('./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

<?php
include('./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>";

做好的demo网址,仅供参考,请勿调用,里面的联盟ID和推广位ID都是我的

①转链demo网址
link
②查询订单demo网址
link
③查询推广位demo网址
link

交流QQ群:589231594

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

莫生灬灬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值