部分代码如下:
$access_token = json_decode($this->access_token())->access_token;
$endpoint = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=".$access_token;
Log::info('微信检测敏感词url',[$endpoint]);
$params = [
'openid' => $open_id['openid'],
'scene' => 4,
'version' => 2,
'content' => "测试数据:反动分子大麻海洛因台独一个台湾测试数据",
];
Log::info('微信检测敏感词params',[$params]);
$result = $this->postsCurl($params,$endpoint);
return [true,$result];
}
public function postsCurl(array $data,$endpoint)
{
// 构造请求头
$headers = array(
'Content-Type: application/json'
);
// 定义变量
$url = $endpoint;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
Log::info('微信检测敏感词检测结果',[$response]);
return json_decode($response, true);
}
Log打印结果:
[2024-07-24 14:23:30] local.INFO: 微信检测敏感词params [{"openid":"oo5Kt5GkFBZMSfVuspTWWU","scene":4,"version":2,"content":"测试数据:反动分子大麻海洛因台独一个台湾测试数据"}]
[2024-07-24 14:23:30] local.INFO: 微信检测敏感词url ["https://api.weixin.qq.com/wxa/msg_sec_check?access_token=82_uKM2Ag80M7rrrwcZ5FnLxpjZkRyjPkagvd_-3FAOREVUNFEYzhltzKEiF0_fX2C6BxzkdSr_jJslZwySgCYghObBGGCEXOicCpc2q2VxgLrqzDE7aw_EACALLM"]
微信检测敏感词检测结果:{
"errcode": 0,
"errmsg": "ok",
"detail": [
{
"strategy": "keyword",
"errcode": 0
},
{
"strategy": "content_model",
"errcode": 0,
"suggest": "pass",
"label": 100,
"prob": 90
}
],
"trace_id": "66a09de2-154c2720-2cb5f",
"result": {
"suggest": "pass",
"label": 100
}
}
不要依赖于免费的东西....https://developers.weixin.qq.com/community/develop/article/doc/0006283ce18ee0b10520fc90266013
//以下传参是可以的(有点奇怪,但是解决了~) 必须'scene' => 2, $params = [ 'openid' => $open_id['openid'], 'scene' => 2, 'version' => 2, 'content' => $content, ]; if($title) $params['title'] = $title;
看一下传入的内容是不是utf-8编码
'openid' => $open_id['openid'],
'scene' => 4,
'version' => 2,
'content' => "测试数据:反动分子大麻海洛因台独一个台湾测试数据",
];
$utf = mb_detect_encoding($params['content'], "UTF-8", true) == "UTF-8";
Log::info('微信检测编码',[$utf]);
//检测结果是 true 。。。。
特3456书yuuo莞6543李zxcz蒜7782法fgnv级
这个是2的
https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/sec-center/sec-check/msgSecCheck.html