|
@@ -0,0 +1,38 @@
|
|
|
+'use strict';
|
|
|
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
|
+const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
+const _ = require('lodash');
|
|
|
+const assert = require('assert');
|
|
|
+const crypto = require('crypto');
|
|
|
+
|
|
|
+class Kd100Service extends CrudService {
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx, 'kd100');
|
|
|
+ this.httpUtil = this.ctx.service.util.httpUtil;
|
|
|
+ this.kd100Api = 'https://poll.kuaidi100.com/poll/query.do';
|
|
|
+ }
|
|
|
+
|
|
|
+ async search({ no, type }) {
|
|
|
+ const customer = '5EC65D1966B410C333013563B7156AEE';
|
|
|
+ const key = 'jrwohIUD2299';
|
|
|
+ const param = { com: type, num: no };
|
|
|
+ const md5Str = `${JSON.stringify(param)}${key}${customer}`;
|
|
|
+ const sign = _.toUpper(await this.getSign(md5Str));
|
|
|
+ const body = { customer, sign, param: JSON.stringify(param) };
|
|
|
+ console.log(body);
|
|
|
+ const res = await this.ctx.curl(this.kd100Api, {
|
|
|
+ method: 'POST',
|
|
|
+ data: body,
|
|
|
+ dataType: 'json',
|
|
|
+ contentType: 'application/x-www-form-urlencoded',
|
|
|
+ });
|
|
|
+ if (res.status === 200) return res.data;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getSign(data) {
|
|
|
+ const md5 = crypto.createHash('md5');
|
|
|
+ return md5.update(data).digest('hex');
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = Kd100Service;
|