This article mainly introduces the steps of client development-logging on to the applet. I think it is quite good. now I will share it with you and give you a reference. Let's take a look at this article. This article mainly introduces the client development-the steps for logging on to the mini-app. I think it is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
The main purpose of this applet is to grant user information authorization to your database after logging on with user information, in this way, the openid obtained by the code obtained by each login can be found in the project database.
During the test, you need to log on to the code, so you will use the development tool ~!
// Normally returned JSON data packet {"openid": "OPENID", "session_key": "SESSIONKEY" "expires_in": 2592000}
// Return a JSON packet when an error occurs (the Code in this example is invalid) {"errcode": 40029, "errmsg": "invalid code "}
So we can write the code as follows:
The company has written all the message formats sent by myself. I only need to write the request path and request parameters to OK.
// @ Param code the code generated by the user login // @ Return OAuthResult the public OAuthResult getOAuthResultByCode (String code) class containing openid and session_key and expires_in is returned) {String path = "/sns/jscode2session"; Map
Parameters = new HashMap <> (); parameters. put ("appid", WechatConstant. WECHAT_APP_ID); parameters. put ("secret", WechatConstant. WECHAT_APP_SECRET); parameters. put ("js_code", code); parameters. put ("grant_type", "authorization_code"); OAuthResult oAuthResult = messageSender. getMessageForObject (path, parameters, OAuthResult. class, false); if (oAuthResult. getOpenid () = null) {throw new BusinessException (BusinessException. code. OAUTH_PROCESS_ERROR, "OAuth exception, cause:" + oAuthResult. getErrmsg ();} return oAuthResult ;}
The above is all the content of this article. I hope it will be helpful to everyone's learning, and I hope you can support your own home.
The above is the detailed content of the step-by-step development tutorial for logging on to the client. For more information, see other related articles in the first PHP community!