package com.ruoyi.utils.lakala.test;

import com.lkl.laop.sdk.Config;
import com.lkl.laop.sdk.LKLSDK;
import com.lkl.laop.sdk.exception.SDKException;
import com.lkl.laop.sdk.request.V3CcssCounterOrderQueryRequest;
import com.lkl.laop.sdk.request.V3LabsTradeQueryRequest;
import com.lkl.laop.sdk.utils.FileUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;

@Slf4j
public class BaseCommonDemo {

    //拉卡拉开放平台进行配置开通
    private static final String appId = "OP00000003";

    //商户证书序列号,和商户私钥对应
    private static final String serialNo = "00dfba8194c41b84cf";

    //商户私钥地址,用于请求签名
    private static final String priKeyPath = "D:/OP00000003_private_key.pem";

    //拉卡拉公钥证书地址,用于验签（测试证书为：lkl-apigw-v2.cer）
    private static final String lklCerPath = "D:/lkl-apigw-v2.cer";

    //拉卡拉支付平台证书地址2(用于拉卡拉通知验签，证书与lklCerPath)一致，测试证书为：lkl-apigw-v2.cer）
    private static final String lklNotifyCerPath="D:/lkl-apigw-v2.cer";

    //拉卡拉开放平台服务地址
    private static final String serverUrl = "https://test.wsmsd.cn/sit";

    //如果需要密文传输请申请拉卡拉SM4密钥
    private static final String sm4Key = "0I4M0kmwFrNUU8hZ9AFpfA==";

    //根据请求接口拼装参数
//
//    V3LabsTradeQueryRequest v3LabsTradeQueryRequest=new V3LabsTradeQueryRequest();
//
//        v3LabsTradeQueryRequest.setMerchantNo("xxxx");
//
//        v3LabsTradeQueryRequest.setTermNo("xxx");
//
//        v3LabsTradeQueryRequest.setOutTradeNo("xxxx");



    //发起请求-正常请求
//
//    String response=LKLSDK.httpPost(v3LabsTradeQueryRequest);
//
//
//
//    //发起请求2(密文传输接口)-请求报文加密,响应信息无需解密
//
//    String response2=LKLSDK.httpPost(v3LabsTradeQueryRequest,true,false);
//
//
//
//    //发起请求3(密文传输接口)-请求报文加密,响应信息需解密
//
//    String response3=LKLSDK.httpPost(v3LabsTradeQueryRequest,true,true);
//
//
//
//    //发起请求4-自定义接口参数实体,直接发送接口地址
//
//    String response3=LKLSDK.httpPost("url","bodyJson");
//
//
//
//    //处理响应
//
//        log.info(response);

//以下代码向您展示了使用拉卡拉SDK for Java接收回调通知的示例


//拉卡拉开放平台采用数据流传输

    public ResponseEntity<?> messageHandle(HttpServletRequest request) throws Exception {

        // 1. 配置初始化-全局只需要初始化一次
        doInit();

        //验签并解析请求
        String body = LKLSDK.notificationHandle(request);

        System.out.println("验签成功,请求body：" + body);

        //业务处理
        return ResponseEntity.ok(body);

    }

    public static void doInit() throws SDKException {
        //初始化配置(全局只需配置一次)
        LKLSDK.init(new Config(appId,serialNo,priKeyPath,lklCerPath,lklNotifyCerPath,sm4Key,serverUrl));
    }

    public static void main(String[] args) throws SDKException {
        doInit();

        //聚合收银台
        V3CcssCounterOrderQueryRequest v3CcssCounterOrderQueryRequest = new V3CcssCounterOrderQueryRequest();

        v3CcssCounterOrderQueryRequest.setMerchantNo("82229007392000A");

        v3CcssCounterOrderQueryRequest.setPayOrderNo("24041911012001101011001235881");

        v3CcssCounterOrderQueryRequest.setOutOrderNo("82229007392000A20240419134553");
        v3CcssCounterOrderQueryRequest.setChannelId("95");

        String response=LKLSDK.httpPost(v3CcssCounterOrderQueryRequest);

        System.out.println(response);

        //

    }


}
