Search in sources :

Example 1 with WxMpUser

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);
}
Also used : WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser)

Example 2 with WxMpUser

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;
}
Also used : WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser)

Example 3 with 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();
}
Also used : WxMpOAuth2AccessToken(me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Aggregations

WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)3 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)1 WxMpOAuth2AccessToken (me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken)1