


Split explanation of WeChat distribution platform developed with php+WeChat interface (1) WeChat oauth2 interface
Jul 30, 2016 pm 01:30 PMI am an ITmigrant worker. I am not a master or a great god, but I hope to become Lei Feng. Without Shenma's writing, I will just complain. If the explanation is not clear, you can continue to ask questions. I will try my best to answer as time permits.
This article does not provide the entire system source code. It will only open part of the source code and talk about the development experience, ideas, and answers to questions. I hope it will be helpful to novices. As for the experts and experts who have just passed it by or left valuable comments, I would like to thank you here. .
Let’s stop talking and get to the point.
Basics
phpCurrent mainstreamWEBThere is no doubt that development languages ??needless to say. The WeChat interface mainly uses the WeChat authorized login interface, WeChatJSSDKsharing interface, and WeChat payment interface. We must complain about the series of WeChat interfaces that are full of pitfalls. The distribution system is a marketing model that will be explained later. First, let’s talk about the first step of WeChat login (oauth2Third-party authorization interface), which I personally think is more important. It has the advantages of high user experience, high security, and lays a convenient foundation for the subsequent distribution system. The disadvantages are only Accessing in WeChat’s built-in browser is inconvenient for publicity and promotion in other ways than WeChat. You can only use QR codes (there are many third-party tools online to generate QR codes in the form of links, and you can also use programs to achieve this. If you are interested, you can leave a message. ).
First take a look at the legendary WeChatAPIinterface document, the official website document addresshttp://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b 468d75.html
You must have a certified service account to use this interface. If you don’t have one, you can apply for a test account to experience it but it cannot be promoted.
Instructions on the webpage authorization callback domain name
The document is relatively clear. When not using a third-party platform, you need to configure the path through which the project needs to obtain WeChat user information. Either first- or second-level domain names are acceptable. This one is relatively clear
Looking down, I didn’t understand it the first time, and I didn’t understand it the second time. . . . . . The project started to be developed a year ago. The documentation at that time was even simpler than it is now, and there were very few reference materials on the Internet. There were no official examples. Fortunately, I finally found some clues from an article and it was done. I’m going to complain about it
Other instructions
First introduce a few parameters appid and appsecretYou can find these two parameters used in many interface calls in the WeChat public platform.
The most important parameter is also the purpose of calling the authorization interface, openid, which is the only identification of a WeChat ID corresponding to the public platform. Once it is obtained, it can be considered that the user has logged in with WeChat, and all subsequent business processes and database records It's all built around it.
Let’s talk about how to obtain openid and basic user information such as avatar, nickname, city, gender, etc. This is a rather painful process. There are so many steps to fool us, right? I'll give you a reason for safety reasons. Sorry for whining again.
Get the code in three steps
1, what is a code? ? ? I don’t know, but I need to get it to proceed to the next step
Interface address:https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&resp/span> appid has just been improved and can be found on the public platform. redirect_uri is the key point. It is when the user sends a request to the WeChat server through the above interface address. The WeChat server transmits it through GET A parameter code returns to redirect_uri, just use $_GET to accept it. scope is also an important parameter. It has two types snsapi_base and snsapi_userinfo. Let’s talk about the difference. If you only want to achieve WeChat login, you only need openid then use it. snsapi_base,The advantage is that the user does not know that you have captured his openid when visiting. In addition to grabbing openid, using snsapi_userinfo can also capture a lot more WeChat user information. Now many WeChat applications require avatars and nicknames so you can use snsapi_userinfo directly. The disadvantages are A page showing whether WeChat authorization is allowed will pop up first, and the user must agree to the next step before proceeding. As shown in the picture:
2. openidand access_tokenThrough the and appid and appsecretinterface: https://api.weixin.qq .com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_codereturns data in format 3 ... through and access_tokeninterface https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID &lang=zh_CN returns data in formatparameters default returns English data when not written Example code Snippet a .php $url='http://www.xxx.com/b.php'; $url=urlencode($url); $href="https:// open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=$url&resp/span> @header("location:$href"); b.php $code=$_GET['code']; $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code='.$code. '&grant_type=authorization_code'; $js/span> $jsonstr = json_decode($jsonstr,true); $access_token= $jsonstr['access_token']; $openid =$jsonstr['openid']; $userurl='https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid; $userinfo=file_get_contents($userurl); $userinfo = json_decode($userinfo,true); Okay, it’s barely implemented. . . . . . . . . . However, after a period of operation, the information capture is not stable, and some users will not get their avatars and nicknames. I have been pondering for a long time and don’t know where the problem is ? ? ? ? ? Oh, there is a problem with the function . Although it can be achieved by using file_get_contents, the performance effect is extremely unstable. Later, I switched to curl, which is much more stable but does not work. Reaching 100%catch is caused by many factors, but it is basically within the acceptable range.
Time is limited today. There is another way to define the distribution system and obtain WeChat user avatar nickname and other information without popping up the authorization interface. unionidNeeded to be used when developing multiple public platforms and to achieve persistent login status. cookie, as well as the shopping cart implementation of the mall part of the distribution system client will be explained in the second time. Attached is a QR code for the system access path. You can take a look at it first and it can only be accessed through WeChat. You can also ask questions about the system architecture, front-end JSscripts and the implementation of a series of functional modules. I will change the content of the next update based on what most people want
The above introduces the split explanation of the WeChat distribution platform developed by PHP + WeChat interface (1) WeChat oauth2 interface, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.
Copyright Statement: This article This is an original article by the blogger and may not be reproduced without the blogger's permission.

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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)

Web development design is a promising career field. However, this industry also faces many challenges. As more businesses and brands turn to the online marketplace, web developers have the opportunity to demonstrate their skills and succeed in their careers. However, as demand for web development continues to grow, the number of developers is also increasing, resulting in increasingly fierce competition. But it’s exciting that if you have the talent and will, you can always find new ways to create unique designs and ideas. As a web developer, you may need to keep looking for new tools and resources. These new tools and resources not only make your job more convenient, but also improve the quality of your work, thus helping you win more business and customers. The trends of web development are constantly changing.

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ?tookazaLovnetakProsto, Kakao?idal.Posenesko

Do you want to connect your website to Yandex Webmaster Tools? Webmaster tools such as Google Search Console, Bing and Yandex can help you optimize your website, monitor traffic, manage robots.txt, check for website errors, and more. In this article, we will share how to add your WordPress website to the Yandex Webmaster Tool to monitor your search engine traffic. What is Yandex? Yandex is a popular search engine based in Russia, similar to Google and Bing. You can excel in Yandex

How to configure Zend in Apache? The steps to configure Zend Framework in an Apache Web Server are as follows: Install Zend Framework and extract it into the Web Server directory. Create a .htaccess file. Create the Zend application directory and add the index.php file. Configure the Zend application (application.ini). Restart the Apache Web server.

Do you need to fix HTTP image upload errors in WordPress? This error can be particularly frustrating when you create content in WordPress. This usually happens when you upload images or other files to your CMS using the built-in WordPress media library. In this article, we will show you how to easily fix HTTP image upload errors in WordPress. What is the reason for HTTP errors during WordPress media uploading? When you try to upload files to Wo using WordPress media uploader

Apache server is a powerful web server software that acts as a bridge between browsers and website servers. 1. It handles HTTP requests and returns web page content based on requests; 2. Modular design allows extended functions, such as support for SSL encryption and dynamic web pages; 3. Configuration files (such as virtual host configurations) need to be carefully set to avoid security vulnerabilities, and optimize performance parameters, such as thread count and timeout time, in order to build high-performance and secure web applications.

In processing next-auth generated JWT...
