From 5c3083a996eb5b3368a37f9ebf6f54ff3ae11ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Tue, 21 Feb 2023 10:06:33 +0800 Subject: [PATCH] - update wechatpayapiv3 --- ...ches.out-batch-no.details.out-detail-no.go | 52 --------------- ...nsfer.batches.out-batch-no.out_batch_no.go | 63 +++++++++++++++++++ 2 files changed, 63 insertions(+), 52 deletions(-) delete mode 100644 service/wechatpayapiv3/transfer.batches.out-batch-no.details.out-detail-no.go create mode 100644 service/wechatpayapiv3/transfer.batches.out-batch-no.out_batch_no.go diff --git a/service/wechatpayapiv3/transfer.batches.out-batch-no.details.out-detail-no.go b/service/wechatpayapiv3/transfer.batches.out-batch-no.details.out-detail-no.go deleted file mode 100644 index f8def5d9..00000000 --- a/service/wechatpayapiv3/transfer.batches.out-batch-no.details.out-detail-no.go +++ /dev/null @@ -1,52 +0,0 @@ -package wechatpayapiv3 - -import ( - "context" - "encoding/json" - "github.com/dtapps/go-library/utils/gorequest" - "net/http" - "time" -) - -type TransferBatchesOutBatchNoDetailsOutDetailResponse struct { - OutBatchNo string `json:"out_batch_no"` // 商家批次单号 - BatchId string `json:"batch_id"` // 微信批次单号 - Appid string `json:"appid"` // 直连商户的appid - OutDetailNo string `json:"out_detail_no"` // 商家明细单号 - DetailId string `json:"detail_id"` // 微信明细单号 - DetailStatus string `json:"detail_status"` // 明细状态 - TransferAmount int `json:"transfer_amount"` // 转账金额 - TransferRemark string `json:"transfer_remark"` // 转账备注 - FailReason string `json:"fail_reason"` // 明细失败原因 - Openid string `json:"openid"` // 用户在直连商户应用下的用户标示 - UserName string `json:"user_name"` // 收款用户姓名 - InitiateTime time.Time `json:"initiate_time"` // 转账发起时间 - UpdateTime time.Time `json:"update_time"` // 明细更新时间 -} - -type TransferBatchesOutBatchNoDetailsOutDetailResult struct { - Result TransferBatchesOutBatchNoDetailsOutDetailResponse // 结果 - Body []byte // 内容 - Http gorequest.Response // 请求 - Err error // 错误 -} - -func newTransferBatchesOutBatchNoDetailsOutDetailResult(result TransferBatchesOutBatchNoDetailsOutDetailResponse, body []byte, http gorequest.Response, err error) *TransferBatchesOutBatchNoDetailsOutDetailResult { - return &TransferBatchesOutBatchNoDetailsOutDetailResult{Result: result, Body: body, Http: http, Err: err} -} - -// TransferBatchesOutBatchNoDetailsOutDetail 商家明细单号查询明细单API -// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_6.shtml -func (c *Client) TransferBatchesOutBatchNoDetailsOutDetail(ctx context.Context, outBatchNo string, outDetailNo string) *TransferBatchesOutBatchNoDetailsOutDetailResult { - // 参数 - params := gorequest.NewParams() - // 请求 - request, err := c.request(ctx, apiUrl+"/v3/transfer/batches/out-batch-no/"+outBatchNo+"details/out-detail-no//"+outDetailNo, params, http.MethodGet, false) - if err != nil { - return newTransferBatchesOutBatchNoDetailsOutDetailResult(TransferBatchesOutBatchNoDetailsOutDetailResponse{}, request.ResponseBody, request, err) - } - // 定义 - var response TransferBatchesOutBatchNoDetailsOutDetailResponse - err = json.Unmarshal(request.ResponseBody, &response) - return newTransferBatchesOutBatchNoDetailsOutDetailResult(response, request.ResponseBody, request, err) -} diff --git a/service/wechatpayapiv3/transfer.batches.out-batch-no.out_batch_no.go b/service/wechatpayapiv3/transfer.batches.out-batch-no.out_batch_no.go new file mode 100644 index 00000000..6e5cf932 --- /dev/null +++ b/service/wechatpayapiv3/transfer.batches.out-batch-no.out_batch_no.go @@ -0,0 +1,63 @@ +package wechatpayapiv3 + +import ( + "context" + "encoding/json" + "github.com/dtapps/go-library/utils/gorequest" + "net/http" +) + +type TransferBatchesOutBatchNoOutBatchNoResponse struct { + TransferBatch struct { + Mchid string `json:"mchid"` // 微信支付分配的商户号 + OutBatchNo string `json:"out_batch_no"` // 商户系统内部的商家批次单号,在商户系统内部唯一 + BatchId string `json:"batch_id"` // 微信批次单号,微信商家转账系统返回的唯一标识 + Appid string `json:"appid"` // 申请商户号的appid或商户号绑定的appid(企业号corpid即为此appid) + BatchStatus string `json:"batch_status"` // WAIT_PAY: 待付款确认。需要付款出资商户在商家助手小程序或服务商助手小程序进行付款确认 ACCEPTED:已受理。批次已受理成功,若发起批量转账的30分钟后,转账批次单仍处于该状态,可能原因是商户账户余额不足等。商户可查询账户资金流水,若该笔转账批次单的扣款已经发生,则表示批次已经进入转账中,请再次查单确认 PROCESSING:转账中。已开始处理批次内的转账明细单 FINISHED:已完成。批次内的所有转账明细单都已处理完成 CLOSED:已关闭。可查询具体的批次关闭原因确认 + BatchType string `json:"batch_type"` // API:API方式发起 WEB:页面方式发起 + BatchName string `json:"batch_name"` // 该笔批量转账的名称 + BatchRemark string `json:"batch_remark"` // 转账说明,UTF8编码,最多允许32个字符 + CloseReason string `json:"close_reason,omitempty"` // 如果批次单状态为“CLOSED”(已关闭),则有关闭原因 + TotalAmount int `json:"total_amount"` // 转账金额单位为“分” + TotalNum int `json:"total_num"` // 一个转账批次单最多发起三千笔转账 + CreateTime string `json:"create_time"` // 批次受理成功时返回,按照使用rfc3339所定义的格式,格式为YYYY-MM-DDThh:mm:ss+TIMEZONE + UpdateTime string `json:"update_time"` // 批次最近一次状态变更的时间,按照使用rfc3339所定义的格式,格式为YYYY-MM-DDThh:mm:ss+TIMEZONE + SuccessAmount int `json:"success_amount"` // 转账成功的金额,单位为“分”。当批次状态为“PROCESSING”(转账中)时,转账成功金额随时可能变化 + SuccessNum int `json:"success_num"` // 转账成功的笔数。当批次状态为“PROCESSING”(转账中)时,转账成功笔数随时可能变化 + FailAmount int `json:"fail_amount"` // 转账失败的金额,单位为“分” + FailNum int `json:"fail_num"` // 转账失败的笔数 + TransferSceneId string `json:"transfer_scene_id"` // 指定的转账场景ID + } `json:"transfer_batch"` // 转账批次单基本信息 + TransferDetailList []struct { + DetailId string `json:"detail_id"` // 微信支付系统内部区分转账批次单下不同转账明细单的唯一标识 + OutDetailNo string `json:"out_detail_no"` // 商户系统内部区分转账批次单下不同转账明细单的唯一标识 + DetailStatus string `json:"detail_status"` // INIT: 初始态。 系统转账校验中 WAIT_PAY: 待确认。待商户确认, 符合免密条件时, 系统会自动扭转为转账中 PROCESSING:转账中。正在处理中,转账结果尚未明确 SUCCESS:转账成功 FAIL:转账失败。需要确认失败原因后,再决定是否重新发起对该笔明细单的转账(并非整个转账批次单) + } `json:"transfer_detail_list,omitempty"` // 当批次状态为“FINISHED”(已完成),且成功查询到转账明细单时返回。包括微信明细单号、明细状态信息 +} + +type TransferBatchesOutBatchNoOutBatchNoResult struct { + Result TransferBatchesOutBatchNoOutBatchNoResponse // 结果 + Body []byte // 内容 + Http gorequest.Response // 请求 + Err error // 错误 +} + +func newTransferBatchesOutBatchNoOutBatchNoResult(result TransferBatchesOutBatchNoOutBatchNoResponse, body []byte, http gorequest.Response, err error) *TransferBatchesOutBatchNoOutBatchNoResult { + return &TransferBatchesOutBatchNoOutBatchNoResult{Result: result, Body: body, Http: http, Err: err} +} + +// TransferBatchesOutBatchNoOutBatchNo 通过商家批次单号查询批次单 +// https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch/get-transfer-batch-by-out-no.html +func (c *Client) TransferBatchesOutBatchNoOutBatchNo(ctx context.Context, outBatchNo string, notMustParams ...gorequest.Params) *TransferBatchesOutBatchNoOutBatchNoResult { + // 参数 + params := gorequest.NewParamsWith(notMustParams...) + // 请求 + request, err := c.request(ctx, apiUrl+"/v3/transfer/batches/out-batch-no/"+outBatchNo, params, http.MethodGet, false) + if err != nil { + return newTransferBatchesOutBatchNoOutBatchNoResult(TransferBatchesOutBatchNoOutBatchNoResponse{}, request.ResponseBody, request, err) + } + // 定义 + var response TransferBatchesOutBatchNoOutBatchNoResponse + err = json.Unmarshal(request.ResponseBody, &response) + return newTransferBatchesOutBatchNoOutBatchNoResult(response, request.ResponseBody, request, err) +}