new wxpay
This commit is contained in:
@@ -53,8 +53,6 @@ type AlipayConfig struct {
|
||||
type WxpayConfig struct {
|
||||
AppID string
|
||||
MchID string
|
||||
MchPublicKeyID string
|
||||
MchPublicKeyPath string
|
||||
MchCertificateSerialNumber string
|
||||
MchApiv3Key string
|
||||
MchPrivateKeyPath string
|
||||
|
||||
@@ -210,6 +210,7 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
|
||||
"G10XM02": (*ApiRequestService).ProcessG10XM02Request,
|
||||
"G11BJ06": (*ApiRequestService).ProcessG11BJ06Request,
|
||||
"G29BJ05": (*ApiRequestService).ProcessG29BJ05Request,
|
||||
"Marriage": (*ApiRequestService).ProcessMarriageRequest,
|
||||
}
|
||||
|
||||
// PreprocessRequestApi 调用指定的请求处理函数
|
||||
@@ -1854,6 +1855,21 @@ func (a *ApiRequestService) ProcessRIS031Request(params []byte) ([]byte, error)
|
||||
|
||||
return []byte(Value.Raw), nil
|
||||
}
|
||||
|
||||
// ProcessMarriageRequest 婚姻状态查询,优先使用西部数据G09XM02接口,失败时回退到羽山IDV044接口
|
||||
func (a *ApiRequestService) ProcessMarriageRequest(params []byte) ([]byte, error) {
|
||||
// 首先尝试使用西部数据接口查询
|
||||
resp, err := a.ProcessG09XM02Request(params)
|
||||
if err != nil {
|
||||
// 西部数据接口查询失败,尝试使用羽山接口
|
||||
logx.Infof("西部数据婚姻查询失败,尝试使用羽山接口: %v", err)
|
||||
resp, err = a.ProcessIDV044Request(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
func (a *ApiRequestService) ProcessG09XM02Request(params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
@@ -1895,7 +1911,6 @@ func (a *ApiRequestService) ProcessG09XM02Request(params []byte) ([]byte, error)
|
||||
response := map[string]string{
|
||||
"status": statusCode,
|
||||
}
|
||||
|
||||
// 序列化为JSON
|
||||
jsonResponse, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,22 +47,17 @@ func NewWechatPayService(c config.Config, userAuthModel model.UserAuthModel) *We
|
||||
mchID := c.Wxpay.MchID
|
||||
mchCertificateSerialNumber := c.Wxpay.MchCertificateSerialNumber
|
||||
mchAPIv3Key := c.Wxpay.MchApiv3Key
|
||||
mchPublicKeyID := c.Wxpay.MchPublicKeyID
|
||||
|
||||
// 从文件中加载商户私钥
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(c.Wxpay.MchPrivateKeyPath)
|
||||
if err != nil {
|
||||
logx.Errorf("加载商户私钥失败: %v", err)
|
||||
panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
|
||||
}
|
||||
// 从文件中加载公钥
|
||||
mchPublicKey, err := utils.LoadPublicKeyWithPath(c.Wxpay.MchPublicKeyPath)
|
||||
if err != nil {
|
||||
logx.Errorf("加载商户私钥失败: %v", err)
|
||||
panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
|
||||
}
|
||||
|
||||
// 使用商户私钥和其他参数初始化微信支付客户端
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayPublicKeyAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchPublicKeyID, mchPublicKey),
|
||||
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
|
||||
}
|
||||
client, err := core.NewClient(context.Background(), opts...)
|
||||
if err != nil {
|
||||
@@ -71,14 +66,12 @@ func NewWechatPayService(c config.Config, userAuthModel model.UserAuthModel) *We
|
||||
}
|
||||
// 在初始化时获取证书访问器并创建 notifyHandler
|
||||
certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
|
||||
//notifyHandler, err := notify.NewRSANotifyHandler(mchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(certificateVisitor))
|
||||
//if err != nil {
|
||||
// logx.Errorf("获取证书访问器失败: %v", err)
|
||||
// panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
|
||||
//}
|
||||
notifyHandler := notify.NewNotifyHandler(
|
||||
mchAPIv3Key,
|
||||
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, mchPublicKeyID, *mchPublicKey))
|
||||
notifyHandler, err := notify.NewRSANotifyHandler(mchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(certificateVisitor))
|
||||
if err != nil {
|
||||
logx.Errorf("获取证书访问器失败: %v", err)
|
||||
panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
|
||||
}
|
||||
logx.Infof("微信支付客户端初始化成功")
|
||||
return &WechatPayService{
|
||||
config: c.Wxpay,
|
||||
wechatClient: client,
|
||||
|
||||
Reference in New Issue
Block a user