Skip to content

Instantly share code, notes, and snippets.

@mygoare
Last active June 16, 2020 09:54
Show Gist options
  • Save mygoare/0249530121590b89e31b3325531a3940 to your computer and use it in GitHub Desktop.
Save mygoare/0249530121590b89e31b3325531a3940 to your computer and use it in GitHub Desktop.
利用微信小程序云开发 云函数 规避 域名请求限制
// 云函数代码
// querycloud/
const request = require('request');
exports.main = async (event, context) => {
return new Promise((resolve, reject) => {
request(event, (err, res, body) => {
if (err) return reject(err);
resolve(body);
});
});
}
// 封装的 wx.vrequest
// data: options 对于的是云函数的 event 参数
wx.vrequest = function(options) {
return new Promise((resolve, reject)=> {
wx.cloud.callFunction({
name: 'querycloud',
data: options,
success: res => {
console.log('vrequest success');
resolve(res);
},
fail: err => {
console.error('vrequest fail', err)
reject(err);
}
})
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment