卡密类型处理
This commit is contained in:
parent
a929f507b1
commit
d20fd39530
6
Makefile
6
Makefile
|
@ -29,6 +29,12 @@ zltx:
|
||||||
make build-linux name=zltx && \
|
make build-linux name=zltx && \
|
||||||
make build-win name=zltx
|
make build-win name=zltx
|
||||||
|
|
||||||
|
.PHONY: zltx_card
|
||||||
|
zltx_card:
|
||||||
|
make build-mac name=zltx_card && \
|
||||||
|
make build-linux name=zltx_card && \
|
||||||
|
make build-win name=zltx_card
|
||||||
|
|
||||||
.PHONY: union_pay_cpn
|
.PHONY: union_pay_cpn
|
||||||
union_pay_cpn:
|
union_pay_cpn:
|
||||||
make build-mac name=union_pay_cpn && \
|
make build-mac name=union_pay_cpn && \
|
||||||
|
|
|
@ -3,7 +3,7 @@ module plugins/alipay_cpn
|
||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/carlmjohnson/requests v0.24.2
|
github.com/carlmjohnson/requests v0.24.2
|
||||||
github.com/go-playground/validator/v10 v10.22.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||||
github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
||||||
replace plugins/utils => ../../utils
|
replace plugins/utils => ../../utils
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/carlmjohnson/requests v0.24.2
|
github.com/carlmjohnson/requests v0.24.2
|
||||||
github.com/go-playground/validator/v10 v10.22.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||||
github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
||||||
replace plugins/utils => ../../utils
|
replace plugins/utils => ../../utils
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/carlmjohnson/requests v0.24.2
|
github.com/carlmjohnson/requests v0.24.2
|
||||||
github.com/go-playground/validator/v10 v10.22.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
||||||
replace plugins/utils => ../../utils
|
replace plugins/utils => ../../utils
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/carlmjohnson/requests v0.24.2
|
github.com/carlmjohnson/requests v0.24.2
|
||||||
github.com/go-playground/validator/v10 v10.22.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
||||||
replace plugins/utils => ../../utils
|
replace plugins/utils => ../../utils
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
||||||
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
|
|
|
@ -5,7 +5,7 @@ go 1.22.2
|
||||||
replace plugins/utils => ../../utils
|
replace plugins/utils => ../../utils
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
||||||
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
|
|
|
@ -3,7 +3,7 @@ module plugins/zltx
|
||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
github.com/carlmjohnson/requests v0.24.2
|
github.com/carlmjohnson/requests v0.24.2
|
||||||
github.com/go-playground/validator/v10 v10.22.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/hashicorp/go-plugin v1.6.1
|
github.com/hashicorp/go-plugin v1.6.1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca h1:snL161P7OynMA8hRVMLDjwnzZA2Q4mePg/iT/dyIfzA=
|
||||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||||
github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso=
|
||||||
|
|
|
@ -1,22 +1,11 @@
|
||||||
package po
|
package po
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"plugins/zltx/internal/vo"
|
"plugins/zltx/internal/vo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Card struct {
|
|
||||||
Number string `json:"number"`
|
|
||||||
Password string `json:"password"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Card) ToString() string {
|
|
||||||
bytes, _ := json.Marshal(c)
|
|
||||||
return string(bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Req interface {
|
type Req interface {
|
||||||
Validate() error
|
Validate() error
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
"plugins/zltx/internal/po"
|
"plugins/zltx/internal/po"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ func (c *Config) queryReq(in *proto.QueryRequest) *po.QueryReq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryResp(request *proto.QueryRequest, resp po.QueryResp, appKey string) (*proto.QueryResponse, error) {
|
func queryResp(request *proto.QueryRequest, resp po.QueryResp) (*proto.QueryResponse, error) {
|
||||||
data, _ := json.Marshal(resp)
|
data, _ := json.Marshal(resp)
|
||||||
pb := &proto.QueryResponse{
|
pb := &proto.QueryResponse{
|
||||||
Result: &proto.Result{
|
Result: &proto.Result{
|
||||||
|
@ -72,23 +71,10 @@ func queryResp(request *proto.QueryRequest, resp po.QueryResp, appKey string) (*
|
||||||
Extra: nil,
|
Extra: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if resp.CardCode != "" {
|
|
||||||
s, err := cardCodeDecode(resp.CardCode, []byte(appKey))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
parts := strings.Split(s, "_")
|
|
||||||
car := &po.Card{
|
|
||||||
Number: parts[0],
|
|
||||||
Password: parts[1],
|
|
||||||
}
|
|
||||||
b, _ := json.Marshal(car)
|
|
||||||
pb.Result.Extra = b
|
|
||||||
}
|
|
||||||
return pb, nil
|
return pb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func notifyResp(in po.Notify, appKey string) (*proto.NotifyResponse, error) {
|
func notifyResp(in po.Notify) (*proto.NotifyResponse, error) {
|
||||||
data, _ := json.Marshal(in)
|
data, _ := json.Marshal(in)
|
||||||
pb := &proto.NotifyResponse{
|
pb := &proto.NotifyResponse{
|
||||||
Result: &proto.Result{
|
Result: &proto.Result{
|
||||||
|
@ -100,18 +86,5 @@ func notifyResp(in po.Notify, appKey string) (*proto.NotifyResponse, error) {
|
||||||
Extra: nil,
|
Extra: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if in.CardCode != "" {
|
|
||||||
s, err := cardCodeDecode(in.CardCode, []byte(appKey))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
parts := strings.Split(s, "_")
|
|
||||||
car := &po.Card{
|
|
||||||
Number: parts[0],
|
|
||||||
Password: parts[1],
|
|
||||||
}
|
|
||||||
b, _ := json.Marshal(car)
|
|
||||||
pb.Result.Extra = b
|
|
||||||
}
|
|
||||||
return pb, nil
|
return pb, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
orderMethod = "/recharge/order"
|
orderRechargeMethod = "/recharge/order"
|
||||||
queryMethod = "/recharge/query"
|
queryMethod = "/recharge/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ZLTXService struct{}
|
type ZLTXService struct{}
|
||||||
|
@ -36,7 +36,8 @@ func (p *ZLTXService) Order(ctx context.Context, request *proto.OrderRequest) (*
|
||||||
}
|
}
|
||||||
|
|
||||||
var response po.OrderResp
|
var response po.OrderResp
|
||||||
err = requests.URL(c.BaseUri + orderMethod).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
baseUrl := fmt.Sprintf("%s%s", c.BaseUri, orderRechargeMethod)
|
||||||
|
err = requests.URL(baseUrl).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ func (p *ZLTXService) Query(ctx context.Context, request *proto.QueryRequest) (*
|
||||||
return nil, errors.New("请求错误,msg:" + response.Message)
|
return nil, errors.New("请求错误,msg:" + response.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryResp(request, response, c.AppKey)
|
return queryResp(request, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ZLTXService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
func (p *ZLTXService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||||
|
@ -91,5 +92,5 @@ func (p *ZLTXService) Notify(_ context.Context, request *proto.NotifyRequest) (*
|
||||||
return nil, fmt.Errorf("验签不通过")
|
return nil, fmt.Errorf("验签不通过")
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifyResp(poReq, c.AppKey)
|
return notifyResp(poReq)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
module plugins/zltx_card
|
||||||
|
|
||||||
|
go 1.22.2
|
||||||
|
|
||||||
|
require (
|
||||||
|
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
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-playground/locales v0.14.1 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
|
github.com/hashicorp/go-hclog v0.14.1 // indirect
|
||||||
|
github.com/hashicorp/yamux v0.1.1 // indirect
|
||||||
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.4 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.10 // indirect
|
||||||
|
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
|
||||||
|
github.com/oklog/run v1.0.0 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
golang.org/x/crypto v0.25.0 // indirect
|
||||||
|
golang.org/x/net v0.27.0 // indirect
|
||||||
|
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
|
||||||
|
)
|
|
@ -0,0 +1,68 @@
|
||||||
|
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=
|
||||||
|
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-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=
|
||||||
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
|
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
|
||||||
|
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||||
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU=
|
||||||
|
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
|
||||||
|
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
|
||||||
|
github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0=
|
||||||
|
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
|
||||||
|
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||||
|
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
|
||||||
|
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
|
||||||
|
github.com/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=
|
||||||
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
|
||||||
|
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||||
|
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 h1:7GoSOOW2jpsfkntVKaS2rAr1TJqfcxotyaUcuxoZSzg=
|
||||||
|
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||||
|
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
|
||||||
|
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/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=
|
||||||
|
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||||
|
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||||
|
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||||
|
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||||
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||||
|
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||||
|
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
|
||||||
|
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
|
||||||
|
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
|
||||||
|
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||||
|
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -0,0 +1,12 @@
|
||||||
|
package po
|
||||||
|
|
||||||
|
import "plugins/zltx_card/internal/vo"
|
||||||
|
|
||||||
|
type Notify struct {
|
||||||
|
MerchantId int `json:"merchantId"`
|
||||||
|
OutTradeNo string `json:"outTradeNo"`
|
||||||
|
RechargeAccount string `json:"rechargeAccount"`
|
||||||
|
Status vo.OrderStatus `json:"status"`
|
||||||
|
CardCode string `json:"cardCode"` // 卡密才可能会有
|
||||||
|
Sign string `json:"sign" validate:"required"`
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package po
|
||||||
|
|
||||||
|
import "plugins/zltx_card/internal/vo"
|
||||||
|
|
||||||
|
type OrderReq struct {
|
||||||
|
Number uint32 `validate:"required" json:"number"`
|
||||||
|
MerchantId string `validate:"required" json:"merchantId"`
|
||||||
|
OutTradeNo string `validate:"required" json:"outTradeNo"`
|
||||||
|
ProductId string `validate:"required" json:"productId"`
|
||||||
|
TimeStamp int64 `validate:"required" json:"timeStamp"`
|
||||||
|
Mobile string `validate:"required" json:"mobile"`
|
||||||
|
NotifyUrl string `validate:"required" json:"notifyUrl"`
|
||||||
|
Version string `validate:"required" json:"version"`
|
||||||
|
Sign string
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderResp struct {
|
||||||
|
Code any `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
CodeStr vo.Code // 充值接口返回的请求码,可能是整数类型、浮点数类型、字符串,统一处理成字符串
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package po
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"plugins/zltx_card/internal/vo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Card struct {
|
||||||
|
Number string `json:"number"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Card) ToString() string {
|
||||||
|
bytes, _ := json.Marshal(c)
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Req interface {
|
||||||
|
Validate() error
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Req = (*OrderReq)(nil)
|
||||||
|
var _ Req = (*QueryReq)(nil)
|
||||||
|
var _ Req = (*Notify)(nil)
|
||||||
|
|
||||||
|
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 nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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 nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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 nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Resp interface {
|
||||||
|
SetCodeStr()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Resp = (*OrderResp)(nil)
|
||||||
|
|
||||||
|
func (r *OrderResp) SetCodeStr() {
|
||||||
|
r.CodeStr = vo.Code(fmt.Sprintf("%v", r.Code))
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package po
|
||||||
|
|
||||||
|
import "plugins/zltx_card/internal/vo"
|
||||||
|
|
||||||
|
type QueryReq struct {
|
||||||
|
MerchantId string `validate:"required"`
|
||||||
|
OutTradeNo string `validate:"required"`
|
||||||
|
TimeStamp int64 `validate:"required"`
|
||||||
|
Version string `validate:"required"`
|
||||||
|
Sign string
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryResp struct {
|
||||||
|
Code vo.Code `json:"code"`
|
||||||
|
Status vo.OrderStatus `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
OutTradeNo string `json:"outTradeNo"`
|
||||||
|
CardCode string `json:"cardCode"` // 卡密才可能会有
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
|
"plugins/zltx_card/internal/po"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
AppId string `json:"app_id"`
|
||||||
|
AppKey string `json:"app_key"`
|
||||||
|
BaseUri string `json:"base_uri"`
|
||||||
|
NotifyUrl string `json:"notify_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func transConfig(config []byte) (*Config, error) {
|
||||||
|
var c Config
|
||||||
|
err := json.Unmarshal(config, &c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) orderReq(in *proto.OrderRequest) *po.OrderReq {
|
||||||
|
p := &po.OrderReq{
|
||||||
|
MerchantId: c.AppId,
|
||||||
|
OutTradeNo: in.Order.OrderNo,
|
||||||
|
ProductId: in.Product.ProductNo,
|
||||||
|
Mobile: in.Order.Account,
|
||||||
|
Number: in.Order.Quantity,
|
||||||
|
Version: "1.0",
|
||||||
|
TimeStamp: time.Now().Unix(),
|
||||||
|
NotifyUrl: c.NotifyUrl,
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||||
|
data, _ := json.Marshal(resp)
|
||||||
|
return &proto.OrderResponse{
|
||||||
|
Result: &proto.Result{
|
||||||
|
Status: proto.Status_ING,
|
||||||
|
OrderNo: request.Order.OrderNo,
|
||||||
|
TradeNo: "", // 下单无该值返回
|
||||||
|
Message: resp.Message,
|
||||||
|
Data: data,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) queryReq(in *proto.QueryRequest) *po.QueryReq {
|
||||||
|
return &po.QueryReq{
|
||||||
|
MerchantId: c.AppId,
|
||||||
|
OutTradeNo: in.Order.OrderNo,
|
||||||
|
TimeStamp: time.Now().Unix(),
|
||||||
|
Version: "1.0",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func queryResp(request *proto.QueryRequest, resp po.QueryResp, appKey string) (*proto.QueryResponse, error) {
|
||||||
|
data, _ := json.Marshal(resp)
|
||||||
|
pb := &proto.QueryResponse{
|
||||||
|
Result: &proto.Result{
|
||||||
|
Status: resp.Status.GetOrderStatus(),
|
||||||
|
OrderNo: request.Order.OrderNo,
|
||||||
|
TradeNo: request.Order.TradeNo,
|
||||||
|
Message: resp.Message,
|
||||||
|
Data: data,
|
||||||
|
Extra: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return pb, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func notifyResp(in po.Notify, appKey string) (*proto.NotifyResponse, error) {
|
||||||
|
data, _ := json.Marshal(in)
|
||||||
|
pb := &proto.NotifyResponse{
|
||||||
|
Result: &proto.Result{
|
||||||
|
Status: in.Status.GetOrderStatus(),
|
||||||
|
OrderNo: in.OutTradeNo,
|
||||||
|
TradeNo: "",
|
||||||
|
Message: "",
|
||||||
|
Data: data,
|
||||||
|
Extra: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if in.CardCode != "" {
|
||||||
|
s, err := cardCodeDecode(in.CardCode, []byte(appKey))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
parts := strings.Split(s, "_")
|
||||||
|
car := &po.Card{}
|
||||||
|
if len(parts) > 1 {
|
||||||
|
car.Number = parts[0]
|
||||||
|
car.Password = parts[1]
|
||||||
|
}
|
||||||
|
b, _ := json.Marshal(car)
|
||||||
|
pb.Result.Extra = b
|
||||||
|
}
|
||||||
|
return pb, nil
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"gitea.cdlsxd.cn/sdk/plugin/utils"
|
||||||
|
"net/url"
|
||||||
|
"plugins/zltx_card/internal/po"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func sign(values []byte) string {
|
||||||
|
hash := md5.Sum(values)
|
||||||
|
return strings.ToUpper(hex.EncodeToString(hash[:]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func urlValues(req po.Req, appKey string) url.Values {
|
||||||
|
uv := url.Values{}
|
||||||
|
var kvStr []string
|
||||||
|
kvRows := utils.SortStruct(req)
|
||||||
|
for _, kv := range kvRows {
|
||||||
|
if kv.Key == "sign" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
uv.Set(kv.Key, kv.Value)
|
||||||
|
if kv.Key != "version" {
|
||||||
|
kvStr = append(kvStr, kv.Key+"="+kv.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kvStr = append(kvStr, "key="+appKey)
|
||||||
|
signStr := strings.Join(kvStr, "&")
|
||||||
|
uv.Set("sign", sign([]byte(signStr)))
|
||||||
|
|
||||||
|
return uv
|
||||||
|
}
|
||||||
|
|
||||||
|
func req(req po.Req, appKey string) (url.Values, error) {
|
||||||
|
if err := req.Validate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return urlValues(req, appKey), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func verify(notify *po.Notify, appKey string) bool {
|
||||||
|
kvRows := utils.SortStruct(notify)
|
||||||
|
var kvStr []string
|
||||||
|
|
||||||
|
for _, kv := range kvRows {
|
||||||
|
if kv.Key != "sign" && kv.Key != "version" {
|
||||||
|
kvStr = append(kvStr, kv.Key+"="+kv.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kvStr = append(kvStr, "key="+appKey)
|
||||||
|
signStr := strings.Join(kvStr, "&")
|
||||||
|
|
||||||
|
return sign([]byte(signStr)) == notify.Sign
|
||||||
|
}
|
||||||
|
|
||||||
|
func cardCodeDecode(code string, key []byte) (string, error) {
|
||||||
|
decoded, err := base64.StdEncoding.DecodeString(code)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("base64 decode error: %v", err)
|
||||||
|
}
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("aes new cipher error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(decoded) < aes.BlockSize {
|
||||||
|
return "", fmt.Errorf("ciphertext too short")
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted := make([]byte, len(decoded))
|
||||||
|
mode := cipher.NewCBCDecrypter(block, make([]byte, aes.BlockSize))
|
||||||
|
mode.CryptBlocks(decrypted, decoded)
|
||||||
|
|
||||||
|
padding := decrypted[len(decrypted)-1]
|
||||||
|
decrypted = decrypted[:len(decrypted)-int(padding)]
|
||||||
|
|
||||||
|
return string(decrypted), nil
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package vo
|
||||||
|
|
||||||
|
type Code string
|
||||||
|
|
||||||
|
const CodeSuccess Code = "0000"
|
||||||
|
const RechargeCodeSuccess Code = "2000"
|
||||||
|
|
||||||
|
var ResMessageMap = map[Code]string{
|
||||||
|
"1000": "Ip limit(ip未绑定或绑定失败)",
|
||||||
|
"1001": "Missing parameters(参数异常)",
|
||||||
|
"1002": "Invalid merchant(无效商户信息)",
|
||||||
|
"1003": "Invalid signature(签名校验失败)",
|
||||||
|
"1004": "Request expiration(请求时间过期)",
|
||||||
|
"1005": "Order repeat(订单重复)",
|
||||||
|
"1006": "Invalid item(商品未开通)",
|
||||||
|
"1007": "Item price invalid(商品价格无效)",
|
||||||
|
"1008": "Insufficient Balance(余额不足)",
|
||||||
|
"1009": "Interface adjustment(商品映射无效)",
|
||||||
|
"1010": "Interface price adjustment(映射价格无效)",
|
||||||
|
"1011": "Account format matching(充值账号格式不匹配)",
|
||||||
|
"1012": "no order(无订单信息)",
|
||||||
|
"1999": "unknown error(异常错误,建议人工处理或查询订单状态)",
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Code) IsRechargeSuccess() bool {
|
||||||
|
return c == RechargeCodeSuccess
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Code) GetMessage() string {
|
||||||
|
if message, ok := ResMessageMap[c]; ok {
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Code) IsSuccess() bool {
|
||||||
|
return c == CodeSuccess
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package vo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OrderStatus string
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrderSuccess OrderStatus = "01" // 充值成功
|
||||||
|
OrderPending OrderStatus = "02" // 充值处理中
|
||||||
|
OrderFail OrderStatus = "03" // 充值失败
|
||||||
|
OrderAbnormal OrderStatus = "04" // 充值异常,处理中
|
||||||
|
)
|
||||||
|
|
||||||
|
var orderStatusMap = map[OrderStatus]proto.Status{
|
||||||
|
OrderSuccess: proto.Status_SUCCESS,
|
||||||
|
OrderPending: proto.Status_ING,
|
||||||
|
OrderFail: proto.Status_FAIL,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o OrderStatus) IsSuccess() bool {
|
||||||
|
return o == OrderSuccess
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o OrderStatus) IsPending() bool {
|
||||||
|
return o == OrderPending
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o OrderStatus) IsFail() bool {
|
||||||
|
return o == OrderFail
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o OrderStatus) IsAbnormal() bool {
|
||||||
|
return o == OrderAbnormal
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o OrderStatus) GetOrderStatus() proto.Status {
|
||||||
|
if resultStatus, ok := orderStatusMap[o]; ok {
|
||||||
|
return resultStatus
|
||||||
|
}
|
||||||
|
return proto.Status_ING
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
|
"github.com/carlmjohnson/requests"
|
||||||
|
"plugins/zltx_card/internal/po"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 插件通信信息,若不对应则会报错panic
|
||||||
|
const (
|
||||||
|
Tag = "zltx_card"
|
||||||
|
Version = 1
|
||||||
|
CookieKey = "zltx_card"
|
||||||
|
CookieValue = "zltx_card"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
orderMethod = "/card/order"
|
||||||
|
queryMethod = "/card/query"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ZLTXCardService struct{}
|
||||||
|
|
||||||
|
func (p *ZLTXCardService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||||||
|
c, err := transConfig(request.Config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uv, err := req(c.orderReq(request), c.AppKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var response po.OrderResp
|
||||||
|
baseUrl := fmt.Sprintf("%s%s", c.BaseUri, orderMethod)
|
||||||
|
err = requests.URL(baseUrl).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
response.SetCodeStr()
|
||||||
|
if !response.CodeStr.IsRechargeSuccess() {
|
||||||
|
return nil, fmt.Errorf("请求错误,msg:" + response.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return orderResp(request, response), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ZLTXCardService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||||
|
c, err := transConfig(request.Config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uv, err := req(c.queryReq(request), c.AppKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var response po.QueryResp
|
||||||
|
err = requests.URL(c.BaseUri + queryMethod).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !response.Code.IsSuccess() {
|
||||||
|
return nil, errors.New("请求错误,msg:" + response.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryResp(request, response, c.AppKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ZLTXCardService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||||
|
c, err := transConfig(request.Config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var poReq po.Notify
|
||||||
|
err = json.Unmarshal(request.Body, &poReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("解析异常,msg:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = poReq.Validate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !verify(&poReq, c.AppKey) {
|
||||||
|
return nil, fmt.Errorf("验签不通过")
|
||||||
|
}
|
||||||
|
|
||||||
|
return notifyResp(poReq, c.AppKey)
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var zltx = &ZLTXCardService{}
|
||||||
|
|
||||||
|
func config() []byte {
|
||||||
|
c := &Config{
|
||||||
|
AppId: "23329",
|
||||||
|
AppKey: "8db16e8cc8363ed4eb4c14f9520bcc32",
|
||||||
|
BaseUri: "http://test.openapi.1688sup.cn",
|
||||||
|
NotifyUrl: "http://test.openapi.1688sup.cn",
|
||||||
|
}
|
||||||
|
marshal, _ := json.Marshal(c)
|
||||||
|
return marshal
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfig(t *testing.T) {
|
||||||
|
t.Run("TestConfig", func(t *testing.T) {
|
||||||
|
c := config()
|
||||||
|
fmt.Printf("%+s\n", string(c))
|
||||||
|
assert.NotEmpty(t, c)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrder(t *testing.T) {
|
||||||
|
request := &proto.OrderRequest{
|
||||||
|
Config: config(),
|
||||||
|
Order: &proto.OrderRequest_Order{
|
||||||
|
OrderNo: "test_card_zltx_4",
|
||||||
|
Account: "18666666666",
|
||||||
|
Quantity: 1,
|
||||||
|
Amount: 0,
|
||||||
|
Extra: nil,
|
||||||
|
},
|
||||||
|
Product: &proto.OrderRequest_Product{
|
||||||
|
ProductNo: "222",
|
||||||
|
Extra: []byte(`{}`),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
t.Run("TestOrder", func(t *testing.T) {
|
||||||
|
got, err := zltx.Order(context.Background(), request)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Order() error = %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v", got)
|
||||||
|
assert.Equal(t, int(proto.Status_ING), int(got.Result.Status))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQuery(t *testing.T) {
|
||||||
|
request := &proto.QueryRequest{
|
||||||
|
Config: config(),
|
||||||
|
Order: &proto.QueryRequest_Order{
|
||||||
|
OrderNo: "test_card_zltx_4",
|
||||||
|
TradeNo: "",
|
||||||
|
Account: "",
|
||||||
|
Extra: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
t.Run("TestQuery", func(t *testing.T) {
|
||||||
|
got, err := zltx.Query(context.Background(), request)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Query() error = %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v \n", got)
|
||||||
|
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
in := &proto.NotifyRequest{
|
||||||
|
Config: config(),
|
||||||
|
Queries: nil,
|
||||||
|
Headers: nil,
|
||||||
|
Body: []byte(`{"merchantId":10, "outTradeNo":"123", "rechargeAccount":"1866666666", "status":"01", "sign":"sign"}`),
|
||||||
|
}
|
||||||
|
t.Run("TestNotify", func(t *testing.T) {
|
||||||
|
got, err := zltx.Notify(context.Background(), in)
|
||||||
|
if !assert.Nil(t, err) {
|
||||||
|
t.Errorf("Notify() error = %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%s \n", got.String())
|
||||||
|
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
|
||||||
|
})
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitea.cdlsxd.cn/sdk/plugin/shared"
|
||||||
|
"github.com/hashicorp/go-plugin"
|
||||||
|
"plugins/zltx_card/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
plugin.Serve(&plugin.ServeConfig{
|
||||||
|
HandshakeConfig: shared.HandshakeConfig(internal.Version, internal.CookieKey, internal.CookieValue),
|
||||||
|
Plugins: shared.PluginSet(shared.NewPlugin(&internal.ZLTXCardService{}, internal.Tag)),
|
||||||
|
GRPCServer: plugin.DefaultGRPCServer,
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue