package org.springblade.modules.app.init;

import com.czb.gateway.api.APIConstance;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.upyzt.Upyzt;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.net.URL;

@Slf4j
@Component
public class InitWork implements CommandLineRunner {
	@Override
	public void run(String... args) throws Exception {

//		String rootMchId = "1002512373299546172";
//		String signPrivateKeyFilePath = "upyzt/sign_private_key.pem";
//		String encryptKeyFilePath = "upyzt/encrypt_public_key.pem";
//        String verifyKeyFilePath = "upyzt/verify_public_key.pem";
//        Upyzt.setRootMchId(rootMchId);
//        Upyzt.setSignPrivateKeyPath(getResPath(signPrivateKeyFilePath));
//        Upyzt.setEncryptPublicKeyPath(getResPath(encryptKeyFilePath));
        //Upyzt.setVerifyPublicKeyPath(getResPath(verifyKeyFilePath));
		//APIConstance.initialize(getResPath("smart_pay/config.properties"));
//		APIConstance.initialize(getResPath("/data/wwwroot/dev_xmt.hopdata.vip/smart_pay/config.properties"));
        log.info("init pem success");
	}

	private String getResPath(String subPath) {
        if (subPath == null) {
            throw new NullPointerException();
        }
        URL resource = Thread.currentThread().getContextClassLoader().getResource(subPath);
        return resource != null ? resource.getPath() : subPath;
    }
}
