
// // mock的地址
// const bin = require('bankcardinfo');
// var http= require("http");
// var merchant_public_key  = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUgUEnNB5a/pku7qCI2Eu9V9gyemawnGwdbiAqrcvUGOltep2fLSzf3fZNmfntqxhvLOz7JKVNk/lriXg0l7P76T5ZRvP7UkVWlnK/RMz2krYt5bUlB9EDi0sqWRI00/7JbHBMY+DzDpkF1Fz94HsIzVs9XGESO3Rpyj5vmRWofwIDAQAB";
// var merchant_private_key = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANSBQSc0Hlr+mS7uoIjYS71X2DJ6ZrCcbB1uICqty9QY6W16nZ8tLN/d9k2Z+e2rGG8s7PskpU2T+WuJeDSXs/vpPllG8/tSRVaWcr9EzPaSti3ltSUH0QOLSypZEjTT/slscExj4PMOmQXUXP3gewjNWz1cYRI7dGnKPm+ZFah/AgMBAAECgYB8AcFngz6DkzcI8C+2K6JnJ6/+JPdv8JgWxID45tqfNrphLMB2dwJM0VY+CrCSRNnJZsoT9FqSXtuaKWqAJlbchhPZjupA9RkWFzlGpCQ63/CC71RYYY03eCnc7AIpn52whkjfWG/yf57jKzEwUT+U034uvXdaA+lVvJ0xqpj3gQJBAOmLODjecn450TJbNQaop+7Q5Hz2TUIxbYakzPpcLGv1QYgHa657r7PJ23ZltDBGldMaNTZfqJrtDcq0rTA4lBECQQDo8CcdUhMZ3JbR2UZN0CG8ljMbNWgNWBa37ebE3ZG5yYldc7zY9US/+/7lhxNDqG0saTvM9pJwEc3ccVMvksOPAkEAqq7V+zIQKVJmItBn06MFgNNoei+kTUFEk8f0CvG8gXYwW5NYzp+UzOg1HbW82B9uNmeMBl4pInknwEMF5B0lkQJAdRxQPgCGk+kAdo6LNxHd9Ed7eEF4h8Ty3xQfgnh3DHYTtsU6e8WMBA24kENB3zEtejeKFjkdVHTPD/Z1wSRDZwJAAvNuq0YuRDsESOAerkBZKonA5CD0M4vHTRqihHrjBohv6y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4vHTRqihHrjBohv6yxBU8P7gALrX7qmoaZ3aLmN8wHdOAGTR6LZjQdkoQ==";
// var execSync = require('child_process').execSync;
// var request = require('request');

// function applyJarMethod(){
//   var par_str = "",re_str = "";
//   for(var i in arguments){
//     if( i != 0 ){
//     	par_str += arguments[i] + " ";
//     }
//   }
//   var re_str = execSync(
//     'java -jar ./libs/' + arguments[0] + '.jar ' + par_str
//   );  
//   return re_str.toString('utf8').replace(/[\r\n]/g, '');;
// }

// function runMethod(ajr_name,args){
//   var par_str = "",re_str = "";
//   var re_str = execSync(
//     'java -jar ./libs/' + ajr_name + '.jar ' + args.join(" ")
//   );  
//   return re_str.toString('utf8').replace(/[\r\n]/g, '');;
// }

// function getHeader() {
//     return {
//         "Content-type": "application/json; charset=UTF-8",
//         "Accept": "application/json; charset=UTF-8"
//     };
// }
// var Mem_storage = {};

// function getCardType(data){
//   return new Promise(function (resolve, reject) {
//       bin.getBankBin(data,function(err,body){
//         if (err) {
//           reject(err)
//         } else {
//           console.log(body)
//           resolve(body)
//         }
//       })
//     }) 
// }



// function requestPromise (option) {
//   return new Promise(function (resolve, reject) {
//     request(option, function (err, res, body) {
//       if (err) {
//         reject(err)
//       } else {
//         resolve(body)
//       }
//     })
//   })
// } 

// function getJsonValueString(obj){
//   var str = ""
//   for(var name in obj){
//     str+= obj[name]
//   }
//   return str
// }

// function callback (url, data){
//     let option = {
//       url: url,
//       method: "POST",
//       headers: {
//           "Content-Type": "application/x-www-form-urlencoded"
//       },
//       body: querystring.stringify(data)
//     }
//     console.log(option);
//     request(option,function(error,resp,body){
//       console.log("--CallBack---success!!!---");
//     });
// }
// var aeskey="1111111111111111";

// // public function

// app.use(async function (ctx, next) {
// 	//call back module
// 	//before judgment
// 	//do judgment
// 	//after judgment


// 	if (ctx.path.indexOf("run/jar") != -1){
// 		ctx.response.body = {data:applyJarMethod( ctx.request.body.jar, ctx.request.body.class_name, ctx.request.body.function_name, ctx.request.body.param_string)}
// 		ctx.status = 200;
// 		return;
// 	}

// 	if (ctx.path.indexOf("run/method") != -1){
// 		var call_res = ctx.request.body;
// 		ctx.status = 200;
// 		ctx.response.body = runMethod(call_res.jar_name,call_res.params);
// 		return
// 	}

//   if (ctx.path.indexOf("run/applyJarMethod") != -1){

//     ctx.status = 200;
//     var _list = []
//     for(var i = 2 ;i < 255; i++){
//       var _ip = "192.168.4."+i
//       var pwd = applyJarMethod("paycenter","AES","encryptToBase64",JSON.stringify(JSON.stringify({"ip" : _ip})), aeskey);
//       _list.push({
//         _ip : pwd
//       })
//     }
//     ctx.response.body = _list
//     return
//   }


//     if (ctx.path.indexOf("blackpearl/callback") != -1){
//       // 接收的内容是（开始回调，回调内容，给谁）
//       // 进入回调
//       var call_res = ctx.request.body;
//       var call_back_key = ctx.request.body.call_back_key;
//       delete call_res[call_back_key];
//       call_res["sign"] = applyJarMethod("paycenter","RSA","sign",getJsonValueString(call_res),merchant_private_key);
//       var resp={}
//       resp["encryptkey"] = applyJarMethod("paycenter","RSA","encrypt",aeskey,merchant_public_key);
//       resp["data"] = applyJarMethod("paycenter","AES","encryptToBase64",JSON.stringify(JSON.stringify(call_res)), aeskey);
// 			callback( Mem_storage[call_back_key].callbackurl,  resp)
//       ctx.status = 200;
// 			delete Mem_storage[call_back_key];
//       return;
//     }

//     if (ctx.path === "/hf/sign"){
//       ctx.status = 200;
// 			console.log(ctx.request.body.data);
// 			let reback = applyJarMethod("hengfeng", ctx.request.body.method, ctx.request.body.key,  JSON.stringify(ctx.request.body.data));
//       ctx.response.body = {data:reback};
//       return ;
//     }
//     console.log("psth: " + ctx.path + "    Mock Start!!!")
//     var xyqb_requ_json = ctx.request.body
//     var aesKey1 = applyJarMethod("paycenter","RSA","decrypt",xyqb_requ_json["encryptkey"],merchant_private_key);
//     var json = JSON.parse(applyJarMethod("paycenter","AES","decryptFromBase64",xyqb_requ_json["data"], aesKey1));
//     delete json["sign"]
//     // 记录需要回调的地址
//         if (ctx.path=="/tzt-api/api/bindcard/request"){
// 					// console.log("------------更新requestno----：")
// 					Mem_storage[ctx.request.ip+json["cardno"]]["requestno"] = json["requestno"]
//         }else if(ctx.path == "/tzt-api/api/bindcard/confirm"){
//         	json = Mem_storage[ctx.request.ip+json["requestno"]]
//         }else if(ctx.path == "/tzt-api/api/bindpay/request"){
//         	//还款回调,这里获取回调的URL并记录
// 					var call_back_key = ctx.request.ip+json["requestno"];
// 					Mem_storage[call_back_key] = json
//         }else if(ctx.path == "/tzt-api/api/bindpay/confirm"){
//         	//还款的时候把cakk_back_key带进去
// 					json["call_back_key"] = ctx.request.ip+json["requestno"];
//         }




//         let header = getHeader();
//         let option = {
//             url: "http://192.168.4.241" + ctx.path,
//             method: "POST",
//             json: true,
//             body: json
//         };
// 				//调用TOWER开始
//         console.log("----mock server request----")
//         console.log(option)
//         let res = await requestPromise(option);
//         console.log("----mock server responce----")
//         // console.log(res)
// 				//调用TOWER结束
//         if (ctx.path === '/tzt-api/api/bankcard/check') {
//           // do request
//           // res1 = await back(json["cardno"]);
//           let cardType = await getCardType(json["cardno"]);
//           res["bankname"] = cardType.bankName;
//           res["bankcode"] = cardType.bankCode;
// 					Mem_storage[ctx.request.ip+json["cardno"]] = {
// 						"bankcode"  :res["bankcode"],
// 						"bankname"  :res["bankname"],
// 						"cardlast"  :res["cardlast"],
// 						"cardtop"   :res["cardtop"],
// 						"errorcode" :"",
// 						"errormsg"  :"",
// 						"merchantno":res["merchantno"],
// 						"yborderid" :"TZAU" + randomString(32)
// 					}
//         }else if(ctx.path == "/tzt-api/api/bindcard/request"){
//         	if( Mem_storage[ctx.request.ip+json["cardno"]] != undefined){
// 						Mem_storage[ctx.request.ip+json["cardno"]]["status"] = res["status"]
// 						Mem_storage[ctx.request.ip+json["cardno"]]["yborderid"] = "TZAU" + randomString(32)
// 						Mem_storage[ctx.request.ip+json["cardno"]]["requestno"] = json["requestno"]
// 						Mem_storage[ctx.request.ip+json["requestno"]] = JSON.parse(JSON.stringify(Mem_storage[ctx.request.ip+json["cardno"]]));
// 						delete Mem_storage[ctx.request.ip+json["cardno"]]
// 						res = Mem_storage[ctx.request.ip+json["requestno"]]
// 					}
// 				}else if(ctx.path === '/tzt-api/api/bindcard/confirm'){
// 					res = JSON.parse(JSON.stringify(Mem_storage[ctx.request.ip+json["requestno"]]));
// 					delete Mem_storage[ctx.request.ip+json["requestno"]]
//         }else if(ctx.path === "/tzt-api/api/bindpay/confirm"){

//         		// delete Mem_storage[ctx.request.ip+json["requestno"]]
//         }


//         res["sign"] = applyJarMethod("paycenter","RSA","sign",getJsonValueString(res),merchant_private_key);
//         var resp={}
//         resp["encryptkey"] = xyqb_requ_json["encryptkey"];
//         resp["data"] = applyJarMethod("paycenter","AES","encryptToBase64",JSON.stringify(JSON.stringify(res)), aesKey1);
// 				console.log(resp);
//         ctx.response.body = resp;
//         console.log("psth: " + ctx.path + "    Mock Success!!!")
//         return
// })
