当前位置:网站首页>微信小程序8-云函数
微信小程序8-云函数
2022-07-17 22:28:00 【k55】
微信小程序1-小程序基础,开发工具安装使用
微信小程序2-WXSS,WXS
微信小程序3-小程序生命周期和组件
微信小程序4-小程序的api
微信小程序5-真机测试
微信小程序6-云开发-云数据库
微信小程序7-云存储
1.云函数
云函数是一段运行在云端的代码,无需管理服务器,在开发工具内编写、一键上传部署即可运行后端代码。
1).创建云函数
小程序内提供了专门用于云函数调用的 API,开发者可以在云函数内使用 wx-server-sdk 提供的 getWXContext 方法获取到每次调用的上下文(appid、openid 等),无需维护复杂的鉴权机制,即可获取天然可信任的用户登录态(openid)。
(1).找到当前文件夹中的 ”cloudfunctions“文件 -> 右键 选择当前环境

(2).新建Node.js云函数



// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
}
}
(3).部署云函数

2).使用云函数
wx.cloud.callFunction({
name: 'getUserInfo',
data: {
},
success: (res) => {
console.log(res)
}
})

边栏推荐
- csrf防护机制
- P1004 [NOIP2000 提高组] 方格取数
- ICML2022 | 幾何多模態對比錶示學習
- MySQL storage functions and triggers
- 傅里叶变换的再理解
- Characteristics of DMA mode
- 06_服务调用Feign
- End repeated development and personalize the login system in twoorthree times
- Tianqin Chapter 9 after class exercise code
- Single channel 6Gsps 12 bit AD acquisition and single channel 6Gsps 16 bit Da (ad9176) output sub card based on vita57.1 standard
猜你喜欢
随机推荐
TDesign compositionapi refactoring path
Compositionapi component development paradigm
背包问题 (Knapsack problem)
DMA方式的特点
分布式事务总结
ORA-08103
Is it safe to buy funds in a securities account? I want to make a fixed investment in the fund
High performance pxie data preprocessing board based on kinex ultrascale series FPGA (ku060 +fmc sub card interface)
3438. 数制转换
Leetcode 1275. Find out the winner of tic tac toe
Unix ls
长安链学习研究-存储分析wal机制
[Axi] interpret the additional signals of the Axi protocol (QoS signal, region signal, and user signal)
ObjectARX -- implementation of custom circle
2021.07.13 [station B] collapsed like this
国科大. 深度学习. 期末试题与简要思路分析
Tips for using setup
kube-proxy & Service & Endpoint
08_服务熔断Hystrix
Performance design of distributed transaction









