微信小程序 - 敏感內容檢測 文本檢測 圖片檢測


目錄

 

文本安全內容檢測接口

這是接口基於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
            })
     }
   },
})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM