Skip to content

Commit

Permalink
refactor: 微信构造cleint增加xhttp.Client参数
Browse files Browse the repository at this point in the history
  • Loading branch information
wbl committed Jan 4, 2024
1 parent 59d755f commit d657e96
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wechat/v3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ type ClientV3 struct {
// apiV3Key:APIv3Key,商户平台获取
// privateKey:商户API证书下载后,私钥 apiclient_key.pem 读取后的字符串内容
func NewClientV3(mchid, serialNo, apiV3Key, privateKey string) (client *ClientV3, err error) {
return NewClientV3WithXClient(mchid, serialNo, apiV3Key, privateKey, xhttp.NewClient())
}

// NewClientV3WithXClient 初始化微信客户端 V3
// mchid:商户ID 或者服务商模式的 sp_mchid
// serialNo:商户API证书的证书序列号
// apiV3Key:APIv3Key,商户平台获取
// privateKey:商户API证书下载后,私钥 apiclient_key.pem 读取后的字符串内容
// xclient: 自定义xhttp.Client
func NewClientV3WithXClient(mchid, serialNo, apiV3Key, privateKey string, xclient *xhttp.Client) (client *ClientV3, err error) {
if mchid == util.NULL || serialNo == util.NULL || apiV3Key == util.NULL || privateKey == util.NULL {
return nil, gopay.MissWechatInitParamErr
}
Expand All @@ -47,7 +57,7 @@ func NewClientV3(mchid, serialNo, apiV3Key, privateKey string) (client *ClientV3
privateKey: priKey,
ctx: context.Background(),
DebugSwitch: gopay.DebugOff,
hc: xhttp.NewClient(),
hc: xclient,
}
return client, nil
}
Expand Down

0 comments on commit d657e96

Please sign in to comment.