红包发放调试
This commit is contained in:
parent
e8d8ec626f
commit
77125628fa
|
@ -45,13 +45,13 @@ func alipayOrderRedPack() {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
request := &proto.OrderRequest{
|
request := &proto.OrderRequest{
|
||||||
Config: config(),
|
Config: getAlpayRedConf(),
|
||||||
Order: &proto.OrderRequest_Order{
|
Order: &proto.OrderRequest_Order{
|
||||||
OrderNo: "lsxd202406071545141534",
|
OrderNo: "lsxd202406071545141534",
|
||||||
Account: "18512869479",
|
Account: "18666173766",
|
||||||
Quantity: 1,
|
Quantity: 1,
|
||||||
Amount: 0.01,
|
Amount: 0.01,
|
||||||
Extra: []byte(`{"name":"樊波"}`),
|
Extra: []byte(`{"name":"李子铭"}`),
|
||||||
},
|
},
|
||||||
Product: &proto.OrderRequest_Product{
|
Product: &proto.OrderRequest_Product{
|
||||||
ProductNo: "",
|
ProductNo: "",
|
||||||
|
@ -76,8 +76,8 @@ func alipayQueryRedPack() {
|
||||||
queryRequest := &proto.QueryRequest{
|
queryRequest := &proto.QueryRequest{
|
||||||
Config: getAlpayRedConf(),
|
Config: getAlpayRedConf(),
|
||||||
Order: &proto.QueryRequest_Order{
|
Order: &proto.QueryRequest_Order{
|
||||||
OrderNo: "lsxd202306071545141532",
|
OrderNo: "lsxd202406071545141534",
|
||||||
TradeNo: "20230607110070000006320086925897",
|
TradeNo: "20240918020070011550480064889781",
|
||||||
Account: "",
|
Account: "",
|
||||||
Extra: []byte(``),
|
Extra: []byte(``),
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,5 +3,6 @@ package main
|
||||||
// main 这只是一个演示
|
// main 这只是一个演示
|
||||||
func main() {
|
func main() {
|
||||||
//wechatCpn()
|
//wechatCpn()
|
||||||
alipayOrderRedPack()
|
//alipayOrderRedPack()
|
||||||
|
alipayQueryRedPack()
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module plugins
|
||||||
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
|
||||||
plugins/utils v0.0.0-00010101000000-000000000000
|
plugins/utils v0.0.0-00010101000000-000000000000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -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=
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (s *AlipayRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
||||||
}
|
}
|
||||||
|
|
||||||
var sp string
|
var sp string
|
||||||
err = requests.URL(baseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
err = requests.URL(baseUri).Post().Params(uv).ToString(&sp).Fetch(ctx)
|
||||||
|
|
||||||
var response *po.OrderResp
|
var response *po.OrderResp
|
||||||
sp = helper.ToChinese(sp)
|
sp = helper.ToChinese(sp)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"plugins/alipay_redpack/internal/po"
|
"plugins/alipay_redpack/internal/po"
|
||||||
"plugins/alipay_redpack/internal/vo"
|
"plugins/alipay_redpack/internal/vo"
|
||||||
"plugins/utils/alipay"
|
"plugins/utils/alipay"
|
||||||
|
"plugins/utils/helper"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,13 +65,13 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
||||||
Identity: order.Account,
|
Identity: order.Account,
|
||||||
IdentityType: "ALIPAY_USER_ID",
|
IdentityType: "ALIPAY_USER_ID",
|
||||||
}
|
}
|
||||||
if isValidPhoneNumber(order.Account) || isEmailValid(order.Account) {
|
if helper.IsPhoneNumber(order.Account) || helper.IsEmail(order.Account) {
|
||||||
type OrderExtra struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
if order.Extra == nil {
|
if order.Extra == nil {
|
||||||
return nil, fmt.Errorf("order extra is nil")
|
return nil, fmt.Errorf("order extra is nil")
|
||||||
}
|
}
|
||||||
|
type OrderExtra struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
var orderExtra OrderExtra
|
var orderExtra OrderExtra
|
||||||
err = json.Unmarshal(order.Extra, &orderExtra)
|
err = json.Unmarshal(order.Extra, &orderExtra)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -82,8 +83,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
||||||
payeeInfo.IdentityType = "ALIPAY_LOGON_ID"
|
payeeInfo.IdentityType = "ALIPAY_LOGON_ID"
|
||||||
payeeInfo.Name = orderExtra.Name
|
payeeInfo.Name = orderExtra.Name
|
||||||
}
|
}
|
||||||
|
return &po.OrderReq{
|
||||||
o := &po.OrderReq{
|
|
||||||
OutBizNo: order.OrderNo,
|
OutBizNo: order.OrderNo,
|
||||||
TransAmount: order.Amount,
|
TransAmount: order.Amount,
|
||||||
ProductCode: "STD_RED_PACKET",
|
ProductCode: "STD_RED_PACKET",
|
||||||
|
@ -92,8 +92,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
||||||
Remark: productExtra.Wishing,
|
Remark: productExtra.Wishing,
|
||||||
PayeeInfo: &payeeInfo,
|
PayeeInfo: &payeeInfo,
|
||||||
BusinessParams: `{"sub_biz_scene":"REDPACKET"}`,
|
BusinessParams: `{"sub_biz_scene":"REDPACKET"}`,
|
||||||
}
|
}, nil
|
||||||
return o, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func orderResp(request *proto.OrderRequest, resp *po.OrderResp) *proto.OrderResponse {
|
func orderResp(request *proto.OrderRequest, resp *po.OrderResp) *proto.OrderResponse {
|
||||||
|
|
|
@ -13,20 +13,9 @@ import (
|
||||||
"gitea.cdlsxd.cn/sdk/plugin/utils"
|
"gitea.cdlsxd.cn/sdk/plugin/utils"
|
||||||
"net/url"
|
"net/url"
|
||||||
"plugins/alipay_redpack/internal/po"
|
"plugins/alipay_redpack/internal/po"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isValidPhoneNumber(phoneNumber string) bool {
|
|
||||||
phoneRegex := `^1[34578]\d{9}$`
|
|
||||||
return regexp.MustCompile(phoneRegex).MatchString(phoneNumber)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isEmailValid(email string) bool {
|
|
||||||
var emailRegex = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
|
|
||||||
return emailRegex.MatchString(email)
|
|
||||||
}
|
|
||||||
|
|
||||||
func req(config *Config, req *po.Param) (url.Values, error) {
|
func req(config *Config, req *po.Param) (url.Values, error) {
|
||||||
var strToBeSigned strings.Builder
|
var strToBeSigned strings.Builder
|
||||||
uv := url.Values{}
|
uv := url.Values{}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
"golang.org/x/text/encoding/simplifiedchinese"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FileExists(filePath string) bool {
|
func FileExists(filePath string) bool {
|
||||||
|
@ -17,3 +18,13 @@ func ToChinese(s string) string {
|
||||||
encodedName, _, _ := transform.String(encoder, s)
|
encodedName, _, _ := transform.String(encoder, s)
|
||||||
return encodedName
|
return encodedName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsPhoneNumber(phoneNumber string) bool {
|
||||||
|
phoneRegex := `^1[34578]\d{9}$`
|
||||||
|
return regexp.MustCompile(phoneRegex).MatchString(phoneNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsEmail(email string) bool {
|
||||||
|
var emailRegex = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
|
||||||
|
return emailRegex.MatchString(email)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue