Skip to content

Commit

Permalink
add V3 transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbit committed Aug 18, 2022
1 parent ddd9d03 commit 3d10a34
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 17 deletions.
112 changes: 112 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,115 @@
- 请求参数: 应用退款结果URL收到的POST Body内容
- 响应结果:
- 参考校验支付支付结果

1. V3版商家转账到零钱
- 对应配置项: `v3-transfer`
- 访问方法: POST
- URI: 直接根据配置值访问,如`/v3/transfer`
- **[注意]** 该接口配置成一个内网可以访问的API
- 本接口只是“发出转账申请”,成功申请后需要在后台审核确认才能转出零钱
- 请求参数

```json
{
"payApp": "go-wxpay-gateway配置文件中的应用名",
"appId": "应用的appId",
"batchNo": "本次转账的批次,应用内唯一",
"batchName": "批次名称",
"batchRemark": "批次描述",
"details": [
{
"tradeNo": "批次内唯一交易id",
"amount": 30, // 金额,单位"",
"desc": "描述",
"openId": "收款人在appId内的openId",
"userName": "2000以上,必须给收款人实名"
},
{...}
]
}
```

- 响应结果

```json
{
"code": 200,
"msg": "OK",
"result":{
"wxBatchId":"1030000040101068797782022081801027450232" // 微信批次id
}
}
```

1. V3版商家批次查询
- 对应配置项: `v3-query-transfer`
- 访问方法: POST
- URI: 直接根据配置值访问,如`/v3/query-transfer`
- **[注意]** 该接口配置成一个内网可以访问的API
- 请求参数

```json
{
"payApp": "go-wxpay-gateway配置文件中的应用名",
"status": "查询的状态值", // "ALL" | "SUCCESS" | "FAIL", 不给用ALL
"needDetail": true, // 是否展示详情
"wxBatchId": "转账申请成功返回的微信批次id"
"------ or -----": "或者",
"batchNo": "转账的批次,应用内唯一"
}
```

- 响应结果

```json
{
"code": 200,
"msg": "OK",
"result":{
"status":"FINISHED",
"total": 1, // 数目
"details": [
{
"detail_id":"1040000040101068797782022081801020503999", // 微信详情id
"out_detail_no":"tt202208170001", // 对应自己的tradeNo
"detail_status":"SUCCESS" // 详情状态
}
]
}
}
```

1. V3版商家转账详情查询
- 对应配置项: `v3-query-transfer-detail`
- 访问方法: POST
- URI: 直接根据配置值访问,如`/v3/query-transfer-detail`
- **[注意]** 该接口配置成一个内网可以访问的API
- 请求参数

```json
{
"payApp": "go-wxpay-gateway配置文件中的应用名",
"wxBatchId": "转账申请成功返回的微信批次id",
"wxDetailId": "批次查询时返回的微信详情id",
"------ or -----": "或者",
"batchNo": "转账的批次,应用内唯一",
"tradeNo": "转账时详情的唯一id"
}
```

- 响应结果

```json
{
"code": 200,
"msg": "OK",
"result":{
"detail_status":"SUCCESS", // 详情状态
"amount": 30, // 金额,单位分
"remark": "转账时的备注",
"reason": "失败原因。如果成功,返回空"
}
}
```
8 changes: 8 additions & 0 deletions conf/conf-gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"close-order": "/close-order",
"transfer": "/transfer",
"query-transfer": "/query-transfer",
"v3-transfer": "/v3/transfer",
"v3-query-transfer": "/v3/query-transfer",
"v3-query-transfer-detail": "/v3/query-transfer-detail",
"realname-auth-root": "/realname/auth -- will be replaced with ${realname-auth-root}/:op {url|identity|getinfo}",
"verify-notify-pay": "/verify-notify-pay",
"verify-notify-refund": "/verify-notify-refund"
Expand All @@ -33,6 +36,7 @@
"mch-cert-pem-file": "your-cert-pem-file-name, only used when refunding",
"mch-key-pem-file": "your-key-pem-file-name, only used when refunding",
"mch-cert-serialno": "optional, only used when real-name getinfo",
"wxpay-v3-cert": "optional, only used for batch-transfer",
"receipt": true
}
],
Expand Down Expand Up @@ -73,6 +77,9 @@ type EndpointConf struct {
QueryOrder string `json:"query-order"`
CloseOrder string `json:"close-order"`
Transfer string `json:"transfer"`
V3Transfer string `json:"v3-transfer"`
V3QueryTransfer string `json:"v3-query-transfer"`
V3QueryTransferDetail string `json:"v3-query-transfer-detail"`
QueryTransfer string `json:"query-transfer"`
RealnameAuthRoot string `json:"realname-auth-root"`
VerifyNotifyPay string `json:"verify-notify-pay"`
Expand All @@ -86,6 +93,7 @@ type MerchantConf struct {
MchCertPemFile string `json:"mch-cert-pem-file"`
MchKeyPemFile string `json:"mch-key-pem-file"`
MchCertSerialNo string `json:"mch-cert-serialno"`
WxpayV3Cert string `json:"wxpay-v3-cert"`
Receipt bool `json:"receipt"`
}

Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ go 1.12

require (
github.com/beevik/etree v1.1.0
github.com/rosbit/gnet v0.0.3 // indirect
github.com/rosbit/gnet v0.0.10
github.com/rosbit/go-aes v0.0.1
github.com/rosbit/logmerger v0.0.1
github.com/rosbit/mgin v0.0.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
github.com/rosbit/mgin v0.0.1
github.com/wechatpay-apiv3/wechatpay-go v0.2.14
)
21 changes: 16 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
Expand All @@ -14,18 +19,22 @@ github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/mroth/weightedrand v0.4.1 h1:rHcbUBopmi/3x4nnrvwGJBhX9d0vk+KgoLUZeDP6YyI=
github.com/mroth/weightedrand v0.4.1/go.mod h1:3p2SIcC8al1YMzGhAIoXD+r9olo/g/cdJgAD905gyNE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rosbit/gnet v0.0.3 h1:N4k8+NlbqnoI3JIuxdyx7Qjg+j2gkcuT/dcPCjc3y+g=
github.com/rosbit/gnet v0.0.3/go.mod h1:4p58JSylqipqD061GlEB7pSjeU6qJwhxHpzW832KMZI=
github.com/rosbit/gnet v0.0.10 h1:zBFcCxtG3WDR9TPywsWb3Yb7WbP8YoQR2KatMuQSEk8=
github.com/rosbit/gnet v0.0.10/go.mod h1:4p58JSylqipqD061GlEB7pSjeU6qJwhxHpzW832KMZI=
github.com/rosbit/go-aes v0.0.1 h1:tmOiz5IO6pyQ35nrGClsSw0AAF8bCAZR5zIcK+Hd8uI=
github.com/rosbit/go-aes v0.0.1/go.mod h1:CyPYFnM8SsrEw2Hvz5QtDIaAQnxy/n8rHv8NR/7Lm5Y=
github.com/rosbit/logmerger v0.0.1/go.mod h1:wzp/9K8Zu6+onB3moySMgBgXHNlXDj81vHWixaUHes0=
github.com/rosbit/mgin v0.0.1 h1:jXtu0Bn7MrxLGKfhf1wVmuaeLZUN76w8e9jyUNvdh28=
github.com/rosbit/mgin v0.0.1/go.mod h1:Cio++agodWrwVHBmV5I5lHZ+fcFP9PGYITYNFoz2yF4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/wechatpay-apiv3/wechatpay-go v0.2.14 h1:wLg8Yr4/LrCbUdRL2cVTNwCnkJB/7IXj8MKoiI+Q7DY=
github.com/wechatpay-apiv3/wechatpay-go v0.2.14/go.mod h1:jZzgos/NDEbnH1WFWOIa4wvcie3lqz1hZ4Z0O34Ntsk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand All @@ -37,7 +46,9 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build:
@if [ "$o" == "macos" ]; then \
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X 'main.buildTime=`TZ=UTC-8 date '+%F %T'`' -X 'main.osInfo=`uname -sr`' -X 'main.goInfo=`go version`' -extldflags -static"; \
elif [ "$s" == "static" ]; then \
go build -ldflags "-X 'main.buildTime=`TZ=UTC-8 date '+%F %T'`' -X 'main.osInfo=`uname -sr`' -X 'main.goInfo=`go version`' -linkmode external -extldflags -static" -tags $t -o go-wxpay-$t; \
go build -ldflags "-X 'main.buildTime=`TZ=UTC-8 date '+%F %T'`' -X 'main.osInfo=`uname -sr`' -X 'main.goInfo=`go version`' -linkmode external -extldflags -static" -tags "$t timetzdata" -o go-wxpay-$t; \
else \
go build -ldflags "-X 'main.buildTime=`TZ=UTC-8 date '+%F %T'`' -X 'main.osInfo=`uname -sr`' -X 'main.goInfo=`go version`'"; \
fi
12 changes: 9 additions & 3 deletions rest/rest-close-order.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
)

// POST /queryorder
// POST /closeorder
// POST Body:
// {
// "appId": "appId of mp/mini-prog",
Expand Down Expand Up @@ -39,13 +39,19 @@ func CloseOrder(c *mgin.Context) {
return
}

sent, recv, err := wxpay.CloseOrder(
res, sent, recv, err := wxpay.CloseOrder(
closeParam.AppId,
mchConf.MchId,
mchConf.MchApiKey,
closeParam.OrderId,
isSandbox,
)
sendResultWithMsg(c, closeParam.Debug, sent, recv, err)
if err != nil {
sendResultWithMsg(c, closeParam.Debug, sent, recv, err)
return
}
sendResultWithMsg(c, closeParam.Debug, sent, recv, nil, map[string]interface{}{
"result": res,
})
}

80 changes: 80 additions & 0 deletions rest/v3-rest-query-transfer-detail.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package rest

import (
"github.com/rosbit/mgin"
"go-wxpay-gateway/v3"
"fmt"
"net/http"
)

// POST /v3/query-transfer-detail
// POST Body:
// {
// "payApp": "name-of-app-in-wxpay-gateway",
//
// "wxBatchId": "wx-batchid",
// "wxDetailId": "wx-detailid"
// ---- or ---
// "batchNo": "unique-bach-no",
// "tradeNo": "unique-trade-no"
// }
func V3QueryTransferDetail(c *mgin.Context) {
var params struct {
PayApp string

WxBatchId string
WxDetailId string
// ---- or ----
BatchNo string
TradeNo string
}

if code, err := c.ReadJSON(&params); err != nil {
c.Error(code, err.Error())
return
}
if len(params.WxBatchId) == 0 && len(params.BatchNo) == 0 {
c.Error(http.StatusBadRequest, "wxBatchId or batchNo expected")
return
}

var queryTransferDetail v3.FnQueryTransferDetail
var batchNo, tradeNo string
if len(params.WxBatchId) > 0 {
if len(params.WxDetailId) == 0 {
c.Error(http.StatusBadRequest, "wxDetailId expected")
return
}
queryTransferDetail, batchNo, tradeNo = v3.QueryTransferDetailByWxBatchId, params.WxBatchId, params.WxDetailId
} else {
if len(params.TradeNo) == 0 {
c.Error(http.StatusBadRequest, "tradeNo expected")
return
}
queryTransferDetail, batchNo, tradeNo = v3.QueryTransferDetailByBatchNo, params.BatchNo, params.TradeNo
}

res, err := queryTransferDetail(params.PayApp, batchNo, tradeNo)
if err != nil {
sendResultWithMsg(c, false, nil, nil, err)
return
}
fmt.Printf("res: %v\n", res)

c.JSON(http.StatusOK, map[string]interface{}{
"code": http.StatusOK,
"msg": "OK",
"result": map[string]interface{}{
"status": *res.DetailStatus,
"amount": *res.TransferAmount,
"remark": *res.TransferRemark,
"reason": func()string{
if res.FailReason == nil {
return ""
}
return string(*res.FailReason)
}(),
},
})
}

Loading

0 comments on commit 3d10a34

Please sign in to comment.