This commit is contained in:
wucongxing8150 2024-07-25 18:00:42 +08:00
parent c21b47fc73
commit 5dd3c44917
5 changed files with 20 additions and 12 deletions

View File

@ -10,8 +10,8 @@ import (
// CallBack 回调 // CallBack 回调
type CallBack struct{} type CallBack struct{}
// WxJsapiPay 微信支付回调-jsapi // WxPaySingle 微信支付回调-单项
func (r *CallBack) WxJsapiPay(c *gin.Context) { func (r *CallBack) WxPaySingle(c *gin.Context) {
notifyReq, err := weChat.ParseNotify(c) notifyReq, err := weChat.ParseNotify(c)
if err != nil { if err != nil {
responses.FailWithMessage(err.Error(), c) responses.FailWithMessage(err.Error(), c)
@ -19,5 +19,8 @@ func (r *CallBack) WxJsapiPay(c *gin.Context) {
} }
// 记录日志 // 记录日志
utils.LogJsonErr("微信支付回调-jsapi", notifyReq) utils.LogJsonErr("微信支付回调-单项", notifyReq)
// 查询订单
} }

View File

@ -98,7 +98,8 @@ func publicRouter(r *gin.Engine, api controller.Api) {
// 微信支付回调 // 微信支付回调
wxpayGroup := callbackGroup.Group("/wxpay") wxpayGroup := callbackGroup.Group("/wxpay")
{ {
wxpayGroup.POST("/jsapi", api.CallBack.WxJsapiPay) // 单项
wxpayGroup.POST("/single", api.CallBack.WxPaySingle)
} }
} }
} }

View File

@ -49,7 +49,7 @@ dysms:
wechat: wechat:
app-id: wxc8ac5051745bc795 app-id: wxc8ac5051745bc795
app-secret: 678b63a8a7541e528abc3040c3cea809 app-secret: 678b63a8a7541e528abc3040c3cea809
pay-notify-url: callback/wxpay/inquiry/success pay-notify-url: callback/wxpay/single
refund-notify-url: callback/wxpay/inquiry/refund refund-notify-url: callback/wxpay/inquiry/refund
refund-notify-domain: https://dev.hospital.applets.igandanyiyuan.com/ refund-notify-domain: https://dev.hospital.applets.igandanyiyuan.com/
pay-1659662936: pay-1659662936:

View File

@ -9,15 +9,13 @@ import (
"hepa-calc-api/config" "hepa-calc-api/config"
) )
var (
mchId = config.C.Wechat.Pay1659662936.MchId // 商户号
mchCertificateSerialNumber = config.C.Wechat.Pay1659662936.MchCertificateSerialNumber // 商户证书序列号
v3ApiSecret = config.C.Wechat.Pay1659662936.V3ApiSecret // 商户APIv3密钥
privateKeyPath = "extend/weChat/certs/" + mchId + "/apiclient_key.pem" // 商户私钥文件地址
)
// 创建客户端 // 创建客户端
func createClient() (*core.Client, error) { func createClient() (*core.Client, error) {
mchId := config.C.Wechat.Pay1659662936.MchId // 商户号
mchCertificateSerialNumber := config.C.Wechat.Pay1659662936.MchCertificateSerialNumber // 商户证书序列号
v3ApiSecret := config.C.Wechat.Pay1659662936.V3ApiSecret // 商户APIv3密钥
privateKeyPath := "extend/weChat/certs/" + config.C.Wechat.Pay1659662936.MchId + "/apiclient_key.pem" // 商户私钥文件地址
if mchId == "" { if mchId == "" {
return nil, errors.New("商户号错误") return nil, errors.New("商户号错误")
} }

View File

@ -10,10 +10,16 @@ import (
"github.com/wechatpay-apiv3/wechatpay-go/core/notify" "github.com/wechatpay-apiv3/wechatpay-go/core/notify"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments" "github.com/wechatpay-apiv3/wechatpay-go/services/payments"
"github.com/wechatpay-apiv3/wechatpay-go/utils" "github.com/wechatpay-apiv3/wechatpay-go/utils"
"hepa-calc-api/config"
) )
// ParseNotify 回调通知的验签与解密 // ParseNotify 回调通知的验签与解密
func ParseNotify(c *gin.Context) (notifyReq *notify.Request, err error) { func ParseNotify(c *gin.Context) (notifyReq *notify.Request, err error) {
mchId := config.C.Wechat.Pay1659662936.MchId // 商户号
mchCertificateSerialNumber := config.C.Wechat.Pay1659662936.MchCertificateSerialNumber // 商户证书序列号
v3ApiSecret := config.C.Wechat.Pay1659662936.V3ApiSecret // 商户APIv3密钥
privateKeyPath := "extend/weChat/certs/" + config.C.Wechat.Pay1659662936.MchId + "/apiclient_key.pem" // 商户私钥文件地址
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(privateKeyPath) mchPrivateKey, err := utils.LoadPrivateKeyWithPath(privateKeyPath)
if err != nil { if err != nil {