自定消息类型
This commit is contained in:
parent
0de049a20d
commit
fde43f6237
14
Makefile
14
Makefile
|
@ -41,18 +41,6 @@ zltx_v2:
|
|||
make build-linux name=zltx_v2 && \
|
||||
make build-win name=zltx_v2
|
||||
|
||||
.PHONY: union_pay_cpn
|
||||
union_pay_cpn:
|
||||
make build-mac name=union_pay_cpn && \
|
||||
make build-linux name=union_pay_cpn && \
|
||||
make build-win name=union_pay_cpn
|
||||
|
||||
.PHONY: union_pay_redpack
|
||||
union_pay_redpack:
|
||||
make build-mac name=union_pay_redpack && \
|
||||
make build-linux name=union_pay_redpack && \
|
||||
make build-win name=union_pay_redpack
|
||||
|
||||
.PHONY: alipay_cpn
|
||||
alipay_cpn:
|
||||
make build-mac name=alipay_cpn && \
|
||||
|
@ -78,4 +66,4 @@ wechat_redpack:
|
|||
make build-win name=wechat_redpack
|
||||
|
||||
.PHONY: all
|
||||
all: zltx_v1 zltx_card_v1 union_pay_cpn union_pay_redpack alipay_cpn alipay_redpack wechat_cpn wechat_redpack zltx_v2
|
||||
all: zltx_v1 zltx_card_v1 alipay_cpn alipay_redpack wechat_cpn wechat_redpack
|
|
@ -64,7 +64,7 @@ func alipayOrderRedPack() {
|
|||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Printf("Order res:%+v", result)
|
||||
log.Printf("Order res:%+v\n", result)
|
||||
}
|
||||
|
||||
func alipayQueryRedPack() {
|
||||
|
@ -86,7 +86,7 @@ func alipayQueryRedPack() {
|
|||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Printf("Query res:%+v", resQuery)
|
||||
log.Printf("Query res:%+v\n", resQuery)
|
||||
}
|
||||
|
||||
func alipayNotifyRedPack() {
|
||||
|
|
|
@ -2,5 +2,8 @@ package main
|
|||
|
||||
// main 这只是一个演示
|
||||
func main() {
|
||||
alipayOrderRedPack()
|
||||
//alipayOrderRedPack()
|
||||
//zltxQuery()
|
||||
//wechatQueryCpn()
|
||||
//alipayQueryRedPack()
|
||||
}
|
||||
|
|
45
cmd/zltx.go
45
cmd/zltx.go
|
@ -10,25 +10,27 @@ import (
|
|||
)
|
||||
|
||||
var zltxConf = &manage.Config{
|
||||
Cmd: "pkg/mac/zltx.so",
|
||||
Tag: "zltx",
|
||||
Cmd: "pkg/mac/zltx_v1.so",
|
||||
Tag: "zltx_v1",
|
||||
Version: 1,
|
||||
CookieKey: "zltx",
|
||||
CookieValue: "zltx",
|
||||
CookieKey: "zltx_v1",
|
||||
CookieValue: "zltx_v1",
|
||||
}
|
||||
|
||||
func config() []byte {
|
||||
type Config struct {
|
||||
AppId string `json:"app_id"`
|
||||
AppKey string `json:"app_key"`
|
||||
BaseUri string `json:"base_uri"`
|
||||
NotifyUrl string `json:"notify_url"`
|
||||
AppId string `json:"app_id"`
|
||||
AppKey string `json:"app_key"`
|
||||
BaseUri string `json:"base_uri"`
|
||||
NotifyUrl string `json:"notify_url"`
|
||||
MerchantId int64 `json:"merchant_id"`
|
||||
}
|
||||
c := &Config{
|
||||
AppId: "23329",
|
||||
AppKey: "8db16e8cc8363ed4eb4c14f9520bcc32",
|
||||
BaseUri: "http://test.openapi.1688sup.cn",
|
||||
NotifyUrl: "http://test.openapi.1688sup.cn",
|
||||
AppId: "1",
|
||||
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
|
||||
BaseUri: "http://test.openapi.1688sup.cn",
|
||||
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
MerchantId: 25537,
|
||||
}
|
||||
marshal, _ := json.Marshal(c)
|
||||
return marshal
|
||||
|
@ -72,3 +74,22 @@ func zltx() {
|
|||
}
|
||||
log.Printf("Query res:%+v", resQuery)
|
||||
}
|
||||
|
||||
func zltxQuery() {
|
||||
err := manage.Add(zltxConf)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer manage.Close()
|
||||
queryRequest := &proto.QueryRequest{
|
||||
Config: config(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "test_plugin_zltx_v1_direct_2",
|
||||
},
|
||||
}
|
||||
resQuery, err := instance.Query(context.Background(), zltxConf.Tag, queryRequest)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Printf("Query res:%+v", resQuery)
|
||||
}
|
||||
|
|
3
go.mod
3
go.mod
|
@ -3,7 +3,7 @@ module plugins
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
plugins/utils v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
|
@ -12,6 +12,7 @@ replace plugins/utils => ./utils
|
|||
require (
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
||||
|
|
6
go.sum
6
go.sum
|
@ -1,5 +1,5 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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=
|
||||
|
@ -11,6 +11,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
|
|
@ -5,8 +5,7 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -17,6 +16,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||
github.com/carlmjohnson/requests v0.24.2/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU=
|
||||
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/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -32,6 +30,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -45,6 +47,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -64,7 +68,8 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -2,9 +2,8 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"plugins/alipay_cpn/internal/po"
|
||||
)
|
||||
|
||||
|
@ -32,21 +31,25 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques
|
|||
}
|
||||
poReq, err := orderReq(request.Order, request.Product)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
param, err := c.paramReq(poReq, orderMethod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
uv, err := req(c, param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response *po.OrderResp
|
||||
if err = requests.URL(baseUri).Post().Params(uv).ToJSON(&response).Fetch(ctx); err != nil {
|
||||
bodyBytes, _, err := Post(ctx, uv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response *po.OrderResp
|
||||
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
|
||||
return orderResp(request, response), nil
|
||||
}
|
||||
|
@ -58,20 +61,25 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques
|
|||
}
|
||||
poReq, err := queryReq(request.Order)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
param, err := c.paramReq(poReq, queryMethod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
uv, err := req(c, param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bodyBytes, _, err := Post(ctx, uv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response po.QueryResp
|
||||
if err = requests.URL(baseUri).Post().BodyForm(uv).ToJSON(&response).Fetch(ctx); err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
|
||||
return queryResp(request, response), nil
|
||||
|
@ -89,7 +97,7 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques
|
|||
return nil, err
|
||||
}
|
||||
if !b {
|
||||
return nil, fmt.Errorf("验签失败")
|
||||
return nil, proto.ErrorSignFail("验签失败")
|
||||
}
|
||||
return notifyResp(n), nil
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package po
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
|
@ -31,7 +32,7 @@ func (req *OrderReq) Validate() error {
|
|||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
return proto.ErrorParamFail(fmt.Sprintf("参数有误: %v", err))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -46,7 +47,7 @@ func (req *QueryReq) Validate() error {
|
|||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
return proto.ErrorParamFail(fmt.Sprintf("参数有误: %v", err))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -61,7 +62,7 @@ func (req *Notify) Validate() error {
|
|||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
return proto.ErrorParamFail(fmt.Sprintf("参数有误: %v", err))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -17,11 +17,11 @@ type Config struct {
|
|||
Npk string `validate:"required" json:"npk"` // 回调公钥
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
func (c *Config) validate() error {
|
||||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置有误:" + err.Error())
|
||||
return proto.ErrorConfigFail(fmt.Sprintf("配置参数有误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -31,9 +31,9 @@ func transConfig(config []byte) (*Config, error) {
|
|||
var c Config
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("配置参数解析失败: %v", err))
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
if err = c.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
|
@ -65,7 +65,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
if order.Extra != nil {
|
||||
err := json.Unmarshal(order.Extra, &extra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
return nil, proto.ErrorParamFail(fmt.Sprintf("order拓展参数转换有误: %v", err))
|
||||
}
|
||||
}
|
||||
o := &po.OrderReq{
|
||||
|
@ -101,7 +101,7 @@ func queryReq(in *proto.QueryRequest_Order) (*po.QueryReq, error) {
|
|||
if in.Extra != nil {
|
||||
err := json.Unmarshal(in.Extra, &extra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
return nil, proto.ErrorParamFail(fmt.Sprintf("order拓展参数转换有误: %v", err))
|
||||
}
|
||||
}
|
||||
return &po.QueryReq{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
|
@ -8,11 +9,13 @@ import (
|
|||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/utils"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"plugins/alipay_cpn/internal/po"
|
||||
"plugins/utils/request"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -33,28 +36,39 @@ func req(config *Config, req *po.Param) (url.Values, error) {
|
|||
s := strings.TrimRight(strToBeSigned.String(), "&")
|
||||
sign, err := Sign(s, []byte(utils.NewPrivate().Build(config.Prk)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorSignFail(err.Error())
|
||||
}
|
||||
uv.Set("sign", sign)
|
||||
|
||||
return uv, nil
|
||||
}
|
||||
|
||||
func Post(ctx context.Context, uv url.Values) ([]byte, http.Header, error) {
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
respBody, respHeader, err := request.Post(ctx, baseUri+"?"+uv.Encode(), nil, request.WithHeaders(headers))
|
||||
if err != nil {
|
||||
return nil, nil, proto.ErrorRequestFail(err.Error())
|
||||
}
|
||||
return respBody, respHeader, nil
|
||||
}
|
||||
|
||||
func Sign(data string, privateKeyPEM []byte) (string, error) {
|
||||
block, _ := pem.Decode(privateKeyPEM)
|
||||
if block == nil {
|
||||
return "", errors.New("failed to parse PEM block containing the private key")
|
||||
return "", proto.ErrorSignFail("failed to parse PEM block containing the private key")
|
||||
}
|
||||
|
||||
privyKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse DER encoded private key: %v", err)
|
||||
return "", proto.ErrorSignFail(fmt.Sprintf("failed to parse DER encoded private key: %v", err))
|
||||
}
|
||||
|
||||
hashed := sha256.Sum256([]byte(data))
|
||||
signature, err := rsa.SignPKCS1v15(rand.Reader, privyKey.(*rsa.PrivateKey), crypto.SHA256, hashed[:])
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to sign: %v", err)
|
||||
return "", proto.ErrorSignFail(fmt.Sprintf("failed to sign:%v", err))
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(signature), nil
|
||||
|
@ -78,7 +92,12 @@ func Verify(n *po.Notify, publicKeyPEM string) (bool, error) {
|
|||
strToBeSigned.WriteString(fmt.Sprintf("%s=%s&", kv.Key, kv.Value))
|
||||
}
|
||||
s := strings.TrimRight(strToBeSigned.String(), "&")
|
||||
return check(s, n.Sign, []byte(utils.NewPublic().Build(publicKeyPEM)))
|
||||
b, err := check(s, n.Sign, []byte(utils.NewPublic().Build(publicKeyPEM)))
|
||||
if err != nil {
|
||||
return false, proto.ErrorSignFail(err.Error())
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func check(data, signature string, publicKeyPEM []byte) (bool, error) {
|
||||
|
|
|
@ -5,8 +5,7 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -17,6 +16,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||
github.com/carlmjohnson/requests v0.24.2/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU=
|
||||
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/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -32,6 +30,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
|
@ -48,6 +50,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -69,7 +73,8 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -2,9 +2,8 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"plugins/alipay_redpack/internal/po"
|
||||
"plugins/utils/alipay"
|
||||
)
|
||||
|
@ -34,7 +33,7 @@ func (s *AlipayRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
|||
}
|
||||
poReq, err := orderReq(request.Order, request.Product)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
param, err := c.paramReq(poReq, orderMethod)
|
||||
if err != nil {
|
||||
|
@ -45,11 +44,16 @@ func (s *AlipayRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var response *po.OrderResp
|
||||
if err = requests.URL(baseUri).Post().Params(uv).ToJSON(&response).Fetch(ctx); err != nil {
|
||||
bodyBytes, _, err := Post(ctx, uv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response *po.OrderResp
|
||||
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
|
||||
return orderResp(request, response), nil
|
||||
}
|
||||
|
||||
|
@ -58,11 +62,8 @@ func (s *AlipayRedPackService) Query(ctx context.Context, request *proto.QueryRe
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
poReq, err := queryReq(request.Order)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
param, err := c.paramReq(poReq, queryMethod)
|
||||
|
||||
param, err := c.paramReq(queryReq(request.Order), queryMethod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -71,9 +72,14 @@ func (s *AlipayRedPackService) Query(ctx context.Context, request *proto.QueryRe
|
|||
return nil, err
|
||||
}
|
||||
|
||||
bodyBytes, _, err := Post(ctx, uv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response po.QueryResp
|
||||
if err = requests.URL(baseUri).Post().BodyForm(uv).ToJSON(&response).Fetch(ctx); err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return queryResp(request, response), nil
|
||||
|
@ -92,10 +98,10 @@ func (s *AlipayRedPackService) Notify(_ context.Context, request *proto.NotifyRe
|
|||
}
|
||||
b, err := Verify(n, cert.PublicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorSignFail(err.Error())
|
||||
}
|
||||
if !b {
|
||||
return nil, fmt.Errorf("验签失败")
|
||||
return nil, proto.ErrorSignFail("验签失败")
|
||||
}
|
||||
return notifyResp(n), nil
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ type Config struct {
|
|||
Prk string `validate:"required" json:"prk"`
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
func (c *Config) validate() error {
|
||||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置有误:" + err.Error())
|
||||
return proto.ErrorConfigFail(fmt.Sprintf("配置参数有误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -32,9 +32,9 @@ func transConfig(config []byte) (*Config, error) {
|
|||
var c Config
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("配置参数解析失败: %v", err))
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
if err = c.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
|
@ -46,7 +46,7 @@ func (c *Config) paramReq(req po.Req, method string) (*po.Param, error) {
|
|||
}
|
||||
cert, err := alipay.GetCert(c.AppId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(err.Error())
|
||||
}
|
||||
return &po.Param{
|
||||
AlipayRootCertSn: cert.RootCertSN,
|
||||
|
@ -122,13 +122,13 @@ func orderResp(request *proto.OrderRequest, resp *po.OrderResp) *proto.OrderResp
|
|||
}
|
||||
}
|
||||
|
||||
func queryReq(in *proto.QueryRequest_Order) (*po.QueryReq, error) {
|
||||
func queryReq(in *proto.QueryRequest_Order) *po.QueryReq {
|
||||
return &po.QueryReq{
|
||||
OutBizNo: in.OrderNo,
|
||||
OrderId: in.TradeNo,
|
||||
ProductCode: "STD_RED_PACKET",
|
||||
BizScene: "DIRECT_TRANSFER",
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func queryResp(request *proto.QueryRequest, resp po.QueryResp) *proto.QueryResponse {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
|
@ -10,9 +11,12 @@ import (
|
|||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/utils"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"plugins/alipay_redpack/internal/po"
|
||||
"plugins/utils/request"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -31,13 +35,24 @@ func req(config *Config, req *po.Param) (url.Values, error) {
|
|||
|
||||
sign, err := Sign(s, []byte(utils.NewPrivate().Build(config.Prk)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorSignFail(err.Error())
|
||||
}
|
||||
uv.Set("sign", sign)
|
||||
|
||||
return uv, nil
|
||||
}
|
||||
|
||||
func Post(ctx context.Context, uv url.Values) ([]byte, http.Header, error) {
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
respBody, respHeader, err := request.Post(ctx, baseUri+"?"+uv.Encode(), nil, request.WithHeaders(headers))
|
||||
if err != nil {
|
||||
return nil, nil, proto.ErrorRequestFail(err.Error())
|
||||
}
|
||||
return respBody, respHeader, nil
|
||||
}
|
||||
|
||||
func Sign(data string, privateKeyPEM []byte) (string, error) {
|
||||
block, _ := pem.Decode(privateKeyPEM)
|
||||
if block == nil {
|
||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
|
@ -17,6 +17,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||
|
@ -20,6 +18,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -55,6 +55,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -69,6 +73,8 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ
|
|||
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/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -133,8 +139,9 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
|||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
|
@ -17,6 +17,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||
|
@ -20,6 +18,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -55,6 +55,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -69,6 +73,8 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ
|
|||
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/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -133,8 +139,9 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
|||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||
|
@ -16,6 +16,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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=
|
||||
|
@ -11,6 +11,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -31,6 +33,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -44,6 +50,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
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=
|
||||
|
@ -71,8 +79,9 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
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=
|
||||
|
|
|
@ -15,7 +15,7 @@ func transConfig(config []byte) (*wechat.Server, error) {
|
|||
var c wechat.Server
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(err.Error())
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -23,40 +23,50 @@ func (p *WeChatCpnService) Order(ctx context.Context, request *proto.OrderReques
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := orderReq(request.GetOrder(), request.GetProduct())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
|
||||
svc, err := srv(ctx, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorRequestFail(err.Error())
|
||||
}
|
||||
|
||||
resp, result, err := svc.SendCoupon(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("微信返回错误 %v", p.err(ctx, err))
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("微信返回错误:%s", p.err(ctx, err)))
|
||||
}
|
||||
|
||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||
return nil, fmt.Errorf("微信返回错误 StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status))
|
||||
}
|
||||
return orderResp(request.GetOrder(), *resp.CouponId), nil
|
||||
}
|
||||
|
||||
func (p *WeChatCpnService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||
config, err := transConfig(request.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
svc, err := srv(ctx, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := queryReq(request.GetOrder())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, result, err := svc.QueryCoupon(ctx, *req)
|
||||
if err != nil {
|
||||
return nil, p.err(ctx, err)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("微信返回错误:%s", p.err(ctx, err)))
|
||||
}
|
||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||
return nil, fmt.Errorf("微信返回错误 StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status))
|
||||
}
|
||||
return queryResp(request, resp), nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||
|
@ -16,6 +16,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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=
|
||||
|
@ -11,6 +11,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -31,6 +33,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -44,6 +50,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
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=
|
||||
|
@ -71,8 +79,9 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
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=
|
||||
|
|
|
@ -14,7 +14,7 @@ func transConfig(config []byte) (*wechat.Server, error) {
|
|||
var c wechat.Server
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(err.Error())
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -24,43 +24,49 @@ func (p *WeChatRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := orderReq(request.GetOrder(), request.GetProduct())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
|
||||
svc, err := transferBatchApiService(ctx, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorRequestFail(err.Error())
|
||||
}
|
||||
|
||||
resp, result, err := svc.InitiateBatchTransfer(ctx, req)
|
||||
if err != nil {
|
||||
return nil, p.err(ctx, err)
|
||||
return nil, proto.ErrorRequestFail("微信返回错误:" + p.err(ctx, err).Error())
|
||||
}
|
||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||
return nil, fmt.Errorf("微信返回错误 Response StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status))
|
||||
}
|
||||
return orderResp(request.GetOrder(), *resp.BatchId), nil
|
||||
}
|
||||
|
||||
func (p *WeChatRedPackService) 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
|
||||
}
|
||||
|
||||
req, err := queryReq(request.GetOrder())
|
||||
if err != nil {
|
||||
return nil, proto.ErrorParamFail(err.Error())
|
||||
}
|
||||
|
||||
svc, err := transferDetailApiService(ctx, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorRequestFail(err.Error())
|
||||
}
|
||||
|
||||
resp, result, err := svc.GetTransferDetailByOutNo(ctx, *req)
|
||||
if err != nil {
|
||||
return nil, p.err(ctx, err)
|
||||
return nil, proto.ErrorRequestFail("微信返回错误:" + p.err(ctx, err).Error())
|
||||
}
|
||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||
return nil, fmt.Errorf("微信返回错误 Response StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status))
|
||||
}
|
||||
return queryResp(request, resp), nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ module plugins/zltx
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.15
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
|
|
|
@ -2,6 +2,8 @@ gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8h
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.15 h1:IcfTDd9K4QWX80gQuYurCavdsPyxi5tM5sW3MRGWdh8=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.15/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||
|
|
|
@ -3,7 +3,7 @@ module plugins/zltx_card
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.15
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
|
|
|
@ -2,6 +2,8 @@ gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8h
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.15 h1:IcfTDd9K4QWX80gQuYurCavdsPyxi5tM5sW3MRGWdh8=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.15/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||
|
|
|
@ -3,7 +3,7 @@ module plugins/zltx_card_v1
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.14
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -13,6 +13,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v1.0.12 h1:gA7zRagOro38rbRVIfFgGRuGOr+Wig8EjeqQkYedFXc=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.12/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.13 h1:v9YUJci9Npb6svojARQkkbWpdsm74/X9g/uAECtrCJg=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.13/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.14 h1:nBV4AJYdFTiwOdIwhfKuhHg60DCcHOZDFW5/W42bqGM=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.14/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
@ -12,6 +8,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -32,6 +30,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -45,6 +47,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -64,7 +68,8 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -21,7 +21,7 @@ func (c *Config) validate() error {
|
|||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置参数有误:" + err.Error())
|
||||
return proto.ErrorConfigFail(fmt.Sprintf("配置参数有误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -31,7 +31,7 @@ func transConfig(config []byte) (*Config, error) {
|
|||
var c Config
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("配置参数解析失败: %v", err))
|
||||
}
|
||||
if err = c.validate(); err != nil {
|
||||
return nil, err
|
||||
|
@ -54,6 +54,13 @@ func (c *Config) dctW() (*card.Card, error) {
|
|||
return &card.Card{DctWServer: server}, nil
|
||||
}
|
||||
|
||||
func Result(message string) *proto.Result {
|
||||
return &proto.Result{
|
||||
Status: proto.Status_ING,
|
||||
Message: fmt.Sprintf("需人工排查处理:%s", message),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) orderReq(in *proto.OrderRequest) *card.Order {
|
||||
return &card.Order{
|
||||
Number: in.Order.Quantity,
|
||||
|
|
|
@ -33,10 +33,13 @@ func (p *ZLTXCardV1Service) Order(ctx context.Context, request *proto.OrderReque
|
|||
|
||||
resp, err := dctW.Order(ctx, c.orderReq(request))
|
||||
if err != nil {
|
||||
if proto.IsResponseFail(err) {
|
||||
return &proto.OrderResponse{Result: Result(err.Error())}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if !resp.GetCode().IsSuccess() {
|
||||
return nil, fmt.Errorf(resp.Message)
|
||||
return nil, proto.ErrorRequestFail(resp.Message)
|
||||
}
|
||||
|
||||
return orderResp(request, resp), nil
|
||||
|
@ -58,7 +61,7 @@ func (p *ZLTXCardV1Service) Query(ctx context.Context, request *proto.QueryReque
|
|||
return nil, err
|
||||
}
|
||||
if !resp.GetCode().IsSuccess() {
|
||||
return nil, fmt.Errorf(resp.Message)
|
||||
return nil, proto.ErrorRequestFail(resp.Message)
|
||||
}
|
||||
|
||||
return queryResp(request, resp, cardCode)
|
||||
|
@ -72,7 +75,7 @@ func (p *ZLTXCardV1Service) Notify(ctx context.Context, request *proto.NotifyReq
|
|||
|
||||
httpHeaders := make(http.Header)
|
||||
if err = json.Unmarshal(request.Headers, &httpHeaders); err != nil {
|
||||
return nil, fmt.Errorf("headers Unmarshal err [%v]", err)
|
||||
return nil, proto.ErrorParamFail(fmt.Sprintf("headers Unmarshal err [%v]", err))
|
||||
}
|
||||
newHeaders := make(http.Header)
|
||||
for key, values := range httpHeaders {
|
||||
|
|
|
@ -9,22 +9,15 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var zltx = &ZLTXCardV1Service{}
|
||||
var cardService = &ZLTXCardV1Service{}
|
||||
|
||||
func config() []byte {
|
||||
//c := &Config{
|
||||
// AppId: "1",
|
||||
// AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
|
||||
// BaseUri: "http://test.openapi.1688sup.cn",
|
||||
// NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
// MerchantId: 23329,
|
||||
//}
|
||||
c := &Config{
|
||||
AppId: "101",
|
||||
AppKey: "95E7EC7D4A394FF8D11788E5E436DE99",
|
||||
BaseUri: "https://openapi.1688sup.com",
|
||||
NotifyUrl: "https://market.86698.cn/v1/order/direct/notify",
|
||||
MerchantId: 25715,
|
||||
AppId: "1",
|
||||
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
|
||||
BaseUri: "http://test.openapi.1688sup.cn",
|
||||
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
MerchantId: 23329,
|
||||
}
|
||||
marshal, _ := json.Marshal(c)
|
||||
return marshal
|
||||
|
@ -42,7 +35,7 @@ func TestOrder(t *testing.T) {
|
|||
request := &proto.OrderRequest{
|
||||
Config: config(),
|
||||
Order: &proto.OrderRequest_Order{
|
||||
OrderNo: "test_plugin_zltx_v1_card_2",
|
||||
OrderNo: "test_plugin_zltx_v1_card_3",
|
||||
Account: "",
|
||||
Quantity: 1,
|
||||
Extra: nil,
|
||||
|
@ -54,7 +47,7 @@ func TestOrder(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("TestOrder", func(t *testing.T) {
|
||||
got, err := zltx.Order(context.Background(), request)
|
||||
got, err := cardService.Order(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Errorf("Order() error = %v", err)
|
||||
return
|
||||
|
@ -68,14 +61,14 @@ func TestQuery(t *testing.T) {
|
|||
request := &proto.QueryRequest{
|
||||
Config: config(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "test_plugin_zltx_v1_card_2",
|
||||
OrderNo: "test_plugin_zltx_v1_card_3",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: nil,
|
||||
},
|
||||
}
|
||||
t.Run("TestQuery", func(t *testing.T) {
|
||||
got, err := zltx.Query(context.Background(), request)
|
||||
got, err := cardService.Query(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Errorf("Query() error = %v", err)
|
||||
return
|
||||
|
@ -89,11 +82,11 @@ func TestNotify(t *testing.T) {
|
|||
in := &proto.NotifyRequest{
|
||||
Config: config(),
|
||||
Queries: nil,
|
||||
Headers: []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=101,sign=6ECA9F00E426FBE0137ACFA2920D058D"],"Connection":["close"],"Content-Length":["140"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`),
|
||||
Body: []byte(`{"merchantId":25715,"outTradeNo":"202411261524470700010001","tradeNo":"715948765692968961","status":"01","cardCode":"AlT5ZLb4VwYbKqTudDcyR4WZzrOLFtMUD00HNNvBFs0="}`),
|
||||
Headers: []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=CA2F9A1C822AC95A2E2BF175F7403A93"],"Connection":["close"],"Content-Length":["145"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`),
|
||||
Body: []byte(`{"merchantId":23329,"outTradeNo":"test_plugin_zltx_v1_card_3","tradeNo":"716590229825404929","status":"01","cardCode":"bplpAB7dQzSD9xczvO7WGQ=="}`),
|
||||
}
|
||||
t.Run("TestNotify", func(t *testing.T) {
|
||||
got, err := zltx.Notify(context.Background(), in)
|
||||
got, err := cardService.Notify(context.Background(), in)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Errorf("Notify() error = %v", err)
|
||||
return
|
||||
|
|
|
@ -3,7 +3,7 @@ module plugins/zltx_v1
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.14
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -13,6 +13,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v1.0.11 h1:NMMgw2p7ZF7EbWjkSO7ttM62BLhsG0bGmPdGGS1gpJc=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.11/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.12 h1:gA7zRagOro38rbRVIfFgGRuGOr+Wig8EjeqQkYedFXc=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.12/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.13 h1:v9YUJci9Npb6svojARQkkbWpdsm74/X9g/uAECtrCJg=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.13/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.14 h1:nBV4AJYdFTiwOdIwhfKuhHg60DCcHOZDFW5/W42bqGM=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.14/go.mod h1:FLuWLP2QP2aBzI2HCdZ7tvl1ieMuMOpTWvItmNGCeGA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
@ -14,6 +8,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -34,6 +30,10 @@ 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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -47,6 +47,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -66,7 +68,8 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -23,7 +23,7 @@ func (c *Config) validate() error {
|
|||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置参数有误:" + err.Error())
|
||||
return proto.ErrorConfigFail(fmt.Sprintf("配置参数有误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -33,7 +33,7 @@ func transConfig(config []byte) (*Config, error) {
|
|||
var c Config
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorSignFail(fmt.Sprintf("配置参数解析失败: %v", err))
|
||||
}
|
||||
if err = c.validate(); err != nil {
|
||||
return nil, err
|
||||
|
@ -52,6 +52,13 @@ func (c *Config) server() (*core.DctWServer, error) {
|
|||
)
|
||||
}
|
||||
|
||||
func Result(message string) *proto.Result {
|
||||
return &proto.Result{
|
||||
Status: proto.Status_ING,
|
||||
Message: fmt.Sprintf("需人工排查处理:%s", message),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) orderReq(in *proto.OrderRequest) (*direct.Order, error) {
|
||||
// 账号类型(1:手机号 2:QQ号 其他:0)
|
||||
accountType := int8(0)
|
||||
|
@ -61,7 +68,7 @@ func (c *Config) orderReq(in *proto.OrderRequest) (*direct.Order, error) {
|
|||
qqPattern := `^[1-9][0-9]{4,11}$`
|
||||
qqRegex, err := regexp.Compile(qqPattern)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("正则表达式编译失败: %v", err)
|
||||
return nil, proto.ErrorParamFail(fmt.Sprintf("正则表达式编译失败: %v", err))
|
||||
}
|
||||
if qqRegex.MatchString(in.Order.Account) {
|
||||
accountType = 2
|
||||
|
|
|
@ -36,13 +36,17 @@ func (p *ZLTXV1Service) Order(ctx context.Context, request *proto.OrderRequest)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a := &direct.Direct{DctWServer: server}
|
||||
resp, err := a.Order(ctx, req)
|
||||
if err != nil {
|
||||
if proto.IsResponseFail(err) {
|
||||
return &proto.OrderResponse{Result: Result(err.Error())}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if !resp.GetCode().IsSuccess() {
|
||||
return nil, fmt.Errorf(resp.Message)
|
||||
return nil, proto.ErrorRequestFail(resp.Message)
|
||||
}
|
||||
|
||||
return orderResp(request, resp), nil
|
||||
|
@ -65,7 +69,7 @@ func (p *ZLTXV1Service) Query(ctx context.Context, request *proto.QueryRequest)
|
|||
return nil, err
|
||||
}
|
||||
if !resp.GetCode().IsSuccess() {
|
||||
return nil, fmt.Errorf(resp.Message)
|
||||
return nil, proto.ErrorRequestFail(resp.Message)
|
||||
}
|
||||
|
||||
return queryResp(request, resp)
|
||||
|
@ -84,7 +88,7 @@ func (p *ZLTXV1Service) Notify(ctx context.Context, request *proto.NotifyRequest
|
|||
|
||||
httpHeaders := make(http.Header)
|
||||
if err = json.Unmarshal(request.Headers, &httpHeaders); err != nil {
|
||||
return nil, fmt.Errorf("headers Unmarshal err [%v]", err)
|
||||
return nil, proto.ErrorParamFail(fmt.Sprintf("headers Unmarshal err [%v]", err))
|
||||
}
|
||||
newHeaders := make(http.Header)
|
||||
for key, values := range httpHeaders {
|
||||
|
|
|
@ -9,23 +9,23 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var zltx = &ZLTXV1Service{}
|
||||
var direct = &ZLTXV1Service{}
|
||||
|
||||
func config() []byte {
|
||||
//c := &Config{
|
||||
// AppId: "1",
|
||||
// AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
|
||||
// BaseUri: "http://test.openapi.1688sup.cn",
|
||||
// NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
// MerchantId: 25537,
|
||||
//}
|
||||
c := &Config{
|
||||
AppId: "101",
|
||||
AppKey: "5k8bJV6axIukpkwz5vdte8QCw5etlC+txi+Nu69nIhOMN4VhmcNgf/THdllpt0jO",
|
||||
BaseUri: "https://openapi.1688sup.com",
|
||||
AppId: "1",
|
||||
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
|
||||
BaseUri: "http://test.openapi.1688sup.cn",
|
||||
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
MerchantId: 25537,
|
||||
}
|
||||
//c := &Config{
|
||||
// AppId: "101",
|
||||
// AppKey: "95E7EC7D4A394FF8D11788E5E436DE99",
|
||||
// BaseUri: "https://openapi.1688sup.com",
|
||||
// NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
// MerchantId: 25537,
|
||||
//}
|
||||
marshal, _ := json.Marshal(c)
|
||||
return marshal
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func TestOrder(t *testing.T) {
|
|||
request := &proto.OrderRequest{
|
||||
Config: config(),
|
||||
Order: &proto.OrderRequest_Order{
|
||||
OrderNo: "test_plugin_zltx_v1_direct_1",
|
||||
OrderNo: "test_plugin_zltx_v1_direct_2",
|
||||
Account: "583989020@qq.com",
|
||||
Quantity: 1,
|
||||
Extra: nil,
|
||||
|
@ -54,7 +54,7 @@ func TestOrder(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("TestOrder", func(t *testing.T) {
|
||||
got, err := zltx.Order(context.Background(), request)
|
||||
got, err := direct.Order(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Errorf("Order() error = %v", err)
|
||||
return
|
||||
|
@ -68,14 +68,14 @@ func TestQuery(t *testing.T) {
|
|||
request := &proto.QueryRequest{
|
||||
Config: config(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "test_plugin_zltx_v1_direct_1",
|
||||
OrderNo: "test_plugin_zltx_v1_direct_2",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: nil,
|
||||
},
|
||||
}
|
||||
t.Run("TestQuery", func(t *testing.T) {
|
||||
got, err := zltx.Query(context.Background(), request)
|
||||
got, err := direct.Query(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Errorf("Query() error = %v", err)
|
||||
return
|
||||
|
@ -89,11 +89,11 @@ func TestNotify(t *testing.T) {
|
|||
in := &proto.NotifyRequest{
|
||||
Config: config(),
|
||||
Queries: nil,
|
||||
Headers: []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=642F82644ABB88E73C04F7881B93E6FA"],"Connection":["close"],"Content-Length":["102"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`),
|
||||
Body: []byte(`{"merchantId":"25537","outTradeNo":"test_zltx_direct_2","status":"03","rechargeAccount":"18666666666"}`),
|
||||
Headers: []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=6EF1284331EAC9734715C87FEF59D2EF"],"Connection":["close"],"Content-Length":["146"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`),
|
||||
Body: []byte(`{"merchantId":25537,"outTradeNo":"test_plugin_zltx_v1_direct_2","tradeNo":"716586208482959361","status":"03","rechargeAccount":"583989020@qq.com"}`),
|
||||
}
|
||||
t.Run("TestNotify", func(t *testing.T) {
|
||||
got, err := zltx.Notify(context.Background(), in)
|
||||
got, err := direct.Notify(context.Background(), in)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Errorf("Notify() error = %v", err)
|
||||
return
|
||||
|
|
|
@ -5,12 +5,12 @@ go 1.22.2
|
|||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
google.golang.org/grpc v1.64.0
|
||||
plugins/utils v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
|
@ -18,6 +18,7 @@ require (
|
|||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
@ -38,7 +39,6 @@ require (
|
|||
golang.org/x/sys v0.22.0 // indirect
|
||||
golang.org/x/text v0.16.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
|
||||
)
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6 h1:fcQrgdRT4zVmxqK8rsB4Oo7jnhnXDqsgQ8GagR+DSic=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.6/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7 h1:2wOzkUfS17P6U/i6CWFjLyXrdLMnW3osk897ZfOUCxY=
|
||||
gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2 v0.0.0-20240919023950-493c464e0ed7/go.mod h1:aS6ecVHvGLGzYYFIhxBrRWmq69ifo6pt1G92QblSdQQ=
|
||||
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/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||
github.com/carlmjohnson/requests v0.24.2/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU=
|
||||
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/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2 h1:EsEA7AmPQ2YQQ0FZrDWO2HgBNqeWM8z/mWKzS5UkQaQ=
|
||||
github.com/go-kratos/kratos/v2 v2.8.2/go.mod h1:+Vfe3FzF0d+BfMdajA11jT0rAyJWublRE/seZQNZVxE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
@ -38,6 +36,10 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
|
|||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
|
@ -55,6 +57,8 @@ 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/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
|
@ -74,7 +78,8 @@ 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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -2,17 +2,19 @@ package internal
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/api"
|
||||
"gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/notify"
|
||||
"gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/sdk"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"plugins/zltxv2/internal/vo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppId string `json:"app_id"`
|
||||
AppKey string `json:"app_key"`
|
||||
BaseUri string `json:"base_uri"`
|
||||
AppId string `json:"app_id" validate:"required"`
|
||||
AppKey string `json:"app_key" validate:"required"`
|
||||
BaseUri string `json:"base_uri" validate:"required"`
|
||||
NotifyUrl string `json:"notify_url"`
|
||||
}
|
||||
|
||||
|
@ -26,10 +28,23 @@ func (c *Card) ToJson() []byte {
|
|||
return bytes
|
||||
}
|
||||
|
||||
func (c *Config) validate() error {
|
||||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return proto.ErrorConfigFail(fmt.Sprintf("配置参数有误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func transConfig(config []byte) (*Config, error) {
|
||||
var c Config
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, proto.ErrorConfigFail(err.Error())
|
||||
}
|
||||
if err = c.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
|
@ -39,9 +54,13 @@ func (c *Config) client() (*sdk.Client, error) {
|
|||
scheme := getScheme(c.BaseUri)
|
||||
domain, err := getDomain(c.BaseUri, scheme)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorConfigFail(err.Error())
|
||||
}
|
||||
return sdk.NewClientWithAccessKey(c.AppKey, scheme, domain)
|
||||
cl, err := sdk.NewClientWithAccessKey(c.AppKey, scheme, domain)
|
||||
if err != nil {
|
||||
return nil, proto.ErrorConfigFail(err.Error())
|
||||
}
|
||||
return cl, nil
|
||||
}
|
||||
|
||||
func (c *Config) orderReq(in *proto.OrderRequest) *api.OrderCreateReq {
|
||||
|
@ -81,7 +100,7 @@ func (c *Config) queryReq(in *proto.QueryRequest) *api.OrderQueryReq {
|
|||
func queryResp(appKey string, request *proto.QueryRequest, resp *api.OrderQueryResp) (*proto.QueryResponse, error) {
|
||||
data, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
status := vo.OrderStatus(resp.TradeStatus)
|
||||
pb := &proto.QueryResponse{
|
||||
|
@ -110,18 +129,18 @@ func getQueryCard(appKey string, card *api.Cards) (*Card, error) {
|
|||
if t.IsPwdNo() {
|
||||
pwd, err := decryptAES(card.Pwd, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
no, err := decryptAES(card.No, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
car.Password = pwd
|
||||
car.Number = no
|
||||
} else if t.IsPwd() {
|
||||
pwd, err := decryptAES(card.Pwd, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
car.Password = pwd
|
||||
} else if t.IsUrl() {
|
||||
|
@ -133,7 +152,7 @@ func getQueryCard(appKey string, card *api.Cards) (*Card, error) {
|
|||
func notifyResp(appKey string, resp *notify.OrderReq) (*proto.NotifyResponse, error) {
|
||||
data, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
status := vo.OrderStatus(resp.TradeStatus)
|
||||
pb := &proto.NotifyResponse{
|
||||
|
@ -165,18 +184,18 @@ func getNotifyCard(appKey string, cards []notify.Cards) ([]byte, error) {
|
|||
if t.IsPwdNo() {
|
||||
pwd, err := decryptAES(card.Pwd, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
no, err := decryptAES(card.No, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
car.Password = pwd
|
||||
car.Number = no
|
||||
} else if t.IsPwd() {
|
||||
pwd, err := decryptAES(card.Pwd, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorResponseFail(err.Error())
|
||||
}
|
||||
car.Password = pwd
|
||||
} else if t.IsUrl() {
|
||||
|
|
|
@ -34,10 +34,10 @@ func (p *ZLTXV2Service) Order(ctx context.Context, request *proto.OrderRequest)
|
|||
}
|
||||
response, errResp, err := api.OrderCreate(ctx, client, c.AppId, c.orderReq(request))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常[%v]", err)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("请求异常[%v]", err))
|
||||
}
|
||||
if errResp != nil {
|
||||
return nil, fmt.Errorf("请求错误[code:%d]-[reason:%s]-[msg:%s]", errResp.Code, errResp.Reason, errResp.Message)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("请求错误[code:%d]-[reason:%s]-[msg:%s]", errResp.Code, errResp.Reason, errResp.Message))
|
||||
}
|
||||
|
||||
return orderResp(request, response), nil
|
||||
|
@ -55,10 +55,10 @@ func (p *ZLTXV2Service) Query(ctx context.Context, request *proto.QueryRequest)
|
|||
|
||||
response, errResp, err := api.OrderQuery(ctx, client, c.AppId, c.queryReq(request))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常[%v]", err)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("请求异常[%v]", err))
|
||||
}
|
||||
if errResp != nil {
|
||||
return nil, fmt.Errorf("请求错误[code:%d]-[reason:%s]-[msg:%s]", errResp.Code, errResp.Reason, errResp.Message)
|
||||
return nil, proto.ErrorRequestFail(fmt.Sprintf("请求错误[code:%d]-[reason:%s]-[msg:%s]", errResp.Code, errResp.Reason, errResp.Message))
|
||||
}
|
||||
|
||||
return queryResp(c.AppKey, request, response)
|
||||
|
@ -71,7 +71,7 @@ func (p *ZLTXV2Service) Notify(_ context.Context, request *proto.NotifyRequest)
|
|||
}
|
||||
httpHeaders := make(http.Header)
|
||||
if err := json.Unmarshal(request.Headers, &httpHeaders); err != nil {
|
||||
return nil, fmt.Errorf("headers Unmarshal err [%v]", err)
|
||||
return nil, proto.ErrorParamFail(fmt.Sprintf("headers Unmarshal err [%v]", err))
|
||||
}
|
||||
newHeaders := make(http.Header)
|
||||
for key, values := range httpHeaders {
|
||||
|
@ -87,7 +87,7 @@ func (p *ZLTXV2Service) Notify(_ context.Context, request *proto.NotifyRequest)
|
|||
}
|
||||
n, err := notify.NewNotify(c.AppId, c.AppKey).ParseAndVerify(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, proto.ErrorSignFail(err.Error())
|
||||
}
|
||||
|
||||
return notifyResp(c.AppKey, n)
|
||||
|
|
|
@ -14,11 +14,10 @@ var zltx = &ZLTXV2Service{}
|
|||
|
||||
func config() []byte {
|
||||
c := &Config{
|
||||
AppId: "23329",
|
||||
AppKey: "8db16e8cc8363ed4eb4c14f9520bcc32",
|
||||
BaseUri: "http://211.137.105.198:17100",
|
||||
//NotifyUrl: "https://utils.85938.cn/utils/v1/wechat/notify",
|
||||
NotifyUrl: "http://120.55.12.245:8098/v1/order/direct/notify",
|
||||
AppId: "23329",
|
||||
AppKey: "8db16e8cc8363ed4eb4c14f9520bcc32",
|
||||
BaseUri: "http://211.137.105.198:17100",
|
||||
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
|
||||
}
|
||||
marshal, _ := json.Marshal(c)
|
||||
return marshal
|
||||
|
|
|
@ -3,7 +3,7 @@ module plugins/utils
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/tjfoc/gmsm v1.4.1
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17 h1:agk+9iA1ZI6fLVLtxEnuOWxcDzSq9QH7VBFvhlZZsbw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v1.0.17/go.mod h1:O/bYQWg1o9g/cBq9qNA3kLIpuPt7VDZqj1bPE6s04NM=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
||||
|
|
|
@ -9,28 +9,91 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func Request(_ context.Context, method, url string, body []byte) ([]byte, http.Header, error) {
|
||||
// RequestOptions 用于配置请求的各种选项
|
||||
type RequestOptions struct {
|
||||
Timeout time.Duration
|
||||
Headers map[string]string
|
||||
StatusCodeFunc func(int) bool
|
||||
}
|
||||
|
||||
// RequestOption 是一个函数类型,用于设置RequestOptions的各个字段
|
||||
type RequestOption func(*RequestOptions)
|
||||
|
||||
// WithTimeout 设置请求超时时间的选项函数
|
||||
func WithTimeout(timeout time.Duration) RequestOption {
|
||||
return func(options *RequestOptions) {
|
||||
options.Timeout = timeout
|
||||
}
|
||||
}
|
||||
|
||||
// WithHeaders 设置请求头的选项函数
|
||||
func WithHeaders(headers map[string]string) RequestOption {
|
||||
return func(options *RequestOptions) {
|
||||
options.Headers = headers
|
||||
}
|
||||
}
|
||||
|
||||
// WithStatusCodeFunc 设置自定义状态码处理函数的选项函数
|
||||
func WithStatusCodeFunc(statusCodeFunc func(int) bool) RequestOption {
|
||||
return func(options *RequestOptions) {
|
||||
options.StatusCodeFunc = statusCodeFunc
|
||||
}
|
||||
}
|
||||
|
||||
func Post(ctx context.Context, url string, body []byte, options ...RequestOption) ([]byte, http.Header, error) {
|
||||
return Request(ctx, http.MethodPost, url, body, options...)
|
||||
}
|
||||
|
||||
func Get(ctx context.Context, url string, options ...RequestOption) ([]byte, http.Header, error) {
|
||||
return Request(ctx, http.MethodGet, url, nil, options...)
|
||||
}
|
||||
|
||||
func Put(ctx context.Context, url string, body []byte, options ...RequestOption) ([]byte, http.Header, error) {
|
||||
return Request(ctx, http.MethodPut, url, body, options...)
|
||||
}
|
||||
|
||||
// Request 封装的HTTP请求函数,使用选项模式进行配置
|
||||
func Request(_ context.Context, method, url string, body []byte, options ...RequestOption) ([]byte, http.Header, error) {
|
||||
// 设置默认选项
|
||||
defaultOptions := &RequestOptions{
|
||||
Timeout: 15 * time.Second,
|
||||
Headers: make(map[string]string),
|
||||
StatusCodeFunc: func(code int) bool {
|
||||
return code == http.StatusOK
|
||||
},
|
||||
}
|
||||
|
||||
// 根据传入的选项更新默认选项
|
||||
for _, option := range options {
|
||||
option(defaultOptions)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("创建HTTP请求失败: %v", err)
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
for key, value := range defaultOptions.Headers {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
|
||||
httpClient := &http.Client{
|
||||
Timeout: 15 * time.Second,
|
||||
Timeout: defaultOptions.Timeout,
|
||||
}
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("发送HTTP请求失败: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("读取响应体失败: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
if !defaultOptions.StatusCodeFunc(resp.StatusCode) {
|
||||
return nil, nil, fmt.Errorf("请求异常:%s", resp.Status)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_Get(t *testing.T) {
|
||||
uri := "https://gateway.dev.cdlsxd.cn/adminyx/admin/v1/key_batch/list"
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
||||
uv := url.Values{}
|
||||
uv.Set("page", "1")
|
||||
uv.Set("limit", "2")
|
||||
|
||||
respBody, respHeader, err := Get(context.Background(), uri+"?"+uv.Encode(), WithHeaders(headers))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("响应体:", string(respBody))
|
||||
fmt.Println("响应头:", respHeader)
|
||||
}
|
||||
|
||||
func Test_Request(t *testing.T) {
|
||||
url := "https://gateway.dev.cdlsxd.cn/adminyx/admin/v1/key_batch/get_zip_url/109"
|
||||
|
||||
respBody, respHeader, err := Get(context.Background(), url)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("响应体:", string(respBody))
|
||||
fmt.Println("响应头:", respHeader)
|
||||
}
|
||||
|
||||
func Test_RequestHeaders(t *testing.T) {
|
||||
url := "http://example.com/api"
|
||||
body := []byte("request body")
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer token",
|
||||
}
|
||||
|
||||
respBody, respHeader, err := Post(context.Background(), url, body, WithTimeout(10*time.Second), WithHeaders(headers))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("响应体:", string(respBody))
|
||||
fmt.Println("响应头:", respHeader)
|
||||
}
|
||||
|
||||
func Test_RequestStatusCode(t *testing.T) {
|
||||
url := "http://example.com/api/update"
|
||||
body := []byte("update data")
|
||||
|
||||
isSuccess := func(code int) bool {
|
||||
return code == http.StatusOK || code == http.StatusCreated
|
||||
}
|
||||
|
||||
respBody, respHeader, err := Put(context.Background(), url, body, WithStatusCodeFunc(isSuccess))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("响应体:", string(respBody))
|
||||
fmt.Println("响应头:", respHeader)
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
||||
|
@ -21,7 +22,7 @@ func (c *Server) Validate() error {
|
|||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置有误:" + err.Error())
|
||||
return proto.ErrorConfigFail("配置有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -30,22 +31,22 @@ func (c *Server) Validate() error {
|
|||
func newClient(ctx context.Context, c *Server) (*core.Client, error) {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("MchID[%s] get current dir error:%v", c.MchID, err)
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("MchID[%s] get current dir error:%v", c.MchID, err))
|
||||
}
|
||||
filePath := fmt.Sprintf("%s/%s/%s/%s", dir, "cert", "wechat", c.MchID)
|
||||
if !putils.FileExists(filePath) {
|
||||
return nil, fmt.Errorf("MchID[%s]微信密钥证书信息不存在,请联系技术人员处理", c.MchID)
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("MchID[%s]微信密钥证书信息不存在,请联系技术人员处理", c.MchID))
|
||||
}
|
||||
// 商户相关配置,商户API私钥
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(fmt.Sprintf("%s/%s", filePath, "wechat_private_key.pem"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("MchID[%s] load merchant private key error:%v", c.MchID, err)
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("MchID[%s] load merchant private key error:%v", c.MchID, err))
|
||||
}
|
||||
var client *core.Client
|
||||
// 微信支付平台配置
|
||||
wechatPayCertificate, err := utils.LoadCertificateWithPath(fmt.Sprintf("%s/%s", filePath, "wechat_cert.pem"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("平台证书有误:%v", err)
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("平台证书有误:%v", err))
|
||||
}
|
||||
client, err = core.NewClient(
|
||||
ctx,
|
||||
|
@ -57,7 +58,7 @@ func newClient(ctx context.Context, c *Server) (*core.Client, error) {
|
|||
option.WithWechatPayCertificate([]*x509.Certificate{wechatPayCertificate}),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建 Client 失败:%v", err)
|
||||
return nil, proto.ErrorConfigFail(fmt.Sprintf("创建 Client 失败:%v", err))
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package wechat
|
|||
|
||||
import (
|
||||
"context"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/auth"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
|
||||
|
@ -41,5 +42,8 @@ func GetClient(ctx context.Context, c *Server) (*core.Client, error) {
|
|||
func (s *Server) Verify(ctx context.Context, message, signature string) error {
|
||||
var verifier auth.Verifier
|
||||
verifier = verifiers.NewSHA256WithRSAVerifier(nil)
|
||||
return verifier.Verify(ctx, s.MchCertificateSerialNumber, message, signature)
|
||||
if err := verifier.Verify(ctx, s.MchCertificateSerialNumber, message, signature); err != nil {
|
||||
return proto.ErrorSignFail(err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue