issue #3 获取用户基本信息

This commit is contained in:
Daniel Qian
2014-08-26 12:37:38 +08:00
parent e03bb0dfb8
commit 4c8c42475e
6 changed files with 181 additions and 3 deletions

View File

@@ -31,6 +31,7 @@ import chanjarster.weixin.bean.result.WxError;
import chanjarster.weixin.bean.result.WxMassSendResult;
import chanjarster.weixin.bean.result.WxMassUploadResult;
import chanjarster.weixin.bean.result.WxMediaUploadResult;
import chanjarster.weixin.bean.result.WxUser;
import chanjarster.weixin.exception.WxErrorException;
import chanjarster.weixin.util.fs.FileUtil;
import chanjarster.weixin.util.http.MediaDownloadRequestExecutor;
@@ -41,6 +42,7 @@ import chanjarster.weixin.util.http.SimplePostRequestExecutor;
import chanjarster.weixin.util.json.GsonHelper;
import chanjarster.weixin.util.json.WxGsonBuilder;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.internal.Streams;
@@ -248,6 +250,13 @@ public class WxServiceImpl implements WxService {
execute(new SimplePostRequestExecutor(), url, json.toString());
}
public WxUser userInfo(String openid, String lang) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/user/info";
lang = lang == null ? "zh_CN" : lang;
String responseContent = execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang);
;return WxUser.fromJson(responseContent);
}
/**
* 向微信端发送请求在这里执行的策略是当发生access_token过期时才去刷新然后重新执行请求而不是全局定时请求
* @param executor