微信小程序云開發(fā)如何使用云函數(shù)生成二維碼
更新時間:2019年05月18日 09:47:50 作者:潘高
這篇文章主要為大家詳細介紹了微信小程序云開發(fā)如何使用云函數(shù)生成二維碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序云開發(fā)使用云函數(shù)生成二維碼的具體代碼,供大家參考,具體內(nèi)容如下
首先,需要給對應的云函數(shù)安裝 request-promise 依賴。(不會給云函數(shù)安裝依賴的盆友請移步 微信小程序中的云開發(fā)如何使用npm安裝依賴)
生成二維碼的云函數(shù)如下:
// 云函數(shù)入口文件 const cloud = require('wx-server-sdk') const rp = require('request-promise') cloud.init() // 云函數(shù)入口函數(shù) exports.main = async (event, context) => { const page = event.page const scene = event.scene //appid和秘鑰 const appid = '***', secret = '***'; const AccessToken_options = { method: 'GET', url: 'https://api.weixin.qq.com/cgi-bin/token', qs: { appid, secret, grant_type: 'client_credential' }, json: true }; //獲取AccessToken const resultValue = await rp(AccessToken_options); const token = resultValue.access_token; //獲取小程序碼配置 const code_options = { method: 'POST', url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + token, body: { 'page': page, 'width': 430, 'scene': scene }, json: true, encoding: null }; //獲取二進制圖片 const buffer = await rp(code_options); const upload = await cloud.uploadFile({ cloudPath: 'wxacode.png', fileContent: buffer, }) return { wxacodefileID: upload.fileID } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript關聯(lián)數(shù)組用法分析【概念、定義、遍歷】
這篇文章主要介紹了JavaScript關聯(lián)數(shù)組用法,結(jié)合實例形式分析了關聯(lián)數(shù)組的概念、定義與遍歷操作相關實現(xiàn)技巧,需要的朋友可以參考下2017-03-03