package com.platform.yijia.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;

/**
 * 随行付，公共方法
 */
public class SXFPaySign {
    //合作方私钥(替换成自己的)
    // public static final String privateKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM+4PMi2ZPqpeCQ1IIV8mWYmGubr3DoEEJ3W2oEu8bFMVVpK5Jx6WhQ9xR83OQW7lbMI+BbumilKXfHdHrW7gWvu7yB2dD50GbT6bZXXnuddui+BnS/Yc9QxFS+HLcOX8bsmgJ5P/4D1Klm4k3OOsGJ3CsLDuz8RwNlxwuhg8+lQIDAQAB";
    //测试环境私钥
    //public static final String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMz7g8yLZk+ql4JDUghXyZZiYa5uvcOgQQndbagS7xsUxVWkrknHpaFD3FHzc5BbuVswj4Fu6aKUpd8d0etbuBa+7vIHZ0PnQZtPptldee5126L4GdL9hz1DEVL4ctw5fxuyaAnk//gPUqWbiTc46wYncKwsO7PxHA2XHC6GDz6VAgMBAAECgYEAgC2C1CQTPRvqk+0u3cKvbtdkR6Q+C5cpNFb/XAtC80dAwnYw+jfarYX2vlQi3pFMzeYGxqQpep3DP0qxWqBG8uu7Depw2HlWcw+6z68G3Vpkprx9FHnsy/ijCX/76HMmDmGN1r68FnDZXHKdaLZPQeNxDY3Hz83Quq04yav5Ah0CQQDoVoZZM6SyF+gz4/mg29UwkEXcn5uUARWo7QrO6vOsYzTEiNvNIlLFxd5xE2i9LAKKLWBtuaMovrdC4fHguQaLAkEA4dvINHcuehDHVzgS5I/6hB5PnQZOrnZFDZUd7woh9xUu9qQTxZpPcbfSpDFCKDbTknM1dn+7WpLk6Zd9YGyTXwJACXu2oh90gnxtUujkQIeYjRHmeBnfrMvaiXmbblSyu3+VIMyBRD85Z68q5CyposcQF3nArNnd6gTW0BkO2WBT/wJAUUGbA5UlOXEz5mMcGPLbtBCbn+iXAhk2uq49OLSyh4wtezqIinz7u/PgaoX2QTWIZJXiVCGcK/fRN2DzEG+/jQJAIQQFJNUX5i7aUS4By8xrffUpeTTiszu+WTU5Rz2jRoT8YwgqiqAWG9dNSggcfnJIz968a+Jg5s483y06mEEmjA==";
    //生产环境私钥
    public static final String privateKey="MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAPCpA8iF1tYerDYcZTGiPkRHlQKlkM2vy752cLZydVUrfKkGQaSMBHbmgK7LgenQ6cjWl2mM5zLOWxqNKxsUj/xMbkAdYXKtYy1nL6NLo3RI+cXbUB5tNiS4ojSwjFg4AHIfjGyBnnQar/dulfuNJ3QBsfHBDR/DsIfXUaBcmsoFAgMBAAECgYEA8A7YHEUNWUb9Z3iJpKn/TKLOy/YVbGdoaFPC+OtRiSS40+3OuvGEXoptYG7V50MigNk17e7EjNR04hZhIkEvoX/d9KLIKRtZUOMga6GhqD/PqRpgKq8JObMkvJ1U7KeEimUqBeukbvzBUJrVQT1RpbXmX3zpf0kj7l/FPOfZD8ECQQD9RpXw7gtv96N6WIF2k42UMAMLVuGivTW2bZzxP6TCD/FeZMG2JNy3nydCc2v6GuGDQZ8WCQIpzK72gMzLrYVVAkEA8z+w+Ao8Y6BxX8P/5GZg4x1ZHqQOfsrWbC6iMeIenLkAgMpEPYLYpm5nZ0db7pf5OU037bSXxQoauQnjOM8x8QJBANzQGk94Kg6PFz7GRPDNScTlavIK6CMK1PZccFTASPNMFQJX067qSmfoYMEFgiEGKJBXuMvsRK+OnQeaWXJFsRUCQFva9Uz1MJC+iZGMRhlNv9CDyJ+VfBPNLON1SLJlnQG5qsL3noVL39wZXNrXS5Pxt5831aLhy14Qzr6JSVCujUECQQDD0KIfodS9dxKnstJaaX2B5aYXPYsI+4PBMeFw4inl+9JFJb85U1SmuYAkGPj8OFBtxkhzeHXkvD5aMKj0cUVs";
    //随行付公钥
   // public static final String sxfPublic = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOmsrFtFPTnEzfpJ/hDl5RODBxw4i9Ex3NmmG/N7A1+by032zZZgLLpdNh8y5otjFY0E37Nyr4FGKFRSSuDiTk8vfx3pv6ImS1Rxjjg4qdVHIfqhCeB0Z2ZPuBD3Gbj8hHFEtXZq8+msAFu/5ZQjiVhgs5WWBjh54LYWSum+d9+wIDAQAB";
   //生产环境随行付公钥
    public static final String sxfPublic = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjo1+KBcvwDSIo+nMYLeOJ19Ju4ii0xH66ZxFd869EWFWk/EJa3xIA2+4qGf/Ic7m7zi/NHuCnfUtUDmUdP0JfaZiYwn+1Ek7tYAOc1+1GxhzcexSJLyJlR2JLMfEM+rZooW4Ei7q3a8jdTWUNoak/bVPXnLEVLrbIguXABERQ0Ze0X9Fs0y/zkQFg8UjxUN88g2CRfMC6LldHm7UBo+d+WlpOYH7u0OTzoLLiP/04N1cfTgjjtqTBI7qkOGxYs6aBZHG1DJ6WdP+5w+ho91sBTVajsCxAaMoExWQM2ipf/1qGdsWmkZScPflBqg7m0olOD87ymAVP/3Tcbvi34bDfwIDAQAB";
    /**
     * 封装传参信息，增加公共信息，增加业务信息
     * @param reqData
     * @return
     */
    public static String getSXFPay(JSONObject reqData ) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String dataStr = df.format(new Date());
        ApiRequestBean<JSONObject> reqBean = new ApiRequestBean<JSONObject>();
        //reqBean.setOrgId("77563944");//测试 合作机构id
        reqBean.setOrgId("73153713");//生产合作机构id
        reqBean.setReqId(UUID.randomUUID().toString().replaceAll("-", ""));//请求id 订单号
        reqBean.setSignType("RSA");//签名类型
        reqBean.setTimestamp(dataStr);//请求时间
        reqBean.setVersion("1.0");//版本
        //将业务参数存放在 JSON 对象中
        reqBean.setReqData(reqData);
        String req = JSONObject.toJSONString(reqBean);
        System.out.println("req:" + req);
        return req;
    }


    /**
     *封装组织加密串
     */
    public static String getSignContent(String req){
        System.out.println("req:" + req);
        //此处不要改变reqData里面值的顺序用LinkedHashMap
        HashMap reqMap = JSON.parseObject(req, LinkedHashMap.class, Feature.OrderedField);
        //组装加密串
        String signContent = RSASignature.getOrderContent(reqMap);
        return "";
    }

}
