Compare commits

...

4 Commits

Author SHA1 Message Date
System Administrator b4b7ed672c test
4 months ago
杨赟 f40f4f1565 修改进制
3 years ago
杨赟 bac0b487d7 修改文档
3 years ago
杨赟 ff1764098b 修改位置支付配置
3 years ago

@ -19,7 +19,6 @@ func main() {
// 初始化配置 // 初始化配置
if err := pay.InitWxpay(pay.WxpayConfig{ if err := pay.InitWxpay(pay.WxpayConfig{
MchID: "mchID", // 支付商户号 MchID: "mchID", // 支付商户号
MchCertificateSerialNumber: "mchCertificateSerialNumber", // 证书序列号
MchAPIv3Key: "mchAPIv3Key", // apiV3密钥 MchAPIv3Key: "mchAPIv3Key", // apiV3密钥
PrivateKey: "privateKey", // 私钥证书密钥 PrivateKey: "privateKey", // 私钥证书密钥
PrivateCert: "privateCert", // 私钥证书 PrivateCert: "privateCert", // 私钥证书

@ -4,11 +4,12 @@ go 1.17
require ( require (
git.oa00.com/go/rsa v1.0.0 git.oa00.com/go/rsa v1.0.0
github.com/smartwalle/alipay/v3 v3.1.7 github.com/smartwalle/alipay/v3 v3.2.21
github.com/wechatpay-apiv3/wechatpay-go v0.2.11 github.com/wechatpay-apiv3/wechatpay-go v0.2.18
) )
require ( require (
github.com/smartwalle/crypto4go v1.0.2 // indirect github.com/smartwalle/ncrypto v1.0.4 // indirect
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 // indirect github.com/smartwalle/ngx v1.0.9 // indirect
github.com/smartwalle/nsign v1.0.9 // indirect
) )

@ -2,26 +2,29 @@ git.oa00.com/go/rsa v1.0.0 h1:cscSyfYeNxqUjEt/rUiPjPlqeZW/pdLDqVTrS64llJM=
git.oa00.com/go/rsa v1.0.0/go.mod h1:y4272MGmgvdEGcXIcPRBwteDo/zeqTEtRpqJBpK1Luk= git.oa00.com/go/rsa v1.0.0/go.mod h1:y4272MGmgvdEGcXIcPRBwteDo/zeqTEtRpqJBpK1Luk=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/smartwalle/alipay/v3 v3.1.7 h1:J4U5slABafKVD/b9gPCZe/3HAPB8Pa2NOYOPcugEJBo= github.com/smartwalle/alipay/v3 v3.2.21 h1:zQmzYOGU4WCc2f21VzqBqC60iEJ6meVxe1Sl33nJ+vE=
github.com/smartwalle/alipay/v3 v3.1.7/go.mod h1:cZUMCCnsux9YAxA0/f3PWUR+7wckWtE1BqxbVRtGij0= github.com/smartwalle/alipay/v3 v3.2.21/go.mod h1:lVqFiupPf8YsAXaq5JXcwqnOUC2MCF+2/5vub+RlagE=
github.com/smartwalle/crypto4go v1.0.2 h1:9DUEOOsPhmp00438L4oBdcL8EZG1zumecft5bWj5phI= github.com/smartwalle/ncrypto v1.0.4 h1:P2rqQxDepJwgeO5ShoC+wGcK2wNJDmcdBOWAksuIgx8=
github.com/smartwalle/crypto4go v1.0.2/go.mod h1:LQ7vCZIb7BE5+MuMtJBuO8ORkkQ01m4DXDBWPzLbkMY= github.com/smartwalle/ncrypto v1.0.4/go.mod h1:Dwlp6sfeNaPMnOxMNayMTacvC5JGEVln3CVdiVDgbBk=
github.com/smartwalle/ngx v1.0.9 h1:pUXDvWRZJIHVrCKA1uZ15YwNti+5P4GuJGbpJ4WvpMw=
github.com/smartwalle/ngx v1.0.9/go.mod h1:mx/nz2Pk5j+RBs7t6u6k22MPiBG/8CtOMpCnALIG8Y0=
github.com/smartwalle/nsign v1.0.9 h1:8poAgG7zBd8HkZy9RQDwasC6XZvJpDGQWSjzL2FZL6E=
github.com/smartwalle/nsign v1.0.9/go.mod h1:eY6I4CJlyNdVMP+t6z1H6Jpd4m5/V+8xi44ufSTxXgc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/wechatpay-apiv3/wechatpay-go v0.2.11 h1:KEVmn6VxFeoCdnTno4yLOWMmdG/wS7KWURzeuVXH6RU= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/wechatpay-apiv3/wechatpay-go v0.2.11/go.mod h1:W8ucVAOCKOii933cWROLaDLmRQ2cg/vHHVF4vGAVq9Q= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= github.com/wechatpay-apiv3/wechatpay-go v0.2.18 h1:vj5tvSmnEIz3ZsnFNNUzg+3Z46xgNMJbrO4aD4wP15w=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= github.com/wechatpay-apiv3/wechatpay-go v0.2.18/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -3,6 +3,7 @@ package pay
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"git.oa00.com/go/rsa" "git.oa00.com/go/rsa"
"github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers" "github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
@ -19,7 +20,6 @@ type wxpay struct {
} }
type WxpayConfig struct { type WxpayConfig struct {
MchID string // 商户号 MchID string // 商户号
MchCertificateSerialNumber string // 商户证书序列号
MchAPIv3Key string // 商户APIv3密钥 MchAPIv3Key string // 商户APIv3密钥
PrivateKey string // 私钥 PrivateKey string // 私钥
PrivateCert string // 私钥证书 PrivateCert string // 私钥证书
@ -27,14 +27,19 @@ type WxpayConfig struct {
// InitWxpay @Title 初始化微信支付 // InitWxpay @Title 初始化微信支付
func InitWxpay(config WxpayConfig) error { func InitWxpay(config WxpayConfig) error {
// 加载私钥证书 // 加载私钥
privateKey, err := rsa.ParsePrivateKey(config.PrivateKey, rsa.PKCS8) privateKey, err := rsa.ParsePrivateKey(config.PrivateKey, rsa.PKCS8)
if err != nil { if err != nil {
return errors.New("私钥错误") return errors.New("私钥错误")
} }
// 加载私钥证书
certificate, err := rsa.ParseCertificate(config.PrivateCert)
if err != nil {
return errors.New("证书错误")
}
// 使用商户私钥等初始化 client并使它具有自动定时获取微信支付平台证书的能力 // 使用商户私钥等初始化 client并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{ opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(config.MchID, config.MchCertificateSerialNumber, privateKey, config.MchAPIv3Key), option.WithWechatPayAutoAuthCipher(config.MchID, fmt.Sprintf("%x", certificate.SerialNumber), privateKey, config.MchAPIv3Key),
} }
Wxpay.Client, err = core.NewClient(context.Background(), opts...) Wxpay.Client, err = core.NewClient(context.Background(), opts...)
if err != nil { if err != nil {

Loading…
Cancel
Save