微信内容检测 msgSecCheck

 

参考教程 https://developers.weixin.qq.com/community/develop/doc/0002c858d486a87ac217fb7cf5b404?highLine=msgSecCheck

官方文档 https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/sec-check/security.msgSecCheck.html

 

/**
 * Notes: 敏感词检测 微信API
 * User: 
 * Date: 2020/12/03
 * Time: 9:46:58
 * @param $text
 * @return bool true不含敏感词 false
 */
public function check_sensitive_words_wx($content){
    Log::info('敏感词check_sensitive_words_wx--$content--'.$content);

    // 小程序配置信息
    $wxConfig = WxappModel::getWxappCache($this->wxapp_id);

    $cacheKey = $wxConfig['app_id'] . '@access_token';
    if (!$access_token = Cache::get($cacheKey)) {
        // 请求API获取 access_token
        $access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$wxConfig['app_id']}&secret={$wxConfig['app_secret']}";

        $res = curl($access_token_url);
        $res_data = json_decode($res, true);
        if (array_key_exists('errcode', $res_data)) return false;
        $access_token = $res_data['access_token'];
        // 写入缓存
        Cache::set($cacheKey, $res_data['access_token'], 6000);    // 7000
    }

    $url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=".$access_token;
    $data = ['content'=>$content] ;
    $msg_res_json = curlPost($url,json_encode($data,JSON_UNESCAPED_UNICODE));
    $msg_res = json_decode($msg_res_json,true);

    if( (0 == $msg_res['errcode'] ) && ('ok' == $msg_res['errmsg'])  ){
        return true;
    }elseif ((87014 == $msg_res['errcode'] ) && ('risky content' == $msg_res['errmsg'])){
        return false;
    }else{
        return false;
    }


 

}


 

//"{"errcode":47001,"errmsg":"data format error rid: 5fcb4a24-45aedc6b-796e54e2"}"
    //"{"errcode":47001,"errmsg":"data format error rid: 5fcb4a54-335b0b51-15807df4"}"
//报数据格式错误时,使用JSON_UNESCAPED_UNICODE参数

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值