移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.0 KiB

let AccessToken
function getAccessToken() {
return new Promise((resolve, reject) => {
uni.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx6d80755768234f3b&secret=c8180f2ab1b8454d403c7aa336782e21',
method: "GET",
success(res) {
resolve(res.data.access_token)
},
fail(err) {
console.error(err)
resolve(false)
}
})
})
}
function getCode(data, token) {
return new Promise((resolve) => {
uni.request({
url: `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${token}`,
method: "POST",
responseType: "arraybuffer",
data: JSON.stringify(data),
success(res) {
resolve(res)
},
fail(err) {
console.error(err)
resolve(false)
}
})
})
}
export async function getMiniCode(data) {
const token = await getAccessToken()
const code = await getCode(data, token)
const arrayBuffer = new Uint8Array(code.data)
const base64 = wx.arrayBufferToBase64(arrayBuffer)
return `data:image/jpeg;base64,${base64}`
}