京东联盟Python接口测试Demo

By | 2017年12月27日

京东联盟的Python接口下载地址: jos-python-open-api-sdk-2.0.zip

这里是基于python 2.x的demo。

1)初始化

def setDefaultAppInfo():
  jd.setDefaultAppInfo("APPKEY", "APPSECRET")

2)获取商品信息

def getgoodsInfo(gid):
  goodsInfoRequest = ServicePromotionGoodsInfoRequest()
  goodsInfoRequest.skuIds =gid
  try:
    resp = goodsInfoRequest.getResponse("TOKEN")
    result = resp['jingdong_service_promotion_goodsInfo_responce']['getpromotioninfo_result']
    resp = json.loads(result)
    if len(resp['result']) == 0:
      print(u"没有找到商品信息")
    else:
      result = resp['result'][0]
      print(u"商品ID:"+str(result["skuId"]))
      print(u"商品名称:"+result["goodsName"])
      print(u"PC价格:"+str(result["unitPrice"]))
      print(u"WL价格:"+str(result["wlUnitPrice"]))
      print(u"PC比率:"+str(result["commisionRatioPc"]))
      print(u"WL比率:"+str(result["commisionRatioWl"]))
      print(u"商品图片"+str(result["imgUrl"]))
  except Exception as e:
    print(e)

3)获取商品返现链接地址

def getCode(gid):
    promotionGetcodeRequest = ServicePromotionGetcodeRequest()
    promotionGetcodeRequest.promotionType = 7
    promotionGetcodeRequest.materialId = "http://item.jd.com/"+str(gid)+".html"
    promotionGetcodeRequest.unionId = "UNIONID"
    promotionGetcodeRequest.channel = "PC"
    promotionGetcodeRequest.webId = "WEBID"
    try:
        resp = promotionGetcodeRequest.getResponse("TOKEN")
        result = resp['jingdong_service_promotion_getcode_responce']['queryjs_result']
        result = json.loads(result)
        print(u"返现地址:"+str(result['url']))
    except Exception as  e:
       print(e)

4)demo预览

5)文件下载:

jd-sdk-python-demo