百度智能AI平台审核内容

百度智能AI平台

const request = require("request");

const AK = "";
const SK = "";

function getToken() {
  const options = {
    method: "POST",
    url:
      "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" +
      AK +
      "&client_secret=" +
      SK,
  };
  return new Promise((resolve) => {
    request(options, function (error, response) {
      if (error) throw new Error(error);
      resolve(JSON.parse(response.body).access_token);
    });
  });
}

async function valitateMsg() {
  const token = await getToken();
  const options = {
    method: "POST",
    url:
      "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=" +
      token,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      Accept: "application/json",
    },
    form: {
      text: "看片+v1234567890",
    },
  };

  request(options, function (error, response) {
    if (error) throw new Error(error);
    const res = JSON.parse(response.body);
    console.log(res.conclusion, res.data[0].msg);
  });
}

你可能感兴趣的:(JavaScript,javascript,前端)