本文整理了Java中me.chanjar.weixin.mp.api.WxMpService.oauth2getAccessToken()
方法的一些代码示例,展示了WxMpService.oauth2getAccessToken()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMpService.oauth2getAccessToken()
方法的具体详情如下:
包路径:me.chanjar.weixin.mp.api.WxMpService
类名称:WxMpService
方法名:oauth2getAccessToken
[英]```
用code换取oauth2的access token
详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
[中]```
用code换取oauth2的access token
详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
@SneakyThrows
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
final String code = request.getParameter("code");
WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
return new WeChatMpOAuth2AccessTokenAuthentication(accessToken);
}
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
@RequestMapping("/greet")
public String greetUser(@PathVariable String appid, @RequestParam String code, ModelMap map) {
WxMpService mpService = WxMpConfiguration.getMpServices().get(appid);
try {
WxMpOAuth2AccessToken accessToken = mpService.oauth2getAccessToken(code);
WxMpUser user = mpService.oauth2getUserInfo(accessToken, null);
map.put("user", user);
} catch (WxErrorException e) {
e.printStackTrace();
}
return "greet_user";
}
}
代码示例来源:origin: sqmax/springboot-project
@GetMapping("/userInfo")
public String userInfo(@RequestParam("code") String code,
@RequestParam("state") String returnUrl){
WxMpOAuth2AccessToken wxMpOAuth2AccessToken=new WxMpOAuth2AccessToken();
try {
wxMpOAuth2AccessToken=wxMpService.oauth2getAccessToken(code);
}catch (WxErrorException e){
log.error("【微信网页授权】,{}",e);
throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(),e.getError().getErrorMsg());
}
String openId=wxMpOAuth2AccessToken.getOpenId();
log.info("【微信网页授权】获取openid,returnUrl={}",returnUrl);
return "redirect:"+ returnUrl+"?openid="+openId;
}//以上两个方法是SDK方式微信网页授权的过程,
// 访问http://sqmax.natapp1.cc/sell/wechat/authorize?returnUrl=http://www.imooc.com,
代码示例来源:origin: linxinzhe/java-springboot-sell
@GetMapping("/userInfo")
public String userInfo(@RequestParam("code") String code,
@RequestParam("state") String returnUrl) {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
try {
wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
} catch (WxErrorException e) {
log.error("【微信网页授权】{}", e);
throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(), e.getError().getErrorMsg());
}
String openId = wxMpOAuth2AccessToken.getOpenId();
return "redirect:" + returnUrl + "?openid=" + openId;
}
代码示例来源:origin: sqmax/springboot-project
@GetMapping("/qrUserInfo")
public String qrUserInfo(@RequestParam("code") String code,
@RequestParam("state") String returnUrl){
WxMpOAuth2AccessToken wxMpOAuth2AccessToken=new WxMpOAuth2AccessToken();
try{
wxMpOAuth2AccessToken=wxOpenService.oauth2getAccessToken(code);
}catch (WxErrorException e){
log.error("【微信网页】{}",e);
throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(),e.getError().getErrorMsg());
}
log.info("wxMpOAuth2AccessToken={}", JsonUtil.toJson(wxMpOAuth2AccessToken));
String openId=wxMpOAuth2AccessToken.getOpenId();
return "redirect:"+returnUrl+"?openid="+openId;
}
}
代码示例来源:origin: linxinzhe/java-springboot-sell
@GetMapping("/qrUserInfo")
public String qrUserInfo(@RequestParam("code") String code) {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
try {
wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
} catch (WxErrorException e) {
log.error("【微信网页授权】{}", e);
throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(), e.getError().getErrorMsg());
}
log.info("wxMpOAuth2AccessToken={}", wxMpOAuth2AccessToken);
String openId = wxMpOAuth2AccessToken.getOpenId();
String redirectUrl = projectUrlConfig.getSell() + "/sell/seller/login";
return "redirect:" + redirectUrl + "?openid=" + openId;
}
}
代码示例来源:origin: aillamsun/genesis
/**
* @param @param code 授权换取的code
* @param isDetails 是否是获取了 详细信息
* @param @return 参数
* @return Map<String,Object> 返回类型
* @throws WxErrorException
* @throws
* @Title: oauthReturn
* @Description: TODO 授权成功后 获取 授权用户的信息
*/
public static Map<String, Object> oauthReturn(String code, boolean isDetails) throws WxErrorException {
Map<String, Object> userInfo = new HashMap<String, Object>();
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = null;
wxMpOAuth2AccessToken = WxMpServiceFactory.getWxMpService().oauth2getAccessToken(code);
if (wxMpOAuth2AccessToken == null) {
return userInfo;
}
userInfo.put("openId", wxMpOAuth2AccessToken.getOpenId());
if (isDetails) {
WxMpUser wxMpUser = WxMpServiceFactory.getWxMpService().oauth2getUserInfo(wxMpOAuth2AccessToken, null);
if (wxMpUser != null) {
userInfo.put("detailsInfo", wxMpUser);
}
}
return userInfo;
}
代码示例来源:origin: liuweijw/fw-cloud-framework
try {
boolean isSopeBase = from.intValue() == 1;
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
openId = wxMpOAuth2AccessToken.getOpenId();
log.info("【wxauth.openId】:state|" + state);
内容来源于网络,如有侵权,请联系作者删除!