支付宝转账
This commit is contained in:
parent
0c7aeececa
commit
1c0a06f612
|
@ -44,7 +44,7 @@ func (s *AlipayRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
|||
return nil, err
|
||||
}
|
||||
var response po.OrderResp
|
||||
err = requests.URL(c.BaseUri).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||
err = requests.URL(c.BaseUri).Post().BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
|
|
@ -23,13 +23,23 @@ func config() []byte {
|
|||
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: "240403164049635931",
|
||||
OrderNo: "lsxd202306071545141533",
|
||||
Account: "18666173766",
|
||||
Extra: []byte(``),
|
||||
Quantity: 1,
|
||||
Amount: 0.01,
|
||||
Extra: []byte(`{"name":"李子铭"}`),
|
||||
},
|
||||
Product: &proto.OrderRequest_Product{
|
||||
ProductNo: "",
|
||||
|
@ -43,7 +53,7 @@ func TestOrder(t *testing.T) {
|
|||
t.Errorf("Order() error = %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%+v", got)
|
||||
fmt.Printf("%s", got.String())
|
||||
assert.Equal(t, int(proto.Status_ING), int(got.Result.Status))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
type PayeeInfo struct {
|
||||
Identity string `validate:"required" json:"identity"`
|
||||
IdentityType string `validate:"required" json:"identity_type"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type BusinessParams struct {
|
||||
|
|
|
@ -57,35 +57,50 @@ func (c *Config) paramReq(req po.Req, method string) (*po.Param, error) {
|
|||
}
|
||||
|
||||
func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Product) (*po.OrderReq, error) {
|
||||
type Extra struct {
|
||||
type ProductExtra struct {
|
||||
Wishing string `json:"wishing"`
|
||||
}
|
||||
var extra Extra
|
||||
var productExtra ProductExtra
|
||||
if product.Extra != nil {
|
||||
err := json.Unmarshal(product.Extra, &extra)
|
||||
err := json.Unmarshal(product.Extra, &productExtra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("product extra json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
payeeInfo := &po.PayeeInfo{
|
||||
payeeInfo := po.PayeeInfo{
|
||||
Identity: order.Account,
|
||||
IdentityType: "ALIPAY_USER_ID",
|
||||
}
|
||||
if isValidPhoneNumber(order.Account) {
|
||||
type OrderExtra struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
var orderExtra OrderExtra
|
||||
if product.Extra != nil {
|
||||
err := json.Unmarshal(order.Extra, &orderExtra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
if orderExtra.Name == "" {
|
||||
return nil, fmt.Errorf("姓名,当identity_type=ALIPAY_LOGON_ID时,本字段必填")
|
||||
}
|
||||
payeeInfo.IdentityType = "ALIPAY_LOGON_ID"
|
||||
payeeInfo.Name = orderExtra.Name
|
||||
}
|
||||
businessParams := &po.BusinessParams{
|
||||
SubBizScene: "REDPACKET",
|
||||
}
|
||||
|
||||
o := &po.OrderReq{
|
||||
OutBizNo: order.OrderNo,
|
||||
TransAmount: fmt.Sprintf("%.2f", order.Amount),
|
||||
ProductCode: product.ProductNo,
|
||||
ProductCode: "STD_RED_PACKET",
|
||||
BizScene: "DIRECT_TRANSFER",
|
||||
OrderTitle: extra.Wishing,
|
||||
Remark: extra.Wishing,
|
||||
PayeeInfo: payeeInfo,
|
||||
OrderTitle: productExtra.Wishing,
|
||||
Remark: productExtra.Wishing,
|
||||
PayeeInfo: &payeeInfo,
|
||||
BusinessParams: businessParams.ToString(),
|
||||
}
|
||||
return o, nil
|
||||
|
|
Loading…
Reference in New Issue