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
1. Use Docker Compose to configure startup If you...
Separate the front and back ends and use nginx to...
This time we will mainly learn about layout, whic...
MySQL tuning Explain tool detailed explanation an...
In the process of database operation, it is inevi...
The META tag is an auxiliary tag in the head area...
In the database, both UNION and UNION ALL keyword...
Chinese Tutorial https://www.ncnynl.com/category/...
The growth path from a Linux novice to a Linux ma...
Table of contents 1. Use RGB to represent color 2...
Effect picture: 1. Introduction Your own applet n...
Preface When developing WeChat applets, you often...
Responsive layout systems are already very common...
1. Paradigm The English name of the paradigm is N...
There are many attributes in CSS. Some attributes...