|
17 | 17 | * Created by Binary Wang on 2016/7/21.
|
18 | 18 | */
|
19 | 19 | public class WxMpUserServiceImpl implements WxMpUserService {
|
20 |
| - private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/user"; |
21 |
| - private WxMpService wxMpService; |
22 |
| - |
23 |
| - public WxMpUserServiceImpl(WxMpService wxMpService) { |
24 |
| - this.wxMpService = wxMpService; |
25 |
| - } |
26 |
| - |
27 |
| - @Override |
28 |
| - public void userUpdateRemark(String openid, String remark) throws WxErrorException { |
29 |
| - String url = API_URL_PREFIX + "/info/updateremark"; |
30 |
| - JsonObject json = new JsonObject(); |
31 |
| - json.addProperty("openid", openid); |
32 |
| - json.addProperty("remark", remark); |
33 |
| - this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); |
34 |
| - } |
35 |
| - |
36 |
| - @Override |
37 |
| - public WxMpUser userInfo(String openid, String lang) throws WxErrorException { |
38 |
| - String url = API_URL_PREFIX + "/info"; |
39 |
| - lang = lang == null ? "zh_CN" : lang; |
40 |
| - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang); |
41 |
| - return WxMpUser.fromJson(responseContent); |
42 |
| - } |
43 |
| - |
44 |
| - @Override |
45 |
| - public WxMpUserList userList(String next_openid) throws WxErrorException { |
46 |
| - String url = API_URL_PREFIX + "/get"; |
47 |
| - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid); |
48 |
| - return WxMpUserList.fromJson(responseContent); |
49 |
| - } |
50 |
| - |
51 |
| - @Override |
52 |
| - public List<WxMpUser> userInfoList(List<String> openidList) throws WxErrorException { |
53 |
| - return userInfoList(new WxMpUserQuery(openidList)); |
54 |
| - } |
55 |
| - |
56 |
| - @Override |
57 |
| - public List<WxMpUser> userInfoList(WxMpUserQuery userQuery) throws WxErrorException { |
58 |
| - String url = API_URL_PREFIX + "/info/batchget"; |
59 |
| - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, userQuery.toJsonString()); |
60 |
| - return WxMpUser.fromJsonList(responseContent); |
61 |
| - } |
| 20 | + private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/user"; |
| 21 | + private WxMpService wxMpService; |
| 22 | + |
| 23 | + public WxMpUserServiceImpl(WxMpService wxMpService) { |
| 24 | + this.wxMpService = wxMpService; |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void userUpdateRemark(String openid, String remark) throws WxErrorException { |
| 29 | + String url = API_URL_PREFIX + "/info/updateremark"; |
| 30 | + JsonObject json = new JsonObject(); |
| 31 | + json.addProperty("openid", openid); |
| 32 | + json.addProperty("remark", remark); |
| 33 | + this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public WxMpUser userInfo(String openid, String lang) throws WxErrorException { |
| 38 | + String url = API_URL_PREFIX + "/info"; |
| 39 | + lang = lang == null ? "zh_CN" : lang; |
| 40 | + String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang); |
| 41 | + return WxMpUser.fromJson(responseContent); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public WxMpUserList userList(String next_openid) throws WxErrorException { |
| 46 | + String url = API_URL_PREFIX + "/get"; |
| 47 | + String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid); |
| 48 | + return WxMpUserList.fromJson(responseContent); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public List<WxMpUser> userInfoList(List<String> openidList) throws WxErrorException { |
| 53 | + return userInfoList(new WxMpUserQuery(openidList)); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public List<WxMpUser> userInfoList(WxMpUserQuery userQuery) throws WxErrorException { |
| 58 | + String url = API_URL_PREFIX + "/info/batchget"; |
| 59 | + String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, userQuery.toJsonString()); |
| 60 | + return WxMpUser.fromJsonList(responseContent); |
| 61 | + } |
62 | 62 |
|
63 | 63 | }
|
0 commit comments