今天为大家分享WordPress实现京东推广自动转链教程,有了它只需要填入推广链接即可自动转换为你的推广链接,方便快捷。有个缺点必须提前说明,此方法会请求京东联盟API,所以网页响应时间会延长一些,一般来讲速度都还可以接受,对网页打开速度有要求的就自己测试吧。

前面已经给大家分享过使用京东联盟API转链是如何实现的了,并且在很久之前就已经分享过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签名

function sign_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_method as $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推广转链

function gettgurl($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;

}

在文章或页面中使用只需要添加如下短代码即可:

[dmdtg]https://item.jd.com/100010572322.html[/dmdtg]

如果转链失败,链接将不会发生变化,所以在发布前请一定要自己预览一下,免得造成损失!

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部