Skip to content

Commit

Permalink
v1.5.67
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Dec 17, 2021
1 parent d0dfc19 commit f759823
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 4 deletions.
4 changes: 3 additions & 1 deletion doc/wechat_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ wechat.V3DecryptScoreNotifyCipherText()
* 申请特约商户资金账单:`client.V3BillEcommerceFundFlowBill()`
* 下载账单:`client.V3BillDownLoadBill()`
* <font color='#07C160' size='4'>提现(服务商)</font>
* 待实现-[文档](https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter6_1.shtml)
* 特约商户余额提现:`client.V3Withdraw()`
* 查询特约商户提现状态:`client.V3WithdrawStatus()`
* 按日下载提现异常文件:`client.V3WithdrawDownloadErrBill()`
* <font color='#07C160' size='4'>微信支付分(公共API)</font>
* 创建支付分订单:`client.V3ScoreOrderCreate()`
* 查询支付分订单:`client.V3ScoreOrderQuery()`
Expand Down
7 changes: 5 additions & 2 deletions release_note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
(4) 微信V3:新增 client.V3PartnerTransferDetail()
(5) 微信V3:新增 client.V3PartnerTransferMerchantQuery()
(6) 微信V3:新增 client.V3PartnerTransferMerchantDetail()
(7) 微信V3:修改 V3TransferDetailQuery() => V3TransferDetail()
(8) 微信V3:修改 V3TransferMerchantDetailQuery() => V3TransferMerchantDetail()
(7) 微信V3:新增 client.V3Withdraw()
(8) 微信V3:新增 client.V3WithdrawStatus()
(9) 微信V3:新增 client.V3WithdrawDownloadErrBill()
(10) 微信V3:修改 V3TransferDetailQuery() => V3TransferDetail()
(11) 微信V3:修改 V3TransferMerchantDetailQuery() => V3TransferMerchantDetail()

版本号:Release 1.5.66
修改记录:
Expand Down
1 change: 1 addition & 0 deletions wechat/v3/applyment_for_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (c *ClientV3) V3EcommerceApply(ctx context.Context, bm gopay.BodyMap) (*Eco
}

// 查询申请状态API
// 注意:applyId 和 outRequestNo 二选一
// Code = 0 is success
// 电商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_2.shtml
func (c *ClientV3) V3EcommerceApplyStatus(ctx context.Context, applyId int64, outRequestNo string) (*EcommerceApplyStatusRsp, error) {
Expand Down
4 changes: 4 additions & 0 deletions wechat/v3/bill.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

// 申请交易账单API
// 注意:如 bill_date 为空,默认查前一天的
// Code = 0 is success
// 商户文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_6.shtml
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_6.shtml
Expand Down Expand Up @@ -49,6 +50,7 @@ func (c *ClientV3) V3BillTradeBill(ctx context.Context, bm gopay.BodyMap) (wxRsp
}

// 申请资金账单API
// 注意:如 bill_date 为空,默认查前一天的
// Code = 0 is success
// 商户文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_7.shtml
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_7.shtml
Expand Down Expand Up @@ -84,6 +86,7 @@ func (c *ClientV3) V3BillFundFlowBill(ctx context.Context, bm gopay.BodyMap) (wx
}

// 申请特约商户资金账单API
// 注意:如 bill_date 为空,默认查前一天的
// Code = 0 is success
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter7_2.shtml
func (c *ClientV3) V3BillEcommerceFundFlowBill(ctx context.Context, bm gopay.BodyMap) (wxRsp *EcommerceFundFlowBillRsp, err error) {
Expand Down Expand Up @@ -124,6 +127,7 @@ func (c *ClientV3) V3BillEcommerceFundFlowBill(ctx context.Context, bm gopay.Bod
}

// 申请单个子商户资金账单API
// 注意:如 bill_date 为空,默认查前一天的
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_12.shtml
func (c *ClientV3) V3BillSubFundFlowBill(ctx context.Context, bm gopay.BodyMap) (wxRsp *BillRsp, err error) {
Expand Down
14 changes: 14 additions & 0 deletions wechat/v3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,17 @@ func TestV3GoldPlanFilterManage(t *testing.T) {
}
xlog.Debugf("wxRsp: %#v", wxRsp)
}

func TestV3Withdraw(t *testing.T) {
bm := make(gopay.BodyMap)
bm.Set("sub_mchid", "2021060717").
Set("out_request_no", "123456").
Set("amount", 1000)

wxRsp, err := client.V3Withdraw(ctx, bm)
if err != nil {
xlog.Error(err)
return
}
xlog.Debugf("wxRsp: %#v", wxRsp)
}
40 changes: 40 additions & 0 deletions wechat/v3/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,22 @@ type GoldPlanManageRsp struct {
Error string `json:"-"`
}

// 特约商户余额提现 Rsp
type WithdrawRsp struct {
Code int `json:"-"`
SignInfo *SignInfo `json:"-"`
Response *Withdraw `json:"response,omitempty"`
Error string `json:"-"`
}

// 查询特约商户提现状态 Rsp
type WithdrawStatusRsp struct {
Code int `json:"-"`
SignInfo *SignInfo `json:"-"`
Response *WithdrawStatus `json:"response,omitempty"`
Error string `json:"-"`
}

// ==================================分割==================================

type JSAPIPayParams struct {
Expand Down Expand Up @@ -2301,3 +2317,27 @@ type AuditDetail struct {
type GoldPlanManage struct {
SubMchid string `json:"sub_mchid"`
}

type Withdraw struct {
SubMchid string `json:"sub_mchid"` // 服务商特约商户号,由微信支付生成并下发。
WithdrawId string `json:"withdraw_id"` // 微信支付提现单号
AccountType string `json:"account_type,omitempty"` // 出款账户类型
}

type WithdrawStatus struct {
SubMchid string `json:"sub_mchid"` // 服务商特约商户号,由微信支付生成并下发。
SpMchid string `json:"sp_mchid"` // 服务商户号
Status string `json:"status"` // 提现单状态:CREATE_SUCCESS:受理成功,SUCCESS:提现成功,FAIL:提现失败,REFUND:提现退票,CLOSE:关单,INIT:业务单已创建
WithdrawId string `json:"withdraw_id"` // 微信支付提现单号
OutRequestNo string `json:"out_request_no"` // 商户提现单号
Amount int `json:"amount"` // 提现金额
CreateTime string `json:"create_time"` // 创建时间
UpdateTime string `json:"update_time"` // 更新时间
reason string `json:"reason"` // 提现失败原因,仅在提现失败、退票、关单时有值
Remark string `json:"remark"` // 商户对提现单的备注,若发起提现时未传入相应值或输入不合法,则该值为空
BankMemo string `json:"bank_memo"` // 展示在收款银行系统中的附言,由数字、字母、汉字组成(能否成功展示依赖银行系统支持)。若发起提现时未传入相应值或输入不合法,则该值为空
AccountType string `json:"account_type"` // 出款账户类型
AccountNumber string `json:"account_number"` // 服务商提现入账的银行账号,仅显示后四位。
AccountBank string `json:"account_bank"` // 服务商提现入账的开户银行
BankName string `json:"bank_name"` // 服务商提现入账的开户银行全称(含支行)
}
108 changes: 107 additions & 1 deletion wechat/v3/withdraw.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
package wechat

// 提现
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/go-pay/gopay"
"github.com/go-pay/gopay/pkg/util"
)

// 特约商户余额提现API
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter6_1.shtml
func (c *ClientV3) V3Withdraw(ctx context.Context, bm gopay.BodyMap) (*WithdrawRsp, error) {
authorization, err := c.authorization(MethodPost, v3Withdraw, bm)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdPost(ctx, bm, v3Withdraw, authorization)
if err != nil {
return nil, err
}

wxRsp := &WithdrawRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(Withdraw)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询特约商户提现状态API
// 注意:withdrawId 和 outRequestNo 二选一
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter6_2.shtml
func (c *ClientV3) V3WithdrawStatus(ctx context.Context, withdrawId, outRequestNo string, bm gopay.BodyMap) (*WithdrawStatusRsp, error) {
if withdrawId == gopay.NULL && outRequestNo == gopay.NULL {
return nil, fmt.Errorf("withdrawId[%s] and outRequestNo[%s] empty at the same time", withdrawId, outRequestNo)
}
var uri string
if withdrawId != gopay.NULL {
uri = fmt.Sprintf(v3WithdrawStatusById, withdrawId) + "?" + bm.EncodeURLParams()
} else {
uri = fmt.Sprintf(v3WithdrawStatusByNo, outRequestNo) + "?" + bm.EncodeURLParams()
}
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
wxRsp := &WithdrawStatusRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(WithdrawStatus)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 按日下载提现异常文件API
// 注意:如 bill_date 为空,默认查前一天的
// Code = 0 is success
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter6_3.shtml
func (c *ClientV3) V3WithdrawDownloadErrBill(ctx context.Context, bm gopay.BodyMap) (wxRsp *BillRsp, err error) {
if bm != nil {
if bm.GetString("bill_date") == util.NULL {
now := time.Now()
yesterday := time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, time.Local).Format(util.DateLayout)
bm.Set("bill_date", yesterday)
}
bm.Remove("bill_type")
}
uri := fmt.Sprintf(v3WithdrawDownloadErrBill, "NO_SUCC") + "?" + bm.EncodeURLParams()
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, uri, authorization)
if err != nil {
return nil, err
}

wxRsp = &BillRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(TradeBill)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

0 comments on commit f759823

Please sign in to comment.