背景说明 :小程序内用留言板块,用户留言含有敏感词,导致版本审核失败,所以用户留言需经过校验

官方链接直达

需求比较简单,所以直接上代码了

   //小程序的access_token    String ACCESS_TOKEN = "";    /**     * 小程序敏感词过滤     *     * @param content 待校验的正文     * @return 0 无敏感词,1 有敏感词,2 校验失败     */    public Integer checkWords(String content) {        String url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + ACCESS_TOKEN;        MapString, Object map = new HashMapString, Object();        map.put("content", content);        String result = HttpUtils.sendPost(url, JSONObject.toJSONString(map));        System.out.println("敏感词校验结果:" + result);        MapString, Object resultMap = JSONObject.parseObject(result, Map.class);        if (resultMap.containsKey("errcode") && resultMap.get("errcode").toString().equals("0")) {            return 0;        }        if (resultMap.get("errcode").toString().equals("42001")) {            System.out.println("小程序accessToken过期");            return 2;        }        return 1;    }

代码中使用的HttpUtils可以在网上进行查找,也可以加我qq进行索要

TAG标签: 微信小程序微信敏感词

http://www.xiaochengxub.com/read-106008.html