node-easywechat 3.5.20 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.6.0 (2024-03-16)
5
+
6
+ - Feat: 调整postJson请求参数,与easywechat一致;同时增加patchJson、postXml两个方法 (#69)
7
+
4
8
  ## v3.5.20 (2024-03-12)
5
9
 
6
10
  - Fix: 限制仅post请求才解析请求体
@@ -4,45 +4,62 @@ import HttpClientResponse from "../HttpClientResponse";
4
4
  declare class HttpClientMethodsMixin extends HttpClientInterface {
5
5
  /**
6
6
  * 发送get请求
7
- * @param url
8
- * @param payload
7
+ * @param url 请求地址
8
+ * @param payload axios配置项
9
9
  * @returns
10
10
  */
11
11
  get(url: string, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
12
12
  /**
13
13
  * 发送post请求
14
- * @param url
15
- * @param payload
14
+ * @param url 请求地址
15
+ * @param payload axios配置项
16
16
  * @returns
17
17
  */
18
18
  post(url: string, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
19
- /**
20
- * 发送post请求(JSON数据)
21
- * @param url
22
- * @param payload
23
- * @returns
24
- */
25
- postJson(url: string, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
26
19
  /**
27
20
  * 发送patch请求
28
- * @param url
29
- * @param payload
21
+ * @param url 请求地址
22
+ * @param payload axios配置项
30
23
  * @returns
31
24
  */
32
25
  patch(url: string, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
33
26
  /**
34
27
  * 发送put请求
35
28
  * @param url
36
- * @param payload
29
+ * @param payload axios配置项
37
30
  * @returns
38
31
  */
39
32
  put(url: string, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
40
33
  /**
41
34
  * 发送delete请求
42
35
  * @param url
43
- * @param payload
36
+ * @param payload axios配置项
44
37
  * @returns
45
38
  */
46
39
  delete(url: string, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
40
+ /**
41
+ * 发送post请求(JSON数据)
42
+ * @param url 请求地址
43
+ * @param data JSON对象
44
+ * @param payload axios配置项
45
+ * @returns
46
+ */
47
+ postJson(url: string, data: object, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
48
+ /**
49
+ * 发送patch请求(JSON数据)
50
+ * @param url 请求地址
51
+ * @param data JSON 对象
52
+ * @param payload axios配置项
53
+ * @returns
54
+ */
55
+ patchJson(url: string, data: object, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
56
+ /**
57
+ * 发送post请求(XML数据)
58
+ * @param url 请求地址
59
+ * @param data XML字符串 或 键值对
60
+ * @param payload axios配置项
61
+ * @returns
62
+ */
63
+ postXml(url: string, data: string | Record<string, any>, payload?: AxiosRequestConfig): Promise<HttpClientResponse>;
47
64
  }
48
65
  export = HttpClientMethodsMixin;
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  const HttpClientInterface_1 = __importDefault(require("../Contracts/HttpClientInterface"));
15
+ const merge_1 = __importDefault(require("merge"));
15
16
  class HttpClientMethodsMixin extends HttpClientInterface_1.default {
16
17
  /**
17
18
  * 发送get请求
18
- * @param url
19
- * @param payload
19
+ * @param url 请求地址
20
+ * @param payload axios配置项
20
21
  * @returns
21
22
  */
22
23
  get(url, payload = {}) {
@@ -26,8 +27,8 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
26
27
  }
27
28
  /**
28
29
  * 发送post请求
29
- * @param url
30
- * @param payload
30
+ * @param url 请求地址
31
+ * @param payload axios配置项
31
32
  * @returns
32
33
  */
33
34
  post(url, payload = {}) {
@@ -35,26 +36,10 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
35
36
  return this.request('post', url, payload);
36
37
  });
37
38
  }
38
- /**
39
- * 发送post请求(JSON数据)
40
- * @param url
41
- * @param payload
42
- * @returns
43
- */
44
- postJson(url, payload = {}) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (!payload)
47
- payload = {};
48
- if (!payload['headers'])
49
- payload['headers'] = {};
50
- payload['headers']['Content-Type'] = 'application/json';
51
- return this.request('post', url, payload);
52
- });
53
- }
54
39
  /**
55
40
  * 发送patch请求
56
- * @param url
57
- * @param payload
41
+ * @param url 请求地址
42
+ * @param payload axios配置项
58
43
  * @returns
59
44
  */
60
45
  patch(url, payload = {}) {
@@ -65,7 +50,7 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
65
50
  /**
66
51
  * 发送put请求
67
52
  * @param url
68
- * @param payload
53
+ * @param payload axios配置项
69
54
  * @returns
70
55
  */
71
56
  put(url, payload = {}) {
@@ -76,7 +61,7 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
76
61
  /**
77
62
  * 发送delete请求
78
63
  * @param url
79
- * @param payload
64
+ * @param payload axios配置项
80
65
  * @returns
81
66
  */
82
67
  delete(url, payload = {}) {
@@ -84,5 +69,59 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
84
69
  return this.request('delete', url, payload);
85
70
  });
86
71
  }
72
+ /**
73
+ * 发送post请求(JSON数据)
74
+ * @param url 请求地址
75
+ * @param data JSON对象
76
+ * @param payload axios配置项
77
+ * @returns
78
+ */
79
+ postJson(url, data, payload = {}) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ if (!payload)
82
+ payload = {};
83
+ if (!payload['headers'])
84
+ payload['headers'] = {};
85
+ payload['headers']['Content-Type'] = 'application/json';
86
+ payload.json = merge_1.default.recursive({}, data);
87
+ return this.request('post', url, payload);
88
+ });
89
+ }
90
+ /**
91
+ * 发送patch请求(JSON数据)
92
+ * @param url 请求地址
93
+ * @param data JSON 对象
94
+ * @param payload axios配置项
95
+ * @returns
96
+ */
97
+ patchJson(url, data, payload = {}) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ if (!payload)
100
+ payload = {};
101
+ if (!payload['headers'])
102
+ payload['headers'] = {};
103
+ payload['headers']['Content-Type'] = 'application/json';
104
+ payload.json = merge_1.default.recursive({}, data);
105
+ return this.request('patch', url, payload);
106
+ });
107
+ }
108
+ /**
109
+ * 发送post请求(XML数据)
110
+ * @param url 请求地址
111
+ * @param data XML字符串 或 键值对
112
+ * @param payload axios配置项
113
+ * @returns
114
+ */
115
+ postXml(url, data, payload = {}) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ if (!payload)
118
+ payload = {};
119
+ if (!payload['headers'])
120
+ payload['headers'] = {};
121
+ payload['headers']['Content-Type'] = 'text/xml';
122
+ payload.xml = typeof data === 'object' ? merge_1.default.recursive({}, data) : data;
123
+ return this.request('post', url, payload);
124
+ });
125
+ }
87
126
  }
88
127
  module.exports = HttpClientMethodsMixin;
@@ -66,7 +66,7 @@ class Client {
66
66
  }
67
67
  else {
68
68
  if (payload.xml) {
69
- if (Array.isArray(payload.xml)) {
69
+ if (typeof payload.xml === 'object') {
70
70
  payload.xml = (0, Utils_1.buildXml)(this.attachLegacySignature(payload.xml));
71
71
  }
72
72
  if (typeof payload.xml !== 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.5.20",
3
+ "version": "3.6.0",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {