|
@@ -75,6 +75,10 @@ public class WxLoginService
|
|
|
@Value("${wx.gzh.appsecret}")
|
|
|
private String gzh_appsrcret;
|
|
|
|
|
|
+ private String gzh_wxTokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
|
|
+
|
|
|
+ private String gzh_wxTokenParam = "grant_type=client_credential&appid=%s&secret=%s";
|
|
|
+
|
|
|
private String gzh_wxAuthUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
|
|
|
|
|
|
private String gzh_wxAuthParam = "appid=%s&secret=%s&code=%s&grant_type=authorization_code";
|
|
@@ -83,6 +87,14 @@ public class WxLoginService
|
|
|
|
|
|
private String gzh_wxUserInfoParam = "access_token=%s&openid=%s&lang=zh_CN";
|
|
|
|
|
|
+ private String gzh_wxUserListUrl = "https://api.weixin.qq.com/cgi-bin/user/get";
|
|
|
+
|
|
|
+ private String gzh_wxUserListParam = "access_token=%s";
|
|
|
+
|
|
|
+ private String gzh_wxUserCgiInfoUrl = "https://api.weixin.qq.com/cgi-bin/user/info";
|
|
|
+
|
|
|
+ private String gzh_wxUserCgiInfoParam = "access_token=%s&openid=%s&lang=zh_CN";
|
|
|
+
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
@@ -327,6 +339,42 @@ public class WxLoginService
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
+ public String getWxGzhAccessToken() {
|
|
|
+ String key = "WX_GZH_ACCESS_TOKEN";
|
|
|
+ String accessToken = redisCache.getCacheObject(key);
|
|
|
+ // if(Validator.isEmpty(accessToken)){
|
|
|
+ String param = String.format(gzh_wxTokenParam, gzh_appid, gzh_appsrcret);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxTokenUrl,param);
|
|
|
+ //解析json
|
|
|
+ JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
+ accessToken = String.valueOf(jsonObject.get("access_token"));
|
|
|
+ if(Validator.isNotEmpty(accessToken)){
|
|
|
+ redisCache.setCacheObject(key, accessToken,7100, TimeUnit.SECONDS);//7200有效期
|
|
|
+ }
|
|
|
+ // }
|
|
|
+ return accessToken;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getWxGzhUserList() {
|
|
|
+ String accessToken = getWxGzhAccessToken();
|
|
|
+ String nextOpenid = null;
|
|
|
+ String param = String.format(gzh_wxUserListParam, accessToken);
|
|
|
+ if(Validator.isNotEmpty(nextOpenid)){
|
|
|
+ param += "&next_openid="+nextOpenid;
|
|
|
+ }
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxUserListUrl,param);
|
|
|
+ System.out.println(resultString);
|
|
|
+ return resultString;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getWxGzhUserCgiInfo(String openid) {
|
|
|
+ String accessToken = getWxGzhAccessToken();
|
|
|
+ String param = String.format(gzh_wxUserCgiInfoParam, accessToken,openid);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxUserCgiInfoUrl,param);
|
|
|
+ System.out.println(resultString);
|
|
|
+ return resultString;
|
|
|
+ }
|
|
|
+
|
|
|
//公众号获取用户信息
|
|
|
public User getWxGzhUnionIdUser(WxLoginBody loginBody) {
|
|
|
String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
|