插件v2调整

This commit is contained in:
李子铭 2025-01-22 18:01:45 +08:00
parent 3e4f3ce530
commit 36b9f16a74
4 changed files with 19 additions and 20 deletions

View File

@ -9,7 +9,6 @@ import (
"gitea.cdlsxd.cn/sdk/plugin/utils" "gitea.cdlsxd.cn/sdk/plugin/utils"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"net/http" "net/http"
"regexp"
) )
type Config struct { type Config struct {
@ -66,17 +65,9 @@ func (c *Config) orderReq(in *proto.OrderRequest) (*direct.Order, error) {
accountType := int8(0) accountType := int8(0)
if utils.IsPhoneNumber(in.Order.Account) { if utils.IsPhoneNumber(in.Order.Account) {
accountType = 1 accountType = 1
} else { } else if utils.IsValidQQ(in.Order.Account) {
qqPattern := `^[1-9][0-9]{4,11}$` accountType = 2
qqRegex, err := regexp.Compile(qqPattern)
if err != nil {
return nil, proto.ErrorParamFail(fmt.Sprintf("正则表达式编译失败: %v", err))
}
if qqRegex.MatchString(in.Order.Account) {
accountType = 2
}
} }
d := &direct.Order{ d := &direct.Order{
Number: in.Order.Quantity, Number: in.Order.Quantity,
MerchantId: c.MerchantId, MerchantId: c.MerchantId,

View File

@ -18,7 +18,7 @@ func config() []byte {
AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9", AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9",
BaseUri: "http://test.openapi.1688sup.cn", BaseUri: "http://test.openapi.1688sup.cn",
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify", NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
MerchantId: 23329, MerchantId: 23369, // 23329
} }
//c := &Config{ //c := &Config{
// AppId: "101", // AppId: "101",
@ -40,21 +40,26 @@ func TestConfig(t *testing.T) {
} }
func TestOrder(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{ request := &proto.OrderRequest{
Config: config(), Config: config(),
Order: &proto.OrderRequest_Order{ Order: &proto.OrderRequest_Order{
OrderNo: "test_plugin_zltx_v1_direct_3", OrderNo: "202501131732090710010002",
Account: "18666173766", Account: "18666173766",
Quantity: 1, Quantity: 1,
//Extra: []byte(`{"jdCode":"123456"}`), // 京东e卡官方默认的拓展参数 //Extra: []byte(`{"jdCode":"123456"}`), // 京东e卡官方拓展参数
//Extra: []byte(`{"jdSmsCode":"123456"}`), // 京东e卡专票拓展参数 Extra: []byte(`{"jdSmsCode":"123456"}`), // 京东e卡专票拓展参数
}, },
Product: &proto.OrderRequest_Product{ Product: &proto.OrderRequest_Product{
ProductNo: "101", // 101 2255 360 ProductNo: "360", // 101 2255 360
Extra: []byte(`{}`), Extra: []byte(`{}`),
}, },
} }
t.Logf("%s\n", request.String())
return
t.Run("TestOrder", func(t *testing.T) { t.Run("TestOrder", func(t *testing.T) {
got, err := srv.Order(context.Background(), request) got, err := srv.Order(context.Background(), request)
if err != nil { if err != nil {

View File

@ -15,6 +15,8 @@ func (o AccountType) AccountType(account string) AccountType {
return AccountTypeDefault return AccountTypeDefault
} else if helper.IsPhoneNumber(account) { } else if helper.IsPhoneNumber(account) {
return AccountTypePhone return AccountTypePhone
} else if helper.IsValidQQ(account) {
return AccountTypeQQ
} }
return AccountTypeDefault return AccountTypeDefault
} }

View File

@ -33,7 +33,8 @@ func IsEmail(email string) bool {
// IsValidQQ 检查给定的字符串是否为有效的 QQ 号 // IsValidQQ 检查给定的字符串是否为有效的 QQ 号
func IsValidQQ(qq string) bool { func IsValidQQ(qq string) bool {
// QQ号正则表达式5到11位数字且开头不为0的情况 // QQ号正则表达式5到11位数字且开头不为0的情况,
re := regexp.MustCompile(`^(?!0)[0-9]{5,11}$`) regex := `^[1-9][0-9]{4,11}$`
return re.MatchString(qq) //re := regexp.MustCompile(`^[1-9]\d{4,10}$`)
return regexp.MustCompile(regex).MatchString(qq)
} }