This commit is contained in:
lwl0608 2024-02-05 21:55:44 +08:00
parent 2261c021fa
commit f0050a938e
4 changed files with 24 additions and 70 deletions

View File

@ -32,34 +32,7 @@ wxpay:
appid: "wxc28fd8aaf31984b6"
serial_no: "51D8E75620B9569F10FF5363022F3C9D2152DF50"
apiv3_key: "UoaswgnuKYwIadqxCVag1IZlq5n9USvt"
private_key: "-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDgxWmqIZVZEVdO
/XNOzc66UkyYAS6/LzTAWP6WW/wIfilaDSDAe99jUspFKl1YmubJkDJ5Y2WaHcOy
irgfYX3GHMrr1x7vtqON6eQPiGShlf9HlOQCdi1zmUrBeMWj5Tcll+ldyazYaqR4
yG6ahhj1BnsqZ+W6Sa9xtTfMtTUrBvJuHm4dWAQR62A2Teetk9YN9cxiOwL7BXaJ
o5hYaumNobz7pIz6XHqBgEhBH6Qv8ka746NOR1UFSvMeqHWv+uyBzUthdIKFLCRE
gQmFToXs7oJsuF2nshZKnMPta3Xvi8wbPbAZc4b4KwLLv9SxBKiRhztagF8KqYn1
k4RB8mFDAgMBAAECggEAFfMxXmvpKcmHvS8DE68FgSyITk/PQNxbSm1mb0iMVEf9
wc2GZUWziv+KwTZh50U5RHXQeAo84dAGTGk/kdDzd2VYa6+WVdKAJluw6dNoAF+l
jlf77EGeLqvJoRsqMdcwi3tKTt5jAr9nUGRCaNSvmz4GyR1cUdTgTTplOJh5mLnm
GGZQPVR87pex00QCTtQ7dggG/vg8QM+XbBeSAkWByeUDsrCo4pKbsY+kxKGCkhV0
3hxgHz2v7QZ8kanbgVPZzB76tOxRf9ghUQ5TFPc9kjgtQmn5ViqzMTXdotFXlE/u
n82BreEK03E9kWE3Uvt9jf21oJkQGQsRqTNYd8uIAQKBgQDyNOIIOnOgwt3coiZk
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-----"
private_key_path: "/app/wishpal-ironfan/etc/mix/wxpaycert/apiclient_key.pem"
notify_url: "https://api.wishpal.cn/ext/vas/wxpay_callback"
crypto:

View File

@ -63,12 +63,12 @@ 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"` // 回调地址
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商户平台获取
PrivateKeyPath string `json:"private_key_path" yaml:"private_key_path"` // 商户API证书下载后私钥 apiclient_key.pem 读取后的字符串内容
NotifyUrl string `json:"notify_url" yaml:"notify_url"` // 回调地址
}
// 账号相关验密配置

View File

@ -3,6 +3,7 @@ package wxpaycli
import (
"context"
"net/http"
"os"
"time"
"github.com/go-pay/gopay"
@ -30,7 +31,15 @@ func GetDefaultWxpayClient() *WxpayClient {
}
func Init(cfg *configcenter.WxpayClientConfig) (err error) {
wxpayCli, err := wxpay.NewClientV3(cfg.MchId, cfg.SerialNo, cfg.ApiV3Key, cfg.PrivateKey)
// private key
bs, err := os.ReadFile(cfg.PrivateKeyPath)
if err != nil {
logger.Error("real PrivateKeyPath fail, cfg: %v, err: %v", util.ToJson(cfg), err)
return
}
privateKey := string(bs)
wxpayCli, err := wxpay.NewClientV3(cfg.MchId, cfg.SerialNo, cfg.ApiV3Key, privateKey)
if err != nil {
logger.Error("NewClientV3 fail, cfg: %v, err: %v", util.ToJson(cfg), err)
return

View File

@ -4,48 +4,20 @@ import (
"context"
"fmt"
"os"
"service/app/mix/conf"
"service/library/configcenter"
"service/library/idgenerator"
"testing"
)
func TestMain(m *testing.M) {
cfg := &configcenter.WxpayClientConfig{
MchId: "1665016206",
AppId: "wxc28fd8aaf31984b6",
SerialNo: "51D8E75620B9569F10FF5363022F3C9D2152DF50",
ApiV3Key: "UoaswgnuKYwIadqxCVag1IZlq5n9USvt",
PrivateKey: `-----BEGIN PRIVATE KEY-----
MIIEvgIBAD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8lx3EEWHEbSboGPbf
G3gxm9a1nwKBgAdH06uPpj4k3WpubV0BiWvM24WCZPp2get4O1WJ0PI2ZcqPbBlQ
GtRZ8FwOhXFIEmz8W+r/eNZ153ErOXzj1NhdvWEEIT9dvMlVjypi62P/Cs/31KDn
C5edktlcVy1CV30CjkVmg6EP00ADBlkIJqZzA7wSt8iNGwcNCuhNON75AoGBAOGA
GXIj24RwM1Agr8UenHZix6HFsnh7YdazjT11RU7gYoTcnkUBvP5vpzaV10puX7D+
JvOJrTjmK3k5xJkIPaWq/rEBu6yZ45DwHEV9I81h3BSErX852nswVGznprzXq1tI
KoE5BoLfwMqU90nkqsVT9mgbb2W5ZINrsI/uK0RjAoGBAL+9L8iJx6/M4yQosTrQ
IL6SOxPU3HlfkqZzObiQ8vs7VdIpGhB1EMc9UEKe8RcnpTUeLsVeNHdiDZzRHtJ3
RxZS/AsjJtYAZ2f/maJhgQsh6JN1AceDhMhx1iTsjr/ockyUZuXKiCr5Q43tzrMJ
tMrOrkquEUSn+XDIomat7Bnw
-----END PRIVATE KEY-----`,
NotifyUrl: "https://api.tiefen.fun/vas/wxpay_callback",
cfg := new(conf.ConfigSt)
err := configcenter.LoadConfig("/Users/erwin/wishpalv2/service/etc/mix/mix-test.yaml", cfg)
if err != nil {
fmt.Printf("%v\n", err)
}
err := Init(cfg)
err = Init(cfg.Wxpay)
if err != nil {
fmt.Println(err)
os.Exit(1)