package com.cpop.pay.framewok.handler.wxPay;

import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
import com.github.binarywang.wxpay.service.WxPayService;
import com.cpop.core.utils.ServletUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author DB
 * @version 1.0.0
 * @since 2024-03-13 11:29
 */
@Getter
@Component
@Slf4j
public class WxPayHandler {

    /**
     *  获取普通微信支付
     */
    @Resource(name = "normalWxPayService")
    private WxPayService normalWxPayService;

    /**
     *  获取普通微信支付
     */
    @Resource(name = "serviceWxPayService")
    private WxPayService serviceWxPayService;

    /**
     * 获取签约头
     * @author DB
     * @since 2024/1/20
     * @return SignatureHeader
     */
    public SignatureHeader getSignatureHeader() {
        HttpServletRequest request = ServletUtils.getRequest();
        SignatureHeader signatureHeader = new SignatureHeader();
        signatureHeader.setSigned(request.getHeader("Wechatpay-Signature"));
        signatureHeader.setNonce(request.getHeader("Wechatpay-Nonce"));
        signatureHeader.setSerialNo(request.getHeader("Wechatpay-Serial"));
        signatureHeader.setTimeStamp(request.getHeader("Wechatpay-Timestamp"));
        log.info("微信支付分回调ID:{}",request.getHeader("Request-ID"));
        return signatureHeader;
    }

}
