diff --git a/api/service/OrderMember.go b/api/service/OrderMember.go index 6a07c23..af726e0 100644 --- a/api/service/OrderMember.go +++ b/api/service/OrderMember.go @@ -288,7 +288,7 @@ func (r *OrderMemberService) GetJsapiPrepay(m *model.OrderMember) (prepay *jsapi MchId: config.C.Wechat.Pay1281030301.MchId, Description: "肝病算一算", OutTradeNo: m.OrderNo, - NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.MemberRefundNotifyUrl, + NotifyUrl: config.C.Wechat.NotifyDomain + config.C.Wechat.MemberRefundNotifyUrl, Amount: weChat.JsapiRequestAmountRequest{ Total: int64(m.PaymentAmountTotal * 100), Currency: "CNY", @@ -322,7 +322,7 @@ func (r *OrderMemberService) GetAppPrepay(m *model.OrderMember) (prepay *app.Pre MchId: config.C.Wechat.Pay1281030301.MchId, Description: "肝病算一算", OutTradeNo: m.OrderNo, - NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.MemberRefundNotifyUrl, + NotifyUrl: config.C.Wechat.NotifyDomain + config.C.Wechat.MemberRefundNotifyUrl, Amount: weChat.AppRequestAmountRequest{ Total: int64(m.PaymentAmountTotal * 100), Currency: "CNY", diff --git a/api/service/OrderSingle.go b/api/service/OrderSingle.go index 1bd26d3..41c7e52 100644 --- a/api/service/OrderSingle.go +++ b/api/service/OrderSingle.go @@ -313,11 +313,11 @@ func (r *OrderSingleService) GetJsapiPrepay(m *model.OrderSingle) (prepay *jsapi } jsapiRequest := weChat.JsapiRequest{ - AppId: config.C.Wechat.AppId, + AppId: config.C.Wechat.TestPayAppId, MchId: config.C.Wechat.Pay1281030301.MchId, Description: "肝病算一算", OutTradeNo: m.OrderNo, - NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.SingleRefundNotifyUrl, + NotifyUrl: config.C.Wechat.NotifyDomain + config.C.Wechat.SinglePayNotifyUrl, Amount: weChat.JsapiRequestAmountRequest{ Total: int64(m.PaymentAmountTotal * 100), Currency: "CNY", @@ -347,11 +347,11 @@ func (r *OrderSingleService) GetAppPrepay(m *model.OrderSingle) (prepay *app.Pre } appRequest := weChat.AppRequest{ - AppId: config.C.Wechat.AppId, + AppId: config.C.Wechat.TestPayAppId, MchId: config.C.Wechat.Pay1281030301.MchId, Description: "肝病算一算", OutTradeNo: m.OrderNo, - NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.SingleRefundNotifyUrl, + NotifyUrl: config.C.Wechat.NotifyDomain + config.C.Wechat.SingleRefundNotifyUrl, Amount: weChat.AppRequestAmountRequest{ Total: int64(m.PaymentAmountTotal * 100), Currency: "CNY", diff --git a/config.yaml b/config.yaml index 44fa59d..b46ab23 100644 --- a/config.yaml +++ b/config.yaml @@ -49,11 +49,12 @@ dysms: wechat: app-id: wx68affaa9d23528f8 app-secret: 2963c90242ddb2421c939591ad9e903d + test-pay-app-id: wxa4132ef4701ac5e4 single-pay-notify-url: callback/wxpay/single # 单项支付回调地址 single-refund-notify-url: callback/wxpay/single/refund # 单项退款回调地址 member-pay-notify-url: callback/wxpay/member # 会员支付回调地址 member-refund-notify-url: callback/wxpay/member/refund # 会员退款回调地址 - refund-notify-domain: https://dev-hepa.igandan.com/api/ + notify-domain: https://dev-hepa.igandan.com/api/ pay-1281030301: mch-id: 1281030301 v3-api-secret: sB2tCkT70uwEy7cQCu1llA6nilTbek6F diff --git a/config/wechat.go b/config/wechat.go index d74e756..9a7fd05 100644 --- a/config/wechat.go +++ b/config/wechat.go @@ -1,13 +1,14 @@ package config type Wechat struct { - AppId string `mapstructure:"app-id" json:"app-id" yaml:"patient-app-id"` + AppId string `mapstructure:"app-id" json:"app-id" yaml:"app-id"` AppSecret string `mapstructure:"app-secret" json:"app-secret" yaml:"app-secret"` + TestPayAppId string `mapstructure:"test-pay-app-id" json:"test-pay-app-id" yaml:"test-pay-app-id"` SinglePayNotifyUrl string `mapstructure:"single-pay-notify-url" json:"single-pay-notify-url" yaml:"single-pay-notify-url"` // 单项支付回调地址 SingleRefundNotifyUrl string `mapstructure:"single-refund-notify-url" json:"single-refund-notify-url" yaml:"single-refund-notify-url"` // 单项退款回调地址 MemberPayNotifyUrl string `mapstructure:"member-pay-notify-url" json:"member-pay-notify-url" yaml:"member-pay-notify-url"` // 会员支付回调地址 MemberRefundNotifyUrl string `mapstructure:"member-refund-notify-url" json:"member-refund-notify-url" yaml:"member-refund-notify-url"` // 会员退款回调地址 - RefundNotifyDomain string `mapstructure:"refund-notify-domain" json:"refund-notify-domain" yaml:"refund-notify-domain"` + NotifyDomain string `mapstructure:"notify-domain" json:"notify-domain" yaml:"notify-domain"` Pay1281030301 Pay1281030301 `mapstructure:"pay-1281030301" json:"pay-1281030301" yaml:"pay-1281030301"` } diff --git a/extend/weChat/prepay.go b/extend/weChat/prepay.go index 132b34b..08e49df 100644 --- a/extend/weChat/prepay.go +++ b/extend/weChat/prepay.go @@ -6,7 +6,6 @@ import ( "github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/services/payments/app" "github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi" - "hepa-calc-api/utils" ) /** @@ -61,24 +60,29 @@ func (r JsapiRequest) GetJsapiPrepay() (prepay *jsapi.PrepayWithRequestPaymentRe svc := jsapi.JsapiApiService{Client: client} // 得到prepay_id,以及调起支付所需的参数和签名 - resp, result, err := svc.PrepayWithRequestPayment(context.Background(), - jsapi.PrepayRequest{ - Appid: core.String(r.AppId), - Mchid: core.String(r.MchId), - Description: core.String(r.Description), - OutTradeNo: core.String(r.OutTradeNo), - NotifyUrl: core.String(r.NotifyUrl), - Amount: &jsapi.Amount{ - Total: core.Int64(r.Amount.Total), - Currency: core.String("CNY"), - }, - Payer: &jsapi.Payer{ - Openid: core.String(r.Payer.OpenId), - }, + PrepayRequest := jsapi.PrepayRequest{ + Appid: core.String(r.AppId), + Mchid: core.String(r.MchId), + Description: core.String(r.Description), + OutTradeNo: core.String(r.OutTradeNo), + NotifyUrl: core.String(r.NotifyUrl), + Amount: &jsapi.Amount{ + Total: core.Int64(r.Amount.Total), + Currency: core.String("CNY"), }, + Payer: &jsapi.Payer{ + Openid: core.String(r.Payer.OpenId), + }, + } + + resp, result, err := svc.PrepayWithRequestPayment(context.Background(), + PrepayRequest, ) - utils.LogJsonInfo("发起支付", *result) + if err != nil { + return nil, err + } + if result.Response.StatusCode != 200 { return nil, errors.New("发起支付失败") } @@ -118,6 +122,10 @@ func (r AppRequest) GetAppPrepay() (prepay *app.PrepayWithRequestPaymentResponse }, ) + if err != nil { + return nil, err + } + if result.Response.StatusCode != 200 { return nil, errors.New("发起支付失败") }