wordpress短代码转php,WordPress短代码实现京东推广自动转链

//京东推广短代码

//https://www.daimadog.com/6955.html

function dmd_jd_tg($array,$content)

{

$url=gettgurl($content);

if(!$url){

$url=$content;

} return $url;

}

add_shortcode('dmdtg', 'dmd_jd_tg');

//https://www.daimadog.com/6915.html

//京东联盟api签名

functionsign_method($method,$data=array(),$secretkey){date_default_timezone_set("PRC");$sign_method=array(

'app_key'=> '你的appkey',

'timestamp'=>date('Y-m-d H:i:s'),

'format' => 'json',

'method' =>$method,

'v' => '1.0',

'sign_method'=>'md5',

);$sign_method=array_merge($sign_method,$data);ksort($sign_method);$data=$secretkey;

foreach ($sign_methodas$key=>$value) {$data.=trim($key) .trim($value);

}$data.=$secretkey;$sign_method['sign'] =strtoupper(md5($data));

return$sign_method;

}//https://www.daimadog.com/6915.html

//京东联盟api推广转链

functiongettgurl($tgurl){$url='https://router.jd.com/api';$method='jd.union.open.promotion.common.get';$secretkey='你的secretkey';$param=array();$data['promotionCodeReq'] =array('materialId'=>$tgurl,'siteId'=>'你的站点ID');$param['param_json'] =json_encode($data);$GoodsList=sign_method($method,$param,$secretkey);$GoodsList=curl_post('https://router.jd.com/api',$GoodsList);$GoodsList=json_decode($GoodsList);$code=json_decode($GoodsList->jd_union_open_promotion_common_get_response->result)->code;if($code==200){

$tgurl=json_decode($GoodsList->jd_union_open_promotion_common_get_response->result)->data->clickURL;

}

return$tgurl;

}

// post请求

function curl_post($url, $curlPost)

{

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_REFERER, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

$result = curl_exec($ch);

curl_close($ch);

return $result;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值