Home  >  Article  >  WeChat Applet  >  How to call background service in WeChat applet (picture and text tutorial)

How to call background service in WeChat applet (picture and text tutorial)

不言
不言forward
2019-02-16 14:39:566750browse

The content of this article is about how to call the background service (picture and text tutorial) of the WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. Helps.

Written at the beginning, this article briefly records that in the WeChat applet application where the front and back ends are separated, the implementation idea of ​​the front end accessing the background service does not involve too much technical implementation.

First, take a picture of the official website. It clearly explains what needs to be done to provide login information for each mini program user in the background service. The user gets the login credentials given by the backend and accesses the backend service.

How to call background service in WeChat applet (picture and text tutorial)

Silent authorization and non-silent authorization

Let’s talk about these two concepts first, Silent authorization, as the name suggests, this authorization action is very important to the user. It is said that it is not perceptible, but the applet quietly did it. Therefore, information obtained without notifying the user of the authorization method is not important. However, silent authorization is an important first step because it provides the code for subsequent actions. To call silent authorization, you can use the API provided by the applet: wx.login(). Let’s talk about non-silent authorization. As the name suggests, its authorization must be obvious, and it must be approved by the user before it can be executed. API: wx.getUserInfo(), whether to use this interface depends on the actual needs of the mini program.

Get openId in the background

The applet provides an interface code2session. You can get the openId by calling this interface with the temporary login credential code we obtained through silent authorization. openId is the unique identification of the user in the current applet. Note that this step is done on the backend server. It will be clearer if we refer to the official website's documentation (backend API). It says:

The back-end API cannot be called directly through wx.request within the applet, that is, api.weixin.qq.com cannot be configured as the server domain name.

But we have questions. When we develop it ourselves, the call on the mini program is successful, which is different from what the official website says. If you encounter the same questions as me, you can take a look at this (the focus is on 4.4.2 server interface).

Generate token based on OAuth2.0

In the background, you can use SpringSecurity's OAuth2.0 tool and openId to generate the accompanying validation of the back-end data requested by the front-end. Verification information token. The author has no in-depth understanding of how to implement it specifically... After obtaining this token, the front end can store it in webStorage. Every time the background service is called, the request interceptor can be used to add the token to the config parameter. The backend can determine the identity of the user who sent the request, ensuring the security of the system.

How to call background service in WeChat applet (picture and text tutorial)

#Summary: The above roughly describes the development ideas for the custom login state in the background of the mini program.

Reference for this article: Basic Tutorial on WeChat Mini Program Development https://www.html.cn/study/20.html


The above is the detailed content of How to call background service in WeChat applet (picture and text tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete