当前位置:网站首页>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
边栏推荐
- The news of thunderbolt
- Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports
- REUSE_ ALV_ GRID_ Display event implementation (data_changed)
- ZigBee explain in simple terms lesson 2 hardware related and IO operation
- About abstact and virtual
- BOM文档
- Serious hazard warning! Log4j execution vulnerability is exposed!
- 循环位移
- Feelings of virtual project failure
- Leetcode513. Find the value in the lower left corner of the tree
猜你喜欢
转帖——不要迷失在技术的海洋中
![[arm] add desktop application for buildreoot of rk3568 development board](/img/9a/28015cdea7362261c39ffc7f6e13a9.png)
[arm] add desktop application for buildreoot of rk3568 development board

How to ensure the efficiency and real-time of pushing large-scale group messages in mobile IM?

使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告

状态模式,身随心变

There are applications related to web network request API in MATLAB (under update)

LeetCode_ Binary search tree_ Simple_ 108. convert an ordered array to a binary search tree
![Operator priority, associativity, and whether to control the evaluation order [detailed explanation]](/img/c3/a646a7c7cb82e00746923f7b023058.jpg)
Operator priority, associativity, and whether to control the evaluation order [detailed explanation]

【ARM】讯为rk3568开发板buildroot添加桌面应用

Recursively traverse directory structure and tree presentation
随机推荐
Leetcode114. Expand binary tree into linked list
pytorch(环境、tensorboard、transforms、torchvision、dataloader)
Gram 矩阵
[activity recommendation] cloud native, industrial Internet, low code, Web3, metauniverse... Which is the architecture hot spot in 2022
9 common classes
LeetCode_二叉搜索树_简单_108.将有序数组转换为二叉搜索树
Wechat team sharing: technical decryption behind wechat's 100 million daily real-time audio and video chats
bingc(继承)
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
Redis discovery bloom filter
使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告
skimage. morphology. medial_ axis
Could not get unknown property ‘*‘ for SigningConfig container of type org.gradle.api.internal
售前分析
组合模式、透明方式和安全方式
The wechat team disclosed that the wechat interface is stuck with a super bug "15..." The context of
Project suspension
[PHP] PHP two-dimensional array is sorted by multiple fields
Some doubts about ARP deception experiment
RIA ideas