1 Star 0 Fork 1

可乐烛光烟 / go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tools.go 960 Bytes
一键复制 编辑 原始数据 按行查看 历史
可乐烛光烟 提交于 2022-11-09 00:21 . Initial commit
/*
* @Author: i@rysa.cn
* @Date: 2022-05-14 17:00:53
* @LastEditTime: 2022-06-01 09:58:48
* @LastEditors: i@rysa.cn
* @Description:
* @FilePath: \go-utils\wechat\pay\tools.go
*/
package pay
import (
"context"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
)
func GetClient(cfg *PayConfig) (*core.Client, context.Context, error) {
ctx := context.Background()
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(cfg.ApiclientKey)
if err != nil {
return nil, ctx, err
}
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(cfg.MchId, cfg.MchCertificateSerialNumber, mchPrivateKey, cfg.MchApiV3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
return nil, ctx, err
}
return client, ctx, nil
}
1
https://gitee.com/rysa/go-utils.git
git@gitee.com:rysa/go-utils.git
rysa
go-utils
go-utils
v1.1.0

搜索帮助