关于snsapi_userinfo网页授权的说明
以snsapi_userinfo为scope发起的网页授权,是用来获取用户的基本信息的。但这种授权需要用户手动同意,并且由于用户同意过,所以无须关注,就可在授权后获取该用户的基本信息。
具体java后端代码如下:
getUserInfo
/**
* 用户服务
*/
@RestController
@RequestMapping("/wx/user")
@Validated
public class WxUserController {
private static String APPID = "你的公众号appid";
private static String SECRET = "你的公众号secret";
private static final long serialVersionUID = 1L;
@Autowired
private LitemallUserService userService;
@Autowired
private UserInfoService userInfoService;
/**
* snsapi_userinfo为scope发起的网页授权
* 是用来获取用户的基本信息的。但这种授权需要用户手动同意,并且由于用户同意过,所以无须关注,就可在授权后获取该用户的基本信息。
*/
@RequestMapping("/getUserInfo")
public Object getUserInfo(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String get_access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?"
+ "appid=" + APPID
+ "&secret=" + SECRET
+ "&code=CODE&grant_type=authorization_code";
String get_userinfo = "https://api.w