From cf84fd78a11112b005f51eb00166646f778e0518 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 10 Dec 2018 15:44:30 +0800 Subject: [PATCH] add mp-alipay request --- packages/uni-mp-alipay/dist/index.js | 30 ++++++++++++++++++- src/core/runtime/wrapper.js | 2 +- .../mp-alipay/service/api/protocols.js | 28 +++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 87df9f297..8c0c767c3 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -132,6 +132,34 @@ const protocols = { } return res }, + request: { + name: 'httpRequest', + args (fromArgs) { + if (!fromArgs.header) { // 默认增加 header 参数,方便格式化 content-type + fromArgs.header = {}; + } + return { + header (header = {}, toArgs) { + const headers = { + 'content-type': 'application/json' + }; + Object.keys(header).forEach(key => { + headers[key.toLocaleLowerCase()] = header[key]; + }); + return { + name: 'headers', + value: headers + } + }, + method: 'method', // TODO 支付宝小程序仅支持 get,post + responseType: false + } + }, + returnValue: { + status: 'statusCode', + headers: 'header' + } + }, setNavigationBarColor: { name: 'setNavigationBar', args: { @@ -227,7 +255,7 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) { if (hasOwn(argsOption, key)) { let keyOption = argsOption[key]; if (isFn(keyOption)) { - keyOption = keyOption(fromArgs[key], fromArgs); + keyOption = keyOption(fromArgs[key], fromArgs, toArgs); } if (!keyOption) { // 不支持的参数 console.warn(`支付宝小程序 ${methodName}暂不支持${key}`); diff --git a/src/core/runtime/wrapper.js b/src/core/runtime/wrapper.js index 03f20fec3..6189636fb 100644 --- a/src/core/runtime/wrapper.js +++ b/src/core/runtime/wrapper.js @@ -29,7 +29,7 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) { if (hasOwn(argsOption, key)) { let keyOption = argsOption[key] if (isFn(keyOption)) { - keyOption = keyOption(fromArgs[key], fromArgs) + keyOption = keyOption(fromArgs[key], fromArgs, toArgs) } if (!keyOption) { // 不支持的参数 console.warn(`__PLATFORM_TITLE__ ${methodName}暂不支持${key}`) diff --git a/src/platforms/mp-alipay/service/api/protocols.js b/src/platforms/mp-alipay/service/api/protocols.js index 452fa9d29..966c50cdf 100644 --- a/src/platforms/mp-alipay/service/api/protocols.js +++ b/src/platforms/mp-alipay/service/api/protocols.js @@ -18,6 +18,34 @@ const protocols = { } return res }, + request: { + name: 'httpRequest', + args (fromArgs) { + if (!fromArgs.header) { // 默认增加 header 参数,方便格式化 content-type + fromArgs.header = {} + } + return { + header (header = {}, toArgs) { + const headers = { + 'content-type': 'application/json' + } + Object.keys(header).forEach(key => { + headers[key.toLocaleLowerCase()] = header[key] + }) + return { + name: 'headers', + value: headers + } + }, + method: 'method', // TODO 支付宝小程序仅支持 get,post + responseType: false + } + }, + returnValue: { + status: 'statusCode', + headers: 'header' + } + }, setNavigationBarColor: { name: 'setNavigationBar', args: { -- GitLab