Search in sources :

Example 1 with WxOAuth2UserInfo

use of me.chanjar.weixin.common.bean.WxOAuth2UserInfo in project weixin-java-mp-demo-springboot by binarywang.

the class WxRedirectController method greetUser.

@RequestMapping("/greet")
public String greetUser(@PathVariable String appid, @RequestParam String code, ModelMap map) {
    if (!this.wxService.switchover(appid)) {
        throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
    }
    try {
        WxOAuth2AccessToken accessToken = wxService.getOAuth2Service().getAccessToken(code);
        WxOAuth2UserInfo user = wxService.getOAuth2Service().getUserInfo(accessToken, null);
        map.put("user", user);
    } catch (WxErrorException e) {
        e.printStackTrace();
    }
    return "greet_user";
}
Also used : WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) WxOAuth2UserInfo(me.chanjar.weixin.common.bean.WxOAuth2UserInfo) WxErrorException(me.chanjar.weixin.common.error.WxErrorException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WxOAuth2UserInfo (me.chanjar.weixin.common.bean.WxOAuth2UserInfo)1 WxOAuth2AccessToken (me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken)1 WxErrorException (me.chanjar.weixin.common.error.WxErrorException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1