This commit is contained in:
lwl0608 2024-02-05 01:15:29 +08:00
parent 332bcc87fc
commit 87ece44a9a
7 changed files with 136 additions and 16 deletions

View File

@ -47,12 +47,6 @@ 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

@ -45,11 +45,37 @@ alipay:
wxpay:
mchid: "1665016206"
appid: "xxxx"
appid: "wxb1acd21d9c4942cc"
serial_no: "51D8E75620B9569F10FF5363022F3C9D2152DF50"
apiv3_key: "UoaswgnuKYwIadqxCVag1IZlq5n9USvt"
private_key: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDgxWmqIZVZEVdO/XNOzc66UkyYAS6/LzTAWP6WW/wIfilaDSDAe99jUspFKl1YmubJkDJ5Y2WaHcOyirgfYX3GHMrr1x7vtqON6eQPiGShlf9HlOQCdi1zmUrBeMWj5Tcll+ldyazYaqR4yG6ahhj1BnsqZ+W6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reEK03E9kWE3Uvt9jf21oJkQGQsRqTNYd8uIAQKBgQDyNOIIOnOgwt3coiZk
LYmo+F/zQQm6R8gebYWO1XCKLkMto9JaeJyEpehZQngMJvJc4r+4tWNFv8rcOHu5
/7SnteVUJK4RBXpKosLqswqD0ySEXzNLloumvxXz8HnXIiTSQ3rtISQSHzp0uunq
fkTzezc9ZRT08Jx6rmLvpKsJ3QKBgQDtklbus1fRQ/zbdddKbTfYMZsWSi7qQiA3
AKM7rY6wrS1gUJtVk9mhNgUe0uIvkkdQvtm/QKiSrtgGkre59g9sekZppCyWId6a
i1tlFvkG16Oc/TsAJDBNJgtWrkPDsjjHSx2VExTeRJ30XGd8lx3EEWHEbSboGPbf
G3gxm9a1nwKBgAdH06uPpj4k3WpubV0BiWvM24WCZPp2get4O1WJ0PI2ZcqPbBlQ
GtRZ8FwOhXFIEmz8W+r/eNZ153ErOXzj1NhdvWEEIT9dvMlVjypi62P/Cs/31KDn
C5edktlcVy1CV30CjkVmg6EP00ADBlkIJqZzA7wSt8iNGwcNCuhNON75AoGBAOGA
GXIj24RwM1Agr8UenHZix6HFsnh7YdazjT11RU7gYoTcnkUBvP5vpzaV10puX7D+
JvOJrTjmK3k5xJkIPaWq/rEBu6yZ45DwHEV9I81h3BSErX852nswVGznprzXq1tI
KoE5BoLfwMqU90nkqsVT9mgbb2W5ZINrsI/uK0RjAoGBAL+9L8iJx6/M4yQosTrQ
IL6SOxPU3HlfkqZzObiQ8vs7VdIpGhB1EMc9UEKe8RcnpTUeLsVeNHdiDZzRHtJ3
RxZS/AsjJtYAZ2f/maJhgQsh6JN1AceDhMhx1iTsjr/ockyUZuXKiCr5Q43tzrMJ
tMrOrkquEUSn+XDIomat7Bnw
-----END PRIVATE KEY-----"
apollo:
app_id: "wishpal_live_service"
cluster: "dev"

Binary file not shown.

View File

@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIEKDCCAxCgAwIBAgIUUdjnViC5Vp8Q/1NjAi88nSFS31AwDQYJ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B3hRfKvZpva3hx4lh8ZC3Et7bIP/r4IV5qCNC
wzN1Niq0aBXtnehOWL+mnnBmmW5QnB80UX1/yFxtaBEK+6R6IObAj7ClUSb0F8ak
0fRkCyWGl985sAUyZVE5g0jQEEcWFhdV9lpwPdprY4S9vck+cCfjPi4EyxEzRh7z
knsvZbjoj/0oTSKgg39D4UEQl6X0e3YR74kIXfKmFK08WxoKKet201pL3bzJKBAY
s+8VBqAKsTvNZJ1/GYPqax7ArpACX4LjgmzCv7/rrM75ce6rXWlkIOBSAz2dHuF0
Q6iPI92vMh32p19Q
-----END CERTIFICATE-----

View File

@ -64,9 +64,11 @@ type RedisConfig struct {
// 微信支付客户端配置
type WxpayClientConfig struct {
MchId string `json:"mchid" yaml:"mchid"` // 商户id
AppId string `json:"appid" yaml:"appid"` // appid
SerialNo string `json:"serial_no" yaml:"serial_no"` // 商户API证书的证书序列号
ApiV3Key string `json:"apiv3_key" yaml:"apiv3_key"` // APIv3Key商户平台获取
PrivateKey string `json:"private_key" yaml:"private_key"` // 商户API证书下载后私钥 apiclient_key.pem 读取后的字符串内容
NotifyUrl string `json:"notify_url" yaml:"notify_url"` // 回调地址
}
// 账号相关验密配置

View File

@ -36,7 +36,9 @@ func Init(cfg *configcenter.WxpayClientConfig) (err error) {
}
defaultWxpayClient = &WxpayClient{
ClientV3: wxpayCli,
ClientV3: wxpayCli,
AppId: cfg.AppId,
NotifyUrl: cfg.NotifyUrl,
}
return
}
@ -51,7 +53,7 @@ type NativePayParam struct {
TimeOutSeconds int // 订单有效时间,单位:秒
}
func (c *WxpayClient) NativePay(ctx context.Context, param *NativePayParam) {
func (c *WxpayClient) NativePay(ctx context.Context, param *NativePayParam) (resp *wxpay.NativeRsp, err error) {
if param.TimeOutSeconds <= 0 {
param.TimeOutSeconds = DefaultOrderTimeoutSeconds
}
@ -66,14 +68,14 @@ func (c *WxpayClient) NativePay(ctx context.Context, param *NativePayParam) {
"currency": "CNY",
},
}
wxRsp, err := c.V3TransactionNative(ctx, bm)
resp, err = c.V3TransactionNative(ctx, bm)
if err != nil {
return
}
if wxRsp.Code != wxpay.Success {
logger.Info("wxpay NativePay resp, fail: %v", util.ToJson(wxRsp))
if resp.Code != wxpay.Success {
logger.Info("wxpay NativePay resp, fail: %v", util.ToJson(resp))
return
}
logger.Info("wxpay NativePay resp, success: %v", util.ToJson(wxRsp))
logger.Info("wxpay NativePay resp, success: %v", util.ToJson(resp))
return
}

View File

@ -0,0 +1,71 @@
package wxpaycli
import (
"context"
"fmt"
"os"
"service/bizcommon/util"
"service/library/configcenter"
"service/library/idgenerator"
"testing"
)
func TestMain(m *testing.M) {
cfg := &configcenter.WxpayClientConfig{
MchId: "1665016206",
AppId: "wxb1acd21d9c4942cc",
SerialNo: "51D8E75620B9569F10FF5363022F3C9D2152DF50",
ApiV3Key: "UoaswgnuKYwIadqxCVag1IZlq5n9USvt",
PrivateKey: `-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDgxWmqIZVZEVdO
/XNOzc66UkyYAS6/LzTAWP6WW/wIfilaDSDAe99jUspFKl1YmubJkDJ5Y2WaHcOy
irgfYX3GHMrr1x7vtqON6eQPiGShlf9HlOQCdi1zmUrBeMWj5Tcll+ldyazYaqR4
yG6ahhj1BnsqZ+W6Sa9xtTfMtTUrBvJuHm4dWAQR62A2Teetk9YN9cxiOwL7BXaJ
o5hYaumNobz7pIz6XHqBgEhBH6Qv8ka746NOR1UFSvMeqHWv+uyBzUthdIKFLCRE
gQmFToXs7oJsuF2nshZKnMPta3Xvi8wbPbAZc4b4KwLLv9SxBKiRhztagF8KqYn1
k4RB8mFDAgMBAAECggEAFfMxXmvpKcmHvS8DE68FgSyITk/PQNxbSm1mb0iMVEf9
wc2GZUWziv+KwTZh50U5RHXQeAo84dAGTGk/kdDzd2VYa6+WVdKAJluw6dNoAF+l
jlf77EGeLqvJoRsqMdcwi3tKTt5jAr9nUGRCaNSvmz4GyR1cUdTg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----END PRIVATE KEY-----`,
NotifyUrl: "https://api.tiefen.fun/vas/wxpay_callback",
}
err := Init(cfg)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
m.Run()
}
func TestWxpayClient_NativePay(t *testing.T) {
cli := GetDefaultWxpayClient()
resp, err := cli.NativePay(context.Background(), &NativePayParam{
Description: "测试哈哈",
OutTradeNo: idgenerator.GenOrderId(),
TotalAmount: 1,
TimeOutSeconds: 3600 * 24,
})
if err != nil {
fmt.Println(err.Error())
return
}
t.Log(util.ToJson(resp))
return
}