This commit is contained in:
李子铭 2024-08-21 16:28:43 +08:00
parent 5715e4c598
commit fe66d8d3a7
31 changed files with 602 additions and 59 deletions

1
go.mod
View File

@ -20,6 +20,7 @@ require (
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
github.com/oklog/run v1.0.0 // indirect github.com/oklog/run v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/wechatpay-apiv3/wechatpay-go v0.2.20 // indirect
golang.org/x/crypto v0.26.0 // indirect golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.22.0 // indirect golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.23.0 // indirect golang.org/x/sys v0.23.0 // indirect

12
go.sum
View File

@ -1,7 +1,9 @@
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240731020946-65ddbab65854 h1:+lG+QB1dfA70NSF35pN3qZCxfIJ0n+1JMS02gM0+vzI= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240731020946-65ddbab65854 h1:+lG+QB1dfA70NSF35pN3qZCxfIJ0n+1JMS02gM0+vzI=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240731020946-65ddbab65854/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240731020946-65ddbab65854/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
@ -43,9 +45,17 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/wechatpay-apiv3/wechatpay-go v0.2.20 h1:gS8oFn1bHGnyapR2Zb4aqTV6l4kJWgbtqjCq6k1L9DQ=
github.com/wechatpay-apiv3/wechatpay-go v0.2.20/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
@ -62,5 +72,7 @@ google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -3,7 +3,7 @@ module plugins/alipay_cpn
go 1.22.2 go 1.22.2
require ( require (
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
github.com/carlmjohnson/requests v0.23.4 github.com/carlmjohnson/requests v0.23.4
github.com/go-playground/validator/v10 v10.22.0 github.com/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1

View File

@ -1,5 +1,5 @@
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 h1:0xL8Kufk3Ka75JpctzFHHyr2gJ8fvsFysOihPSyW3fo= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/carlmjohnson/requests v0.23.4 h1:AxcvapfB9RPXLSyvAHk9YJoodQ43ZjzNHj6Ft3tQGdg= github.com/carlmjohnson/requests v0.23.4 h1:AxcvapfB9RPXLSyvAHk9YJoodQ43ZjzNHj6Ft3tQGdg=

View File

@ -5,7 +5,7 @@ go 1.22.2
replace plugins/utils => ../../utils replace plugins/utils => ../../utils
require ( require (
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
github.com/carlmjohnson/requests v0.23.4 github.com/carlmjohnson/requests v0.23.4
github.com/go-playground/validator/v10 v10.22.0 github.com/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1

View File

@ -1,5 +1,5 @@
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 h1:0xL8Kufk3Ka75JpctzFHHyr2gJ8fvsFysOihPSyW3fo= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/carlmjohnson/requests v0.23.4 h1:AxcvapfB9RPXLSyvAHk9YJoodQ43ZjzNHj6Ft3tQGdg= github.com/carlmjohnson/requests v0.23.4 h1:AxcvapfB9RPXLSyvAHk9YJoodQ43ZjzNHj6Ft3tQGdg=

View File

@ -24,9 +24,9 @@ const (
queryMethod = "alipay.fund.trans.common.query" queryMethod = "alipay.fund.trans.common.query"
) )
type AlipayCpnService struct{} type AlipayRedPackService struct{}
func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) { func (s *AlipayRedPackService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
c, err := transConfig(request.Config) c, err := transConfig(request.Config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -52,7 +52,7 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques
return orderResp(request, response), nil return orderResp(request, response), nil
} }
func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) { func (s *AlipayRedPackService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
c, err := transConfig(request.Config) c, err := transConfig(request.Config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -77,7 +77,7 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques
return queryResp(request, response), nil return queryResp(request, response), nil
} }
func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) { func (s *AlipayRedPackService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
c, err := transConfig(request.Config) c, err := transConfig(request.Config)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -9,7 +9,7 @@ import (
"testing" "testing"
) )
var server = &AlipayCpnService{} var server = &AlipayRedPackService{}
func config() []byte { func config() []byte {
c := &Config{ c := &Config{

View File

@ -9,7 +9,7 @@ import (
func main() { func main() {
plugin.Serve(&plugin.ServeConfig{ plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: shared.HandshakeConfig(internal.Version, internal.CookieKey, internal.CookieValue), HandshakeConfig: shared.HandshakeConfig(internal.Version, internal.CookieKey, internal.CookieValue),
Plugins: shared.PluginSet(shared.NewPlugin(&internal.AlipayCpnService{}, internal.Tag)), Plugins: shared.PluginSet(shared.NewPlugin(&internal.AlipayRedPackService{}, internal.Tag)),
GRPCServer: plugin.DefaultGRPCServer, GRPCServer: plugin.DefaultGRPCServer,
}) })
} }

View File

@ -3,7 +3,7 @@ module plugins/union_pay_cpn
go 1.22.2 go 1.22.2
require ( require (
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
github.com/carlmjohnson/requests v0.23.4 github.com/carlmjohnson/requests v0.23.4
github.com/go-playground/validator/v10 v10.22.0 github.com/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1

View File

@ -1,6 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 h1:0xL8Kufk3Ka75JpctzFHHyr2gJ8fvsFysOihPSyW3fo= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=

View File

@ -5,7 +5,7 @@ go 1.22.2
replace plugins/utils => ../../utils replace plugins/utils => ../../utils
require ( require (
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
github.com/wechatpay-apiv3/wechatpay-go v0.2.18 github.com/wechatpay-apiv3/wechatpay-go v0.2.18

View File

@ -1,5 +1,5 @@
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 h1:0xL8Kufk3Ka75JpctzFHHyr2gJ8fvsFysOihPSyW3fo= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
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/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=

View File

@ -44,7 +44,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
func orderResp(order *proto.OrderRequest_Order, tradeNo string) *proto.OrderResponse { func orderResp(order *proto.OrderRequest_Order, tradeNo string) *proto.OrderResponse {
return &proto.OrderResponse{ return &proto.OrderResponse{
Result: &proto.Result{ Result: &proto.Result{
Status: proto.Status_SUCCESS, Status: proto.Status_ING,
OrderNo: order.GetOrderNo(), OrderNo: order.GetOrderNo(),
TradeNo: tradeNo, TradeNo: tradeNo,
Message: "成功", Message: "成功",

View File

@ -6,8 +6,8 @@ import (
"plugins/utils/weixin" "plugins/utils/weixin"
) )
func getApiSrv(ctx context.Context, c *weixin.Server) (*cashcoupons.CouponApiService, error) { func srv(ctx context.Context, c *weixin.Server) (*cashcoupons.CouponApiService, error) {
client, err := weixin.New(ctx, c) client, err := weixin.GetClient(ctx, c)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -8,10 +8,10 @@ import (
// 插件通信信息,若不对应则会报错panic // 插件通信信息,若不对应则会报错panic
const ( const (
Tag = "weixin_pay_cpn" Tag = "weixin_cpn"
Version = 1 Version = 1
CookieKey = "weixin_pay_cpn" CookieKey = "weixin_cpn"
CookieValue = "weixin_pay_cpn" CookieValue = "weixin_cpn"
) )
type WeiXinCpnService struct{} type WeiXinCpnService struct{}
@ -21,11 +21,11 @@ func (p *WeiXinCpnService) Order(ctx context.Context, request *proto.OrderReques
if err != nil { if err != nil {
return nil, err return nil, err
} }
svc, err := getApiSrv(ctx, config) req, err := orderReq(request.GetOrder(), request.GetProduct())
if err != nil { if err != nil {
return nil, err return nil, err
} }
req, err := orderReq(request.GetOrder(), request.GetProduct()) svc, err := srv(ctx, config)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -41,7 +41,7 @@ func (p *WeiXinCpnService) Order(ctx context.Context, request *proto.OrderReques
func (p *WeiXinCpnService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) { func (p *WeiXinCpnService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
config, err := transConfig(request.Config) config, err := transConfig(request.Config)
svc, err := getApiSrv(ctx, config) svc, err := srv(ctx, config)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -17,7 +17,6 @@ func config() []byte {
MchID: "1605446142", MchID: "1605446142",
MchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76", MchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76",
MchAPIv3Key: "ChengDuLanSeXiongDi1234567890123", MchAPIv3Key: "ChengDuLanSeXiongDi1234567890123",
PrivateKey: "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCyDvodpawS3XDZ\nyGRyhrbQhonxBBLmXgMT5A4zwli2FXFlmHnmeexCjILFMwF2OeRWKhVMbe+6fD0U\n3mXA3bBppqQ65fpra6xjmR7iKUB814RIxbG0SoWhWQJCU/hvGL8m56LQclJo9lyX\nvfxKhi7u4iSbC7E0MiEIFSUCdmNZHX2QmMF1pVXBHOBGpR52PE/i+DijwXuvPczD\nm2DLHCFLdFwUnuEnJbOVY7mc3W01zXeAj89IYp6BZxwCgVM+SFxgaK34lB11lDfW\nzAQgNQbfFdZEKYJgJiTlOpXMYNDaTx6GqkUKXrpRXKoDSSuVeGiCCgh0/RATB6sL\nlYO6+/4VAgMBAAECggEANwUvvleCO3YXuAQXHdiIxxi7qTEEEhE8zDmtNcs5FFK9\n7pHWISTNn6bBheQD8J9k8kcgu7RA3pQjX751HMqkB5GJr/V+kxD7fO9EvsfWeH00\nEDSee8KHVlsluo8t9k5kSsZK5jRdSLfP1sfLHNAn0oMoooxTXnibAl9eR0uD2XYh\n2LTCdbg1Y6UkObf6ikPJI6D6P9F9madzW2zraCXgr42SWYFGEv0iAGXxG9uXc3KU\n81XJa8IIEB4Tlsijx3Zk5ASN/z9K7rJIwciTnHfKJiicTMzjF3CvvhsmrpRVbX4j\nZRPyXgMdGOdCn8u9ZgDnl9A0mnqSQEzLWaAsrbI9hQKBgQDq8B9rhIrEP8J+iD16\nUPpVE224SWlU/2CM1chs/uE6jh3s5XoK+wGoXKjAIEOG9jl2BuUYg0yPsybE8QFc\npAYpz24GGdCxIuQZIL37UoV3CKMeREo7KXG++nmCMQZ3GPPvlXSx3ugDTH76GbRq\nx5uLwbX0L2ewD88IQOvbkpVpdwKBgQDCBXVDWlwgA1mZhOjOp8NO68fDTdhnrKCf\nJS1QmNofCepqSn3s76l19V2F9b888TbIjWQDkmN9BhLisZ/9RqJEb5zrgP+x4DfB\nhKxpsugF4h5/C4ZvpjRGlOu38qQp0k0TuQBjGGHBEZQiE2TgvUx6V4jAHBRpUXh6\nqaZHHJ630wKBgF3h+NxRSdakmAdSUCbp5y9KJUVIaMQjjSSaZY5QyBZLJmA9T2jF\n52KtLG4iNnnfORUWKkSCa3zdHXgDywSHM0NP9eqQNFok1DvKXsDouBbaJ7z3kyZT\nKHYlx5qkFq5PFWO/OLO/nL18ux0cWoF1JI5TqW9b5jZwCs6Eivvidrx/AoGABVTz\nEQPFrleJOc/OOgegNWYDWlmkTc0PqO/zm9hnfhzepUcgyMcZSBWTGWBUfg8+6yn/\nip2WQFRPZo1tER/Ey86paEtmO3Qm9Bl6R3lUKP06y1D8w8q0exASnj57xm5yEc2u\ntgpwfUbHZFxWFFr/ZAlNx8G9ydskTXKmECQ4NGMCgYBvZe4M86EW2j0VBH7f/eUj\nPiCoRGjcM6CMlDArCtcw0d62URr9li8hTtB0aGW0qC1Q/ge+adkw6rhw7WQO7Dag\nOxjaGYcpryIDuiliDG6U0yB8rqA9aW7k3npvivmeX/1mAtGGrliAAX4bb/y3S0nJ\nDwIaCyy1x9BH0libPZpSYA==\n-----END PRIVATE KEY-----\n",
PrivateKeyPath: "/Users/lsxd/code/go/other/mq/wx/wechat_private_key.pem", PrivateKeyPath: "/Users/lsxd/code/go/other/mq/wx/wechat_private_key.pem",
} }
marshal, _ := json.Marshal(c) marshal, _ := json.Marshal(c)

View File

@ -0,0 +1,33 @@
module plugins/weixin_redpack
go 1.22.2
replace plugins/utils => ../../utils
require (
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
github.com/hashicorp/go-plugin v1.6.1
github.com/stretchr/testify v1.9.0
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
plugins/utils v1.0.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@ -0,0 +1,64 @@
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
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/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
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/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 h1:7GoSOOW2jpsfkntVKaS2rAr1TJqfcxotyaUcuxoZSzg=
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wechatpay-apiv3/wechatpay-go v0.2.18 h1:vj5tvSmnEIz3ZsnFNNUzg+3Z46xgNMJbrO4aD4wP15w=
github.com/wechatpay-apiv3/wechatpay-go v0.2.18/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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=

View File

@ -0,0 +1,121 @@
package internal
import (
"encoding/json"
"fmt"
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/transferbatch"
"plugins/utils/weixin"
"plugins/weixin_redpack/internal/vo"
)
func transConfig(config []byte) (*weixin.Server, error) {
var c weixin.Server
err := json.Unmarshal(config, &c)
if err != nil {
return nil, err
}
return &c, nil
}
type OrderExtra struct {
Appid string `json:"app_id"`
OutDetailNo string `json:"out_detail_no"`
}
type ProductExtra struct {
BatchName string `json:"batch_name"`
BatchRemark string `json:"batch_remark"`
}
func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Product) (transferbatch.InitiateBatchTransferRequest, error) {
var orderExtra OrderExtra
err := json.Unmarshal(order.Extra, &orderExtra)
if err != nil {
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("order extra json unmarshal error: %v", err)
}
var productExtra ProductExtra
err = json.Unmarshal(product.Extra, &productExtra)
if err != nil {
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("order extra json unmarshal error: %v", err)
}
return transferbatch.InitiateBatchTransferRequest{
Appid: core.String(orderExtra.Appid),
OutBatchNo: core.String(order.OrderNo), // 微信转账商家批次单号
BatchName: core.String(productExtra.BatchName),
BatchRemark: core.String(productExtra.BatchRemark),
TotalAmount: core.Int64(int64(order.Amount * 100)), // 转账总金额,单位分 100=1元 1000=0.1(需要申请)
TotalNum: core.Int64(int64(order.Quantity)),
TransferDetailList: []transferbatch.TransferDetailInput{
{
OutDetailNo: core.String(orderExtra.OutDetailNo),
TransferAmount: core.Int64(int64(order.Amount * 100)),
TransferRemark: core.String(productExtra.BatchRemark),
Openid: core.String(order.Account),
UserName: nil,
},
},
TransferSceneId: core.String("1000"), // 转账场景ID, 1000 - 现金营销
}, nil
}
func orderResp(order *proto.OrderRequest_Order, tradeNo string) *proto.OrderResponse {
return &proto.OrderResponse{
Result: &proto.Result{
Status: proto.Status_ING,
OrderNo: order.GetOrderNo(),
TradeNo: tradeNo,
Message: "成功",
Data: nil,
Extra: nil,
},
}
}
func queryReq(order *proto.QueryRequest_Order) (*transferbatch.GetTransferDetailByNoRequest, error) {
var orderExtra OrderExtra
if order.Extra != nil {
err := json.Unmarshal(order.Extra, &orderExtra)
if err != nil {
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
}
}
return &transferbatch.GetTransferDetailByNoRequest{
BatchId: core.String(order.OrderNo),
DetailId: core.String(orderExtra.OutDetailNo),
}, nil
}
func queryResp(request *proto.QueryRequest, resp *transferbatch.TransferDetailEntity) *proto.QueryResponse {
data, _ := resp.MarshalJSON()
status := vo.QueryStatus(*resp.DetailStatus)
msg := status.GetText()
if resp.FailReason.Ptr() != nil {
m, ok := vo.FailReasonMsg[*resp.FailReason.Ptr()]
if ok {
msg = fmt.Sprintf("Message:%s, FailReason:%s", msg, m)
} else {
msg = fmt.Sprintf("Message:%s, FailReason:%s", msg, *resp.FailReason.Ptr())
}
}
return &proto.QueryResponse{
Result: &proto.Result{
Status: status.GetOrderStatus(),
OrderNo: request.Order.GetOrderNo(),
TradeNo: request.Order.TradeNo,
Message: msg,
Data: data,
Extra: nil,
},
}
}
func notifyResp() *proto.NotifyResponse {
return &proto.NotifyResponse{
Result: &proto.Result{
Status: proto.Status_ING,
Extra: nil,
},
}
}

View File

@ -0,0 +1,33 @@
package internal
import (
"context"
"github.com/wechatpay-apiv3/wechatpay-go/services/transferbatch"
"plugins/utils/weixin"
)
func transferBatchApiService(ctx context.Context, c *weixin.Server) (*transferbatch.TransferBatchApiService, error) {
client, err := weixin.GetClient(ctx, c)
if err != nil {
return nil, err
}
svc := transferbatch.TransferBatchApiService{Client: client}
return &svc, nil
}
func transferDetailApiService(ctx context.Context, c *weixin.Server) (*transferbatch.TransferDetailApiService, error) {
client, err := weixin.GetClient(ctx, c)
if err != nil {
return nil, err
}
svc := transferbatch.TransferDetailApiService{Client: client}
return &svc, nil
}
func verify(ctx context.Context, c *weixin.Server) error {
err := c.Verify(ctx, "", "")
if err != nil {
return err
}
return nil
}

View File

@ -0,0 +1,9 @@
package vo
type Code int
const CodeSuccess Code = 200
func (c Code) Value() int {
return int(c)
}

View File

@ -0,0 +1,32 @@
package vo
import "github.com/wechatpay-apiv3/wechatpay-go/services/transferbatch"
var FailReasonMsg = map[transferbatch.FailReasonType]string{
"ACCOUNT_FROZEN": "该用户账户被冻结",
"REAL_NAME_CHECK_FAIL": "收款人未实名认证,需要用户完成微信实名认证",
"NAME_NOT_CORRECT": "收款人姓名校验不通过,请核实信息",
"OPENID_INVALID": "Openid格式错误或者不属于商家公众账号",
"TRANSFER_QUOTA_EXCEED": "超过用户单笔收款额度,核实产品设置是否准确",
"DAY_RECEIVED_QUOTA_EXCEED": "超过用户单日收款额度,核实产品设置是否准确",
"MONTH_RECEIVED_QUOTA_EXCEED": "超过用户单月收款额度,核实产品设置是否准确",
"DAY_RECEIVED_COUNT_EXCEED": "超过用户单日收款次数,核实产品设置是否准确",
"PRODUCT_AUTH_CHECK_FAIL": "未开通该权限或权限被冻结,请核实产品权限状态",
"OVERDUE_CLOSE": "超过系统重试期,系统自动关闭",
"ID_CARD_NOT_CORRECT": "收款人身份证校验不通过,请核实信息",
"ACCOUNT_NOT_EXIST": "该用户账户不存在",
"TRANSFER_RISK": "该笔转账可能存在风险,已被微信拦截",
"OTHER_FAIL_REASON_TYPE": "其它失败原因",
"REALNAME_ACCOUNT_RECEIVED_QUOTA_EXCEED": "用户账户收款受限,请引导用户在微信支付查看详情",
"RECEIVE_ACCOUNT_NOT_PERMMIT": "未配置该用户为转账收款人,请在产品设置中调整,添加该用户为收款人",
"PAYEE_ACCOUNT_ABNORMAL": "用户账户收款异常,请联系用户完善其在微信支付的身份信息以继续收款",
"PAYER_ACCOUNT_ABNORMAL": "商户账户付款受限,可前往商户平台获取解除功能限制指引",
"TRANSFER_SCENE_UNAVAILABLE": "该转账场景暂不可用请确认转账场景ID是否正确",
"TRANSFER_SCENE_INVALID": "你尚未获取该转账场景请确认转账场景ID是否正确",
"TRANSFER_REMARK_SET_FAIL": "转账备注设置失败,请调整后重新再试",
"RECEIVE_ACCOUNT_NOT_CONFIGURE": "请前往商户平台-商家转账到零钱-前往功能-转账场景中添加",
"BLOCK_B2C_USERLIMITAMOUNT_BSRULE_MONTH": "超出用户单月转账收款20w限额本月不支持继续向该用户付款",
"BLOCK_B2C_USERLIMITAMOUNT_MONTH": "用户账户存在风险收款受限,本月不支持继续向该用户付款",
"MERCHANT_REJECT": "商户员工(转账验密人)已驳回转账",
"MERCHANT_NOT_CONFIRM": "商户员工(转账验密人)超时未验密",
}

View File

@ -0,0 +1,53 @@
package vo
import "gitea.cdlsxd.cn/BaseSystem/plugin/proto"
// QueryStatus
// INIT: 初始态。 系统转账校验中
// WAIT_PAY: 待确认。待商户确认, 符合免密条件时, 系统会自动扭转为转账中
// PROCESSING:转账中。正在处理中,转账结果尚未明确
// SUCCESS:转账成功
// FAIL:转账失败。需要确认失败原因后,再决定是否重新发起对该笔明细单的转账(并非整个转账批次单)
type QueryStatus string
const (
QueryStatusInit = "INIT"
QueryStatusWaitPay = "WAIT_PAY"
QueryStatusProcessing = "PROCESSING"
QueryStatusSuccess = "SUCCESS"
QueryStatusFail = "FAIL"
)
var queryStatusTextMap = map[QueryStatus]string{
QueryStatusInit: "初始态。 系统转账校验中",
QueryStatusWaitPay: "待确认。待商户确认, 符合免密条件时, 系统会自动扭转为转账中",
QueryStatusProcessing: "转账中。正在处理中,转账结果尚未明确",
QueryStatusSuccess: "转账成功",
QueryStatusFail: "转账失败。需要确认失败原因后,再决定是否重新发起对该笔明细单的转账(并非整个转账批次单)",
}
var queryStatusMap = map[QueryStatus]proto.Status{
QueryStatusInit: proto.Status_ING,
QueryStatusWaitPay: proto.Status_ING,
QueryStatusProcessing: proto.Status_ING,
QueryStatusSuccess: proto.Status_SUCCESS,
QueryStatusFail: proto.Status_FAIL,
}
func (o QueryStatus) GetText() string {
msg, ok := queryStatusTextMap[o]
if !ok {
return ""
}
return msg
}
func (o QueryStatus) GetOrderStatus() proto.Status {
if o == "" {
return proto.Status_INVALID
}
if resultStatus, ok := queryStatusMap[o]; ok {
return resultStatus
}
return proto.Status_FAIL
}

View File

@ -0,0 +1,67 @@
package internal
import (
"context"
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
"plugins/weixin_redpack/internal/vo"
)
// 插件通信信息,若不对应则会报错panic
const (
Tag = "weixin_redpack"
Version = 1
CookieKey = "weixin_redpack"
CookieValue = "weixin_redpack"
)
type WeiXinRedPackService struct{}
func (p *WeiXinRedPackService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
config, err := transConfig(request.Config)
if err != nil {
return nil, err
}
svc, err := transferBatchApiService(ctx, config)
if err != nil {
return nil, err
}
req, err := orderReq(request.GetOrder(), request.GetProduct())
if err != nil {
return nil, err
}
resp, result, err := svc.InitiateBatchTransfer(ctx, req)
if err != nil {
return nil, err
}
if result.Response.StatusCode != vo.CodeSuccess.Value() {
return nil, err
}
return orderResp(request.GetOrder(), *resp.BatchId), nil
}
func (p *WeiXinRedPackService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
req, err := queryReq(request.GetOrder())
if err != nil {
return nil, err
}
config, err := transConfig(request.Config)
if err != nil {
return nil, err
}
svc, err := transferDetailApiService(ctx, config)
if err != nil {
return nil, err
}
resp, result, err := svc.GetTransferDetailByNo(ctx, *req)
if err != nil {
return nil, err
}
if result.Response.StatusCode != vo.CodeSuccess.Value() {
return nil, err
}
return queryResp(request, resp), nil
}
func (p *WeiXinRedPackService) Notify(_ context.Context, _ *proto.NotifyRequest) (*proto.NotifyResponse, error) {
return notifyResp(), nil
}

View File

@ -0,0 +1,89 @@
package internal
import (
"context"
"encoding/json"
"fmt"
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
"github.com/stretchr/testify/assert"
"plugins/utils/weixin"
"testing"
)
var server = &WeiXinRedPackService{}
func config() []byte {
c := &weixin.Server{
MchID: "1629276485",
MchCertificateSerialNumber: "3C7E21B74C04BE6227A690EB44184F219D763F92",
MchAPIv3Key: "ChengDuBale0123456789qwertyuiopa",
// 商户API私钥
PrivateKeyPath: "/Users/lsxd/code/php/yxxt/market/config/wechatcash/apiclient_key.pem",
//PrivateKeyPath: "/Users/lsxd/code/go/other/mq/wx/wechat_private_key.pem",
}
marshal, _ := json.Marshal(c)
return marshal
}
func TestOrder(t *testing.T) {
request := &proto.OrderRequest{
Config: config(),
Order: &proto.OrderRequest_Order{
OrderNo: "240403164049635931",
Account: "oO3vO5AxRWgTjmMD38FTvnB5Rq6o",
Extra: []byte(`{"app_id":"13100720242", "out_detail_no":"stock_creator_mchid"}`),
},
Product: &proto.OrderRequest_Product{
ProductNo: "",
Extra: []byte(`{"batch_name":"13100720242", "batch_remark":"stock_creator_mchid"}`),
},
}
t.Run("TestOrder", func(t *testing.T) {
got, err := server.Order(context.Background(), request)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
fmt.Printf("%+v", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}
func TestQuery(t *testing.T) {
request := &proto.QueryRequest{
Config: config(),
Order: &proto.QueryRequest_Order{
OrderNo: "",
TradeNo: "202408211517304392270563",
Account: "",
Extra: []byte(`{"out_detail_no":"20240821151730439227056399842027"}`),
},
}
t.Run("TestQuery", func(t *testing.T) {
got, err := server.Query(context.Background(), request)
if err != nil {
t.Errorf("Query() error = %v", err)
return
}
fmt.Printf("%+v \n", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}
func TestNotify(t *testing.T) {
in := &proto.NotifyRequest{
Config: config(),
Queries: []byte(``),
Headers: []byte(``),
Body: []byte(``),
}
t.Run("TestNotify", func(t *testing.T) {
got, err := server.Notify(context.Background(), in)
if err != nil {
t.Errorf("Notify() error = %v", err)
return
}
fmt.Printf("TestNotify : %+v \n", got)
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
})
}

View File

@ -0,0 +1,15 @@
package main
import (
"gitea.cdlsxd.cn/BaseSystem/plugin/shared"
"github.com/hashicorp/go-plugin"
"plugins/weixin_redpack/internal"
)
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: shared.HandshakeConfig(internal.Version, internal.CookieKey, internal.CookieValue),
Plugins: shared.PluginSet(shared.NewPlugin(&internal.WeiXinRedPackService{}, internal.Tag)),
GRPCServer: plugin.DefaultGRPCServer,
})
}

View File

@ -3,7 +3,7 @@ module plugins/zltx
go 1.22.2 go 1.22.2
require ( require (
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
github.com/carlmjohnson/requests v0.23.5 github.com/carlmjohnson/requests v0.23.5
github.com/go-playground/validator/v10 v10.22.0 github.com/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1 github.com/hashicorp/go-plugin v1.6.1

View File

@ -1,5 +1,5 @@
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4 h1:0xL8Kufk3Ka75JpctzFHHyr2gJ8fvsFysOihPSyW3fo= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240808015117-a7d6a128aae4/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k= gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/carlmjohnson/requests v0.23.5 h1:NPANcAofwwSuC6SIMwlgmHry2V3pLrSqRiSBKYbNHHA= github.com/carlmjohnson/requests v0.23.5 h1:NPANcAofwwSuC6SIMwlgmHry2V3pLrSqRiSBKYbNHHA=

41
utils/weixin/client.go Normal file
View File

@ -0,0 +1,41 @@
package weixin
import (
"context"
"crypto/x509"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
)
type Server struct {
MchID string `json:"mch_id"`
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"`
MchAPIv3Key string `json:"mch_ap_iv_3_key"`
PrivateKey string `json:"private_key"`
PrivateKeyPath string `json:"private_key_path"`
CertificatePath string `json:"certificate_path"`
}
func newClient(ctx context.Context, c *Server) (*core.Client, error) {
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(c.PrivateKeyPath)
if err != nil {
return nil, fmt.Errorf("MchID[%s] load merchant private key error:%v", c.MchID, err)
}
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(c.MchID, c.MchCertificateSerialNumber, mchPrivateKey, c.MchAPIv3Key),
}
if c.CertificatePath != "" {
payCert, err := utils.LoadCertificateWithPath(c.CertificatePath)
if err != nil {
return nil, fmt.Errorf("MchID[%s] load pay certificate error:%v", c.MchID, err)
}
opts = append(opts, option.WithWechatPayCertificate([]*x509.Certificate{payCert}))
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("MchID[%s] %v", c.MchID, err)
}
return client, nil
}

View File

@ -2,23 +2,12 @@ package weixin
import ( import (
"context" "context"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth" "github.com/wechatpay-apiv3/wechatpay-go/core/auth"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers" "github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
"sync" "sync"
) )
type Server struct {
MchID string `json:"mch_id"`
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"`
MchAPIv3Key string `json:"mch_ap_iv_3_key"`
PrivateKey string `json:"private_key"`
PrivateKeyPath string `json:"private_key_path"`
}
type manager struct { type manager struct {
once sync.Once once sync.Once
mutex sync.RWMutex mutex sync.RWMutex
@ -33,22 +22,7 @@ func init() {
} }
} }
func client(ctx context.Context, c *Server) (*core.Client, error) { func GetClient(ctx context.Context, c *Server) (*core.Client, error) {
mchPrivateKey, err := utils.LoadPrivateKey(c.PrivateKey)
if err != nil {
return nil, fmt.Errorf("MchID[%s] load merchant private key error:%v", c.MchID, err)
}
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(c.MchID, c.MchCertificateSerialNumber, mchPrivateKey, c.MchAPIv3Key),
}
cl, err := core.NewClient(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("MchID[%s] new wechat pay client err:%v", c.MchID, err)
}
return cl, nil
}
func New(ctx context.Context, c *Server) (*core.Client, error) {
instance.mutex.Lock() instance.mutex.Lock()
defer instance.mutex.Unlock() defer instance.mutex.Unlock()
if instance.clients[c.MchID] != nil { if instance.clients[c.MchID] != nil {
@ -56,7 +30,7 @@ func New(ctx context.Context, c *Server) (*core.Client, error) {
} }
var err error var err error
instance.once.Do(func() { instance.once.Do(func() {
instance.clients[c.MchID], err = client(ctx, c) instance.clients[c.MchID], err = newClient(ctx, c)
}) })
if err != nil { if err != nil {
return nil, err return nil, err