- update wechatpayapiv3

master
李光春 1 year ago
parent db94671bbe
commit 62b012ce37

@ -0,0 +1,53 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
"time"
)
type TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResponse struct {
Mchid string `json:"mchid"` // 微信支付分配的商户号
OutBatchNo string `json:"out_batch_no"` // 商户系统内部的商家批次单号,在商户系统内部唯一
BatchId string `json:"batch_id"` // 微信批次单号,微信商家转账系统返回的唯一标识
Appid string `json:"appid"` // 申请商户号的appid或商户号绑定的appid企业号corpid即为此appid
OutDetailNo string `json:"out_detail_no"` // 商户系统内部区分转账批次单下不同转账明细单的唯一标识
DetailId string `json:"detail_id"` // 微信支付系统内部区分转账批次单下不同转账明细单的唯一标识
DetailStatus string `json:"detail_status"` // INIT: 初始态。 系统转账校验中 WAIT_PAY: 待确认。待商户确认, 符合免密条件时, 系统会自动扭转为转账中 PROCESSING:转账中。正在处理中,转账结果尚未明确 SUCCESS:转账成功 FAIL:转账失败。需要确认失败原因后,再决定是否重新发起对该笔明细单的转账(并非整个转账批次单)
TransferAmount int `json:"transfer_amount"` // 转账金额单位为“分”
TransferRemark string `json:"transfer_remark"` // 单条转账备注微信用户会收到该备注UTF8编码最多允许32个字符
FailReason string `json:"fail_reason"` // 如果转账失败则有失败原因
Openid string `json:"openid"` // 商户appid下某用户的openid
UserName string `json:"user_name"` // 收款方姓名。采用标准RSA算法公钥由微信侧提供 商户转账时传入了收款用户姓名、查询时会返回收款用户姓名
InitiateTime time.Time `json:"initiate_time"` // 转账发起的时间按照使用rfc3339所定义的格式格式为YYYY-MM-DDThh:mm:ss+TIMEZONE
UpdateTime time.Time `json:"update_time"` // 明细最后一次状态变更的时间按照使用rfc3339所定义的格式格式为YYYY-MM-DDThh:mm:ss+TIMEZONE
}
type TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult struct {
Result TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newTransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult(result TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResponse, body []byte, http gorequest.Response, err error) *TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult {
return &TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult{Result: result, Body: body, Http: http, Err: err}
}
// TransferBatchesBatchIdBatchIdDetailsDetailIdDetailId 通过微信明细单号查询明细单
// https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-detail/get-transfer-detail-by-no.html
func (c *Client) TransferBatchesBatchIdBatchIdDetailsDetailIdDetailId(ctx context.Context, batchId string, detailId string) *TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(ctx, apiUrl+"/v3/transfer/batches/batch-id/"+batchId+"details/detail-id/"+detailId, params, http.MethodGet, false)
if err != nil {
return newTransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult(TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResponse{}, request.ResponseBody, request, err)
}
// 定义
var response TransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newTransferBatchesBatchIdBatchIdDetailsDetailIdDetailIdResult(response, request.ResponseBody, request, err)
}

@ -0,0 +1,63 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type TransferBatchesBatchIdBatchIdResponse 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 TransferBatchesBatchIdBatchIdResult struct {
Result TransferBatchesBatchIdBatchIdResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newTransferBatchesBatchIdBatchIdResult(result TransferBatchesBatchIdBatchIdResponse, body []byte, http gorequest.Response, err error) *TransferBatchesBatchIdBatchIdResult {
return &TransferBatchesBatchIdBatchIdResult{Result: result, Body: body, Http: http, Err: err}
}
// TransferBatchesBatchIdBatchId 通过微信批次单号查询批次单
// https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch/get-transfer-batch-by-no.html
func (c *Client) TransferBatchesBatchIdBatchId(ctx context.Context, batchId string, notMustParams ...gorequest.Params) *TransferBatchesBatchIdBatchIdResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/v3/transfer/batches/batch-id/"+batchId, params, http.MethodGet, false)
if err != nil {
return newTransferBatchesBatchIdBatchIdResult(TransferBatchesBatchIdBatchIdResponse{}, request.ResponseBody, request, err)
}
// 定义
var response TransferBatchesBatchIdBatchIdResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newTransferBatchesBatchIdBatchIdResult(response, request.ResponseBody, request, err)
}

@ -1,53 +0,0 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
"time"
)
type TransferBatchesBatchIdDetailsDetailIdResponse struct {
Mchid string `json:"mchid"` // 商户号
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 TransferBatchesBatchIdDetailsDetailIdResult struct {
Result TransferBatchesBatchIdDetailsDetailIdResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newTransferBatchesBatchIdDetailsDetailIdResult(result TransferBatchesBatchIdDetailsDetailIdResponse, body []byte, http gorequest.Response, err error) *TransferBatchesBatchIdDetailsDetailIdResult {
return &TransferBatchesBatchIdDetailsDetailIdResult{Result: result, Body: body, Http: http, Err: err}
}
// TransferBatchesBatchIdDetailsDetailId 微信明细单号查询明细单API
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_3.shtml
func (c *Client) TransferBatchesBatchIdDetailsDetailId(ctx context.Context, batchId string, detailId string) *TransferBatchesBatchIdDetailsDetailIdResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(ctx, apiUrl+"/v3/transfer/batches/batch-id/"+batchId+"details/detail-id/"+detailId, params, http.MethodGet, false)
if err != nil {
return newTransferBatchesBatchIdDetailsDetailIdResult(TransferBatchesBatchIdDetailsDetailIdResponse{}, request.ResponseBody, request, err)
}
// 定义
var response TransferBatchesBatchIdDetailsDetailIdResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newTransferBatchesBatchIdDetailsDetailIdResult(response, request.ResponseBody, request, err)
}

@ -1,71 +0,0 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type TransferBatchesBatchIdResponse struct {
TransferBatch struct {
Mchid string `json:"mchid"` // 商户号
OutBatchNo string `json:"out_batch_no"` // 商家批次单号
BatchId string `json:"batch_id"` // 微信批次单号
Appid string `json:"appid"` // 直连商户的appid
BatchStatus string `json:"batch_status"` // 批次状态
BatchType string `json:"batch_type"` // 批次类型
BatchName string `json:"batch_name"` // 批次名称
BatchRemark string `json:"batch_remark"` // 批次备注
CloseReason string `json:"close_reason,omitempty"` // 批次关闭原因
TotalAmount int `json:"total_amount"` // 转账总金额
TotalNum int `json:"total_num"` // 转账总笔数
CreateTime string `json:"create_time"` // 批次创建时间
UpdateTime string `json:"update_time"` // 批次更新时间
SuccessAmount int `json:"success_amount"` // 转账成功金额
SuccessNum int `json:"success_num"` // 转账成功笔数
FailAmount int `json:"fail_amount"` // 转账失败金额
FailNum int `json:"fail_num"` // 转账失败笔数
} `json:"transfer_batch"` // 转账批次单
TransferDetailList []struct {
DetailId string `json:"detail_id"` // 微信明细单号
OutDetailNo string `json:"out_detail_no"` // 商家明细单号
DetailStatus string `json:"detail_status"` // 明细状态
} `json:"transfer_detail_list,omitempty"` // 转账明细单列表
Offset int `json:"offset,omitempty"` // 请求资源起始位置
Limit int `json:"limit,omitempty"` // 最大资源条数
}
type TransferBatchesBatchIdResult struct {
Result TransferBatchesBatchIdResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newTransferBatchesBatchIdResult(result TransferBatchesBatchIdResponse, body []byte, http gorequest.Response, err error) *TransferBatchesBatchIdResult {
return &TransferBatchesBatchIdResult{Result: result, Body: body, Http: http, Err: err}
}
// TransferBatchesBatchId 微信批次单号查询批次单API
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_2.shtml
func (c *Client) TransferBatchesBatchId(ctx context.Context, batchId string, needQueryDetail bool, offset, limit int, detailStatus string) *TransferBatchesBatchIdResult {
// 参数
params := gorequest.NewParams()
params.Set("batch_id", batchId)
params.Set("need_query_detail", needQueryDetail)
params.Set("offset", offset)
params.Set("limit", limit)
if needQueryDetail {
params.Set("detail_status", detailStatus)
}
// 请求
request, err := c.request(ctx, apiUrl+"/v3/transfer/batches/batch-id/"+batchId, params, http.MethodGet, false)
if err != nil {
return newTransferBatchesBatchIdResult(TransferBatchesBatchIdResponse{}, request.ResponseBody, request, err)
}
// 定义
var response TransferBatchesBatchIdResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newTransferBatchesBatchIdResult(response, request.ResponseBody, request, err)
}

@ -8,9 +8,9 @@ import (
)
type TransferBatchesResponse struct {
OutBatchNo string `json:"out_batch_no"` // 商家批次单号
BatchId string `json:"batch_id"` // 微信批次单号
CreateTime string `json:"create_time"` // 批次创建时间
OutBatchNo string `json:"out_batch_no"` // 商户系统内部的商家批次单号,在商户系统内部唯一
BatchId string `json:"batch_id"` // 微信批次单号,微信商家转账系统返回的唯一标识
CreateTime string `json:"create_time"` // 批次受理成功时返回按照使用rfc3339所定义的格式格式为YYYY-MM-DDThh:mm:ss+TIMEZONE
}
type TransferBatchesResult struct {
@ -24,8 +24,8 @@ func newTransferBatchesResult(result TransferBatchesResponse, body []byte, http
return &TransferBatchesResult{Result: result, Body: body, Http: http, Err: err}
}
// TransferBatches 发起商家转账API
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml
// TransferBatches 发起商家转账
// https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch/initiate-batch-transfer.html
func (c *Client) TransferBatches(ctx context.Context, notMustParams ...gorequest.Params) *TransferBatchesResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)

Loading…
Cancel
Save