本文整理汇总了Java中me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java WxMpOAuth2AccessToken类的具体用法?Java WxMpOAuth2AccessToken怎么用?Java WxMpOAuth2AccessToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WxMpOAuth2AccessToken类属于me.chanjar.weixin.mp.bean.result包,在下文中一共展示了WxMpOAuth2AccessToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: userInfo
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@GetMapping("/userInfo")
public String userInfo(@RequestParam("code") String code,
@RequestParam("state") String returnUrl) {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
try {
wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
} catch (WxErrorException ex) {
log.error("【微信网页授权】{}", ex);
throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(), ex.getError().getErrorMsg());
}
String openId = wxMpOAuth2AccessToken.getOpenId();
log.info("opiedId: " + openId);
return "redirect:" + returnUrl + "?openid=" + openId;
}
开发者ID:ldlood,项目名称:SpringBoot_Wechat_Sell,代码行数:17,代码来源:WechatController.java
示例2: qrUserInfo
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@GetMapping("/qruserInfo")
public String qrUserInfo(@RequestParam("code") String code,
@RequestParam("state") String returnUrl) {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
try {
wxMpOAuth2AccessToken = wxOpenService.oauth2getAccessToken(code);
} catch (WxErrorException ex) {
log.error("【微信网页登陆】{}", ex);
throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(), ex.getError().getErrorMsg());
}
String openId = wxMpOAuth2AccessToken.getOpenId();
log.info("opiedId: " + openId);
return "redirect:" + returnUrl + "?openid=" + openId;
}
开发者ID:ldlood,项目名称:SpringBoot_Wechat_Sell,代码行数:17,代码来源:WechatController.java
示例3: deserialize
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
JsonParseException {
WxMpOAuth2AccessToken accessToken = new WxMpOAuth2AccessToken();
JsonObject accessTokenJsonObject = json.getAsJsonObject();
if (accessTokenJsonObject.get("access_token") != null && !accessTokenJsonObject.get("access_token").isJsonNull()) {
accessToken.setAccessToken(GsonHelper.getAsString(accessTokenJsonObject.get("access_token")));
}
if (accessTokenJsonObject.get("expires_in") != null && !accessTokenJsonObject.get("expires_in").isJsonNull()) {
accessToken.setExpiresIn(GsonHelper.getAsPrimitiveInt(accessTokenJsonObject.get("expires_in")));
}
if (accessTokenJsonObject.get("refresh_token") != null && !accessTokenJsonObject.get("refresh_token").isJsonNull()) {
accessToken.setRefreshToken(GsonHelper.getAsString(accessTokenJsonObject.get("refresh_token")));
}
if (accessTokenJsonObject.get("openid") != null && !accessTokenJsonObject.get("openid").isJsonNull()) {
accessToken.setOpenId(GsonHelper.getAsString(accessTokenJsonObject.get("openid")));
}
if (accessTokenJsonObject.get("scope") != null && !accessTokenJsonObject.get("scope").isJsonNull()) {
accessToken.setScope(GsonHelper.getAsString(accessTokenJsonObject.get("scope")));
}
if (accessTokenJsonObject.get("unionid") != null && !accessTokenJsonObject.get("unionid").isJsonNull()) {
accessToken.setUnionId(GsonHelper.getAsString(accessTokenJsonObject.get("unionid")));
}
return accessToken;
}
开发者ID:11590692,项目名称:Wechat-Group,代码行数:27,代码来源:WxMpOAuth2AccessTokenAdapter.java
示例4: showUserInfo
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
/**
* 网页授权获取用户基本信息之后跳转的页面
*
* http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
* @param code
* @param state
* @param model
* @return
* @throws WxErrorException
*/
@RequestMapping(value="/user-info", method={RequestMethod.GET} )
public String showUserInfo(@RequestParam String code, @RequestParam(required=false) String state, Model model) throws WxErrorException {
// 1 第一步:用户同意授权,获取code
// 2 第二步:通过code换取网页授权access_token
// 3 第三步:刷新access_token(如果需要)
// 4 第四步:拉取用户信息(需scope为 snsapi_userinfo)
// 5 附:检验授权凭证(access_token)是否有效
//获取code后,请求以下链接获取access_token:
//https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
WxMpOAuth2AccessToken oAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
if(!wxMpService.oauth2validateAccessToken(oAuth2AccessToken)){
wxMpService.oauth2refreshAccessToken(oAuth2AccessToken.getRefreshToken());
}
WxMpUser user = wxMpService.oauth2getUserInfo(oAuth2AccessToken, "zh_CN");
LOGGER.info(user.toString());
model.addAttribute("user", user);
return "user-info";
}
开发者ID:jihao,项目名称:weixin-server-demo,代码行数:30,代码来源:WeiXinController.java
示例5: oauth2getUserInfo
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException {
StringBuilder url = new StringBuilder();
url.append("https://api.weixin.qq.com/sns/userinfo?");
url.append("access_token=").append(oAuth2AccessToken.getAccessToken());
url.append("&openid=").append(oAuth2AccessToken.getOpenId());
if (lang == null) {
url.append("&lang=zh_CN");
} else {
url.append("&lang=").append(lang);
}
try {
RequestExecutor<String, String> executor = new SimpleGetRequestExecutor();
String responseText = executor.execute(getHttpclient(), this.httpProxy, url.toString(), null);
return WxMpUser.fromJson(responseText);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:21,代码来源:WxMpServiceImpl.java
示例6: deserialize
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
JsonParseException {
WxMpOAuth2AccessToken accessToken = new WxMpOAuth2AccessToken();
JsonObject accessTokenJsonObject = json.getAsJsonObject();
if (accessTokenJsonObject.get("access_token") != null && !accessTokenJsonObject.get("access_token").isJsonNull()) {
accessToken.setAccessToken(GsonHelper.getAsString(accessTokenJsonObject.get("access_token")));
}
if (accessTokenJsonObject.get("expires_in") != null && !accessTokenJsonObject.get("expires_in").isJsonNull()) {
accessToken.setExpiresIn(GsonHelper.getAsPrimitiveInt(accessTokenJsonObject.get("expires_in")));
}
if (accessTokenJsonObject.get("refresh_token") != null && !accessTokenJsonObject.get("refresh_token").isJsonNull()) {
accessToken.setRefreshToken(GsonHelper.getAsString(accessTokenJsonObject.get("refresh_token")));
}
if (accessTokenJsonObject.get("openid") != null && !accessTokenJsonObject.get("openid").isJsonNull()) {
accessToken.setOpenId(GsonHelper.getAsString(accessTokenJsonObject.get("openid")));
}
if (accessTokenJsonObject.get("scope") != null && !accessTokenJsonObject.get("scope").isJsonNull()) {
accessToken.setScope(GsonHelper.getAsString(accessTokenJsonObject.get("scope")));
}
if (accessTokenJsonObject.get("unionid") != null && !accessTokenJsonObject.get("unionid").isJsonNull()) {
accessToken.setUnionId(GsonHelper.getAsString(accessTokenJsonObject.get("unionid")));
}
return accessToken;
}
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:27,代码来源:WxMpOAuth2AccessTokenAdapter.java
示例7: service
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
String code = request.getParameter("code");
try {
response.getWriter().println("<h1>code</h1>");
response.getWriter().println(code);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = this.wxMpService.oauth2getAccessToken(code);
response.getWriter().println("<h1>access token</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());
WxMpUser wxMpUser = this.wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
response.getWriter().println("<h1>user info</h1>");
response.getWriter().println(wxMpUser.toString());
wxMpOAuth2AccessToken = this.wxMpService.oauth2refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
response.getWriter().println("<h1>after refresh</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());
} catch (WxErrorException e) {
e.printStackTrace();
}
response.getWriter().flush();
response.getWriter().close();
}
开发者ID:11590692,项目名称:Wechat-Group,代码行数:33,代码来源:WxMpOAuth2Servlet.java
示例8: getOAuth2AccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxErrorException {
try {
RequestExecutor<String, String> executor = new SimpleGetRequestExecutor();
String responseText = executor.execute(this.getHttpclient(), this.httpProxy, url.toString(), null);
return WxMpOAuth2AccessToken.fromJson(responseText);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:10,代码来源:WxMpServiceImpl.java
示例9: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
StringBuilder url = new StringBuilder();
url.append("https://api.weixin.qq.com/sns/oauth2/access_token?");
url.append("appid=").append(this.configStorage.getAppId());
url.append("&secret=").append(this.configStorage.getSecret());
url.append("&code=").append(code);
url.append("&grant_type=authorization_code");
return this.getOAuth2AccessToken(url);
}
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:12,代码来源:WxMpServiceImpl.java
示例10: oauth2refreshAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
StringBuilder url = new StringBuilder();
url.append("https://api.weixin.qq.com/sns/oauth2/refresh_token?");
url.append("appid=").append(this.configStorage.getAppId());
url.append("&grant_type=refresh_token");
url.append("&refresh_token=").append(refreshToken);
return this.getOAuth2AccessToken(url);
}
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:11,代码来源:WxMpServiceImpl.java
示例11: service
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
String code = request.getParameter("code");
try {
response.getWriter().println("<h1>code</h1>");
response.getWriter().println(code);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = this.wxMpService.oauth2getAccessToken(code);
response.getWriter().println("<h1>access token</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());
WxMpUser wxMpUser = this.wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
response.getWriter().println("<h1>user info</h1>");
response.getWriter().println(wxMpUser.toString());
wxMpOAuth2AccessToken = this.wxMpService.oauth2refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
response.getWriter().println("<h1>after refresh</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());
} catch (WxErrorException e) {
e.printStackTrace();
}
response.getWriter().flush();
response.getWriter().close();
}
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:33,代码来源:WxMpOAuth2Servlet.java
示例12: doGet
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
AsyncContext actx = req.startAsync();
String code = req.getParameter("code");
String state = req.getParameter("state");
if (Checker.hasNull(code, state)) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
OAuth2Handler handler = oAuth2HandlerMap.get(state);
if (handler == null) {
resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
return;
}
actx.start(() -> {
try {
WxMpService wxMpService = WxMpServlet.instance.wxMpService;
WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
String wechat = token.getOpenId();
WxSession session = WechatSession.create();
handler.onOAuth2(actx, (HttpServletResponse) actx.getResponse(), wechat, session);
actx.complete();
} catch (Exception e) {
e.printStackTrace();
}
});
}
开发者ID:ZSCNetSupportDept,项目名称:WechatTicketSystem,代码行数:29,代码来源:OAuth2.java
示例13: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
return mpService.oauth2getAccessToken(code);
}
开发者ID:tanhaichao,项目名称:leopard,代码行数:5,代码来源:WeixinAccountClientImpl.java
示例14: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
// TODO Auto-generated method stub
return null;
}
开发者ID:tanhaichao,项目名称:leopard,代码行数:6,代码来源:QqAccountClientImpl.java
示例15: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String appId, String code) throws WxErrorException {
String url = String.format(OAUTH2_ACCESS_TOKEN_URL, appId, code, getWxOpenConfigStorage().getComponentAppId());
String responseContent = get(url);
return WxMpOAuth2AccessToken.fromJson(responseContent);
}
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:7,代码来源:WxOpenComponentServiceImpl.java
示例16: oauth2refreshAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String appId, String refreshToken) throws WxErrorException {
String url = String.format(OAUTH2_REFRESH_TOKEN_URL, appId, refreshToken, getWxOpenConfigStorage().getComponentAppId());
String responseContent = get(url);
return WxMpOAuth2AccessToken.fromJson(responseContent);
}
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:7,代码来源:WxOpenComponentServiceImpl.java
示例17: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
return wxOpenComponentService.oauth2getAccessToken(appId, code);
}
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:5,代码来源:WxOpenMpServiceImpl.java
示例18: oauth2refreshAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
@Override
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
return wxOpenComponentService.oauth2refreshAccessToken(appId, refreshToken);
}
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:5,代码来源:WxOpenMpServiceImpl.java
示例19: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
/**
* 获取用户的access_token
*
* @param code
* @return
* @throws WxErrorException
*/
WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException;
开发者ID:tanhaichao,项目名称:leopard,代码行数:9,代码来源:WeixinAccountClient.java
示例20: oauth2getAccessToken
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; //导入依赖的package包/类
/**
* <pre>
* 用code换取oauth2的access token
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
*/
WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException;
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:8,代码来源:WxMpService.java
注:本文中的me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论