1 | <h1 align="center">
|
2 | <b>
|
3 | <a href="https://github.com/Blue-Island-X"><img style="width:128px;" src="https://raw.githubusercontent.com/Blue-Island-X/Island-Union-SDK/main/resource/logo.png" /></a><br>
|
4 | </b>
|
5 | </h1>
|
6 |
|
7 | <p align="center">小蓝岛购物平台联盟聚合 SDK</p>
|
8 |
|
9 | <div align="center">
|
10 |
|
11 | [![npm version](https://img.shields.io/npm/v/@blueislandx/island-union-sdk.svg?style=flat-square)](https://www.npmjs.org/package/@blueislandx/island-union-sdk)
|
12 | [![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=@blueislandx/island-union-sdk&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.now.sh/result?p=@blueislandx/island-union-sdk)
|
13 | [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@blueislandx/island-union-sdk?style=flat-square)](https://bundlephobia.com/package/@blueislandx/island-union-sdk@latest)
|
14 | [![npm downloads](https://img.shields.io/npm/dm/@blueislandx/island-union-sdk.svg?style=flat-square)](https://npm-stat.com/charts.html?package=@blueislandx/island-union-sdk)
|
15 | [![Known Vulnerabilities](https://snyk.io/test/npm/@blueislandx/island-union-sdk/badge.svg?style=flat-square)](https://snyk.io/test/npm/@blueislandx/island-union-sdk)
|
16 |
|
17 | </div>
|
18 |
|
19 | 本 SDK 支持以下购物平台联盟:
|
20 | - [淘宝联盟](https://aff-open.taobao.com) [HMAC-SHA256]
|
21 | - [京东联盟](https://union.jd.com)
|
22 | - [多多进宝](https://jinbao.pinduoduo.com)
|
23 | - [苏宁联盟](https://sums.suning.com)
|
24 | - [唯品会联盟](https://union.vip.com) [HMAC-MD5]
|
25 | - [考拉联盟](https://pub.kaola.com)
|
26 | - [有赞联盟](https://www.youzan.com/intro/zanke) [N/A]
|
27 |
|
28 | > P.S: 若没有特别标注, 所有签名算法均使用 [MD5](https://en.wikipedia.org/wiki/MD5) 实现
|
29 |
|
30 | ## 1.如何安装
|
31 | ```
|
32 | npm i @blueislandx/island-union-sdk --save
|
33 | ```
|
34 |
|
35 | ## 2.如何使用
|
36 | - 1.淘宝联盟 [文档](https://open.taobao.com/api.htm?docId=24518&docType=2)
|
37 | ```TypeScript
|
38 | import union from '@blueislandx/island-union-sdk';
|
39 |
|
40 | const client = new union.taobao.Client({
|
41 | appKey: '<你的 AppKey>',
|
42 | secretKey: '<你的 SecretKey>'
|
43 | });
|
44 |
|
45 | const result = await client.execute('<API 方法名称>', { <业务参数> });
|
46 | ```
|
47 |
|
48 | > P.S: 淘宝联盟接口必须传入字符 id, 数字 id 已经下线无法使用
|
49 |
|
50 | - 2.京东联盟 [文档](https://union.jd.com/openplatform/api/v2)
|
51 | ```TypeScript
|
52 | import union from '@blueislandx/island-union-sdk';
|
53 |
|
54 | const client = new union.jd.Client({
|
55 | appKey: '<你的 AppKey>',
|
56 | secretKey: '<你的 SecretKey>'
|
57 | });
|
58 |
|
59 | const result = await client.execute('<API 方法名称>', { <业务参数> });
|
60 | ```
|
61 |
|
62 | - 3.多多进宝 [文档](https://open.pinduoduo.com/application/document/api?id=pdd.ddk.goods.pid.generate)
|
63 |
|
64 | ```TypeScript
|
65 | import union from '@blueislandx/island-union-sdk';
|
66 |
|
67 | const client = new union.pinduoduo.Client({
|
68 | appKey: '<你的 ClientId>',
|
69 | secretKey: '<你的 ClientSecret>'
|
70 | });
|
71 |
|
72 | const result = await client.execute('<API 方法名称>', { <业务参数> });
|
73 | ```
|
74 |
|
75 | > P.S: 多多进宝接口必须传入 goods_sign (字符 id), goods_id (数字 id) 已经下线无法使用
|
76 |
|
77 | - 4.苏宁联盟 [文档](https://open.suning.com/ospos/apipage/toApiMethodDetailMenuNew.do?bustypeId=3)
|
78 |
|
79 | ```TypeScript
|
80 | import union from '@blueislandx/island-union-sdk';
|
81 |
|
82 | const client = new union.suning.Client({
|
83 | appKey: '<你的 AppKey>',
|
84 | secretKey: '<你的 AppSecret>'
|
85 | });
|
86 |
|
87 | const result = await client.execute('<API 方法名称>', { <业务参数> });
|
88 | ```
|
89 |
|
90 | - 5.唯品会联盟 [文档](https://vop.vip.com/home#/api/service/list/2)
|
91 |
|
92 | ```TypeScript
|
93 | import union from '@blueislandx/island-union-sdk';
|
94 |
|
95 | const client = new union.vip.Client({
|
96 | appKey: '<你的 AppKey>',
|
97 | secretKey: '<你的 AppSecret>'
|
98 | });
|
99 |
|
100 | const result = await client.execute('<API 服务名称>', '<API 服务版本>', '<API 方法名称>', { <业务参数> });
|
101 | ```
|
102 |
|
103 | - 6.考拉联盟 [文档](https://kaola-haitao.oss.kaolacdn.com/a5b08dbc-e7ae-4464-9d5d-e55cdc78f121.docx?spm=a2v0d.b9947081.0.0.12fc2fbc2WT1tV&file=a5b08dbc-e7ae-4464-9d5d-e55cdc78f121.docx)
|
104 | ```TypeScript
|
105 | import union from '@blueislandx/island-union-sdk';
|
106 |
|
107 | const client = new union.kaola.Client({
|
108 | secretKey: '<你的 AppSecret>',
|
109 | unionId: '<你的赚客 Id>'
|
110 | });
|
111 |
|
112 | const result = await client.execute('<API 接口名称>', { <业务参数> });
|
113 | ```
|
114 |
|
115 | - 7.有赞联盟 [文档](https://doc.youzanyun.com/list/API/1303) [指南](https://shimo.im/docs/tTwjdRYDcHvDdvQ9/read)
|
116 | ```TypeScript
|
117 | import union from '@blueislandx/island-union-sdk';
|
118 |
|
119 | const client = new union.youzan.Client({
|
120 | appKey: '<你的 AppKey>',
|
121 | secretKey: '<你的 AppSecret>',
|
122 | grantId: '<你的有赞客 Id>'
|
123 | });
|
124 |
|
125 | const result = await client.execute('<API 接口名称>', '<API 接口版本>', { <业务参数> });
|
126 | ```
|
127 |
|
128 | ## 3.错误处理
|
129 |
|
130 | 如果 SDK 请求错误会返回如下格式:
|
131 | ```JSON
|
132 | {
|
133 | "code": <错误代码>,
|
134 | "message": "<错误信息>",
|
135 | "error": true
|
136 | }
|
137 | ```
|
138 |
|
139 | > P.S: 判断一个请求是否失败, 请使用 ``error`` 字段而不是使用 ``code`` 字段
|
140 |
|
141 | > P.S: 错误代码 **不一定** 是整数类型, 请不要 ``parseInt``, SDK 内部已经对字符串的数字进行了处理
|
142 |
|
143 | ## 4.重大变更
|
144 |
|
145 | 自 ``1.1.0`` 起, 导入名称由 ``island`` 改为 ``union``
|
146 |
|
147 | > P.S: 该改动是由于公司内部业务模块化, 全部使用 ``island`` 会导致混乱 |
\ | No newline at end of file |