mirror of
https://github.com/smallfawn/QLScriptPublic.git
synced 2026-06-06 21:12:56 +08:00
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
const axios = require("axios");
|
|
class WeChatCodeServer {
|
|
constructor(options) {
|
|
this.serverUrl = options.url;
|
|
this.appid = options.appid;
|
|
this.auth = options.auth;
|
|
}
|
|
getCode(openid) {
|
|
console.log('等待获取code:');
|
|
return new Promise((resolve, reject) => {
|
|
axios.post(this.serverUrl + '/wx/code', { appid: this.appid, openid }, {
|
|
headers: {
|
|
'auth': this.auth
|
|
},
|
|
timeout: 30 * 1000
|
|
}).then(res => {
|
|
console.log('获取code成功:');
|
|
resolve(res);
|
|
}).catch(err => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
|
|
cloudInit(openid) {
|
|
console.log('等待云函数初始化:');
|
|
return new Promise((resolve, reject) => {
|
|
axios.post(this.serverUrl + '/wx/call/init', { appid: this.appid, openid }, {
|
|
headers: {
|
|
'auth': this.auth
|
|
},
|
|
timeout: 30 * 1000
|
|
}).then(res => {
|
|
console.log('云函数初始化成功:');
|
|
resolve(res);
|
|
}).catch(err => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
cloudCall(openid) {
|
|
console.log('等待云函数调用:');
|
|
return new Promise((resolve, reject) => {
|
|
axios.post(this.serverUrl + '/wx/cloud/call', { appid: this.appid, openid }, {
|
|
headers: {
|
|
'auth': this.auth
|
|
},
|
|
timeout: 30 * 1000
|
|
}).then(res => {
|
|
console.log('云函数调用成功:');
|
|
resolve(res);
|
|
}).catch(err => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
module.exports = WeChatCodeServer; |