//京东推广短代码
//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;
}