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

var RPCClient = require('@alicloud/pop-core').RPCClient;

// const client = new Client('203756805', 'crkyej0xlmqa6bmvqijun6ltxparllyn');//开发
const client = new Client('203763771', 'e5e2ytnn6nrkr9qnqk4w5e6z0xlhkznu');//线上
class aliyunClient {
  constructor() {
    // this.aliReqUrl = "https://aliapi.gongsibao.com/tm/springboard";
    this.aliclient = new RPCClient({
      accessKeyId: 'LTAI4FmyipY1wuLHjLhMWiPa',
      accessKeySecret: 'hp4FF18IDCSym1prqzxrAjnnhNH3ju',
      endpoint: 'https://trademark.aliyuncs.com',
      apiVersion: '2018-07-24'
    });
  }
  async post(aliReqUrl, actionBody) {
    var param = {
      data: actionBody,
      timeout: 20000,
      headers: {
        accept: 'application/json'
      }
    };
    console.log(JSON.stringify(param), "______________峰擎---阿里云参数_______");
    var result = await client.post(aliReqUrl, param);
    console.log(JSON.stringify(result), "______________峰擎---阿里云返回结果_______");
    return result;
  }
  //阿里接口
  async reqbyget(obj, cbk) {
    var self = this;
    var action = obj.action;
    var reqbody = obj.reqbody;
    return self.aliclient.request(action, reqbody, {
      timeout: 3000, // default 3000 ms
      formatAction: true, // default true, format the action to Action
      formatParams: true, // default true, format the parameter name to first letter upper case
      method: 'GET', // set the http method, default is GET
      headers: {}, // set the http request headers
    });
  }
}
module.exports = aliyunClient;
