/**
* 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参数