feat: add gopay config
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"go.ipao.vip/atom/opt"
|
||||
)
|
||||
|
||||
type Config struct{}
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
o := opt.New(opts...)
|
||||
var config Config
|
||||
@@ -20,37 +22,31 @@ func Provide(opts ...opt.Option) error {
|
||||
return err
|
||||
}
|
||||
return container.Container.Provide(func(wechatConfig *w.Config) (*Client, error) {
|
||||
// NewClientV3 初始化微信客户端 v3
|
||||
// mchid:商户ID 或者服务商模式的 sp_mchid
|
||||
// serialNo:商户证书的证书序列号
|
||||
// apiV3Key:apiV3Key,商户平台获取
|
||||
// privateKey:私钥 apiclient_key.pem 读取后的内容
|
||||
// 1、你最多可同时使用3个有效证书,为减少风险,建议及时作废不使用的API证书;
|
||||
// 2、API证书包括:私钥文件及公钥证书(配对使用),仅保存在申请证书的电脑本地,无法从系统下载;
|
||||
// 3、私钥文件名为“prikey_序列号”,公钥证书名为“pubkey_序列号”,序列号请查看上述列表。若无法找到证书文件,可申请新证书。
|
||||
client, err := wechat.NewClientV3(
|
||||
w.Pay.MchID, w.Pay.SerialNo, w.Pay.ApiV3Key, w.Pay.PrivateKey,
|
||||
wechatConfig.MchId, wechatConfig.SerialNo, wechatConfig.APIv3Key, wechatConfig.PrivateKey
|
||||
)
|
||||
wechatConfig.Pay.MchID,
|
||||
wechatConfig.Pay.SerialNo,
|
||||
wechatConfig.Pay.ApiV3Key,
|
||||
wechatConfig.Pay.PrivateKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client.DebugSwitch = gopay.DebugOff
|
||||
if config.Debug {
|
||||
if wechatConfig.DevMode {
|
||||
client.DebugSwitch = gopay.DebugOn
|
||||
}
|
||||
|
||||
return &Client{
|
||||
payClient: client,
|
||||
config: &config,
|
||||
config: wechatConfig,
|
||||
}, nil
|
||||
}, o.DiOptions()...)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
payClient *wechat.ClientV3
|
||||
config *Config
|
||||
config *w.Config
|
||||
}
|
||||
|
||||
func (c *Client) GetClient() *wechat.ClientV3 {
|
||||
@@ -76,11 +72,11 @@ type BodyMap struct {
|
||||
bm gopay.BodyMap
|
||||
}
|
||||
|
||||
func NewBodyMap(c *Config) *BodyMap {
|
||||
func NewBodyMap(c *w.Config) *BodyMap {
|
||||
bm := make(gopay.BodyMap)
|
||||
bm.Set("sp_appid", c.AppId).
|
||||
Set("sp_mchid", c.MchId).
|
||||
Set("notify_url", c.NotifyURL).
|
||||
bm.Set("sp_appid", c.AppID).
|
||||
Set("sp_mchid", c.Pay.MchID).
|
||||
Set("notify_url", c.Pay.NotifyURL).
|
||||
Set("amount", func(bm gopay.BodyMap) {
|
||||
bm.Set("total", 1).
|
||||
Set("currency", "CNY")
|
||||
|
||||
Reference in New Issue
Block a user