获取openid
(1)获取 token(记得在公众号配置授权域名)
/**
appid 公众号appid
appsecert 公众号密钥
**/
public String getToken(String appid,String appSecret){
String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+appSecret;
String result = HttpUtils.sendGet(url);
System.out.println(result);
JSONObject tokenJson = JSONObject.parseObject(result);
String token = tokenJson.get("access_token").toString();
System.out.println("获取到的TOKEN : " + token);
return token;
}
(2)开始获取openid
/**
appid 公众号appid
appSecret 公众号 密钥
code 页面返回的code(用来换取openid,前端获取code方式在下一篇文章)
**/
private String getOpenid(String appid,String appSecret,String code){
String token =null;
//redis中查看token是否存在,(token的有效期2小时,注意一