收藏
回答

安全内容检测接口一直返回pass, 是为什么呢?

'trace_id': '68559aaa-5e9d7428-533ccf37'

if isinstance(txt, bytes):
            content = txt.decode('utf-8')
        else:
            # 如果是字符串,确保编码为UTF-8
            content = str(txt)
            if not isinstance(content, str):
                # 处理非字符串对象(如数字等)
                content = str(content)
            # 最终确保是UTF-8编码的字符串
            content = content.encode('utf-8').decode('utf-8')
        data = {
            "openid": openid,
            "scene": scene,
            "version": version,
            "content": content
        }
        logger.info(f'[check secure begin] params: {json.dumps(data, ensure_ascii=False)}')
        response = requests.post(
            f'{self.base_url}/wxa/msg_sec_check',
            headers={
                'Content-Type': 'application/json; charset=utf-8'
            },
            params={'access_token': self.get_access_token()},
            json=data,
            timeout=(5, 10)
        )


        response.raise_for_status()
        res = response.json()
        logger.info(f'[check secure end] res: {json.dumps(res)}')
        suggest = res.get('result', {}).get('suggest')


        return suggest == 'pass'
回答关注问题邀请回答
收藏

1 个回答

  • 社区运营专员-wetingtu
    社区运营专员-wetingtu
    2天前

    你好,核实此为文字编码错误,传入的content显示为u8***\u5***,导致接口无法识别,请使用utf-8编码。

    2天前
    有用
    回复
登录 后发表内容