吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3709|回复: 20
收起左侧

求京东联盟php自动转链源码

[复制链接]
weihe 发表于 2020-4-1 13:49
201吾爱币
类似下面这样的,不过这是2015年的已经过期不能用了,有大佬能修改一下吗,不胜感激,可以加CB

<?php

$sourceurl = $_GET["u"];

if($sourceurl == ""){

  echo "error:请输入url参数";
  exit();
}

$method = "jingdong.service.promotion.getcode";
$channel = "PC";
$type = 7;
$unionId = "您的京东联盟ID";
$webId = "您在京东联盟注册的网站的ID";
$token = "您的Token";
$appkey = "您的APPKey";
$appSecret = "您的APPSecret";
$v = "2.0";
$time = date('Y-m-d H:i:s',time());

$baseurl = "https://api.jd.com/routerjson?";

//应用参数,json格式
$_360buy_param_json =
'{"channel":"'.$channel.'","materialId":"'.$sourceurl.'","promotionType":'.$type.',"unionId":"'.$unionId.'",
  "webId":"'.$webId.'"}';

//系统参数
$fields = [
    "360buy_param_json" => urlencode($_360buy_param_json),
    "access_token" => urlencode($token),
    "app_key" => urlencode($appkey),
    "method" => urlencode($method),
    "timestamp" => urlencode($time),
    "v" => urlencode($v)
];

$fields_string = "";

//用来计算md5,以appSecret开头
$_tempString = $appSecret;

foreach($fields as $key=>$value)
{
    //直接将参数和值拼在一起
    $_tempString .= $key.$value;
    //作为url参数的字符串
    $fields_string .= $key.'='.$value.'&';
}

//最后再拼上appSecret
$_tempString .= $appSecret;

//计算md5,然后转为大写,sign参数作为url中的最后一个参数
$sign = strtoupper(md5($_tempString));

//加到最后
$fields_string .= ("sign=".$sign);

//最终请求的url
$link = $baseurl.$fields_string;

//发送get请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

//转换为json
$jsonArray = json_decode($result,true);
$queryjs_result= $jsonArray["jingdong_service_promotion_getcode_responce"]["queryjs_result"];

$url = json_decode($queryjs_result,true);
echo urldecode($url["url"]);
?>
修改文件中的几个参数值,然后访问这个php文件,带上参数:u=京东链接(比如u=http://www.jd.com)。

最后页面将直接输出union打头的推广链接。

最佳答案

查看完整内容

// 备注:由于我没有app_key这个参数 这个需要各种审核 所以具体无法测试成功结果 你可填入自己的调试 但是我把错误结果都解决了 目前只有一个Key值错误的问题了 这个需要正确的 没办法了

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ZenHaBit 发表于 2020-4-1 13:49
本帖最后由 ZenHaBit 于 2020-4-1 17:56 编辑

// 备注:由于我没有app_key这个参数 这个需要各种审核 所以具体无法测试成功结果 你可填入自己的调试 但是我把错误结果都解决了 目前只有一个Key值错误的问题了 这个需要正确的 没办法了
<?php
// 具体参数可查看 https://union.jd.com/openplatform/api/10421 文档说明
error_reporting(0);
$sourceurl = $_GET["u"];
if($sourceurl == ""){
  echo "请传入url参数";
  exit();
}
$app_key='1';
$method = "jd.union.open.promotion.common.get";
$sign = "";
$timestamp = date('Y-m-d H:i:s',time());
$format = "json";
$v='1.0';
$sign_method='md5';
$sign='';
$promotionCodeReq=[
    'materialId'=>'',
    'siteId'=>''
];

$baseurl = "https://api.jd.com/routerjson?";

//业务参数
$_360buy_param_json =json_encode($promotionCodeReq);

//系统参数
$fields = [
    "app_key" => $app_key,
    "method" => urlencode($method),
    "timestamp" => urlencode($timestamp),
    "v" => urlencode($v),
    'format'=>$format,
    'sign_method'=>$sign_method,
    'sign'=>
];

$fields_string = "";

$_tempString='';

foreach($fields as $key=>$value)
{
    $_tempString .= $key.$value;
    $fields_string.= $key.'='.$value.'&';
}

$sign = strtoupper(md5($fields_string));

$fields_string .= ("sign=".$sign);

$link = $baseurl.$fields_string;
$result=curl_get($link);
$jsonArray = json_decode($result,true);
$error_result=$jsonArray['error_response'];
if(!empty($error_result)) {
    echo'获取失败';
    echo "\r\n";
    echo'失败原因:'.$error_result['zh_desc'];
    echo "\r\n";
    echo'Falit_MSG:'.$error_result['en_desc'];
}else
{
//    打印成功数据
    $success_result=$jsonArray['data'];
    echo '转换成功:'.$success_result['clickURL'];
}

function curl_get($url){

    $header = array(
        'Accept: application/json',
    );
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_TIMEOUT, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($curl);

    if (curl_error($curl)) {
        print "Error: " . curl_error($curl);
        return null;
    }
    return $data;
}

?>
浴火凤凰_2020 发表于 2020-4-1 14:27
所以现在的问题是什么?已经过期不能用,是这段代码有问题?还是京东的接口不能用了?
 楼主| weihe 发表于 2020-4-1 14:33
浴火凤凰_2020 发表于 2020-4-1 14:27
所以现在的问题是什么?已经过期不能用,是这段代码有问题?还是京东的接口不能用了?

大佬你好,是京东联盟接口改了不能用了,
这是新的API:https://union.jd.com/openplatform/api/10421
大佬您能修改吗,十分感激
浴火凤凰_2020 发表于 2020-4-1 15:10
weihe 发表于 2020-4-1 14:33
大佬你好,是京东联盟接口改了不能用了,
这是新的API:https://union.jd.com/openplatform/api/10421
...

1.你先把代码里必要的参数都补充完整。
2.代码以前不是我写的 我也不知道是获取什么的,
 楼主| weihe 发表于 2020-4-1 18:05
ZenHaBit 发表于 2020-4-1 17:54
// 备注:由于我没有app_key这个参数 这个需要各种审核 所以具体无法测试成功结果 你可填入自己的调试 但是 ...

厉害,谢谢大佬,我先测试一下哈
 楼主| weihe 发表于 2020-4-1 18:11
本帖最后由 weihe 于 2020-4-1 18:15 编辑
ZenHaBit 发表于 2020-4-1 17:54
// 备注:由于我没有app_key这个参数 这个需要各种审核 所以具体无法测试成功结果 你可填入自己的调试 但是 ...

大佬,刚刚试了一下,好像第35排报错了,我加了个逗号就可以了,然后提示获取失败 失败原因:签名参数不正确sign=(解决方案参考:http://open.jd.com/home/home#/doc/common?listId=533) Falit_MSG:Invalid Signature(Solution reference:http://open.jd.com/home/home#/doc/common?listId=533)
 楼主| weihe 发表于 2020-4-1 18:18
weihe 发表于 2020-4-1 18:11
大佬,刚刚试了一下,好像第35排报错了,我加了个逗号就可以了,然后提示获取失败 失败原因:签名参数不正 ...

然后我把sign=md5改了,提示Error: Operation timed out after 1016 milliseconds with 0 bytes received转换成功:
ZenHaBit 发表于 2020-4-1 20:50
weihe 发表于 2020-4-1 18:18
然后我把sign=md5改了,提示Error: Operation timed out after 1016 milliseconds with 0 bytes received ...

哦 我忘记 HTTPS的问题了

$curl = curl_init();

在这一行∧下面增加

curl_setopt($ch, CURLOPT_SSLVERSION, 3);

试试

 楼主| weihe 发表于 2020-4-1 21:17
ZenHaBit 发表于 2020-4-1 20:50
哦 我忘记 HTTPS的问题了

$curl = curl_init();

谢谢大佬,现在提示sign无效了。获取失败 失败原因:无效签名(解决方案参考:http://open.jd.com/home/home#/doc/common?listId=533) Falit_MSG:Invalid Signature(Solution reference:http://open.jd.com/home/home#/doc/common?listId=533)
返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-17 22:03

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表