吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3264|回复: 13
收起左侧

[已解决] 京东联盟 Python sdk

  [复制链接]
zucker 发表于 2022-3-22 11:12
110吾爱币
本帖最后由 zucker 于 2022-3-28 14:41 编辑

已自己解决

图片.png

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

wanglf326 发表于 2022-3-22 11:21
京东联盟不是有自己网页可以查看吗
 楼主| zucker 发表于 2022-3-22 11:31
wanglf326 发表于 2022-3-22 11:21
京东联盟不是有自己网页可以查看吗

不开网页解决,就是sdk的作用
sa123456sc 发表于 2022-3-22 12:07
/**
     * 根据传入的链接获取返回的JDResult
     * @Param url
     * @return
     */
    public static JDResult getShare(String url) throws JdException {
        String skuid = getSkuidByUrl(url);
        if(skuid.equals("-1")){//表示skuid不存在,有可能是因为网址错误
            return JDResult.error4JD(url,"请检查链接是否为京东的购物链接");
        }else{
            JDResult jdResult = getDetailBySkuid(skuid);
            if(((Integer) jdResult.get("code"))==0){//返回的是正确的,有优惠的
                jdResult.put("url",getShareUrl(url));
            }
            return jdResult;
        }
    }
    /**
     * 根据传入的url获取推广的链接(长地址),如果返回值为“-1”,代表失败。
     * @param url   https://item.jd.com/100005239235.html
     * @return
     * @throws JdException
     */
    public static String getShareUrl(String url) throws JdException {
        DefaultJdClient client=new DefaultJdClient(SERVER_URL,accessToken,appKey,appSecret);
        UnionOpenPromotionCommonGetRequest  request=new UnionOpenPromotionCommonGetRequest ();
        PromotionCodeReq promotionCodeReq =new PromotionCodeReq();
        promotionCodeReq.setMaterialId(url);
        promotionCodeReq.setSiteId(siteId);
        request.setPromotionCodeReq(promotionCodeReq);
        UnionOpenPromotionCommonGetResponse  response=client.execute(request);
        if(response.getCode()==200){
            return response.getData().getClickURL();
        }else{
            return "-1";
        }
    }
    /**
     * 通过url获取skuid。-1表示skuid不存在,有可能是因为网址错误
     * @param url
     * @return
     */
    public static String getSkuidByUrl(String url){
        String result="-1";
        String regex = "[0-9]+.html";//匹配规则
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(url);
        while(matcher.find()) {
            result=matcher.group(0).substring(0,matcher.group(0).indexOf(".html"));
        }
        return result;
    }

    /**
     * 根据传入的商品ID返回一个抢购数组。
     *  code :code为0,表示有优惠,code为-1,表示无优惠
     *  imgUrl:图片地址(code为0时才有)
     *  goodsName:商品名称(code为0时才有)
     *  unitPrice:商品价格(code为0时才有)
     *  commission:预估佣金(code为0时才有)
     *  url:原始商品地址(code为-1时才有)
     * @param skuid 商品ID
     * @return
     * @throws JdException
     */
    public static JDResult  getDetailBySkuid(String skuid) throws JdException {
        DefaultJdClient client=new DefaultJdClient(SERVER_URL,accessToken,appKey,appSecret);
        UnionOpenGoodsPromotiongoodsinfoQueryRequest request=new UnionOpenGoodsPromotiongoodsinfoQueryRequest();
        request.setSkuIds(skuid);
        UnionOpenGoodsPromotiongoodsinfoQueryResponse response=client.execute(request);
        if(response.getCode()==200){
            if(response.getMessage().equals("接口成功")){
                PromotionGoodsResp promotionGoodsResp=response.getData()[0];//每次只发一个,所以固定为0
                return JDResult.ok4JD(promotionGoodsResp.getImgUrl(),promotionGoodsResp.getGoodsName(),promotionGoodsResp.getUnitPrice(),promotionGoodsResp.getCommisionRatioWl()*promotionGoodsResp.getUnitPrice()/100,"");
            }else{
                return JDResult.error4JD("https://item.jd.com/"+skuid+".html","没有优惠信息");
            }
        }else{
            return JDResult.error4JD("https://item.jd.com/"+skuid+".html","没有优惠信息");
        }
    }
xzzdjoker 发表于 2022-3-22 12:11
不开网页解决,就是sdk的作用
rjx1155 发表于 2022-3-22 12:41
支持,来学习了
 楼主| zucker 发表于 2022-3-22 12:51
sa123456sc 发表于 2022-3-22 12:07
/**
     * 根据传入的链接获取返回的JDResult
     * @Param url

我要Python
a598656691 发表于 2022-3-22 15:32
不应该是京粉,淘宝联盟吗
唯爱三生 发表于 2022-3-22 15:50
写这个是用来做啥的呢
1024A1024 发表于 2022-3-22 17:10
没看懂,是说京东联盟的开放sdk有问题吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

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

GMT+8, 2024-3-29 19:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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