use of me.chanjar.weixin.mp.bean.result.WxMpUser in project weixin-java-tools by chanjarster.
the class WxMpUserAPITest method testUserInfo.
public void testUserInfo() throws WxErrorException {
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
WxMpUser user = wxService.userInfo(configProvider.getOpenId(), null);
Assert.assertNotNull(user);
}
use of me.chanjar.weixin.mp.bean.result.WxMpUser in project weixin-java-tools by chanjarster.
the class WxMpUserGsonAdapter method deserialize.
public WxMpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject o = json.getAsJsonObject();
WxMpUser wxMpUser = new WxMpUser();
Integer subscribe = GsonHelper.getInteger(o, "subscribe");
if (subscribe != null) {
wxMpUser.setSubscribe(new Integer(0).equals(subscribe) ? false : true);
}
wxMpUser.setCity(GsonHelper.getString(o, "city"));
wxMpUser.setCountry(GsonHelper.getString(o, "country"));
wxMpUser.setHeadImgUrl(GsonHelper.getString(o, "headimgurl"));
wxMpUser.setLanguage(GsonHelper.getString(o, "language"));
wxMpUser.setNickname(GsonHelper.getString(o, "nickname"));
wxMpUser.setOpenId(GsonHelper.getString(o, "openid"));
wxMpUser.setProvince(GsonHelper.getString(o, "province"));
wxMpUser.setSubscribeTime(GsonHelper.getLong(o, "subscribe_time"));
wxMpUser.setUnionId(GsonHelper.getString(o, "unionid"));
Integer sexId = GsonHelper.getInteger(o, "sex");
wxMpUser.setRemark(GsonHelper.getString(o, "remark"));
wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid"));
wxMpUser.setSexId(sexId);
if (new Integer(1).equals(sexId)) {
wxMpUser.setSex("男");
} else if (new Integer(2).equals(sexId)) {
wxMpUser.setSex("女");
} else {
wxMpUser.setSex("未知");
}
return wxMpUser;
}
use of me.chanjar.weixin.mp.bean.result.WxMpUser in project weixin-java-tools by chanjarster.
the class WxMpOAuth2Servlet method service.
@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 = wxMpService.oauth2getAccessToken(code);
response.getWriter().println("<h1>access token</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
response.getWriter().println("<h1>user info</h1>");
response.getWriter().println(wxMpUser.toString());
wxMpOAuth2AccessToken = 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();
}
Aggregations