From 36b9f16a7487553dd28c97de87d90f91efea1101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Wed, 22 Jan 2025 18:01:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6v2=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/zltx_v1/internal/transform.go | 13 ++----------- plugins/zltx_v1/internal/zltx_v1_test.go | 17 +++++++++++------ plugins/zltx_v2/internal/vo/account_type.go | 2 ++ utils/helper/common.go | 7 ++++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/plugins/zltx_v1/internal/transform.go b/plugins/zltx_v1/internal/transform.go index 393f018..4bc754b 100644 --- a/plugins/zltx_v1/internal/transform.go +++ b/plugins/zltx_v1/internal/transform.go @@ -9,7 +9,6 @@ import ( "gitea.cdlsxd.cn/sdk/plugin/utils" "github.com/go-playground/validator/v10" "net/http" - "regexp" ) type Config struct { @@ -66,17 +65,9 @@ func (c *Config) orderReq(in *proto.OrderRequest) (*direct.Order, error) { accountType := int8(0) if utils.IsPhoneNumber(in.Order.Account) { accountType = 1 - } else { - qqPattern := `^[1-9][0-9]{4,11}$` - qqRegex, err := regexp.Compile(qqPattern) - if err != nil { - return nil, proto.ErrorParamFail(fmt.Sprintf("正则表达式编译失败: %v", err)) - } - if qqRegex.MatchString(in.Order.Account) { - accountType = 2 - } + } else if utils.IsValidQQ(in.Order.Account) { + accountType = 2 } - d := &direct.Order{ Number: in.Order.Quantity, MerchantId: c.MerchantId, diff --git a/plugins/zltx_v1/internal/zltx_v1_test.go b/plugins/zltx_v1/internal/zltx_v1_test.go index be0968f..6fa6f5d 100644 --- a/plugins/zltx_v1/internal/zltx_v1_test.go +++ b/plugins/zltx_v1/internal/zltx_v1_test.go @@ -18,7 +18,7 @@ func config() []byte { AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9", BaseUri: "http://test.openapi.1688sup.cn", NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify", - MerchantId: 23329, + MerchantId: 23369, // 23329 } //c := &Config{ // AppId: "101", @@ -40,21 +40,26 @@ func TestConfig(t *testing.T) { } func TestOrder(t *testing.T) { + //d := []byte(`{"jdSmsCode":"123456"}`) + //s := base64.StdEncoding.EncodeToString(d) + //t.Logf("%s\n", s) + request := &proto.OrderRequest{ Config: config(), Order: &proto.OrderRequest_Order{ - OrderNo: "test_plugin_zltx_v1_direct_3", + OrderNo: "202501131732090710010002", Account: "18666173766", Quantity: 1, - //Extra: []byte(`{"jdCode":"123456"}`), // 京东e卡官方,默认的拓展参数 - //Extra: []byte(`{"jdSmsCode":"123456"}`), // 京东e卡专票,拓展参数 + //Extra: []byte(`{"jdCode":"123456"}`), // 京东e卡官方,拓展参数 + Extra: []byte(`{"jdSmsCode":"123456"}`), // 京东e卡专票,拓展参数 }, Product: &proto.OrderRequest_Product{ - ProductNo: "101", // 101 2255 360 + ProductNo: "360", // 101 2255 360 Extra: []byte(`{}`), }, } - + t.Logf("%s\n", request.String()) + return t.Run("TestOrder", func(t *testing.T) { got, err := srv.Order(context.Background(), request) if err != nil { diff --git a/plugins/zltx_v2/internal/vo/account_type.go b/plugins/zltx_v2/internal/vo/account_type.go index 79457df..c47d093 100644 --- a/plugins/zltx_v2/internal/vo/account_type.go +++ b/plugins/zltx_v2/internal/vo/account_type.go @@ -15,6 +15,8 @@ func (o AccountType) AccountType(account string) AccountType { return AccountTypeDefault } else if helper.IsPhoneNumber(account) { return AccountTypePhone + } else if helper.IsValidQQ(account) { + return AccountTypeQQ } return AccountTypeDefault } diff --git a/utils/helper/common.go b/utils/helper/common.go index 5165323..488d423 100644 --- a/utils/helper/common.go +++ b/utils/helper/common.go @@ -33,7 +33,8 @@ func IsEmail(email string) bool { // IsValidQQ 检查给定的字符串是否为有效的 QQ 号 func IsValidQQ(qq string) bool { - // QQ号正则表达式:5到11位数字,且开头不为0的情况 - re := regexp.MustCompile(`^(?!0)[0-9]{5,11}$`) - return re.MatchString(qq) + // QQ号正则表达式:5到11位数字,且开头不为0的情况, + regex := `^[1-9][0-9]{4,11}$` + //re := regexp.MustCompile(`^[1-9]\d{4,10}$`) + return regexp.MustCompile(regex).MatchString(qq) }