- add transfer

master v1.0.8
李光春 2 years ago
parent 93e129d599
commit 17e1ef699c

@ -3,5 +3,5 @@ package wechatpayapiv3
const (
apiUrl = "https://api.mch.weixin.qq.com"
logTable = "wechatpayapiv3"
Version = "1.0.7"
Version = "1.0.8"
)

@ -78,7 +78,7 @@ require (
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c // indirect
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959 // indirect
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

@ -641,8 +641,8 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959 h1:qSa+Hg9oBe6UJXrznE+yYvW51V9UbyIj/nj/KpDigo8=
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd h1:AZeIEzg+8RCELJYq8w+ODLVxFgLMMigSwO/ffKPEd9U=
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

@ -0,0 +1,53 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"go.dtapp.net/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)
}

@ -0,0 +1,71 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"go.dtapp.net/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)
}

@ -0,0 +1,42 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
)
type TransferBatchesResponse struct {
OutBatchNo string `json:"out_batch_no"` // 商家批次单号
BatchId string `json:"batch_id"` // 微信批次单号
CreateTime string `json:"create_time"` // 批次创建时间
}
type TransferBatchesResult struct {
Result TransferBatchesResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newTransferBatchesResult(result TransferBatchesResponse, body []byte, http gorequest.Response, err error) *TransferBatchesResult {
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
func (c *Client) TransferBatches(ctx context.Context, notMustParams ...gorequest.Params) *TransferBatchesResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("appid", c.GetAppId())
// 请求
request, err := c.request(ctx, apiUrl+"/v3/transfer/batches", params, http.MethodPost, false)
if err != nil {
return newTransferBatchesResult(TransferBatchesResponse{}, request.ResponseBody, request, err)
}
// 定义
var response TransferBatchesResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newTransferBatchesResult(response, request.ResponseBody, request, err)
}

@ -0,0 +1,52 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"go.dtapp.net/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)
}

@ -0,0 +1,71 @@
package wechatpayapiv3
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
)
type TransferBatchesOutBatchNoResponse 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"` // 请求资源起始位置
Limit int `json:"limit"` // 最大资源条数
}
type TransferBatchesOutBatchNoResult struct {
Result TransferBatchesOutBatchNoResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newTransferBatchesOutBatchNoResult(result TransferBatchesOutBatchNoResponse, body []byte, http gorequest.Response, err error) *TransferBatchesOutBatchNoResult {
return &TransferBatchesOutBatchNoResult{Result: result, Body: body, Http: http, Err: err}
}
// TransferBatchesOutBatchNo 商家批次单号查询批次单API
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_5.shtml
func (c *Client) TransferBatchesOutBatchNo(ctx context.Context, outBatchNo string, needQueryDetail bool, offset, limit int, detailStatus string) *TransferBatchesOutBatchNoResult {
// 参数
params := gorequest.NewParams()
params.Set("out_batch_no", outBatchNo)
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/out-batch-no/"+outBatchNo, params, http.MethodGet, false)
if err != nil {
return newTransferBatchesOutBatchNoResult(TransferBatchesOutBatchNoResponse{}, request.ResponseBody, request, err)
}
// 定义
var response TransferBatchesOutBatchNoResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newTransferBatchesOutBatchNoResult(response, request.ResponseBody, request, err)
}
Loading…
Cancel
Save