How to get token value
Method to obtain the token value: 1. The applet calls [wx.login()] to obtain the temporary login credential code and returns it to the developer server; 2. The developer server exchanges the code for the user's unique identification openid and session key [session_key].
The operating environment of this article: Windows 7 system, WeChat version 3.1.2, Dell G3 computer.
Method to obtain the token value:
1. The applet calls wx.login()
to obtain the temporary login credential code and return it to Developer server.
2. The developer server exchanges code for the user's unique identifier openid and session key session_key
.
The developer server can then generate a custom login state based on the user ID, which can be used to identify the user's identity during subsequent front-end and back-end interactions in subsequent business logic.
// 登录 wx.login({ success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId // console.log(res) if (res.code) { //发起网络请求 wx.request({ url: 'url', method: 'POST', data: { // x: '', // y: '' code: res.code //将code发给后台拿token }, header: { 'content-type': 'application/json' // 默认值 }, success: function(res) { // 存token console.log('token=' + res.data.data.token) that.globalData.token = res.data.data.token; //拿到后将token存入全局变量 以便其他页面使用 } }) } else { console.log('获取用户登录态失败!' + res.errMsg) } } })
Login Credential Verification
The temporary login credential verification interface is an HTTPS interface. The developer server uses the temporary login credential code to obtain session_key and openid, etc.
In fact, what we have to do is to send the code value to the backend, and the backend can return the token value to us after requesting the corresponding interface! In other pages, token is also needed to request data, so when we get it, we need to save it in a global variable so that the page can get it directly (getApp() .globalData.token).
Related free learning recommendations:
The above is the detailed content of How to get token value. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Solutions to invalid login token include checking whether the Token has expired, checking whether the Token is correct, checking whether the Token has been tampered with, checking whether the Token matches the user, clearing the cache or cookies, checking the network connection and server status, logging in again or requesting a new Token. Contact technical support or developers, etc. Detailed introduction: 1. Check whether the Token has expired. The login Token usually has a validity period set. Once the validity period exceeds, it will be considered invalid, etc.

The problem of invalid login token can be solved by checking the network connection, checking the token validity period, clearing cache and cookies, checking login status, contacting the application developer and strengthening account security. Detailed introduction: 1. Check the network connection, reconnect to the network or change the network environment; 2. Check the token validity period, obtain a new token, or contact the developer of the application; 3. Clear cache and cookies, clear browser cache and Cookie, and then log in to the application again; 4. Check the login status.

Redis stores user tokens. When designing a system similar to e-commerce, a common requirement is that each page needs to carry logged-in user information. There are two common solutions: using cookies to save and using JWT to save. But if Redis cache is used in the system, there is also a third solution - caching the user token in Redis. Generate a token when logging in and store it in Redis //Generate a token object and save it in redis redisTemplate.opsForHash().put("token","user",user)

How to solve C++ syntax error: 'expectedprimary-expressionbefore':'token'? Syntax errors are a common problem in C++ programming. One of the common errors is the "expectedprimary-expressionbefore':'token" error message. This error usually occurs when using conditional expressions and the ternary operator. This article will introduce the cause of this error

1. Token login authentication jwt: JSONWebToken. It is an authentication protocol that is generally used to verify the requested identity information and identity permissions. Composed of three parts: Header, Hayload, Signatureheader: that is, the header information, which is the basic information describing this token, json format {"alg":"HS256", //indicates the signature algorithm, the default is HMACSHA256 (written as HS256) "type":"JWT"//Indicates the type of Token. JWT tokens are uniformly written as JWT}pa

Unexpectedly, ChatGPT would still make stupid mistakes to this day? Master Ng Enda pointed it out at the latest class: ChatGPT will not reverse words! For example, let it reverse the word lollipop, and the output is pilollol, which is completely confusing. Oh, this is indeed a bit surprising. So much so that after a netizen who listened to the class posted a post on Reddit, it immediately attracted a large number of onlookers, and the post quickly reached 6k views. And this is not an accidental bug. Netizens found that ChatGPT is indeed unable to complete this task, and the results of our personal testing are also the same. △The actual test of ChatGPT (GPT-3.5) and even many products including Bard, Bing, Wen Xinyiyan, etc. does not work. △Actual test Bard△Actual test Wenxinyiyan

Token is a kind of virtual currency. It is a digital currency used to represent user permissions, record transaction information, and pay virtual currency. Token can be used to conduct transactions on a specific network, it can be used to buy or sell specific virtual currencies, and it can also be used to pay for specific services.

1. The use of token in the ThinkPhp framework 1. First add two fields token and time_outtoken in the users table of the database to store the user's token time_out is used to set the expiration time of the user token 2. Create the function checkToekn($token) function for Check whether the token exists and update the token. publicfunctioncheckToken($token){$user=new\app\index\model\Users();
