package com.czg.service.market.service.impl;

import com.czg.service.RedisService;
import com.czg.system.service.SysParamsService;
import com.ijpay.core.kit.RsaKit;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 微信支付service
 * @author Administrator
 */
@Component
@Slf4j
public class WxServiceImpl extends BaseWx {

    @DubboReference
    private SysParamsService paramsService;


    public WxServiceImpl(@Autowired RedisService redisService) {
        this.redisService = redisService;
        config = new Config();
    }

    @PostConstruct
    public void init() {
        // 小程序id
        config.appId = paramsService.getSysParamValue("shop_wx_appid");
        // 小程序secrete
        config.appSecret = paramsService.getSysParamValue("shop_wx_secrete");
        config.certPath = "";
        // 微信支付公钥
        config.pubKey = paramsService.getSysParamValue("wx_pub_key");
        // api支付证书私钥
        config.apiCertKey = paramsService.getSysParamValue("wx_apiclient_key");
        // api支付证书公钥
        config.apiCert = paramsService.getSysParamValue("wx_apiclient_cert");
        try {
            config.privateKey = RsaKit.loadPrivateKey(config.apiCertKey);
        } catch (Exception e) {
            log.warn("微信加载api证书失败");
        }
        // 平台证书
        config.platformCertPath = "";
        // 平台证书编号
        config.platformCertNo = "";
        // 商户号
        config.mchId = paramsService.getSysParamValue("wx_mch_id");
        // v3密钥
        config.apiV3Key = paramsService.getSysParamValue("wx_v3_key");
        config.apiV2Key = "";
        // 回调地址
        config.notifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/pay";
        config.refundNotifyUrl = "";
        config.transferNotifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/transfer";
    }

    public BaseWx getAppService() {
        return this;
    }
}

