PrefaceYesterday, there was a project that required the implementation of h5 WeChat authorization. So it took two hours to complete this function. Preparation before starting workProcess description [process communicated in advance]
Domain name, port
The domain name and port number are required because the domain name and port 80 are required for WeChat public account configuration and WeChat server callback. Here, the same domain name and port are adapted to the front-end and back-end IP addresses, and are processed through the nginx unified proxy. Ready to work
Configure WeChat public account Domain name configuration Upload the verification file to the server root path, otherwise the domain name configuration cannot be saved. Whitelist configuration Writing code import React, { useEffect } from "react"; import { View } from "@tarojs/components"; export default () => { useEffect(() => { // The path format of the backend callback: http://xxx.cn/#/pages/webAuthorization?bindFlag=0&openid=xxxxxxxxxxx&unionid=null&isAuth=true var isBindFlag = false, isAuth = false, opendId = '', paramsArray = []; /* * Omitted code: address determination, parameter processing and assignment to isAuth, isBindFlag, openId */ if (!isAuth) { // Unauthorized window.location.href=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${'xxxxxxx'}&redirect_uri=http://xxxxx/api/auth?response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`; } else if (!isBindFlag) { // Not registered window.location.href = '#/pages/login' } else { // Login window.location.href = '#/pages/index' } }, []); return ( <View> </View> ); }; SummarizeThis is the end of this article about H5 WeChat public account authorization. For more relevant WeChat public account authorization content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of the data storage structure of the nginx http module
>>: MySQL trigger definition and usage simple example
Official website explanation: When a component is...
HTML tags have special tags to handle the title of...
Table of contents Props comparison of class compo...
Preface: The group by function retrieves the firs...
1. Use basic text elements to mark up content Fir...
When we use the folder properties dialog box in Wi...
Table of contents 1. Component Organization 2. Co...
Grid is a two-dimensional grid layout system. Wit...
Table of contents Makefile Makefile naming and ru...
Preface: rm under Linux system is irreversible. T...
There are two meta attributes: name and http-equiv...
This article records the installation and configu...
Table of contents Why use a debugger? Basic usage...
Table of contents introduce Usage scenarios Sourc...
Deleting a single table: DELETE FROM tableName WH...