package org.springblade.yeePay.service;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.URLUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeepay.yop.sdk.exception.YopClientException;
import com.yeepay.yop.sdk.security.DigestAlgEnum;
import com.yeepay.yop.sdk.service.common.YopClient;
import com.yeepay.yop.sdk.service.common.YopClientBuilder;
import com.yeepay.yop.sdk.service.common.request.YopRequest;
import com.yeepay.yop.sdk.service.common.response.YopResponse;
import com.yeepay.yop.sdk.utils.FileUtils;
import com.yeepay.yop.sdk.utils.Sm2CertUtils;
import com.yeepay.yop.sdk.utils.Sm2Utils;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.guosen.bussinessRegisterRequest.entity.BussinessRegisterRequest;
import org.springblade.wx.config.WXConfiger;
import org.springblade.yeePay.common.YeePayConst;
import org.springblade.yeePay.entity.*;
import org.springblade.yeePay.event.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URL;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;

@Service
@Slf4j
public class YeePayService {
	@Autowired
	WXConfiger wxConfiger;
	@Autowired
	YeePayConst yeePayConst;
	@Autowired
	private ApplicationEventPublisher eventPublisher;

	YopClient yopClient = YopClientBuilder.builder().build();

	/**
	 *	易宝 公众号配置
	 * @param configAppDto
	 * @return*/
	public R configApp(ConfigAppDto configAppDto) {
		YopRequest request = new YopRequest(yeePayConst.getWeChatConfigAddUrl(), "POST");
		addMerchantNo(request);
		if(configAppDto.getAppIdList()!=null){
			request.addParameter("appIdList", JSON.toJSONString(configAppDto.getAppIdList()));
		}
		if(configAppDto.getTradeAuthDirList()!=null){
			request.addParameter("tradeAuthDirList",JSON.toJSONString(configAppDto.getTradeAuthDirList()));
		}
		try {
			YopResponse response = yopClient.request(request);
			return R.data(JSON.parseObject(response.getStringResult()));
		} catch (YopClientException e) {
			e.printStackTrace();
		}
		return R.fail("配置失败");
	}

	/**
	 *	易宝 查询公众号配置
	 *
	 * @param appIdType
	 * @return*/
	public R queryApp(String appIdType) {
		YopRequest request = new YopRequest(yeePayConst.getWeChatConfigQueryUrl(), "GET");
		if(appIdType!=null){
			request.addParameter("appIdType",appIdType);
		}
		addMerchantNo(request);
		try {
			YopResponse response = yopClient.request(request);
			return R.data(JSON.parseObject(response.getStringResult()));
		} catch (YopClientException e) {
			e.printStackTrace();
		}
		return R.fail("查询失败");
	}

	/**
	 * 	易宝 统一下单
	 *
	 * @param initOrderDto
	 * @return*/
	public R initOrder(InitOrderDto initOrderDto){
		YopRequest request = new YopRequest(yeePayConst.getPrePayUrl(), "POST");
		initOrderDto.setNotifyUrl(yeePayConst.getPayNotify());
		addMerchantNo(request);
		addParamsFromObj(initOrderDto,request,initOrderDto.getClass());
		return execute(request);
	}


	/**
	 * 	添加请求参数
	 * @param obj 请求所需DTO对象
	 * @param request 所需添加参数请求
	 * @param clazz */
	private void addParamsFromObj(Object obj, YopRequest request, Class clazz){
		Arrays.stream(clazz.getDeclaredFields())
			.forEach(field -> {
					field.setAccessible(true);
					try {
						String paramValue = Optional.ofNullable(field.get(obj)).orElse("").toString();
						if(paramValue!=null&!"".equals(paramValue)){
							request.addParameter(field.getName(),paramValue);
						}
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			);
	}

	/**
	 * 	解析解密支付通知数据
	 * @param response 加密数据
	 * */
	public JSONObject deCodeNotifyData(Map<String, Object> response) {
		log.info("回调数据："+JSON.toJSONString(response));
//		Map<String,String> params = notifyParams(response.get("params").toString());

		try {
			String decryptData = Sm4GcmUtils.decrypt_GCM_NoPadding(
				yeePayConst.getSm4Key(),
				response.get("cipherText")+"",
				"",
				""
			);
			log.info("通知解密数据："+ decryptData);
			return JSON.parseObject(decryptData);
		} catch (Exception e) {
			log.error("回调解析错误： "+ e.getMessage());
		}
		return null;
	}

	/**
	 *	代付：转账到银行卡(批量出款)
	 * @param batchTransferDto 转账信息
	 * */
	public R batchTransferToCard(BatchTransferDto batchTransferDto) {
		YopRequest request = new YopRequest(yeePayConst.getBatchTransferUrl(), "POST");
		batchTransferDto.setNotifyUrl(yeePayConst.getBatchTransferNotify());
		batchTransferDto.setParentMerchantNo(batchTransferDto.getParentMerchantNo());
		batchTransferDto.setMerchantNo(batchTransferDto.getMerchantNo());
//		RequestConfig requestConfig = request.getRequestConfig();
		request.setContent(JSONObject.toJSONString(batchTransferDto));
		return execute(request);
	}

	private R execute(YopRequest request){
		YopResponse response = null;
		try {
			response = yopClient.request(request);
			System.out.println(JSON.parseObject(response.getStringResult()));
			return R.data(JSON.parseObject(response.getStringResult()));
		} catch (YopClientException e) {
			e.printStackTrace();
		}
		return R.fail("操作失败");
	}

	/**
	 * 	转账订单查询
	 * @param requestNo 易宝订单号
	 * */
	public R queryTransferOrder( String requestNo ){
		YopRequest request = new YopRequest(yeePayConst.getQueryTransferOrderUrl(), "GET");
		addMerchantNo(request);
		request.addParameter("requestNo", requestNo);
		return execute(request);
	}


	private void addMerchantNo(YopRequest request){
		request.addParameter("parentMerchantNo",yeePayConst.getParentMerchantNo());
	}

	public void orderNotify(Map<String, Object> params) {
		JSONObject decryptData = deCodeNotifyData(params);
		PayNotifyEvent payNotifyEvent = new PayNotifyEvent(decryptData);
		eventPublisher.publishEvent(payNotifyEvent);
	}


	public void transferNotify(Map<String, Object> params) {
		log.info("======================== 转账原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== 转账回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		TransferEvent transferEvent = new TransferEvent(decryptData);
		eventPublisher.publishEvent(transferEvent);
	}

	public void bonusNotify(Map<String, Object> params) {
		log.info("======================== 分润原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== 分润回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		BonusEvent bonusEvent = new BonusEvent(decryptData);
		eventPublisher.publishEvent(bonusEvent);
	}


	/**
	 * 	查询账户余额
	 * */
	public R queryBalance(String merchantNo) {
		YopRequest request = new YopRequest(yeePayConst.getQueryBalanceUrl(), "GET");
		request.addParameter("merchantNo", merchantNo);
		R execute = execute(request);
		log.info("======================== 商户查询余额数据 =======================");
		log.info(JSONUtil.toJsonStr(execute));
		return execute;
	}

	/**
	 * 	网关--充值
	 * @param payGateWayDto 网关入参实体
	 * */
	public R
	payByGateWay(PayGateWayDto payGateWayDto) {
		if(StringUtil.isBlank(payGateWayDto.getDirectPayType())){
			return R.fail("付款方式必填！");
		}
		YopRequest request = new YopRequest(yeePayConst.getPayGateWayUrl(), "POST");
		payGateWayDto.setNotifyUrl(yeePayConst.getGatewayNotify());
		addMerchantNo(request);
		addParamsFromObj(payGateWayDto,request,payGateWayDto.getClass());
		YopResponse response = null;
		String token = null;
		try {
			response = yopClient.request(request);
			token= JSON.parseObject(response.getStringResult()).getString("token");
		} catch (YopClientException e) {
			e.printStackTrace();
			return R.fail("付款失败！");
		}
		Assert.notNull(token,"获取订单token失败，下单异常");
		List<KeyAndValue> params = new ArrayList<>();
		String timeStr = System.currentTimeMillis() / 1000 + "";
		params.add(KeyAndValue.builder().key("appKey").value(yeePayConst.getAppKey()).build());
		params.add(KeyAndValue.builder().key("merchantNo").value(payGateWayDto.getMerchantNo()).build());
		params.add(KeyAndValue.builder().key("token").value(token).build());
		params.add(KeyAndValue.builder().key("timestamp").value(timeStr).build());
		params.add(KeyAndValue.builder().key("directPayType").value(payGateWayDto.getDirectPayType()).build());
		params.add(KeyAndValue.builder().key("cardType").value("").build());
		params.add(KeyAndValue.builder().key("userNo").value("").build());
		params.add(KeyAndValue.builder().key("userType").value("").build());
		params.add(KeyAndValue.builder().key("ext").value("").build());

		String payUrl = "https://cash.yeepay.com/cashier/std?" +
			"appKey="+yeePayConst.getAppKey()+
			"&merchantNo=" + payGateWayDto.getMerchantNo()+
			"&token=" +token+
			"&timestamp=" +timeStr+
			"&directPayType=" + payGateWayDto.getDirectPayType() +
			"&cardType=" +
			"&userNo=" +
			"&userType=" +
			"&ext=" +
			"&sign="+this.sign(params);
		return R.data(JSONObject.parseObject("{\n" +
			" \"payUrl\": \""+payUrl+"\"\n" +
			"}"));


	}

	public static void main(String[] args) throws CertificateException, NoSuchProviderException {
		X509Certificate x509Certificate = Sm2CertUtils.getX509Certificate(FileUtils.getResourceAsStream("config/certs/4421256739.cer"));
		System.out.println(x509Certificate);
	}
	/**
	 * 网关充值回调
	 * */
	public void gatewayNotify(Map<String, Object> params) {
		log.info("======================== 网关充值原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== 网关充值回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		GatewayEvent gatewayEvent = new GatewayEvent(decryptData);
		eventPublisher.publishEvent(gatewayEvent);
	}

	private	 String sign(List<KeyAndValue> params){
		StringBuilder stringBuilder = new StringBuilder();
		params.stream().forEach(item ->
			stringBuilder.append(item.getKey()+"="+item.getValue()+"&")
		);
		String s = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
		System.out.println(s);
		String priKey = yeePayConst.getPrivateKey();
		PrivateKey privateKey1 = Sm2Utils.string2PrivateKey(priKey);
		String sign = Sm2Utils.sign(s, (BCECPrivateKey) privateKey1)+"$"+ DigestAlgEnum.SM3.getValue();
		return sign;
	}

	public void batchTransferNotify(Map<String, Object> params) {
		log.info("======================== (批量) 转账原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== (批量) 转账回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		BatchTransferEvent event = new BatchTransferEvent(decryptData);
		eventPublisher.publishEvent(event);
	}


	//------------------------------------2.0----------------------------------

	/**
	 * 	商户进件申请
	 *
	 * @param bussinessRegisterRequest
	 * @return*/
	public R merchantRegister(BussinessRegisterRequest bussinessRegisterRequest, String parentMerchantNo){
		YopRequest request = new YopRequest(yeePayConst.getMerchantRegisterUrl(), "POST");
		bussinessRegisterRequest.setNotifyUrl(yeePayConst.getMerchantRegisterNotify());
		request.addParameter("parentMerchantNo",parentMerchantNo);
		addParamsFromObj(bussinessRegisterRequest,request,bussinessRegisterRequest.getClass());
		try {
			R execute = execute(request);
			log.info("======================== 商户/小微用户进件申请同步结果数据 =======================");
			log.info(JSONUtil.toJsonStr(execute));
			return execute;
		}catch (Exception e){
			R.fail(e.getMessage());
			return R.fail("系统异常");
		}
	}

	/**
	 * 	小微用户进件申请
	 *
	 * @param bussinessRegisterRequest
	 * @return*/
	public R userRegister(BussinessRegisterRequest bussinessRegisterRequest, String parentMerchantNo){
		YopRequest request = new YopRequest(yeePayConst.getUserRegisterUrl(), "POST");
		bussinessRegisterRequest.setNotifyUrl(yeePayConst.getUserRegisterNotify());
		request.addParameter("parentMerchantNo", parentMerchantNo);
		addParamsFromObj(bussinessRegisterRequest,request,bussinessRegisterRequest.getClass());
		try {
			R execute = execute(request);
			log.info("======================== 商户/小微用户进件申请同步结果数据 =======================");
			log.info(JSONUtil.toJsonStr(execute));
			return execute;
		}catch (Exception e){
			R.fail(e.getMessage());
			return R.fail("系统异常");
		}
	}

	/**
	 * 商户进件回调
	 * @param params
	 */
	public void merchantRegisterNotify(Map<String, Object> params) {
		log.info("======================== 商户入网申请回调原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== 商户入网申请回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		MerchantRegisterEvent merchantEvent = new MerchantRegisterEvent(decryptData);
		eventPublisher.publishEvent(merchantEvent);
	}

	/**
	 * 小微用户进件回调
	 * @param params
	 */
	public void userRegisterNotify(Map<String, Object> params) {
		log.info("======================== 小微用户入网申请回调原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== 小微用户入网申请回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		UserRegisterEvent userRegisterEvent = new UserRegisterEvent(decryptData);
		eventPublisher.publishEvent(userRegisterEvent);
	}

	/**
	 * 	充值-网银下单
	 *
	 * @param rechargeDto
	 * @return*/
	public R merchantRechargeOrder(RechargeDto rechargeDto){
		YopRequest request = new YopRequest(yeePayConst.getRechargeOrderUrl(), "POST");
		rechargeDto.setNotifyUrl(yeePayConst.getRechargeOrderNotify());
		addParamsFromObj(rechargeDto, request, rechargeDto.getClass());
		try{
			log.info("=========================商户充值-网银下单请求数据 =======================");
			log.info(JSONUtil.toJsonStr(rechargeDto));
			R execute = execute(request);
			log.info("=========================商户充值-网银下单同步结果数据 =======================");
			log.info(JSONUtil.toJsonStr(execute));
			return execute;
		}catch (Exception e){
			R.fail(e.getMessage());
			return R.fail("系统异常");
		}
	}

	/**
	 * B2B充值回调（充值回调）
	 * @param params
	 */
	public void rechargeOrderNotify(Map<String, Object> params) {
		log.info("======================== 充值回调原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("======================== 充值回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		RechargeOrderEvent rechargeOrderEvent = new RechargeOrderEvent(decryptData);
		eventPublisher.publishEvent(rechargeOrderEvent);
	}

	/**
	 * 商户间转账下单回调
	 * @param params
	 */
	public void transferOrderNotify(Map<String, Object> params) {
		log.info("======================== 商户间转账下单回调原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("========================商户间转账下单回调调解密数据 =======================");
		log.info(decryptData.toJSONString());
		TransferOrderEvent transferOrderEvent = new TransferOrderEvent(decryptData);
		eventPublisher.publishEvent(transferOrderEvent);
	}

	/**
	 * 付款下单回调（代付回调）
	 * @param params
	 */
	public void payOrderNotify(Map<String, Object> params) {
		log.info("======================== 付款下单回调原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("========================付款下单回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		PayOrderNotifyEvent payOrderNotifyEvent = new PayOrderNotifyEvent(decryptData);
		eventPublisher.publishEvent(payOrderNotifyEvent);
	}

	/**
	 * 提现下单回调（提现回调）
	 * @param params
	 */
	public void withdrawOrderNotify(Map<String, Object> params) {
		log.info("======================== 付款下单回调原始数据 =======================");
		log.info(JSON.toJSONString(params));
		JSONObject decryptData = deCodeNotifyData(params);
		log.info("========================付款下单回调解密数据 =======================");
		log.info(decryptData.toJSONString());
		WithdrawOrderNotifyEvent withdrawOrderNotifyEvent = new WithdrawOrderNotifyEvent(decryptData);
		eventPublisher.publishEvent(withdrawOrderNotifyEvent);
	}

	/**
	 * 	文件上传接口
	 * */
	public R qualUpload(String imageUrl){
		YopRequest request = new YopRequest(yeePayConst.getQualUpload(), "POST");
		try {
			URL url = URLUtil.toUrlForHttp(imageUrl);
			request.addMultiPartFile("merQual", url.openStream());
		} catch (IOException e) {
			e.printStackTrace();
			return R.fail("转账失败");
		}
		R execute = execute(request);
		log.info("============================易宝上传图片结果=========================");
		log.info(JSON.toJSONString(execute));
		return execute;
	}

	/**
	 * 	账户服务-转账-下单（商户间转账）
	 * */
	public R transferOrder(TransferOrderDto transferOrderDto, String parentMerchantNo){
		YopRequest request = new YopRequest(yeePayConst.getTransferOrderUrl(), "POST");
		request.addParameter("parentMerchantNo", parentMerchantNo);
		transferOrderDto.setNotifyUrl(yeePayConst.getTransferOrderNotify());
		addParamsFromObj(transferOrderDto, request, transferOrderDto.getClass());
		R execute = execute(request);
		log.info("=========================商户转账-下单同步请求结果返回数据 =======================");
		log.info(JSONUtil.toJsonStr(execute));
		return execute;
	}
	/**
	 * 	账户服务-转账-查询（商户间转账）
	 * */
	public R transferQuery(TransferQueryDto transferQueryDto, String parentMerchantNo){
		YopRequest request = new YopRequest(yeePayConst.getTransferOrderUrl(), "POST");
		request.addParameter("parentMerchantNo", parentMerchantNo);
		addParamsFromObj(transferQueryDto, request, transferQueryDto.getClass());
		R execute = execute(request);
		log.info("=========================商户转账查询-同步请求结果返回数据 =======================");
		log.info(JSONUtil.toJsonStr(execute));
		return execute;
	}


	/**
	 *	代付：交易到银行卡(单笔出款)
	 * @param payOrderDto 交易信息
	 * */
	public R payOrder(PayOrderDto payOrderDto, String parentMerchantNo) {
		YopRequest request = new YopRequest(yeePayConst.getPayOrderUrl(), "POST");
		payOrderDto.setNotifyUrl(yeePayConst.getPayOrderNotify());
		request.addParameter("parentMerchantNo", parentMerchantNo);
		addParamsFromObj(payOrderDto,request, payOrderDto.getClass());
		log.info("======================代付交易下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}

	/**
	 * 提现：从商户号提现到银行卡
	 * @param withdrawOrderDto 交易信息
	 * */
	public R withdrawOrder(WithdrawOrderDto withdrawOrderDto, String parentMerchantNo) {
		YopRequest request = new YopRequest(yeePayConst.getWithdrawOrderUrl(), "POST");
		withdrawOrderDto.setNotifyUrl(yeePayConst.getWithdrawOrderNotify());
		request.addParameter("parentMerchantNo", parentMerchantNo);
		addParamsFromObj(withdrawOrderDto, request, withdrawOrderDto.getClass());
		log.info("======================提现交易下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}

	/**
	 * 提现：修改提现卡
	 * @param withdrawCardBindDto 添加信息
	 * */
	public R withdrawCardBind(WithdrawCardBindDto withdrawCardBindDto) {
		YopRequest request = new YopRequest(yeePayConst.getWithdrawCardBind(), "POST");
		addParamsFromObj(withdrawCardBindDto, request, withdrawCardBindDto.getClass());
		log.info("======================添加提现卡下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}

	/**
	 * 提现：修改提现卡
	 * @param withdrawCardModifyDto 修改信息
	 * */
	public R withdrawCardModify(WithdrawCardModifyDto withdrawCardModifyDto) {
		YopRequest request = new YopRequest(yeePayConst.getWithdrawCardModify(), "POST");
		addParamsFromObj(withdrawCardModifyDto, request, withdrawCardModifyDto.getClass());
		log.info("======================修改提现卡下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}

	/**
	 * 提现：查询提现卡
	 * @param merchantNo 查询信息
	 * */
	public R withdrawCardQuery(String merchantNo) {
		YopRequest request = new YopRequest(yeePayConst.getWithdrawCardQuery(), "GET");
		request.addParameter("merchantNo", merchantNo);
		log.info("======================查询提现卡下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}

	/**
	 *	分润：交易到银行卡(单笔出款)
	 * @param payOrderDto 交易信息
	 * */
	public R bonusOrder(PayOrderDto payOrderDto, String parentMerchantNo) {
		YopRequest request = new YopRequest(yeePayConst.getPayOrderUrl(), "POST");
		payOrderDto.setNotifyUrl(yeePayConst.getBonusOrderNotify());
		request.addParameter("parentMerchantNo", parentMerchantNo);
		addParamsFromObj(payOrderDto,request, payOrderDto.getClass());
		log.info("======================代付交易下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}

	/**
	 *	产品费率变更
	 * @param productFeeModifyDto 变更信息
	 * */
	public R productFeeModify(ProductFeeModifyDto productFeeModifyDto, String parentMerchantNo) {
		YopRequest request = new YopRequest(yeePayConst.getProductFeeModifyUrl(), "POST");
		productFeeModifyDto.setNotifyUrl(yeePayConst.getMerchantRegisterNotify());
		request.addParameter("parentMerchantNo", parentMerchantNo);
		addParamsFromObj(productFeeModifyDto,request, productFeeModifyDto.getClass());
		log.info("======================产品费率变更下发数据=====================");
		log.info(JSONUtil.toJsonStr(request.getParameters()));
		return execute(request);
	}





//	@Test
//	public void testSign(){
//		String priKey = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgHDZ4N8nM1+6wIgJAO6DgytLX000z7w2gbxKReNqO5rmgCgYIKoEcz1UBgi2hRANCAATe2AJOwtbivaFi4/JbV/a3mWku+MicHwGaxA0x1yNvu9ocHOPvVw+kQyd4Ubo5ECaGajs9k3lMUEQZs5c7siHz";
//		String plainText = "a=123";
//		PrivateKey privateKey = Sm2Utils.string2PrivateKey(priKey);
//		String signature = Sm2Utils.sign(plainText, (BCECPrivateKey) privateKey)+"$"+ DigestAlgEnum.SM3.getValue();
//		System.out.println(signature);
//	}
//	@Test
//	public void testVerify(){
//		String pubKey = "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEEJ8l/z6oUWAQ3cNritO5uRjcmgXl28SD8GgOJMU4+rQkhbE5IdsdrSeDslc2yU4UplLL7vHaNnVr0kZpfbc4sA==";
//		String signature = "YOUmkuvtQtcKItql9-IRn4YrITtHZNbjpTbEnxUJLTPKemZ-iIl6kWOfbZEswozdSRtpMkCjryRcuKMrDCGQWg$SM3";
//		String plainText = "merchantNo=10040049388&token=A9111AC520820FE23643FC932A19F0CB8219909B06922FEFECAE1F8601AFE540&timestamp=1625651888&directPayType=&cardType=&userNo=AutoUserNo75773472&userType=PHONE";
//		PublicKey publicKey = Sm2Utils.string2PublicKey(pubKey);
//		boolean verify = Sm2Utils.verifySign(plainText,signature.split("$")[0], (BCECPublicKey) publicKey);
//		Assert.assertTrue(verify);
//	}
}
