1.获取token
public String getToken(){
try {
HttpClient client = HttpClients.createDefault();
String tokenUrl = MessageFormat.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", APP_ID, APP_SECRET);
HttpGet request = new HttpGet(tokenUrl);
HttpResponse response = client.execute(request);
JSONObject object = getResponseJson(response);
if (object == null) {
return null;
}
return ObjectUtils.isEmpty(object) ? null : object.getString("access_token");
}catch (Exception e){ log.info(e.getMessage()); }
return null;
}
2.获取用户openId
// code前端传;type:1.公众号 2.小程序
public UserOpenIdDto getUserOpenId(String code,Integer type ) {
String resultStr;
UserOpenIdDto use