Skip to content

Commit 679d218

Browse files
committed
fix: 钉钉小程序GET请求时data参数处理不正确
1 parent 85f7e11 commit 679d218

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

dist/index.aio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 1.0.0 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2022 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -151,7 +151,7 @@
151151
if (["alipay" /* 支付宝 */, "dd" /* 钉钉 */].includes(platFormName)) {
152152
config.headers = config.header;
153153
delete config.header;
154-
if ("dd" /* 钉钉 */ === platFormName && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a["Content-Type"]) === "application/json" && Object.prototype.toString.call(config.data) === '[object Object]') {
154+
if ("dd" /* 钉钉 */ === platFormName && config.method !== "GET" && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) === 'application/json' && Object.prototype.toString.call(config.data) === '[object Object]') {
155155
// Content-Type为application/json时,data参数只支持json字符串,需要手动调用JSON.stringify进行序列化
156156
config.data = JSON.stringify(config.data);
157157
}

dist/index.esm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 1.0.0 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2022 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -145,7 +145,7 @@ function transformConfig(config) {
145145
if (["alipay" /* 支付宝 */, "dd" /* 钉钉 */].includes(platFormName)) {
146146
config.headers = config.header;
147147
delete config.header;
148-
if ("dd" /* 钉钉 */ === platFormName && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a["Content-Type"]) === "application/json" && Object.prototype.toString.call(config.data) === '[object Object]') {
148+
if ("dd" /* 钉钉 */ === platFormName && config.method !== "GET" && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) === 'application/json' && Object.prototype.toString.call(config.data) === '[object Object]') {
149149
// Content-Type为application/json时,data参数只支持json字符串,需要手动调用JSON.stringify进行序列化
150150
config.data = JSON.stringify(config.data);
151151
}

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 1.0.0 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2022 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -149,7 +149,7 @@ function transformConfig(config) {
149149
if (["alipay" /* 支付宝 */, "dd" /* 钉钉 */].includes(platFormName)) {
150150
config.headers = config.header;
151151
delete config.header;
152-
if ("dd" /* 钉钉 */ === platFormName && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a["Content-Type"]) === "application/json" && Object.prototype.toString.call(config.data) === '[object Object]') {
152+
if ("dd" /* 钉钉 */ === platFormName && config.method !== "GET" && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) === 'application/json' && Object.prototype.toString.call(config.data) === '[object Object]') {
153153
// Content-Type为application/json时,data参数只支持json字符串,需要手动调用JSON.stringify进行序列化
154154
config.data = JSON.stringify(config.data);
155155
}

dist/miniprogram/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* axios-miniprogram-adapter 1.0.0 (https://github.com/bigMeow/axios-miniprogram-adapter)
2+
* axios-miniprogram-adapter 0.3.4 (https://github.com/bigMeow/axios-miniprogram-adapter)
33
* API https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/doc/api.md
44
* Copyright 2018-2022 bigMeow. All Rights Reserved
55
* Licensed under MIT (https://github.com/bigMeow/axios-miniprogram-adapter/blob/master/LICENSE)
@@ -680,7 +680,7 @@ function transformConfig(config) {
680680
if (["alipay" /* 支付宝 */, "dd" /* 钉钉 */].includes(platFormName)) {
681681
config.headers = config.header;
682682
delete config.header;
683-
if ("dd" /* 钉钉 */ === platFormName && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a["Content-Type"]) === "application/json" && Object.prototype.toString.call(config.data) === '[object Object]') {
683+
if ("dd" /* 钉钉 */ === platFormName && config.method !== "GET" && ((_a = config.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) === 'application/json' && Object.prototype.toString.call(config.data) === '[object Object]') {
684684
// Content-Type为application/json时,data参数只支持json字符串,需要手动调用JSON.stringify进行序列化
685685
config.data = JSON.stringify(config.data);
686686
}
@@ -765,4 +765,4 @@ function mpAdapter(config) {
765765
}
766766

767767
module.exports = mpAdapter;
768-
module.exports.default = mpAdapter;
768+
module.exports.default = mpAdapter;

src/utils/platForm.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function getRequest (): (option: WechatMiniprogram.RequestOption) => Wech
3131
* 支付宝客户端已不再维护 my.httpRequest,建议使用 my.request。另外,钉钉客户端尚不支持 my.request。若在钉钉客户端开发小程序,则需要使用 my.httpRequest。
3232
* my.httpRequest的请求头默认值为{'content-type': 'application/x-www-form-urlencoded'}。
3333
* my.request的请求头默认值为{'content-type': 'application/json'}。
34-
* 还有个 dd.httpRequest
34+
* 还有个 dd.httpRequest
3535
*/
36-
platFormName = EnumPlatForm.支付宝
36+
platFormName = EnumPlatForm.支付宝
3737
return (my.request || my.httpRequest).bind(my)
3838
default:
3939
return wx.request.bind(wx)
@@ -101,7 +101,7 @@ export function transformError (error:any, reject, config) {
101101
reject(createError('Network Error', config, null, '', error))
102102
}
103103
break
104-
case EnumPlatForm.百度:
104+
case EnumPlatForm.百度:
105105
// TODO error.errCode
106106
reject(createError('Network Error', config, null, ''))
107107
break
@@ -116,7 +116,7 @@ export function transformConfig (config: MpRequestConfig): any {
116116
if ([EnumPlatForm.支付宝, EnumPlatForm.钉钉].includes(platFormName)) {
117117
config.headers = config.header
118118
delete config.header
119-
if (EnumPlatForm.钉钉 === platFormName && config.headers?.["Content-Type"] === "application/json" && Object.prototype.toString.call(config.data) === '[object Object]' ) {
119+
if (EnumPlatForm.钉钉 === platFormName && config.method !== "GET" && config.headers?.['Content-Type'] === 'application/json' && Object.prototype.toString.call(config.data) === '[object Object]') {
120120
// Content-Type为application/json时,data参数只支持json字符串,需要手动调用JSON.stringify进行序列化
121121
config.data = JSON.stringify(config.data)
122122
}

0 commit comments

Comments
 (0)