小程序中Java后台调用接口(getAccessToken)获取调用凭据,调用接口(msgSecCheck)检测文本内容是否安全--最终版
private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=小程序APPID&secret=小程序密钥";
// 调用接口(getAccessToken)获取调用凭据
private static String getAccessToken() {
HttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(TOKEN_URL);
try {
HttpResponse response = client.execute(post);
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
JSONObject jsonObject = new JSONObject(result);
return jsonObject.getString("access_token");
} catch (Exception e) {
e.printStackTrace()