public static String getWechatOpenId(String code, String appid, String secret)
{
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
String json = HttpUtils.doGet(url);
oAuthToken jsonToPojo = (oAuthToken)JsonUtils.jsonToPojo(json, oAuthToken.class);
json = jsonToPojo.getOpenid();
return json;
}
public static String getWechatAccess_Token(String appid, String secret)
{
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
return HttpUtils.doGet(url);
}
public static String getWechatAccess_Token()
{
String json = null;
try {
InputStream in = new WechatUtils().getClass().getResourceAsStream("/app.properties");
Properties props = new Properties();
InputStreamReader inputStreamReader = new InputStreamReader(in, "UTF-8");
props.load(inputStreamReader);
String appid = props.getProperty("appid");
String secret = props.getProperty("secret");
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
json = HttpUtils.doGet(url);
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return json;
}