Skip to content

Commit

Permalink
Merge pull request #11605 from SpringHgui/next
Browse files Browse the repository at this point in the history
feat: getExtConfig 支付宝小程序与微信小程序接口返回值差异抹平
  • Loading branch information
Chen-jj authored Apr 13, 2022
2 parents a510b90 + e5fc66e commit 24d429e
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 42 deletions.
148 changes: 134 additions & 14 deletions packages/taro-alipay/src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import { needPromiseApis } from './apis-list'
declare const my: any

const apiDiff = {
login: {
alias: 'getAuthCode',
options: {
set: [
{
key: 'scopes',
value: 'auth_base'
}
]
}
},

showActionSheet: {
options: {
change: [{
Expand Down Expand Up @@ -168,6 +180,102 @@ const apiDiff = {
}
}

const asyncResultApiDiff = {
getScreenBrightness: {
res: {
set: [
{
key: 'value',
value (res) {
return res.brightness
}
}
],
remove: ['brightness']
}
},
scan: {
res: {
set: [
{
key: 'result',
value (res) {
return res.code
}
}
]
}
},
getClipboard: {
res: {
set: [
{
key: 'data',
value (res) {
return res.text
}
}
]
}
},
chooseImage: {
res: {
set: [
{
key: 'tempFilePaths',
value (res) {
return res.apFilePaths
}
}
]
}
},
downloadFile: {
res: {
set: [
{
key: 'tempFilePath',
value (res) {
return res.apFilePath
}
}
]
}
},
getAuthCode: {
res: {
set: [{
key: 'code',
value (res) {
return res.authCode
}
}]
}
},
getExtConfig: {
res: {
set: [{
key: 'extConfig',
value (res) {
return res.data
}
}]
}
},
saveFile: {
res: {
set: [
{
key: 'savedFilePath',
value (res) {
return res.apFilePath
}
}
]
}
}
}

const nativeRequest = my.canIUse('request') ? my.request : my.httpRequest

export function request (options) {
Expand Down Expand Up @@ -319,20 +427,7 @@ export function modifyApis (apis: Set<string>) {
}

export function modifyAsyncResult (key, res) {
if (key === 'saveFile') {
res.savedFilePath = res.apFilePath
} else if (key === 'downloadFile') {
res.tempFilePath = res.apFilePath
} else if (key === 'chooseImage') {
res.tempFilePaths = res.apFilePaths
} else if (key === 'getClipboard') {
res.data = res.text
} else if (key === 'scan') {
res.result = res.code
} else if (key === 'getScreenBrightness') {
res.value = res.brightness
delete res.brightness
} else if (key === 'connectSocket') {
if (key === 'connectSocket') {
res.onClose = function (cb) {
my.onSocketClose(cb)
}
Expand All @@ -357,6 +452,31 @@ export function modifyAsyncResult (key, res) {
my.closeSocket()
}
}

Object.keys(asyncResultApiDiff).forEach(item => {
const apiItem = apiDiff[item]
if (key !== item) {
return
}
if (!apiItem.res) {
return
}

const set = apiItem.res.set
const remove = apiItem.res.remove

if (set) {
set.forEach(setItem => {
res[setItem.key] = typeof setItem.value === 'function' ? setItem.value(res) : setItem.value
})
}

if (remove) {
remove.forEach(removeItem => {
delete res[removeItem]
})
}
})
}

export function initNativeApi (taro) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ require(\\"./taro\\");
var _tarojs_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
var needPromiseApis = new Set([ \\"addCardAuth\\", \\"getOpenUserInfo\\", \\"chooseAlipayContact\\", \\"chooseCity\\", \\"chooseContact\\", \\"choosePhoneContact\\", \\"datePicker\\", \\"getAddress\\", \\"getAuthCode\\", \\"getPhoneNumber\\", \\"getRunData\\", \\"getRunScene\\", \\"getServerTime\\", \\"getTitleColor\\", \\"rsa\\", \\"paySignCenter\\", \\"tradePay\\", \\"isCollected\\", \\"multiLevelSelect\\", \\"onLocatedComplete\\", \\"optionsSelect\\", \\"prompt\\", \\"regionPicker\\", \\"setLocatedCity\\", \\"showAuthGuide\\", \\"textRiskIdentification\\", \\"vibrate\\", \\"watchShake\\", \\"connectBLEDevice\\", \\"disconnectBLEDevice\\", \\"makeBluetoothPair\\", \\"writeBLECharacteristicValue\\", \\"readBLECharacteristicValue\\", \\"notifyBLECharacteristicValueChange\\", \\"getBLEDeviceServices\\", \\"getBLEDeviceCharacteristics\\", \\"openBluetoothAdapter\\", \\"closeBluetoothAdapter\\", \\"getBluetoothAdapterState\\", \\"startBluetoothDevicesDiscovery\\", \\"stopBluetoothDevicesDiscovery\\", \\"getBluetoothDevices\\", \\"getConnectedBluetoothDevices\\" ]);
var apiDiff = {
login: {
alias: \\"getAuthCode\\",
options: {
set: [ {
key: \\"scopes\\",
value: \\"auth_base\\"
} ]
}
},
showActionSheet: {
options: {
change: [ {
Expand Down Expand Up @@ -214,6 +223,89 @@ require(\\"./taro\\");
alias: \\"disconnectBLEDevice\\"
}
};
var asyncResultApiDiff = {
getScreenBrightness: {
res: {
set: [ {
key: \\"value\\",
value: function value(res) {
return res.brightness;
}
} ],
remove: [ \\"brightness\\" ]
}
},
scan: {
res: {
set: [ {
key: \\"result\\",
value: function value(res) {
return res.code;
}
} ]
}
},
getClipboard: {
res: {
set: [ {
key: \\"data\\",
value: function value(res) {
return res.text;
}
} ]
}
},
chooseImage: {
res: {
set: [ {
key: \\"tempFilePaths\\",
value: function value(res) {
return res.apFilePaths;
}
} ]
}
},
downloadFile: {
res: {
set: [ {
key: \\"tempFilePath\\",
value: function value(res) {
return res.apFilePath;
}
} ]
}
},
getAuthCode: {
res: {
set: [ {
key: \\"code\\",
value: function value(res) {
return res.authCode;
}
} ]
}
},
getExtConfig: {
res: {
set: [ {
key: \\"extConfig\\",
value: function value(res) {
return res.data;
}
} ]
}
},
saveFile: {
res: {
set: [ {
key: \\"savedFilePath\\",
value: function value(res) {
return res.apFilePath;
}
} ]
}
}
};
var nativeRequest = my.canIUse(\\"request\\") ? my.request : my.httpRequest;
function request(options) {
options = options || {};
Expand Down Expand Up @@ -360,20 +452,7 @@ require(\\"./taro\\");
apis.delete(\\"alert\\");
}
function modifyAsyncResult(key, res) {
if (key === \\"saveFile\\") {
res.savedFilePath = res.apFilePath;
} else if (key === \\"downloadFile\\") {
res.tempFilePath = res.apFilePath;
} else if (key === \\"chooseImage\\") {
res.tempFilePaths = res.apFilePaths;
} else if (key === \\"getClipboard\\") {
res.data = res.text;
} else if (key === \\"scan\\") {
res.result = res.code;
} else if (key === \\"getScreenBrightness\\") {
res.value = res.brightness;
delete res.brightness;
} else if (key === \\"connectSocket\\") {
if (key === \\"connectSocket\\") {
res.onClose = function(cb) {
my.onSocketClose(cb);
};
Expand All @@ -393,6 +472,27 @@ require(\\"./taro\\");
my.closeSocket();
};
}
Object.keys(asyncResultApiDiff).forEach((function(item) {
var apiItem = apiDiff[item];
if (key !== item) {
return;
}
if (!apiItem.res) {
return;
}
var set = apiItem.res.set;
var remove = apiItem.res.remove;
if (set) {
set.forEach((function(setItem) {
res[setItem.key] = typeof setItem.value === \\"function\\" ? setItem.value(res) : setItem.value;
}));
}
if (remove) {
remove.forEach((function(removeItem) {
delete res[removeItem];
}));
}
}));
}
function initNativeApi(taro) {
Object(_tarojs_shared__WEBPACK_IMPORTED_MODULE_0__[\\"g\\"])(taro, my, {
Expand Down
Loading

0 comments on commit 24d429e

Please sign in to comment.