-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4e6360
commit f541879
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: "[email protected]", | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |