Hang on micro-channel oauth login

This is a small project internship company public micro-channel number, use the ssm. The problem is that users get openid is empty.

Analysis step

  1. First, the user clicks on the public micro-channel number buttons
  2. Access to micro-channel server to obtain code
  3. Jump to the project url
  4. Micro-letter code to get access server, access token and openid.
  5. The openid into session
This is a micro-channel button link
https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxxxxxxxxxxx&redirect_uri=https:xxx.xx.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect //redirect_uri 是返回的url,指向的项目服务器

The Controller layer is treated url

    @RequestMapping(method = RequestMethod.GET)
    public String newPage(HttpServletRequest request, ModelMap map, HttpServletResponse response) {
            getOpenid();
    }

In fact, the problem lies in the controller layer in the request, the user does not request this method of making the request, but the request micro-channel server.
They had a direct approach with a micro letter forwarded request.getSession () setAttribute ( "openid" , openid);. To set the value, the user initiates a request, the value of the user request to getSession.getAttribute ( "openid"), acquired of course, as empty.

Here is what I practice

Jump in a first page, and bring the code, and then the server requests the project page at once, so you get the user's request, and then go visit the micro-controller communication server, to get the token and openid, stored in session

Guess you like

Origin www.cnblogs.com/duangL/p/11670760.html