微信根据openId查询微信用户信息,需要认证服务号。
2014-01-03 13:53
621 查看
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public static JSONObject getWechatUserInfo(String openId,String taken){
String url = WechatAppConfig.wechat_tx_url+"/cgi-bin/user/info?access_token="+taken+"&openid="+openId;
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
try {
client.executeMethod(get);
String returnJson=get.getResponseBodyAsString();
returnJson = new String(returnJson.getBytes("ISO8859_1"),"UTF-8");
JSONObject result = JSONObject.fromObject(returnJson);
if(result.containsKey("nickname"))
return new JsonResult(true).putObject(result).getResult();
else
return new JsonResult(false,result.optString("errcode")+":"+result.optString("errmsg")).getResult();
}
catch (Exception e) {
return new JsonResult(false,e.getMessage()).getResult();
}
return token;
}
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public static JSONObject getWechatUserInfo(String openId,String taken){
String url = WechatAppConfig.wechat_tx_url+"/cgi-bin/user/info?access_token="+taken+"&openid="+openId;
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
try {
client.executeMethod(get);
String returnJson=get.getResponseBodyAsString();
returnJson = new String(returnJson.getBytes("ISO8859_1"),"UTF-8");
JSONObject result = JSONObject.fromObject(returnJson);
if(result.containsKey("nickname"))
return new JsonResult(true).putObject(result).getResult();
else
return new JsonResult(false,result.optString("errcode")+":"+result.optString("errmsg")).getResult();
}
catch (Exception e) {
return new JsonResult(false,e.getMessage()).getResult();
}
return token;
}
相关文章推荐
- 微信根据openId查询微信用户信息,这个功能需要认证服务号
- 微信的接口网页授权获取用户基本信息不是只有认证服务号才有
- PHP获得微信用户的OpenID,然后再通过OpenID和access_token查询用户信息
- PHP获得微信用户的OpenID,然后再通过OpenID和access_token查询用户信息
- [004]微信公众账号开发教程第1篇-根据用户openID获取用户基本信息
- 公众号批量获取用户信息,php通过openid批量获得微信用户信息
- 微信小程序获取用户openid,头像昵称信息,后台java代码
- 微信小程序开发之获取openid及用户信息
- 通达OA 对通达2015版微信查询用户信息模块升级开发(图文)
- C#微信开发之旅(八):通过授权code以及openid获取用户信息
- 微信小程序 获取用户信息(包括openId等敏感信息)
- C#根据用户IP地址查询用户信息
- 通达OA 对通达2015版微信查询用户信息模块升级开发(图文)
- java 根据openId获取用户基本信息
- 微信小程序 获取用户信息(包括openId等敏感信息)
- thinkphp开发根据企业号开发者文档获取企业微信用户信息
- 微信网页授权-公众号支付(获取openid、用户信息等)
- 通达OA二次开发 对通达2015版微信查询用户信息模块升级开发(图文)
- 公众号根据openid获取用户信息,php通过openid得到用户详细信息
- 微信小程序开发之获取openid及用户信息