UNPKG

7.44 kBJavaScriptView Raw
1'use strict';
2
3var util = require('./util');
4var wrapper = util.wrapper;
5var postJSON = util.postJSON;
6
7/**
8 * 增加邮费模板
9 * 详细请看:<http://mp.weixin.qq.com/wiki/8/703923b7349a607f13fb3100163837f0.html>
10 * Examples:
11 * ```
12 * api.addExpress(express, callback);
13 * ```
14 * Express:
15 * ```
16 * {
17 * "delivery_template": {
18 * "Name": "testexpress",
19 * "Assumer": 0,
20 * "Valuation": 0,
21 * "TopFee": [
22 * {
23 * "Type": 10000027,
24 * "Normal": {
25 * "StartStandards": 1,
26 * "StartFees": 2,
27 * "AddStandards": 3,
28 * "AddFees": 1
29 * },
30 * "Custom": [
31 * {
32 * "StartStandards": 1,
33 * "StartFees": 100,
34 * "AddStandards": 1,
35 * "AddFees": 3,
36 * "DestCountry": "中国",
37 * "DestProvince": "广东省",
38 * "DestCity": "广州市"
39 * }
40 * ]
41 * },
42 * {
43 * "Type": 10000028,
44 * "Normal": {
45 * "StartStandards": 1,
46 * "StartFees": 3,
47 * "AddStandards": 3,
48 * "AddFees": 2
49 * },
50 * "Custom": [
51 * {
52 * "StartStandards": 1,
53 * "StartFees": 10,
54 * "AddStandards": 1,
55 * "AddFees": 30,
56 * "DestCountry": "中国",
57 * "DestProvince": "广东省",
58 * "DestCity": "广州市"
59 * }
60 * ]
61 * },
62 * {
63 * "Type": 10000029,
64 * "Normal": {
65 * "StartStandards": 1,
66 * "StartFees": 4,
67 * "AddStandards": 3,
68 * "AddFees": 3
69 * },
70 * "Custom": [
71 * {
72 * "StartStandards": 1,
73 * "StartFees": 8,
74 * "AddStandards": 2,
75 * "AddFees": 11,
76 * "DestCountry": "中国",
77 * "DestProvince": "广东省",
78 * "DestCity": "广州市"
79 * }
80 * ]
81 * }
82 * ]
83 * }
84 * }
85 * ```
86 * Callback:
87 *
88 * - `err`, 调用失败时得到的异常
89 * - `result`, 调用正常时得到的对象
90 *
91 * Result:
92 * ```
93 * {
94 * "errcode": 0,
95 * "errmsg": "success"
96 * "template_id": 123456
97 * }
98 * ```
99 * @param {Object} express 邮费模版
100 * @param {Function} callback 回调函数
101 */
102exports.addExpressTemplate = function (express, callback) {
103 this.preRequest(this._addExpressTemplate, arguments);
104};
105
106/*!
107 * 增加邮费模板的未封装版本
108 */
109exports._addExpressTemplate = function (express, callback) {
110 var url = this.endpoint + '/merchant/express/add?access_token=' + this.token.accessToken;
111 this.request(url, postJSON(express), wrapper(callback));
112};
113
114/**
115 * 修改邮费模板
116 * 详细请看:<http://mp.weixin.qq.com/wiki/8/703923b7349a607f13fb3100163837f0.html>
117 * Examples:
118 * ```
119 * api.deleteExpressTemplate(templateId, callback);
120 * ```
121 * Callback:
122 *
123 * - `err`, 调用失败时得到的异常
124 * - `result`, 调用正常时得到的对象
125 *
126 * Result:
127 * ```
128 * {
129 * "errcode": 0,
130 * "errmsg": "success"
131 * }
132 * ```
133 * @param {Number} templateId 邮费模版ID
134 * @param {Function} callback 回调函数
135 */
136exports.deleteExpressTemplate = function (templateId, callback) {
137 this.preRequest(this._deleteExpressTemplate, arguments);
138};
139
140/*!
141 * 增加邮费模板的未封装版本
142 */
143exports._deleteExpressTemplate = function (templateId, callback) {
144 var data = {
145 template_id: templateId
146 };
147 var url = this.endpoint + '/merchant/express/del?access_token=' + this.token.accessToken;
148 this.request(url, postJSON(data), wrapper(callback));
149};
150
151/**
152 * 修改邮费模板
153 * 详细请看:<http://mp.weixin.qq.com/wiki/8/703923b7349a607f13fb3100163837f0.html>
154 * Examples:
155 * ```
156 * api.updateExpressTemplate(template, callback);
157 * ```
158 * Callback:
159 *
160 * - `err`, 调用失败时得到的异常
161 * - `result`, 调用正常时得到的对象
162 *
163 * Express:
164 * ```
165 * {
166 * "template_id": 123456,
167 * "delivery_template": ...
168 * }
169 * ```
170 * Result:
171 * ```
172 * {
173 * "errcode": 0,
174 * "errmsg": "success"
175 * }
176 * ```
177 * @param {Object} template 邮费模版
178 * @param {Function} callback 回调函数
179 */
180exports.updateExpressTemplate = function (template, callback) {
181 this.preRequest(this._updateExpressTemplate, arguments);
182};
183
184/*!
185 * 修改邮费模板的未封装版本
186 */
187exports._updateExpressTemplate = function (template, callback) {
188 var url = this.endpoint + '/merchant/express/del?access_token=' + this.token.accessToken;
189 this.request(url, postJSON(template), wrapper(callback));
190};
191
192/**
193 * 获取指定ID的邮费模板
194 * 详细请看:<http://mp.weixin.qq.com/wiki/8/703923b7349a607f13fb3100163837f0.html>
195 * Examples:
196 * ```
197 * api.getExpressTemplateById(templateId, callback);
198 * ```
199 * Callback:
200 *
201 * - `err`, 调用失败时得到的异常
202 * - `result`, 调用正常时得到的对象
203 *
204 * Result:
205 * ```
206 * {
207 * "errcode": 0,
208 * "errmsg": "success",
209 * "template_info": {
210 * "Id": 103312916,
211 * "Name": "testexpress",
212 * "Assumer": 0,
213 * "Valuation": 0,
214 * "TopFee": [
215 * {
216 * "Type": 10000027,
217 * "Normal": {
218 * "StartStandards": 1,
219 * "StartFees": 2,
220 * "AddStandards": 3,
221 * "AddFees": 1
222 * },
223 * "Custom": [
224 * {
225 * "StartStandards": 1,
226 * "StartFees": 1000,
227 * "AddStandards": 1,
228 * "AddFees": 3,
229 * "DestCountry": "中国",
230 * "DestProvince": "广东省",
231 * "DestCity": "广州市"
232 * }
233 * ]
234 * },
235 * ...
236 * ]
237 * }
238 * }
239 * ```
240 * @param {Number} templateId 邮费模版Id
241 * @param {Function} callback 回调函数
242 */
243exports.getExpressTemplateById = function (templateId, callback) {
244 this.preRequest(this._getExpressTemplateById, arguments);
245};
246
247/*!
248 * 获取指定ID的邮费模板的未封装版本
249 */
250exports._getExpressTemplateById = function (templateId, callback) {
251 var data = {
252 template_id: templateId
253 };
254 var url = this.endpoint + '/merchant/express/getbyid?access_token=' + this.token.accessToken;
255 this.request(url, postJSON(data), wrapper(callback));
256};
257
258/**
259 * 获取所有邮费模板的未封装版本
260 * 详细请看:<http://mp.weixin.qq.com/wiki/8/703923b7349a607f13fb3100163837f0.html>
261 * Examples:
262 * ```
263 * api.getAllExpressTemplates(callback);
264 * ```
265 * Callback:
266 *
267 * - `err`, 调用失败时得到的异常
268 * - `result`, 调用正常时得到的对象
269 *
270 * Result:
271 * ```
272 * {
273 * "errcode": 0,
274 * "errmsg": "success",
275 * "templates_info": [
276 * {
277 * "Id": 103312916,
278 * "Name": "testexpress1",
279 * "Assumer": 0,
280 * "Valuation": 0,
281 * "TopFee": [...],
282 * },
283 * {
284 * "Id": 103312917,
285 * "Name": "testexpress2",
286 * "Assumer": 0,
287 * "Valuation": 2,
288 * "TopFee": [...],
289 * },
290 * {
291 * "Id": 103312918,
292 * "Name": "testexpress3",
293 * "Assumer": 0,
294 * "Valuation": 1,
295 * "TopFee": [...],
296 * }
297 * ]
298 * }
299 * ```
300 * @param {Function} callback 回调函数
301 */
302exports.getAllExpressTemplates = function (callback) {
303 this.preRequest(this._getAllExpressTemplates, arguments);
304};
305
306/*!
307 * 获取所有邮费模板的未封装版本
308 */
309exports._getAllExpressTemplates = function (callback) {
310 var url = this.endpoint + '/merchant/express/getall?access_token=' + this.token.accessToken;
311 this.request(url, {dataType: 'json'}, wrapper(callback));
312};