当前位置:网站首页>Unicloud cloud development obtains applet user openid
Unicloud cloud development obtains applet user openid
2022-06-26 05:41:00 【Xiaojiexue front end】
Catalog
Two 、openid What is difficult to obtain
3、 ... and 、 Cloud development obtains openid
One 、 Introduce openid
We all need to use... When distinguishing applet users openid, user openid It is equivalent to the user's ID card in the applet . As the unique identification of the user , So get the user openid It's very important , Today, let's teach you how to get the unique identifier of the user openid
Two 、openid What is difficult to obtain
Today I tried many methods on the Internet , It can still be obtained during real machine debugging , As a result, once you upload the code, you can't get it , There should be many students who have encountered this problem , therefore We should put code The value goes to the back end to get openid, Because in the front end it may be caught or crawled to your appid and secret, unsafe , If you put it on the back end to get openid, Unless your server is attacked , Or it's safe .
3、 ... and 、 Cloud development obtains openid
1. First of all we have uniCloud In the catalog cloudfunctions Right click to create cloud function

2. Write cloud functions
'use strict';
exports.main = async (event, context) => {
let appid = "wxc00000000000";// Your own appid
let secret = "xxxxxxxxxxxxxxxxxxxxxxxx";// Your own appsecret
let url =
"https://api.weixin.qq.com/sns/jscode2session?appid=" +
appid +
"&secret=" +
secret +
"&js_code=" +
event.code +
"&grant_type=authorization_code";
let res = await uniCloud.httpclient.request(
url ,// Request path ,
{
dataType:"json"
}
);
let openid = res.data.openid
return openid
};Notice the appid and secret Use your own
3. Client calls uni.login(), Use what you get code Call cloud function
uni.login({
provider: "weixin",
success: function (res) {
uniCloud.callFunction({
name: 'openid',
data: {
code: res.code
},
success: (res) => {
console.log(' The value returned by the cloud function ::::', res.result)
},
fail: () => {
console.log(' Cloud function call failed ')
}
})
},
});4. Look at the output
Now we have successfully obtained the user's openid , It's too difficult to cross the river by feeling the stones , It's all blood and tears
边栏推荐
- Introduction to GUI programming to game practice (II)
- 5分钟包你学会正则表达式
- Could not get unknown property ‘*‘ for SigningConfig container of type org.gradle.api.internal
- 虚拟项目失败感想
- A new journey
- [red team] what preparations should be made to join the red team?
- 【ARM】在NUC977上搭建基于boa的嵌入式web服务器
- About abstact and virtual
- 2021年OWASP-TOP10
- ZigBee explain in simple terms lesson 2 hardware related and IO operation
猜你喜欢

Fedora alicloud source

REUSE_ ALV_ GRID_ Display event implementation (data_changed)

Navicat如何将当前连接信息复用另一台电脑

Leetcode513.找出树的左下角的值

Consul service registration and discovery

How Navicat reuses the current connection information to another computer

Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports

Redis discovery bloom filter

9 common classes

When was the autowiredannotationbeanpostprocessor instantiated?
随机推荐
The wechat team disclosed that the wechat interface is stuck with a super bug "15..." The context of
组合模式、透明方式和安全方式
虚拟项目失败感想
循环位移
【C語言】深度剖析數據在內存中的存儲
怎么把平板作为电脑的第二扩展屏幕
cartographer_ backend_ constraint
[red team] what preparations should be made to join the red team?
LeetCode_二叉搜索树_简单_108.将有序数组转换为二叉搜索树
pytorch(环境、tensorboard、transforms、torchvision、dataloader)
[arm] build boa based embedded web server on nuc977
慢慢学JVM之缓存行和伪共享
定位设置水平,垂直居中(多种方法)
Gram 矩阵
Sql查询时间段内容
LeetCode_ Binary search tree_ Simple_ 108. convert an ordered array to a binary search tree
data = self._ data_ queue. get(timeout=timeout)
Redis discovery bloom filter
Learn cache lines and pseudo sharing of JVM slowly
无线网络存在的安全问题及现代化解决方案