48 lines
973 B
Go
48 lines
973 B
Go
package globals
|
|
|
|
import (
|
|
"context"
|
|
"platform/pkg/env"
|
|
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
|
)
|
|
|
|
var WechatPay *WechatPayClient
|
|
|
|
type WechatPayClient struct {
|
|
Native *native.NativeApiService
|
|
}
|
|
|
|
func InitWechatPay() {
|
|
|
|
appPrivateKey, err := utils.LoadPrivateKey(env.WechatPayMchPrivateKeyPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
wechatPublicKey, err := utils.LoadPublicKey(env.WechatPayPublicKeyPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
client, err := core.NewClient(context.Background(),
|
|
option.WithWechatPayPublicKeyAuthCipher(
|
|
env.WechatPayMchId,
|
|
env.WechatPayMchPrivateKeySerial,
|
|
appPrivateKey,
|
|
env.WechatPayPublicKeyId,
|
|
wechatPublicKey,
|
|
),
|
|
)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
WechatPay = &WechatPayClient{
|
|
Native: &native.NativeApiService{Client: client},
|
|
}
|
|
}
|