mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-24 04:53:50 +08:00
issue #3 获取用户基本信息
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user