"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const MsClient = require("cn.keytop.midend.microservice.Client");
let routeHost = "https://mms-test.keytop.cn/";
let appId = "cn.keytop.stc.cm.app1";
let appKey = "98e56a0213ac603549a07eca7dfb9ed2";
let msId = 'cn.keytop.stc.test.ms-mng';
let version = '2.0';
let authType = MsClient.AuthType.BASE;
const serviceClientConfig = new MsClient.ServiceClientConfig(routeHost, appId, appKey);
const serviceClient = new MsClient.ServiceClientImpl(serviceClientConfig);
/**
 * 测试 500 响应码
 */
const getTest1 = () => __awaiter(void 0, void 0, void 0, function* () {
    let uri = '/msServiceTest/getTest1';
    let tags = '';
    let header = { 'debug-mode': 'true' };
    let paramMap = {};
    paramMap['param1'] = 'param1';
    paramMap['param2'] = 'param2';
    let response = yield serviceClient.get(`${msId}.${uri}`, version, tags, header, paramMap, authType).catch(err => {
        console.log("getTest1=============>" + err);
    });
    if (response) {
        console.log("postTest1=============>" + JSON.stringify(response.data));
    }
});
/**
 * 200 GET 请求
 */
const getTest3 = () => __awaiter(void 0, void 0, void 0, function* () {
    let uri = '/msServiceTest/getTest3';
    let tags = '';
    let header = { 'debug-mode': 'true' };
    let paramMap = {};
    paramMap['param1'] = 'param1';
    paramMap['param2'] = 'param2';
    let response = yield serviceClient.get(`${msId}.${uri}`, version, tags, header, paramMap, authType).catch(err => {
        console.log("getTest3=============>" + err);
    });
    if (response) {
        console.log("getTest3=============>" + JSON.stringify(response.data));
    }
});
/**
 * 500 POST 请求
 */
const postTest1 = () => __awaiter(void 0, void 0, void 0, function* () {
    let uri = '/msServiceTest/postTest1';
    let tags = '';
    let header = { 'debug-mode': 'true' };
    let paramMap = {};
    paramMap['param1'] = 'param1';
    paramMap['param2'] = 'param2';
    let response = yield serviceClient.post(`${msId}.${uri}`, version, tags, header, paramMap, {}, authType, MsClient.RequestBodyType.WWW_FORM).catch(err => {
        console.log("postTest1=============>" + err);
    });
    if (response) {
        console.log("postTest1=============>" + JSON.stringify(response.data));
    }
});
/**
 *  POST JSON 请求
 */
const postTest2 = () => __awaiter(void 0, void 0, void 0, function* () {
    let uri = '/msServiceTest/postTest2';
    let tags = '';
    let header = { 'debug-mode': 'true' };
    let paramMap = {};
    let bodyObj = { 'param1': 'param1', 'param2': 'param2' };
    let response = yield serviceClient.post(`${msId}.${uri}`, version, tags, header, paramMap, bodyObj, authType, MsClient.RequestBodyType.RAW_JSON).catch(err => {
        console.log("postTest2=============>" + err);
    });
    if (response) {
        console.log("postTest2=============>" + JSON.stringify(response.data));
    }
});
/**
 *  POST JSON 请求
 */
const postTest3 = () => __awaiter(void 0, void 0, void 0, function* () {
    let uri = '/msServiceTest/postTest3';
    let tags = '';
    let header = { 'debug-mode': 'true' };
    let paramMap = {};
    paramMap['param1'] = 'param1';
    paramMap['param2'] = 'param2';
    paramMap['param3.p1'] = 'param3.p1';
    paramMap['param3.p2'] = 'param3.p2';
    let response = yield serviceClient.post(`${msId}.${uri}`, version, tags, header, paramMap, {}, authType, MsClient.RequestBodyType.WWW_FORM).catch(err => {
        console.log("postTest3=============>" + err);
    });
    if (response) {
        console.log("postTest3=============>" + JSON.stringify(response.data));
    }
});
/**
 *  文件上传
 */
const upload = () => __awaiter(void 0, void 0, void 0, function* () {
    let uri = '/msServiceTest/upload';
    let tags = '';
    let header = { 'debug-mode': 'true' };
    let paramMap = {};
    paramMap['param1'] = 'param1';
    let files = new Array();
    let file1 = new MsClient.MsFile('file1', fs.createReadStream('d:\\BocompayMerchant.xml'));
    let file2 = new MsClient.MsFile('file2', fs.createReadStream('d:\\BocompayMerchant.xml'));
    files.push(file1);
    files.push(file2);
    let response = yield serviceClient.postFiles(`${msId}.${uri}`, version, tags, header, paramMap, files, authType).catch(err => {
        console.log("upload=============>" + err);
    });
    if (response) {
        console.log("upload=============>" + JSON.stringify(response.data));
    }
});
const testUploadFile = () => __awaiter(void 0, void 0, void 0, function* () {
    let url = 'https://ts.keytop.cn/kt_midend/oss/upload';
    let files = new Array();
    let header = {
        'Authorization': 'KT-MIDEND:OTg4OGRkYWNkNThkNGI2ZDlkNDA5Y2IwZThkMjA4M2Q6OTI2Y2M1OTI1YTQxNDc5YmJiNWExZDdmODI4ZWNjNzY=',
        'charset': 'utf-8'
    };
    let readStream = fs.createReadStream('d:\\BocompayMerchant.xml');
    let file1 = new MsClient.MsFile('upload', readStream);
    files.push(file1);
    let httpClient = new MsClient.SimpleHttpUtil(1000);
    let response = yield httpClient.uploadFiles(url, {}, files, header).catch(err => {
        console.log("upload=============>" + err);
    });
    if (response) {
        console.log("upload=============>" + JSON.stringify(response.data));
    }
});
getTest1();
getTest3();
postTest1();
postTest2();
postTest3();
upload();
//# sourceMappingURL=ServiceClientTest.js.map