This commit is contained in:
lwl0608 2024-02-03 16:04:56 +08:00
parent 9aff51c92b
commit 332bcc87fc
4 changed files with 76 additions and 12 deletions

View File

@ -19,6 +19,7 @@ const (
PayTypeOp = "op" // op直冲
PayTypeAlipay = "alipay" // 支付宝
PayTypeAlipayH5 = "alipay_h5" // 支付宝 h5
PayTypeWxpayNative = "wxpay_native" // 微信native
)
const (

View File

@ -47,6 +47,12 @@ alipay:
appid: "2021004115647165"
private_key: "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCeA8ADj0arLzUK5B3R5bqbOkXm8TBe0dI6XpefxnHeNyksEFhQuWTFtQA550lGj/VMyNQC0R+gL6VK/5SdgonzxMx8bC+/1lIWrl3Q8F+JLsAUcNh6C+WzDw7m5YSrG9361f3+i/gPVC4GRTzx91qLdk1ySGZv/GpSVv49k9qtD83gRCbxJq5FY1QA83Wb5xkJoMwl+SlKvFLNxIIzPQh9DvDF+32FTsVQgm3sX1lsArTA4yp7Y4SG3A8mkOanidYX1KiUawMBWaDgZi1CMpQ+Zbb3w0C0txCeZ8ek5JeUw2EYHJ0awMnFE6+vPDm1LNJ0DodkvszGbmLvXQS2eMfVAgMBAAECggEABj1nq7xQshnfIlr3wn4r7E1UzVXg7x2iC6QIoMqZXIkZGyBaHHX1wMjxBVhY0GyG501W8fWIJi87e8az+7RX9kRjPtaW3CB+hV7FXabgXu51r1j1c3xcycFieUO/BXLIRUuGCDNGzHQqjRzW10dJUBCP5l9tjCaPnEjLKWtZS1QwhtmjmAJalC+oQLnhvlmURSWwyvIIgrqK82DZj5DFgXrxlah21Sou/N4xV/W/d0OkaouDxHtQ4Oy/yE/oc2z+vbcBcHrIt+r2g8gymKPdsDFyglUqZeNRlwYnifSUH7Bmn+1uiXAi86RlUdtCYngNUUNoOStB9oC7gidPHyeb0QKBgQDV58AFBOCHdG2gO+VvKiIpbquWMYTbmbRGmCai911G6zX8X/37nawKWZkyk4kIkrohZtwwL5s6AIlD5F9nRBp+Uk1QvlIYokD3vjUuVPyvpC3raASUvTs0WoWbq3gfPH5Qn5vS1C89CQ/68FC+89CYiexxwq7ybX86lzhYGpRXrwKBgQC9HE7e5Cr9akJrUuPW8NjbKATYg2h8s3/FMa4AbeTLPSEPPp20yRGA5P0xPgV1JocfmVd3VC6ivF6YHKKVnKoVbR74InCi4hhriGb3uLz7i6ngjcxysBfOlKA8lOlMAMY4ZrE2zTp2mUKF1Wp3a0IiC0xGPmdh44xvrO8h4UK1uwKBgGkY3Lealdb31YUM6MWdpftFbPj2i5h6BKFK0HDxqNrXZkcBwwCFj6nmK+c1pfaYYOtYZocmXNY6vTamVlmelIXMWkB5wkxoLBONWQPSrfR+bjFjghyyfQxUDaFWtkZiqo1iXmVP64XJlhhtSr8HfE32Nj4OsXZbZk+bTQu8w3XxAoGBAJJg3wvYQQ52uYKpXoJ5WuIIT/fnf3FG35ebpLvgVECcyIIsTZYqLMpAdVswTrknYWAsKW/MUWzVscK8J3z3DxAWruoSfm0V5SEXK9yDuoRazttp5t6/Py5ADOfXu92Am+38Tx/EK4SxjLRbRVW6SC5h4GBe3Vb/8yxeB5uJ6UERAoGAbsCHaS1NW21qYxeWAD8XC1x8B5vLwcVILP0kIt5CPFgKRcRbJPEfnSF8fFC0OKwJrp32+AhMTOEISwJVkR10Jzqn7VU1bu7lHYkiiOIZJCb1cdjfPxYUR60vpIttoKuz+CBIgc0zo1tu3TgCVdCy//coVRCoLeK+JawP43VLJ+g="
wxpay:
mchid: ""
appid: ""
apollo:
app_id: "wishpal_live_service"
cluster: "dev"

View File

@ -27,11 +27,6 @@ mix_mysql:
read_timeout_s: 5
write_timeout_s: 3
wxpay:
mchid: "1111"
serial_no: "1111"
apiv3_key: "1111"
private_key: "af21aw65aw23efwa132f1waef56wa56awef"
crypto:
aes:
@ -48,6 +43,13 @@ alipay:
private_key: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCtj6Nu2olEB8c8SDSANExaPbmk8LoYP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us8ypI8TBejGJXn9TXVZdDlwPd9hUFY9QlZl82hbm0XMK7fms4K9KbIDJKXX/CTyoUVgPEkFpcF21lQIuhr6C0XlABfVmNlD+TcPwKBgHJuot2ov3UXsZH8/gHKNSsibswrHmS9HobGPz+K1al1Stk5NCxKPrqcjLL70gSf+ozkT7MggwCkLgnln2u1OV0Lh2HAEY9RIwgQhw2fT1GvseNS873no8T5j0rLMCnfxPJjIItWM2cvOhzFY/BQYaAcrElbwlaJdEvkgG+lkrgJAoGBAInYRdHo9V1exDUS0ucQuraoEtuvgOrqatnCbuNZ9EpgjFJxDbHXOIJYPvgfpyws4amdksNQL0Ux9+p+esJOS+JYYkE1nmCTCrfb6SNKr+PdeUteKtTiHJb4zJhGVC2Lk4uBg9AGa/d7j5apWw4RsZ/R1ky1S6KQUkqItbVrhC8l"
notify_url: "https://api.tiefen.fun/ext/vas/alipay_callback"
wxpay:
mchid: "1665016206"
appid: "xxxx"
apiv3_key: "UoaswgnuKYwIadqxCVag1IZlq5n9USvt"
private_key: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDgxWmqIZVZEVdO/XNOzc66UkyYAS6/LzTAWP6WW/wIfilaDSDAe99jUspFKl1YmubJkDJ5Y2WaHcOyirgfYX3GHMrr1x7vtqON6eQPiGShlf9HlOQCdi1zmUrBeMWj5Tcll+ldyazYaqR4yG6ahhj1BnsqZ+W6Sa9xtTfMtTUrBvJuHm4dWAQR62A2Teetk9YN9cxiOwL7BXaJo5hYaumNobz7pIz6XHqBgEhBH6Qv8ka746NOR1UFSvMeqHWv+uyBzUthdIKFLCREgQmFToXs7oJsuF2nshZKnMPta3Xvi8wbPbAZc4b4KwLLv9SxBKiRhztagF8KqYn1k4RB8mFDAgMBAAECggEAFfMxXmvpKcmHvS8DE68FgSyITk/PQNxbSm1mb0iMVEf9wc2GZUWziv+KwTZh50U5RHXQeAo84dAGTGk/kdDzd2VYa6+WVdKAJluw6dNoAF+ljlf77EGeLqvJ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quEUSn+XDIomat7Bnw"
apollo:
app_id: "wishpal_live_service"
cluster: "dev"

View File

@ -1,24 +1,79 @@
package wxpaycli
import (
"context"
"time"
"github.com/go-pay/gopay"
wxpay "github.com/go-pay/gopay/wechat/v3"
"service/bizcommon/util"
"service/library/configcenter"
"service/library/logger"
)
const (
DefaultOrderTimeoutSeconds = 900 // 默认订单超时时间,单位: s
)
var defaultWxpayClient *WxpayClient
type WxpayClient struct {
*wxpay.ClientV3
AppId string `json:"app_id"`
NotifyUrl string `json:"notify_url"`
}
func NewWxpayClient(cfg *configcenter.WxpayClientConfig) (cli *WxpayClient, err error) {
wxPayCli, err := wxpay.NewClientV3(cfg.MchId, cfg.SerialNo, cfg.ApiV3Key, cfg.PrivateKey)
func GetDefaultWxpayClient() *WxpayClient {
return defaultWxpayClient
}
func Init(cfg *configcenter.WxpayClientConfig) (err error) {
wxpayCli, err := wxpay.NewClientV3(cfg.MchId, cfg.SerialNo, cfg.ApiV3Key, cfg.PrivateKey)
if err != nil {
logger.Error("NewClientV3 fail, cfg: %v, err: %v", util.ToJson(cfg), err)
return
}
cli = &WxpayClient{
wxPayCli,
defaultWxpayClient = &WxpayClient{
ClientV3: wxpayCli,
}
return
}
// 验签
// 微信支付 native支付
type NativePayParam struct {
Description string
OutTradeNo string // 商家订单id我们自己的订单id
TotalAmount int64 // 金额,单位:分
TimeOutSeconds int // 订单有效时间,单位:秒
}
func (c *WxpayClient) NativePay(ctx context.Context, param *NativePayParam) {
if param.TimeOutSeconds <= 0 {
param.TimeOutSeconds = DefaultOrderTimeoutSeconds
}
bm := gopay.BodyMap{
"appid": c.AppId,
"description": param.Description,
"out_trade_no": param.OutTradeNo,
"time_expire": time.Now().Add(time.Second * time.Duration(param.TimeOutSeconds)).Format(time.RFC3339),
"notify_url": c.NotifyUrl,
"amount": gopay.BodyMap{
"total": param.TotalAmount,
"currency": "CNY",
},
}
wxRsp, err := c.V3TransactionNative(ctx, bm)
if err != nil {
return
}
if wxRsp.Code != wxpay.Success {
logger.Info("wxpay NativePay resp, fail: %v", util.ToJson(wxRsp))
return
}
logger.Info("wxpay NativePay resp, success: %v", util.ToJson(wxRsp))
return
}