Node.js接入指南

更新时间:

操作步骤

步骤一:安装依赖

npm install aliyun-api-gateway -S

步骤二:填写调用AK/SK、调用路径、调用参数

'use strict';

const Client = require('aliyun-api-gateway').Client;

const request_headers = {
  accept: require('aliyun-api-gateway').CONTENT_TYPE_JSON,
  'Content-Type': require('aliyun-api-gateway').CONTENT_TYPE_JSON
}

const client = new Client('应用AK','应用SK');

async function invoke(path, params, headers) {
  return await client.post('https://openai.edu-aliyun.com' + path, {
    data: params,
    headers: { ...headers, ...request_headers},
    timeout: 300
  });
}

// 调用路径,具体参见 API
let api_path = "/scc/调用路径"

// 调用参数
let params = {
    '参数名称': '参数值'
}

// 请求头
let headers = {}

invoke(api_path, params, headers).then((response) => {
  // 调用结果
  console.log("Body:", JSON.stringify(response));
}).catch((err) => {
  console.log(err.stack);
});