package com.ywt.alipaympapi;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.ywt.alipaympapi.models.Constants;
import com.ywt.rpc.core.RestServerStarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@SpringBootApplication
@EnableAspectJAutoProxy
public class EmptyApplication {

    public static void main(String[] args) {
        SpringApplication.run(EmptyApplication.class, args);
        String serviceName = "com.ywt.AlipayMpRestService";
        System.out.println("--- RegisterService: " + serviceName);
        RestServerStarter.build(null).registry(serviceName, null, "支付宝小程序服务");
        initAlipayEasySdk();
    }

    /**
     * 初始化 alipay-easy-sdk
     * FIXME: 后续扩展多医院需要将 pk & apk 配置化
     */
    private static void initAlipayEasySdk() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipay.com";
        config.signType = "RSA2";

        config.appId = Constants.ALIPAYMP_APPID_NFYYBYFY;
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = Constants.MERCHANT_PRIVATE_KEY;
        // 注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        config.alipayPublicKey = Constants.ALIPAY_PUBLIC_KEY;
        Factory.setOptions(config);
    }
}
