当前位置: 首页 » 标签:京东

京东联盟新版API接口PHP版的坑

京东联盟新版API接口的坑,PHP版,其他版本不会!今天测试了下京东联盟的API,新版看起来和淘宝很像了,操作起来应该很容易!下载SDK,SDK已经封装了好了,就不用自己去封装拼接!看了一下,有composer.json文件,想着可能需要composer install一下,最后出错了,这一点比较喜欢拼多多的API接口,里面直接就有调用demo。composer install之后可以配置下APIKEY就可以直接访问!得,出错了就自己来,进入jd,接口和阿里妈妈的API接口结构很像合并下JdClient.php和RequestCheckUtil.php(习惯尽量将文件合并,以免有太多的include)测试下jd.union.open.promotion.common.get接口,查看下文档示例$c = new JdClient();$c->appKey = appKey;$c->appSecret = appSecret;$c->accessToken = accessToken;$c->serverUrl = SERVER_URL;$req = new UnionOpenPromotionCommonGetRequest();$promotionCodeReq= new PromotionCodeReq;$req->setPromotionCodeReq($promotionCodeReq);$req->setVersion("1.0");$resp = $c->execute($req, $c->accessToken);修改下,像token不需要,version不需要就删除!调整完是include "______Config/config.php";//apikey配置文件include "______API/JdClient.php";//请求文件include "______API/request/UnionOpenGoodsJingfenQueryRequest.php";//接口参数include "______API/request/domain/UnionOpenGoodsJingfenQuery/GoodsReq.php";//接口参数$c = new JdClient();$c->appKey = $ApiConfig["AppKey"];$c->appSecret = $ApiConfig["AppSecret"];$req = new UnionOpenGoodsJingfenQueryRequest();$goodsReq= new GoodsReq;$goodsReq->setEliteId(1);$req->setGoodsReq($goodsReq);$resp = $c->execute($req);print_r($resp);竟然出错,错误代码400参数错误! 调试接口https://api.jd.com/routerjson?access_token=&app_key=27cb4b7af2e42be76ed0a395b6584bbc&method=jd.union.open.goods.jingfen.query&v=1.0&sign=C242FFD55C46C50E172D1FA27DE93F79&360buy_param_json=%7B%22goodsReq%22%3A%7B%22eliteId%22%3A1%7D%7D×tamp=2021-09-08+14%3A17%3A06.166%2B0800urldecode后https://api.jd.com/routerjson?access_token=&app_key=27cb4b7af2e42be76ed0a395b6584bbc&method=jd.union.open.goods.jingfen.query&v=1.0&sign=C242FFD55C46C50E172D1FA27DE93F79&360buy_param_json={"goodsReq":{"eliteId":1}}&timestamp=2021-09-08 14:17:06.166+0800尝试直接接入参数,不用GoodsReq类include "______Config/config.php";//apikey配置文件include "______API/JdClient.php";//请求文件include "______API/request/UnionOpenGoodsJingfenQueryRequest.php";//接口参数$c = new JdClient();$c->appKey = $ApiConfig["AppKey"];$c->appSecret = $ApiConfig["AppSecret"];$req = new UnionOpenGoodsJingfenQueryRequest();$goodsReq= array();$goodsReq["eliteId"]=1;$req->setGoodsReq($goodsReq); //$req->setGoodsReq(json_encode($goodsReq)); 原先用json,一样出错!$resp = $c->execute($req);print_r($resp);最后终于调试成功!被官方的示例折腾了一个多小时笔记4个月前
零分站龄5个月资深站长
一个喜欢折腾,却又折腾不出像样东西的,不会PHP的PHP程序员!
323
文章
8
分类
125
标签
2
友链
onlinelovesky317355746vipsever@vip.qq.com