Android 微信登录昵称乱码问题,及获取微信用户信息

微信第三方登录时昵称,username乱码问题解决方法如下:

/**
	 * 获取微信用户信息
	 * @param access_token 调用凭证
	 * @param openid 普通用户的标识,对当前开发者帐号唯一
	 * @return
	 */
	public static String getWeixinUserinfo(String access_token, String openid){
		String URLs =  ChildendConstant.WEIXIN_USERINFO;//微信登录地址
		String result = "";
		List list = new ArrayList();

		NameValuePair pairappid = new BasicNameValuePair("access_token", access_token);
		NameValuePair pairsecret = new BasicNameValuePair("openid", openid);
		list.add(pairappid);
		list.add(pairsecret);

		try{
			HttpEntity requestHttpEntity = new UrlEncodedFormEntity(list, HTTP.UTF_8);
			URL url = new URL(URLs);
			URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
			HttpPost httpPost = new HttpPost(uri);
			httpPost.setEntity(requestHttpEntity);
			HttpClient httpClient = new DefaultHttpClient();
			HttpResponse response = httpClient.execute(httpPost);
			 if (response.getStatusLine().getStatusCode() == 200) {
                 result = EntityUtils.toString(response.getEntity(),HTTP.UTF_8);//在这里转换
             }
			 return result;

		}catch(Exception e){
			e.printStackTrace();   
		}
		return result;
	}


你可能感兴趣的:(Android)