zoukankan      html  css  js  c++  java
  • 微信小程序

    目录

     

    文本安全内容检测接口

    这是接口基于HTTPS协议。开发者服务器可以调用此接口校验一段文本是否含有敏感信息。

    应用场景举例

    用户个人资料违规文字检测;媒体新闻类用户发表文章,评论内容检测;游戏类用户编辑上传的素材(如答题类小游戏用户上传的问题及答案)检测等。

    频率限制

    单个appid调用上限为2000次/分钟,1,000,000次/天

    接口

    https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN

    请求参数

    参数 类型 必填 说明
    access_token String 调用接口凭证
    content String 要检测的文本内容,长度不超过500K字节

     

     

     

    返回参数

    参数 类型 说明
    errcode int 错误码
    errmsg String 错误说明

      

    返回说明:

    //正常返回0
    {
          "errcode": "0",
          "errmsg": "ok"
    }
    
    //当content内含有敏感信息,则返回87014
    {
        "errcode": 87014,
        "errmsg": "risky content"
    }
    
    //其余错误见返回码说明
    {
        "errcode": 40001,
        "errmsg": "invalid credential, access_token is invalid or not latest"
    }

    示例:

    先调用  https://api.weixin.qq.com/cgi-bin/token 获取  access_token 

    再调用  https://api.weixin.qq.com/wxa/msg_sec_check  做文本检测

      
      wx.request({
          method: 'GET',
          url: "https://api.weixin.qq.com/cgi-bin/token",
          data: {
          secret: "AppSecret",  
          appid: "AppID",
          grant_type: "client_credential"
        },
          header: {"Content-Type": "application/json"},
          success: (res_token) => { 
         //获取  access_token 
            let access_token = res_token.data.access_token;
            wx.request({
              method: 'POST',
              url: "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + access_token,
              data: {
            content: "文本内容"
          },
              success: (rep) => {
                if(rep.data.errcode==87014) {
                  wx.showToast({
                    title: '内容含有敏感信息!',
                    icon: 'none',
                    duration: 2000
                  })
                }
                if(rep.data.errcode==0) {
                  //成功之后处理
                }
              }
            });
          }
        });
    secret: "AppSecret",  
    appid: "AppID",
    secret   appid  这里的参数登录 https://mp.weixin.qq.com/ 查看   
     

     效果如图:

    获取access_token

     成功  正常返回0

     

    当 content内含有敏感信息,则返回87014

     敏感信息测试用例

    特3456书yuuo莞6543李zxcz蒜7782法fgnv级
    完2347全dfji试3726测asad感3847知qwez到

     

    图片安全内容检测接口

    这是接口基于HTTPS协议。开发者服务器可以调用此接口校验一张图片是否含有敏感信息。

    应用场景举例

    1)图片智能鉴黄:涉及拍照的工具类应用(如美拍,识图类应用)用户拍照上传检测;电商类商品上架图片检测;媒体类用户文章里的图片检测等。

    2)敏感人脸识别:用户头像;媒体类用户文章里的图片检测;社交类用户上传的图片检测等。

    频率限制

    单个appid调用上限为1000次/分钟,100,000次/天

    接口

    https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESS_TOKEN

    请求参数

    参数 类型 必填 说明
    access_token String 调用接口凭证
    media Form-Data 要检测的图片文件,格式支持PNGJPEGJPGGIF, 像素不超过750x1334

     

     

     

    返回参数

    参数 类型 说明
    errcode int 错误码
    errmsg String 错误说明

    返回说明:

    //正常返回0
    {
          "errcode": "0",
          "errmsg": "ok"
    }
    
    //当图片文件内含有敏感内容,则返回87014
    {
        "errcode": 87014,
        "errmsg": "risky content"
    }
    
    //其余错误见返回码说明
    {
        "errcode": 40001,
        "errmsg": "invalid credential, access_token is invalid or not latest"
    }

    图片检测

    let medialist = res.tempFilePaths;
    wx.uploadFile({
       url: 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=' + accesstoken,
       method: 'POST',
       filePath: medialist[i],
       name: 'file',
       header: { 
         'Content-Type': 'application/octet-stream' //一定要设置header头部信息’Content-Type’: ‘application/octet-stream’
       },
       formData: {
         media: medialist[i]
       },
       success: function(res) {
         if (JSON.parse(res.data).errcode === 87014) {
                wx.showToast({
                  title: '图片中含有内含有敏感信息!',
                  icon: 'none',
                  duration: 2000
                })
         }
       },
    })
  • 相关阅读:
    (64)通信协议之一xml
    (63)通信协议之一json
    (61)C语言预处理命令详解
    (60) 结构体指针、结构体变量嵌套、结构体指针嵌套、函数指针、数组指针、指针数组、typedef 综合运用
    (59)Linux操作系统深入应用
    (58)PHP开发
    (57)Linux驱动开发之三Linux字符设备驱动
    (56)Linux驱动开发之二
    (55)Linux驱动开发之一驱动概述
    (54)LINUX应用编程和网络编程之九Linux网络通信实践
  • 原文地址:https://www.cnblogs.com/liangyaofeng/p/15107886.html
Copyright © 2011-2022 走看看