前言
因为工作的原因,我头一次接触到了对接官方API,对接主要是针对B2C业务或者B2B、O2O这些,那话不多说上教程
你需要先去官方平台拿到appkey和appsecrt,苏宁开放平台:https://open.suning.com/
官方也有SDK文件,也可拿来参考,官方只有PHP和Java,下面是node.js版本
let appKey = your_appKey;
let appSecret = your_appSecret;
//对接的接口,这里示例是店铺API
let appMethod = "suning.custom.shopinfo.query";
//店铺API请求JSON格式
let params = "{
"sn_request": {
"sn_body": {
"queryShopinfo": {
"shopId": "your_shopId"
}
}
}
}"
//版本号
let versionNo = "v1.2";
let url, result, headers;
//获取当前时间 格式 Y-M-D h:m:s
var curTime = common.timeHelper.format();
加密秘钥 //请求报文base4加密
params_base64 = common.stringHelper.base64_encode(params);
//拼接起来去md5,32位大写,获取到加密秘钥
var signinfo = common.stringHelper.md5(appSecret + appMethod + curTime + appKey + versionNo + params_base64, "hex", false);
url = 'https://open.suning.com/api/http/sopRequest/' + appMethod;
请求头文件 headers = {
"Content-Type": "text/xml; charset=utf-8",
"AppMethod": appMethod,
"AppRequestTime": curTime,
"Format": "json",
"signInfo": signinfo,
"AppKey": appKey,
"VersionNo": versionNo,
"User-Agent": "suning-sdk-php",
"Sdk-Version": "suning-sdk-php-beta0.1"
};
// 拼接三个参数文件去请求
result = await common.httpHelper.json_normal(url, params, headers);
//转化为字符串输出
return common.stringHelper.json_encode(result);
};
https://www.pexels.com/zh-cn/collections/1379530-l47756n/
https://www.pexels.com/zh-cn/collections/1379530-f17napd/
https://www.pexels.com/zh-cn/collections/1379530-h8ytruy/
https://www.pexels.com/zh-cn/collections/1379530-8jblapw/
https://www.pexels.com/zh-cn/collections/1379530-rq09wrw/
https://www.pexels.com/zh-cn/collections/1379530-jjkewjv/
https://www.pexels.com/zh-cn/collections/1379530-bwriptj/
https://www.pexels.com/zh-cn/collections/1379530-tmawq1m/
https://www.pexels.com/zh-cn/collections/1379530-0sy22lm/
https://www.pexels.com/zh-cn/collections/1379530-yooiscz/
https://www.pexels.com/zh-cn/collections/1379530-dewn8cg/
https://www.pexels.com/zh-cn/collections/1379530-cgtat9t/
https://www.pexels.com/zh-cn/collections/1379530-9jdvtks/
https://www.pexels.com/zh-cn/collections/1379530-pevbeef/
https://infogram.com/1379530-1h7v4pdmyydjj4k?live
https://infogram.com/1379530-1h7v4pdmyy3xj4k?live
https://infogram.com/1379530-1h7v4pdmyy3784k?live
https://infogram.com/1379530-1hnp27exrr5py4g?live
https://infogram.com/1379530-1hnq41oxee31p23?live