/** 爱山东网管请求封装
 * 请求拦截、相应拦截、错误统一处理
 */

// const appmark = "sdzwapp"

var http2 = {
	post: function(params, fn) {
		/**
		 * 网关验签接口
		 * @param {1}  = appid应用唯一标识
		 * @param {2}  = interfaceid接口唯一标识
		 * @param {3}  = interfacecontent接口参数,请使用json格式, 例如:{"siteid":"2","cateid":"1"}
		 * @param {4}  = fromport端口来源"0"：PC；"1"：APP；"2"：支付宝；"3"：微信
		 * @param {5}  = signurl签名接口地址
		 * @param {6}  = gatewayurl网关接口地址
		 * @param {7}  = extraData 额外参数,附件,请求头一类的参数
		 * 
		 */

		// var params = '{"ticket":"' + ticket + '"}'
		// const interfaceContent = {
		// 	app_id: appmark,
		// 	servicename: "ticketValidate",
		// 	params: params
		// }
		// var params = '{"ticket":"' + ticket + '"}'
		// debugger
		const interfaceContent = {
			// app_id: appmark,
			// servicename: param.serviceId, // "ticketValidate",
			params: SM.decrypt(JSON.stringify(params.reqParams), params.interfacePublicKey)
		}
		const data = SM.encrypt(JSON.stringify(params.reqParams), params.interfacePublicKey)
		// const data = JSON.stringify(params.reqParams)
		console.log('http2方法进来了', JSON.stringify(params.reqParams))
		const headers = {
			Authorization: "Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiI0ODA3ODFkZmQxYmE0MmM0OGQyZDQ5NTllYzcyYTUwNCIsInVzZXIiOiJqYyIsInN1YiI6ImpjIn0.WfLq11T7iWPiMuzqDY2N54aIqdv-ciYCe6pINqQAeBdqlMiJmkufsqlD2YMmUzsHA-o4WerkiSYnPzexEMiAJA"
		}
		const extraData = {
			header: {
				Authorization: "Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiI0ODA3ODFkZmQxYmE0MmM0OGQyZDQ5NTllYzcyYTUwNCIsInVzZXIiOiJqYyIsInN1YiI6ImpjIn0.WfLq11T7iWPiMuzqDY2N54aIqdv-ciYCe6pINqQAeBdqlMiJmkufsqlD2YMmUzsHA-o4WerkiSYnPzexEMiAJA"
			},
		}
		// vaildInterfacefn("jisnzjk", "ticketvalidate", JSON.stringify(interfaceContent), "1", "https://" + urldomaincreatesign, "https://" + urldomaingateway).then((value) => {
		// vaildInterfaceWithHeadersfn(appid, interfaceid, interfacecontent, fromport, headers, signurl, gatewayurl)
		// vaildInterfaceWithHeadersfn("gqyjglptxiefn", params.serviceId, data, "1", headers, "https://" + urldomaincreatesign, "https://" + urldomaingateway).then((value) => {
		// vaildInterfacefn("gqyjglptxiefn", params.serviceId, data, "1", "https://" + urldomaincreatesign, "https://" + urldomaingateway).then((value) => {
		vaildInterfacefn("gqyjglptxiefn", params.serviceId, data, "1", extraData).then((value) => {
			
			if(value.code === '401'){
				vant.Dialog.alert({
					title: '信息提示',
					message: value.msg,
				})
				return
			}
			
			console.log('vaildInterfacefn响应', value)
			/**
			 * code: 200
			   data: "048b04671ad85e52e" // value 值就是接口返回的data值
			   msg: "请求成功"
			   success: true
		    */

			let sm2_encrypt_result = value
			let sm2_decrypt_result = sm2_Decrypt(sm2_encrypt_result, params.interfacePrivateKey)
			console.log('vaildInterfacefn响应解密', sm2_decrypt_result)
			fn && fn(sm2_decrypt_result)
		})
	},

}