| | |
| | | package org.yeshi.utils.wx; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | import net.sf.json.JSONObject; |
| | | import org.yeshi.utils.HttpUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | |
| | | public static WeiXinUser getWeiXinUser(WeiXinUserParam param) { |
| | | String result = HttpUtil.getAsString(String.format(weiXinUrl2, param.getAccessToken(), param.getOpenId()), |
| | | "ISO-8859-1", "UTF-8"); |
| | | JSONObject jsonObject = null; |
| | | try { |
| | | jsonObject = new JSONObject(result); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | JSONObject jsonObject = JSONObject.fromObject(result); |
| | | |
| | | String nickname = jsonObject.optString("nickname"); |
| | | String province = jsonObject.optString("province"); |
| | | String city = jsonObject.optString("city"); |
| | |
| | | |
| | | private static WeiXinUserParam parseWeiXinUserParam(String result) { |
| | | WeiXinUserParam weiXinUserParam = new WeiXinUserParam(); |
| | | JSONObject jsonObject = null; |
| | | try { |
| | | jsonObject = new JSONObject(result); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | JSONObject jsonObject = JSONObject.fromObject(result); |
| | | |
| | | String openId = jsonObject.optString("openid"); |
| | | if ("".equals(openId)) { |
| | | return null; |