var System = require("../../system")
const uuidv4 = require('uuid/v4');
const crypto = require('crypto');
const cryptoJS = require("crypto-js");
const querystring = require('querystring');
const logCtl = System.getObject("web.oplogCtl");
var settings = require("../../../config/settings");
var moment = require('moment');
const md5 = require("MD5");
class TlApi {
  constructor() {
    this.tlorderSve = System.getObject("service.tlorderSve");
    this.utilstlbankSve = System.getObject("service.utilstlbankSve");
  }
  async getH5PayUrl(pobj) {
    try {
      var result = await this.utilstlbankSve.getH5Url(pobj.company_id,pobj.pay_title,pobj.total_sum,pobj.order_no,pobj.returl);
      console.log(result, "result..................");
      return result;
    } catch (e) {
      console.log(e.stack, "e.......................");
    }
  }
  async getQrCodeInfo(obj) {
    try {
      // {
      //   "orderNo":"",-----//订单号
      //   "company_id":1,-----//公司id
      //   "other_company_id":,-----//其他公司id
      //   "op_type":"wx",-----//支付方式
      //   "totalSum":,-----//订单金额
      //   "sveItemCode":,-----//服务编码
      //   "sveItemName":"测试支付",
      //   "create_ip":""-----//请求ip地址
      // }

      var result = await this.tlorderSve.getQrCodeInfoTl(obj);
      console.log(result, "result..................");
      return result;
    } catch (e) {
      console.log(e.stack, "e.......................");
    }
  }
  async getPayStatus(obj) {
    // "aliPayOrderCode": "121905790000021861",
    // "company_id": 1,
    // "other_company_id":40,
    // "op_type": "alipay",
    // "orderNo": "TMO201910151718RCSW1",
    // "wxPayOrderCode": "121905790000021859"

    try {
      var result = await this.tlorderSve.checkPayStatusTl(obj);
      console.log(result, "result..................");
      return result;
    } catch (e) {
      console.log(e.stack, "e.......................");
    }
  }
  async notifyUrl(obj) {
    try {
      logCtl.info({
        optitle: "test支付页面回调支付状态---info",
        op: "/base/service/impl/orderSve.js/notifyUrl",
        content: "参数=" + JSON.stringify(obj),
        clientIp: obj.client_ip || ""
      });
    } catch (e) {
      logCtl.error({
        optitle: "支付页面回调支付状态---error异常",
        op: "/base/service/impl/orderSve.js/checkPayStatus",
        content: "error：" + e.stack + "，参数=" + JSON.stringify(obj),
        clientIp: obj.client_ip || ""
      });
    }
  }
}
module.exports = TlApi;
