Merge branch 'dev'

This commit is contained in:
wucongxing 2023-12-21 09:07:22 +08:00
commit d36b9217fd
9 changed files with 153 additions and 22 deletions

View File

@ -117,7 +117,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientInquiryRefundNotifyUrl,
}
refund, err := refundRequest.Refund()
refund, err := refundRequest.Refund(1)
if err != nil {
tx.Rollback()
return false, errors.New(err.Error())

View File

@ -171,7 +171,7 @@ func (r *OrderProductService) CancelOrderProduct(req requests.CancelOrderProduct
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientProductRefundNotifyUrl,
}
refund, err := refundRequest.Refund()
refund, err := refundRequest.Refund(2)
if err != nil {
tx.Rollback()
return false, errors.New(err.Error())

View File

@ -70,9 +70,20 @@ wechat:
refund-notify-domain: https://dev.hospital.applets.igandanyiyuan.com/
doctor-app-id: wxc83296720404aa7b
doctor-app-secret: 817665d3763637fe66d56548f8484622
mch-id: 1636644248
v3-api-secret: gdxz292sjSOadN3m2pCda03NfCsmNadY
mch-certificate-serial-number: 7DEC0E6C57E0DC71F077F02F52406566AF39BEBB
pay-1636644248:
mch-id: 1636644248
v3-api-secret: gdxz292sjSOadN3m2pCda03NfCsmNadY
mch-certificate-serial-number: 7DEC0E6C57E0DC71F077F02F52406566AF39BEBB
platform-certs: extend/weChat/certs/1659662936/wechatpay_112FCCD1B9ECC8292703AB7363C73D74B6AFDC1A.pem
private-key: extend/weChat/certs/1636644248/apiclient_key.pem
certificate: extend/weChat/certs/1636644248/apiclient_cert.pem
pay-1659662936:
mch-id: 1659662936
v3-api-secret: gdxz292sjSOadNNad2pCda03NfC2msmY
mch-certificate-serial-number: 12FAA5F61708B795BB5337AE915494E2DC2CA87B
platform-certs: extend/weChat/certs/1659662936/wechatpay_5B5C8A69CC86D1127F6B6AA06AAAF10531EEFE90.pem
private-key: extend/weChat/certs/1659662936/apiclient_key.pem
certificate: extend/weChat/certs/1659662936/apiclient_cert.pem
# [处方平台]
pre:

View File

@ -1,18 +1,37 @@
package config
type Wechat struct {
PatientAppId string `mapstructure:"patient-app-id" json:"patient-app-id" yaml:"patient-app-id"`
PatientAppSecret string `mapstructure:"patient-app-secret" json:"patient-app-secret" yaml:"patient-app-secret"`
PatientInquiryPayNotifyUrl string `mapstructure:"patient-inquiry-pay-notify-url" json:"patient-inquiry-pay-notify-url" yaml:"patient-inquiry-pay-notify-url"`
PatientInquiryRefundNotifyUrl string `mapstructure:"patient-inquiry-refund-notify-url" json:"patient-inquiry-refund-notify-url" yaml:"patient-inquiry-refund-notify-url"`
PatientProductPayNotifyUrl string `mapstructure:"patient-product-pay-notify-url" json:"patient-product-pay-notify-url" yaml:"patient-product-pay-notify-url"`
PatientProductRefundNotifyUrl string `mapstructure:"patient-product-refund-notify-url" json:"patient-product-refund-notify-url" yaml:"patient-product-refund-notify-url"`
PatientDetectionPayNotifyUrl string `mapstructure:"patient-detection-pay-notify-url" json:"patient-detection-pay-notify-url" yaml:"patient-detection-pay-notify-url"`
PatientDetectionRefundNotifyUrl string `mapstructure:"patient-detection-refund-notify-url" json:"patient-detection-refund-notify-url" yaml:"patient-detection-refund-notify-url"`
RefundNotifyDomain string `mapstructure:"refund-notify-domain" json:"refund-notify-domain" yaml:"refund-notify-domain"` // 回调域名
DoctorAppId string `mapstructure:"doctor-app-id" json:"doctor-app-id" yaml:"doctor-app-id"`
DoctorAppSecret string `mapstructure:"doctor-app-secret" json:"doctor-app-secret" yaml:"doctor-app-secret"`
MchId string `mapstructure:"mch-id" json:"mch-id" yaml:"mch-id"` // 商户号
V3ApiSecret string `mapstructure:"v3-api-secret" json:"v3-api-secret" yaml:"v3-api-secret"` // 商户APIv3密钥
MchCertificateSerialNumber string `mapstructure:"mch-certificate-serial-number" json:"mch-certificate-serial-number" yaml:"mch-certificate-serial-number"` // 商户证书序列号
PatientAppId string `mapstructure:"patient-app-id" json:"patient-app-id" yaml:"patient-app-id"`
PatientAppSecret string `mapstructure:"patient-app-secret" json:"patient-app-secret" yaml:"patient-app-secret"`
PatientInquiryPayNotifyUrl string `mapstructure:"patient-inquiry-pay-notify-url" json:"patient-inquiry-pay-notify-url" yaml:"patient-inquiry-pay-notify-url"`
PatientInquiryRefundNotifyUrl string `mapstructure:"patient-inquiry-refund-notify-url" json:"patient-inquiry-refund-notify-url" yaml:"patient-inquiry-refund-notify-url"`
PatientProductPayNotifyUrl string `mapstructure:"patient-product-pay-notify-url" json:"patient-product-pay-notify-url" yaml:"patient-product-pay-notify-url"`
PatientProductRefundNotifyUrl string `mapstructure:"patient-product-refund-notify-url" json:"patient-product-refund-notify-url" yaml:"patient-product-refund-notify-url"`
PatientDetectionPayNotifyUrl string `mapstructure:"patient-detection-pay-notify-url" json:"patient-detection-pay-notify-url" yaml:"patient-detection-pay-notify-url"`
PatientDetectionRefundNotifyUrl string `mapstructure:"patient-detection-refund-notify-url" json:"patient-detection-refund-notify-url" yaml:"patient-detection-refund-notify-url"`
RefundNotifyDomain string `mapstructure:"refund-notify-domain" json:"refund-notify-domain" yaml:"refund-notify-domain"` // 回调域名
DoctorAppId string `mapstructure:"doctor-app-id" json:"doctor-app-id" yaml:"doctor-app-id"`
DoctorAppSecret string `mapstructure:"doctor-app-secret" json:"doctor-app-secret" yaml:"doctor-app-secret"`
Pay1636644248 Pay1636644248 `mapstructure:"pay-1636644248" json:"pay-1636644248" yaml:"pay-1636644248"`
Pay1659662936 Pay1659662936 `mapstructure:"pay-1659662936" json:"pay-1659662936" yaml:"pay-1659662936"`
}
// Pay1636644248 北京欣欣相照
type Pay1636644248 struct {
MchId string `mapstructure:"mch-id" json:"mch-id" yaml:"mch-id"` // 商户号
V3ApiSecret string `mapstructure:"v3-api-secret" json:"v3-api-secret" yaml:"v3-api-secret"` // 商户APIv3密钥
MchCertificateSerialNumber string `mapstructure:"mch-certificate-serial-number" json:"mch-certificate-serial-number" yaml:"mch-certificate-serial-number"` // 商户证书序列号
PlatformCerts string `mapstructure:"platform-certs" json:"platform-certs" yaml:"platform-certs"` // 平台证书
PrivateKey string `mapstructure:"private-key" json:"private-key" yaml:"private-key"`
Certificate string `mapstructure:"certificate" json:"certificate" yaml:"certificate"`
}
// Pay1659662936 成都欣欣相照
type Pay1659662936 struct {
MchId string `mapstructure:"mch-id" json:"mch-id" yaml:"mch-id"` // 商户号
V3ApiSecret string `mapstructure:"v3-api-secret" json:"v3-api-secret" yaml:"v3-api-secret"` // 商户APIv3密钥
MchCertificateSerialNumber string `mapstructure:"mch-certificate-serial-number" json:"mch-certificate-serial-number" yaml:"mch-certificate-serial-number"` // 商户证书序列号
PlatformCerts string `mapstructure:"platform-certs" json:"platform-certs" yaml:"platform-certs"` // 平台证书
PrivateKey string `mapstructure:"private-key" json:"private-key" yaml:"private-key"`
Certificate string `mapstructure:"certificate" json:"certificate" yaml:"certificate"`
}

Binary file not shown.

View File

@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIENzCCAx+gAwIBAgIUEvql9hcIt5W7UzeukVSU4twsqHswDQYJKoZIhvcNAQEL
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
Q0EwHhcNMjMxMjE5MDUxNTA4WhcNMjgxMjE3MDUxNTA4WjCBkDETMBEGA1UEAwwK
MTY1OTY2MjkzNjEbMBkGA1UECgwS5b6u5L+h5ZWG5oi357O757ufMTwwOgYDVQQL
DDPmiJDpg73ph5HniZvmrKPmrKPnm7jnhafkupLogZTnvZHljLvpmaLmnInpmZDl
hazlj7gxCzAJBgNVBAYTAkNOMREwDwYDVQQHDAhTaGVuWmhlbjCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBAPCINl3HwUEM2CzerR5u4GbUnvRJDjVmaEbm
qHlaYRUrrGDIF/Q63QEbcUh+PP+zZ0Grln7hGT5dw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1K/7g3AhCAylUzhD/ghD1Y8F
hlMtw87oNzfTE51I/2sGZgnPX2IqIEOjxx1F8Ebzfh5shJGN40guMpBItsCWYe7s
zj1zdyERL6zxQN2A7o2QvDeX1EsNIdwoEECv06tWjUEGJioFwb3OKBu5n9jJT+Og
EcJFmRasLRQWsooutsDCO7y5wIKrCY9n52eZgk9QlHkYWyiwUqpnrrJ1DC+ueJei
QptFAgMBAAGjgbkwgbYwCQYDVR0TBAIwADALBgNVHQ8EBAMCA/gwgZsGA1UdHwSB
kzCBkDCBjaCBiqCBh4aBhGh0dHA6Ly9ldmNhLml0cnVzLmNvbS5jbi9wdWJsaWMv
aXRydXNjcmw/Q0E9MUJENDIyMEU1MERCQzA0QjA2QUQzOTc1NDk4NDZDMDFDM0U4
RUJEMiZzZz1IQUNDNDcxQjY1NDIyRTEyQjI3QTlEMzNBODdBRDFDREY1OTI2RTE0
MDM3MTANBgkqhkiG9w0BAQsFAAOCAQEAhWwscSAE1OBR3AGBOuFHs3vFJ+y37z5/
EoB9FwVu4zXP1dih101zl83iwIdPEHIR2skXcTjHRI2qdOvu7X5JmWOJP+51RGtX
Y+aWXKfhRzRQOUlpNyltlgsGKzbIXLLBzQjMzBNv+n/HX4q9F0TV3SW4zTiMlhD8
+bGGGwuIhziWpK9qvr3RPU1j+0bggHhIre+cNolnh1FepS4Gt964zhx6THtrS/jI
I64UBBh6moBq7zB5QYloBhW464c7GCEEv5/AdcxGhAe+vuL/mkVRNsSRxVPIxPE6
+qoIiNBmQvL/mL+4UKfX6b9h4wrUQUdQP3ljRdpL3a5YTMTUJuoJSQ==
-----END CERTIFICATE-----

View File

@ -21,9 +21,33 @@ type RefundRequest struct {
}
// Refund 退款
func (r RefundRequest) Refund() (*refunddomestic.Refund, error) {
func (r RefundRequest) Refund(orderType int) (*refunddomestic.Refund, error) {
mchId := ""
mchCertificateSerialNumber := ""
v3ApiSecret := ""
if orderType == 1 {
// 问诊
mchId = config.C.Wechat.Pay1659662936.MchId
mchCertificateSerialNumber = config.C.Wechat.Pay1659662936.MchCertificateSerialNumber
v3ApiSecret = config.C.Wechat.Pay1659662936.V3ApiSecret
} else if orderType == 2 || orderType == 3 {
// 药品/检测
mchId = config.C.Wechat.Pay1636644248.MchId
mchCertificateSerialNumber = config.C.Wechat.Pay1636644248.MchCertificateSerialNumber
v3ApiSecret = config.C.Wechat.Pay1636644248.V3ApiSecret
}
if mchId == "" {
return nil, errors.New("商户号错误")
}
// certsDir := "extend/weChat/certs/" + mchId + "/apiclient_key.pem"
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
certsDir := filepath.Join("extend/weChat/certs", "/1636644248/apiclient_key.pem")
certsDir := filepath.Join("extend/weChat/certs", mchId, "/apiclient_key.pem")
// certsDir := filepath.Join("extend/weChat/certs", "/1636644248/apiclient_key.pem")
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(certsDir)
if err != nil {
return nil, errors.New("微信签名生成失败")
@ -32,7 +56,7 @@ func (r RefundRequest) Refund() (*refunddomestic.Refund, error) {
ctx := context.Background()
// 使用商户私钥等初始化 client并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(config.C.Wechat.MchId, config.C.Wechat.MchCertificateSerialNumber, mchPrivateKey, config.C.Wechat.V3ApiSecret),
option.WithWechatPayAutoAuthCipher(mchId, mchCertificateSerialNumber, mchPrivateKey, v3ApiSecret),
}
client, err := core.NewClient(ctx, opts...)