Skip to content

Commit

Permalink
app transfer api 添加单笔转账接口 (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Madou-Shinni authored Jan 8, 2025
1 parent 0bf8314 commit 44486c2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
38 changes: 38 additions & 0 deletions alipay/v3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,41 @@ func TestDoAliPayAPISelfV3(t *testing.T) {
return
}
}

func TestClientV3_Transfer(t *testing.T) {
bm := make(gopay.BodyMap)
// 收款方信息
type PayeeInfo struct {
Identity string `json:"identity"` // 必选
IdentityType string `json:"identity_type"` // 必选
CertNo string `json:"cert_no"` // 可选
CertType string `json:"cert_type"` // 可选
Name string `json:"name"` // 可选
}
payeeInfo := &PayeeInfo{
Identity: "sjrngj9819@sandbox.com",
IdentityType: "ALIPAY_LOGON_ID",
Name: "sjrngj9819",
}

bm.Set("out_biz_no", util.RandomString(32)).
Set("trans_amount", "0.01").
Set("biz_scene", "DIRECT_TRANSFER").
Set("product_code", "TRANS_ACCOUNT_NO_PWD").
Set("order_title", "转账测试").
Set("payee_info", payeeInfo).
Set("remark", "转账测试").
Set("business_params", struct{}{})

res, err := client.Transfer(ctx, bm)
if err != nil {
xlog.Errorf("client.Transfer(), err:%v", err)
return
}

xlog.Debugf("aliRsp:%s", js.Marshal(res))
if res.StatusCode != Success {
xlog.Errorf("aliRsp.StatusCode:%d", res.StatusCode)
return
}
}
3 changes: 3 additions & 0 deletions alipay/v3/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ const (
v3MobileThreeMetaDetailCheck = "/v3/datadigital/fincloud/generalsaas/mobilethreemeta/detail/check" // 手机号三要素核验详版
v3OcrServerDetect = "/v3/datadigital/fincloud/generalsaas/ocr/server/detect" // 服务端OCR
v3OcrMobileInitialize = "/v3/datadigital/fincloud/generalsaas/ocr/mobile/initialize" // App端OCR初始化

// 转账
v3TransUniTransfer = "/v3/alipay/fund/trans/uni/transfer" // 单笔转账接口
)
61 changes: 61 additions & 0 deletions alipay/v3/transfer_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package alipay

import (
"context"
"encoding/json"
"fmt"
"github.com/go-pay/gopay"
"net/http"
)

// PayeeInfo 收款方信息
type PayeeInfo struct {
Identity string `json:"identity,omitempty"` // 必选
IdentityType string `json:"identity_type,omitempty"` // 必选
CertNo string `json:"cert_no,omitempty"` // 可选
CertType string `json:"cert_type,omitempty"` // 可选
Name string `json:"name,omitempty"` // 可选
}

type TransferRsp struct {
StatusCode int `json:"status_code"`
ErrResponse ErrResponse `json:"-"`

OutBizNo string `json:"out_biz_no"` // 商户订单号
OrderId string `json:"order_id"` // 支付宝转账订单号
PayFundOrderId string `json:"pay_fund_order_id"` // 支付宝支付资金流水号
TransDate string `json:"trans_date"` // 订单支付时间
Status string `json:"status"`
}

// Transfer 单笔转账接口
// StatusCode = 200 is success
func (a *ClientV3) Transfer(ctx context.Context, bm gopay.BodyMap) (aliRsp *TransferRsp, err error) {
err = bm.CheckEmptyError("out_biz_no", "trans_amount", "product_code", "biz_scene", "payee_info", "order_title")
if err != nil {
return nil, err
}

authorization, err := a.authorization(MethodPost, v3TransUniTransfer, bm)
if err != nil {
return nil, err
}

res, bs, err := a.doPost(ctx, bm, v3TransUniTransfer, authorization)
if err != nil {
return nil, err
}

aliRsp = &TransferRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}

if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

0 comments on commit 44486c2

Please sign in to comment.