package com.malk.qiwang.tencent;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
import com.malk.utils.UtilHttp;
import com.malk.utils.UtilMap;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 读取配置文件参考FilePah
 */
@Data
@Component
//@ConfigurationProperties(prefix = "tencentnh")
public class TXYConfNh {

    private String APPID="1326929507";

    private String SecretId="AKID1kOzX2ZD61JYhwMkkes6UsQ1lgccdYWd";

    private String SecretKey="EMQbjt7GLYwHFC4z9bNB49PfyALfuIqk";

    private String Region="ap-shanghai";

    /**
     * 票据类型
     * -
     * 中央非税未返回税号官方说明: 非税发票理论是没有税号的，图片中那个属于信用代码 [两个版本接口均为返回]
     * ppExt: 新版本官方返回数据已结构化, 以官方为准
     */
    @Deprecated
    public static final Map<String, String> TYPE_INVOICE = UtilMap.map("-1, 0, 1, 2, 3, 5, 8, 9, 10, 11, 12, 13, 15, 16",
            "未知类型, 出租车发票, 定额发票, 火车票, 增值税发票, 机票行程单, 通用机打发票, 汽车票, 轮船票, 增值税发票（卷票） , 购车发票, 过路过桥费发票, 非税发票, 全电发票");

    public static void main(String[] args) {
        HashMap mapAll = new HashMap<>();
        List<Map<String, Object>> tableField = new ArrayList<>();

        Map<String, Object> data1 = new HashMap<>();
        data1.put("trxNumber", "FK20250723621");
        data1.put("fromAccountCode", "755915704010801");
        data1.put("fromAccountName", "企业网银新20161341");
        data1.put("toAccountCode", "6214831150131511");
        data1.put("toAccountType", "0");
        data1.put("toAccountName", "吴极客");
        data1.put("payAmount", "1.00");
        data1.put("uses", "这是一个测试用途");
//        data1.put("instructionId", "F00000123");

        Map<String, Object> data2 = new HashMap<>();
        data2.put("trxNumber", "FK20250723631");
        data2.put("fromAccountCode", "755915704010801");
        data2.put("fromAccountName", "企业网银新20161341");
        data2.put("toAccountCode", "6214831150131511");
        data2.put("toAccountType", "0");
        data2.put("toAccountName", "吴极客");
        data2.put("payAmount", "1.00");
        data2.put("uses", "这是一个测试用途");
//        data2.put("instructionId", "F00000123");

// 添加到集合
        tableField.add(data1);
        tableField.add(data2);
        System.out.println(JSONObject.toJSONString(tableField));

        mapAll.put("totalRecord", "2");
        mapAll.put("list", JSONObject.toJSONString(tableField));
        mapAll.put("totalTrxNumber", "FK20250725712");
        mapAll.put("source", "OA");
//        mapAll.put("securityCode", securityCode);
        String url = "https://openapi.xencio.com/sandbox/cfa/api/payment/batchTransfer";

        String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String securityCode = SecureUtil.md5("KHPuj0JMS6nS1ACzc#" + today);

        Map headers = new HashMap<>();
        headers.put("x-xencio-client-id", "4d9414e89bc24b0d89b678d9f20bc56a");
        headers.put("content-Type", "application/x-www-form-urlencoded");
        Map params = new HashMap<>();
//        mapAll.put("securityCode", securityCode);
        headers.put("securityCode", securityCode);
        String response = UtilHttp.doPost(url, headers, null,null,mapAll);//批量制单
        System.out.println(response);

//        String url = "https://openapi.xencio.com/sandbox/cfa/api/payment/batchTransfer";
//
//        // 构建请求参数
//        String listData = "[{\"trxNumber\":\"FK20250723622\",\"fromAccountCode\":\"755915704010801\",\"fromAccountName\":\"企业网银新20161341\",\"toAccountCode\":\"6214831150131511\",\"toAccountType\":\"0\",\"toAccountName\":\"吴极客\",\"payAmount\":\"1.00\",\"uses\":\"这是一个测试用途\"},{\"trxNumber\":\"FK20250723632\",\"fromAccountCode\":\"755915704010801\",\"fromAccountName\":\"企业网银新20161341\",\"toAccountCode\":\"6214831150131511\",\"toAccountType\":\"0\",\"toAccountName\":\"吴极客\",\"payAmount\":\"1.00\",\"uses\":\"这是一个测试用途\"}]";
//
//        // 使用HttpRequest构建请求
//        HttpResponse response = HttpRequest.post(url)
//                .header("content-type", "application/x-www-form-urlencoded")
//                .header("x-xencio-client-id", "4d9414e89bc24b0d89b678d9f20bc56a")
//                .form("totalTrxNumber", "FK20250725709")
//                .form("totalRecord", "2")
//                .form("source", "OA")
//                .form("securityCode", "7336d396b52cd6ee97949d288f6521bd")
//                .form("list", listData)
//                .execute();
//
//        // 输出响应结果
//        System.out.println("响应状态: " + response.getStatus());
//        System.out.println("响应内容: " + response.body());
    }
}