- update request
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.4
李光春 2 years ago
parent cf20a688b0
commit fea0a50e99

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
@ -34,9 +35,9 @@ func newCertificatesResult(result CertificatesResponse, body []byte, http gorequ
// Certificates 获取平台证书列表
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/wechatpay5_1.shtml
func (c *Client) Certificates() *CertificatesResult {
func (c *Client) Certificates(ctx context.Context) *CertificatesResult {
// 请求
request, err := c.request(apiUrl+"/v3/certificates", map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/v3/certificates", map[string]interface{}{}, http.MethodGet)
if err != nil {
return newCertificatesResult(CertificatesResponse{}, request.ResponseBody, request, err)
}

@ -14,7 +14,7 @@ const (
// SDK 相关信息
const (
Version = "1.0.3" // SDK 版本
Version = "1.0.4" // SDK 版本
UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息
)

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -28,11 +29,11 @@ func newEcommerceFundBalanceResult(result EcommerceFundBalanceResponse, body []b
// EcommerceFundBalance 查询二级商户账户实时余额API
// accountType 账户类型 BASIC基本账户 OPERATION运营账户 FEES手续费账户
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_1.shtml
func (c *Client) EcommerceFundBalance(accountType string) *EcommerceFundBalanceResult {
func (c *Client) EcommerceFundBalance(ctx context.Context, accountType string) *EcommerceFundBalanceResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/ecommerce/fund/balance/%s?account_type=%s", c.config.SubMchId, accountType), params, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/ecommerce/fund/balance/%s?account_type=%s", c.config.SubMchId, accountType), params, http.MethodGet)
if err != nil {
return newEcommerceFundBalanceResult(EcommerceFundBalanceResponse{}, request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -27,11 +28,11 @@ func newEcommerceFundEndDayBalanceResult(result EcommerceFundEndDayBalanceRespon
// EcommerceFundEndDayBalance 查询二级商户账户日终余额API
// date 日期 示例值2019-08-17
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_2.shtml
func (c *Client) EcommerceFundEndDayBalance(date string) *EcommerceFundEndDayBalanceResult {
func (c *Client) EcommerceFundEndDayBalance(ctx context.Context, date string) *EcommerceFundEndDayBalanceResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/ecommerce/fund/enddaybalance/%s?date=%s", c.config.SubMchId, date), params, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/ecommerce/fund/enddaybalance/%s?date=%s", c.config.SubMchId, date), params, http.MethodGet)
if err != nil {
return newEcommerceFundEndDayBalanceResult(EcommerceFundEndDayBalanceResponse{}, request.ResponseBody, request, err)
}

@ -3,9 +3,9 @@ module go.dtapp.net/wechatpayopen
go 1.19
require (
go.dtapp.net/dorm v1.0.14
go.dtapp.net/dorm v1.0.17
go.dtapp.net/goip v1.0.24
go.dtapp.net/golog v1.0.21
go.dtapp.net/golog v1.0.22
go.dtapp.net/gorandom v1.0.1
go.dtapp.net/gorequest v1.0.24
gorm.io/gorm v1.23.8
@ -69,14 +69,14 @@ require (
go.dtapp.net/gotime v1.0.5 // indirect
go.dtapp.net/goxml v1.0.1 // indirect
go.mongodb.org/mongo-driver v1.10.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // 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

@ -185,7 +185,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk=
github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@ -212,7 +211,6 @@ github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5W
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
@ -468,7 +466,6 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
@ -503,14 +500,14 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.dtapp.net/dorm v1.0.14 h1:HDsaMwKGlKFKt59Y3hPI9aVnSjfXOyjoHw2uoXErKEo=
go.dtapp.net/dorm v1.0.14/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/dorm v1.0.17 h1:3VQKUl05CDxFg3T1c/M8wYf2I+H+oVGBDh4NCV30nn0=
go.dtapp.net/dorm v1.0.17/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/goip v1.0.24 h1:62k3xt9I/YLUwA5tLp7YC8XPskkswc4RJrvxRRxjwIY=
go.dtapp.net/goip v1.0.24/go.mod h1:tps0yoq5kSykLGDb01vuai47hzAQ6nYUPFWLdlQA2Oo=
go.dtapp.net/gojson v1.0.1 h1:MHeSGlq1KxzL7rCkm18fhwW4GNORHohdDMmxY5PupKY=
go.dtapp.net/gojson v1.0.1/go.mod h1:TkkpTNxHBKxul0e7gC5MrL1K4ICFB9mQ7wHzjBah3/k=
go.dtapp.net/golog v1.0.21 h1:pSGmDz3SJTH7M/NvVLZb+YJd8uNl5g18aORibuaY2JU=
go.dtapp.net/golog v1.0.21/go.mod h1:Wxm2Kh77JN5zFDZ72el9E9c/YkoJnOvHVusB7SqvoC8=
go.dtapp.net/golog v1.0.22 h1:sOJr5f/iLk/6irT/RuwTQSTwvL2DR8SIhzMsKdHo0Ic=
go.dtapp.net/golog v1.0.22/go.mod h1:sbn2WQXmlukcZ4T3Kz9iWOSznL8H3RCkD+1nicZHMfI=
go.dtapp.net/gorandom v1.0.1 h1:IWfMClh1ECPvyUjlqD7MwLq4mZdUusD1qAwAdsvEJBs=
go.dtapp.net/gorandom v1.0.1/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8=
go.dtapp.net/gorequest v1.0.24 h1:N2RJOpCXPWbsjfQ8iYJI1EYC2se3I4QhK1l94DSJsuE=
@ -533,8 +530,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
@ -605,8 +602,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9WKk6PdGOrb9n+SbIvw=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 h1:cik0bxZUSJVDyaHf1hZPSDsU8SZHGQZQMeueXCE7yBQ=
golang.org/x/net v0.0.0-20220811182439-13a9a731de15/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -651,8 +648,8 @@ golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/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=

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -26,11 +27,11 @@ func newMerchantFundBalanceResult(result MerchantFundBalanceResponse, body []byt
// MerchantFundBalance 查询电商平台账户实时余额API
// accountType 账户类型 BASIC基本账户 OPERATION运营账户 FEES手续费账户
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_3.shtml
func (c *Client) MerchantFundBalance(accountType string) *MerchantFundBalanceResult {
func (c *Client) MerchantFundBalance(ctx context.Context, accountType string) *MerchantFundBalanceResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/merchant/fund/balance/%s", accountType), params, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/merchant/fund/balance/%s", accountType), params, http.MethodGet)
if err != nil {
return newMerchantFundBalanceResult(MerchantFundBalanceResponse{}, request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -27,11 +28,11 @@ func newMerchantFundDayEndBalanceResult(result MerchantFundDayEndBalanceResponse
// accountType 账户类型 BASIC基本账户 OPERATION运营账户 FEES手续费账户
// date 日期 示例值2019-08-17
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_4.shtml
func (c *Client) MerchantFundDayEndBalance(accountType, date string) *MerchantFundDayEndBalanceResult {
func (c *Client) MerchantFundDayEndBalance(ctx context.Context, accountType, date string) *MerchantFundDayEndBalanceResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/merchant/fund/dayendbalance/%s?date=%s", accountType, date), params, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/merchant/fund/dayendbalance/%s?date=%s", accountType, date), params, http.MethodGet)
if err != nil {
return newMerchantFundDayEndBalanceResult(MerchantFundDayEndBalanceResponse{}, request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"fmt"
"go.dtapp.net/gorandom"
"time"
@ -22,7 +23,7 @@ type GetJsApiResult struct {
}
// GetJsApi JSAPI调起支付API https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_4.shtml
func (c *Client) GetJsApi(param GetJsApi) (result GetJsApiResult, err error) {
func (c *Client) GetJsApi(ctx context.Context, param GetJsApi) (result GetJsApiResult, err error) {
// sign params
timeStamp := time.Now().Unix()

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
@ -24,7 +25,7 @@ func newPayPartnerTransactionsH5Result(result PayPartnerTransactionsH5Response,
// PayPartnerTransactionsH5 H5下单API
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_3_1.shtml
func (c *Client) PayPartnerTransactionsH5(notMustParams ...gorequest.Params) *PayPartnerTransactionsH5Result {
func (c *Client) PayPartnerTransactionsH5(ctx context.Context, notMustParams ...gorequest.Params) *PayPartnerTransactionsH5Result {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("sp_appid", c.config.SpAppid) // 服务商应用ID
@ -32,7 +33,7 @@ func (c *Client) PayPartnerTransactionsH5(notMustParams ...gorequest.Params) *Pa
params.Set("sub_appid", c.config.SubAppid) // 子商户应用ID
params.Set("sub_mchid", c.config.SubMchId) // 子商户号
// 请求
request, err := c.request(apiUrl+"/v3/pay/partner/transactions/h5", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/v3/pay/partner/transactions/h5", params, http.MethodPost)
if err != nil {
return newPayPartnerTransactionsH5Result(PayPartnerTransactionsH5Response{}, request.ResponseBody, request, err, ApiError{})
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -64,11 +65,11 @@ func newPayPartnerTransactionsIdResult(result PayPartnerTransactionsIdResponse,
// PayPartnerTransactionsId 微信支付订单号查询
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_2.shtml
func (c *Client) PayPartnerTransactionsId(transactionId string) *PayPartnerTransactionsIdResult {
func (c *Client) PayPartnerTransactionsId(ctx context.Context, transactionId string) *PayPartnerTransactionsIdResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/pay/partner/transactions/id/%s?sp_mchid=%s&sub_mchid=%s", transactionId, c.config.SpMchId, c.config.SubMchId), params, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/pay/partner/transactions/id/%s?sp_mchid=%s&sub_mchid=%s", transactionId, c.config.SpMchId, c.config.SubMchId), params, http.MethodGet)
if err != nil {
return newPayPartnerTransactionsIdResult(PayPartnerTransactionsIdResponse{}, request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
@ -24,7 +25,7 @@ func newPayPartnerTransactionsJsapiResult(result PayPartnerTransactionsJsapiResp
// PayPartnerTransactionsJsapi JSAPI下单
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_1.shtml
func (c *Client) PayPartnerTransactionsJsapi(notMustParams ...gorequest.Params) *PayPartnerTransactionsJsapiResult {
func (c *Client) PayPartnerTransactionsJsapi(ctx context.Context, notMustParams ...gorequest.Params) *PayPartnerTransactionsJsapiResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("sp_appid", c.config.SpAppid) // 服务商应用ID
@ -32,7 +33,7 @@ func (c *Client) PayPartnerTransactionsJsapi(notMustParams ...gorequest.Params)
params.Set("sub_appid", c.config.SubAppid) // 子商户应用ID
params.Set("sub_mchid", c.config.SubMchId) // 子商户号
// 请求
request, err := c.request(apiUrl+"/v3/pay/partner/transactions/jsapi", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/v3/pay/partner/transactions/jsapi", params, http.MethodPost)
if err != nil {
return newPayPartnerTransactionsJsapiResult(PayPartnerTransactionsJsapiResponse{}, request.ResponseBody, request, err, ApiError{})
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
@ -18,13 +19,13 @@ func newPayPartnerTransactionsOutTradeNoCloseResult(body []byte, http gorequest.
// PayPartnerTransactionsOutTradeNoClose 关闭订单API
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_3.shtml
func (c *Client) PayPartnerTransactionsOutTradeNoClose(outTradeNo string) *PayPartnerTransactionsOutTradeNoCloseResult {
func (c *Client) PayPartnerTransactionsOutTradeNoClose(ctx context.Context, outTradeNo string) *PayPartnerTransactionsOutTradeNoCloseResult {
// 参数
params := gorequest.NewParams()
params.Set("sp_mchid", c.config.SpMchId) // 服务商户号
params.Set("sub_mchid", c.config.SubMchId) // 子商户号
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/pay/partner/transactions/out-trade-no/%s/close", outTradeNo), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/pay/partner/transactions/out-trade-no/%s/close", outTradeNo), params, http.MethodPost)
if err != nil {
return newPayPartnerTransactionsOutTradeNoCloseResult(request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -68,11 +69,11 @@ func newPayPartnerTransactionsOutTradeNoResult(result PayPartnerTransactionsOutT
// PayPartnerTransactionsOutTradeNo 商户订单号查询
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_2.shtml
func (c *Client) PayPartnerTransactionsOutTradeNo(outTradeNo string) *PayPartnerTransactionsOutTradeNoResult {
func (c *Client) PayPartnerTransactionsOutTradeNo(ctx context.Context, outTradeNo string) *PayPartnerTransactionsOutTradeNoResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/v3/pay/partner/transactions/out-trade-no/%s?sp_mchid=%s&sub_mchid=%s", outTradeNo, c.config.SpMchId, c.config.SubMchId), params, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/v3/pay/partner/transactions/out-trade-no/%s?sp_mchid=%s&sub_mchid=%s", outTradeNo, c.config.SpMchId, c.config.SubMchId), params, http.MethodGet)
if err != nil {
return newPayPartnerTransactionsOutTradeNoResult(PayPartnerTransactionsOutTradeNoResponse{}, request.ResponseBody, request, err, ApiError{})
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
@ -62,12 +63,12 @@ func newRefundDomesticRefundsResult(result RefundDomesticRefundsResponse, body [
// RefundDomesticRefunds 申请退款API
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_9.shtml
func (c *Client) RefundDomesticRefunds(notMustParams ...gorequest.Params) *RefundDomesticRefundsResult {
func (c *Client) RefundDomesticRefunds(ctx context.Context, notMustParams ...gorequest.Params) *RefundDomesticRefundsResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("sub_mchid", c.config.SubMchId) // 子商户号
// 请求
request, err := c.request(apiUrl+"/v3/refund/domestic/refunds", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/v3/refund/domestic/refunds", params, http.MethodPost)
if err != nil {
return newRefundDomesticRefundsResult(RefundDomesticRefundsResponse{}, request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package wechatpayopen
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
@ -62,11 +63,11 @@ func newRefundDomesticRefundsOutRefundNoResult(result RefundDomesticRefundsOutRe
// RefundDomesticRefundsOutRefundNo 查询单笔退款API
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_9.shtml
func (c *Client) RefundDomesticRefundsOutRefundNo(outRefundNo string) *RefundDomesticRefundsOutRefundNoResult {
func (c *Client) RefundDomesticRefundsOutRefundNo(ctx context.Context, outRefundNo string) *RefundDomesticRefundsOutRefundNoResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request(apiUrl+"/v3/refund/domestic/refunds/"+outRefundNo+"?sub_mchid="+c.config.SubMchId, params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/v3/refund/domestic/refunds/"+outRefundNo+"?sub_mchid="+c.config.SubMchId, params, http.MethodGet)
if err != nil {
return newRefundDomesticRefundsOutRefundNoResult(RefundDomesticRefundsOutRefundNoResponse{}, request.ResponseBody, request, err)
}

@ -1,8 +1,11 @@
package wechatpayopen
import "go.dtapp.net/gorequest"
import (
"context"
"go.dtapp.net/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 认证
authorization, err := c.authorization(method, params, url)
@ -38,7 +41,7 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request, Version)
go c.log.GormMiddleware(ctx, request, Version)
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)

Loading…
Cancel
Save