@Override public MessageBlock decode(byte[] bytes) throws ProtocolException { try { String str = new String(bytes, "utf-8"); JSONObject json = JSONObject.parseObject(str); Object data = json.get("data"); MessageBlock mb = new MessageBlock(data); mb.setSerial(json.getLongValue("serial")); mb.setUid(json.getLongValue("uid")); mb.setCmd(json.getIntValue("cmd")); mb.setVersion(json.getFloatValue("version")); mb.setStatus(json.getIntValue("status")); mb.setErr(json.getString("err")); return mb; } catch (UnsupportedEncodingException e) { throw new ProtocolException("decode bytes[] with utf-8 error"); } }
/** * 第三方套件获取企业号管理员登录信息 * * @param authCode oauth2.0授权企业号管理员登录产生的code * @return 登陆信息 * @see <a * href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E7%AE%A1%E7%90%86%E5%91%98%E7%99%BB%E5%BD%95%E4%BF%A1%E6%81%AF">授权获取企业号管理员登录信息</a> * @see com.foxinmy.weixin4j.qy.model.OUserInfo * @throws WeixinException */ public OUserInfo getOUserInfoByCode(String authCode) throws WeixinException { String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri"); WeixinResponse response = weixinExecutor.post( String.format(oauth_logininfo_uri, providerTokenManager.getAccessToken()), String.format("{\"auth_code\":\"%s\"}", authCode)); JSONObject obj = response.getAsJson(); OUserInfo oUser = JSON.toJavaObject(obj, OUserInfo.class); obj = obj.getJSONObject("redirect_login_info"); Token loginInfo = new Token(obj.getString("login_ticket"), obj.getLongValue("expires_in") * 1000l); oUser.setRedirectLoginInfo(loginInfo); cacheStorager.caching( getLoginTicketCacheKey(oUser.getCorpInfo().getCorpId()), oUser.getRedirectLoginInfo()); return oUser; }