Files
public/weixin/init.go
2020-03-29 21:06:06 +08:00

47 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package weixin
import (
"github.com/xxjwxc/public/tools"
"github.com/silenceper/wechat"
wxpay "gopkg.in/go-with/wxpay.v1"
)
const (
// 微信支付商户平台证书路径
certFileLoc = "/cert/apiclient_cert.pem"
keyFileLoc = "/cert/apiclient_key.pem"
rootcaFileLoc = "/cert/rootca.pem"
)
var cfg wechat.Config
var client *wxpay.Client
var wxInfo WxInfo
var certFile string // 微信支付商户平台证书路径
var keyFile string
var rootcaFile string
// InitWxinfo 初始化配置信息
func InitWxinfo(info WxInfo) {
wxInfo = info
certFile = tools.GetModelPath() + certFileLoc
keyFile = tools.GetModelPath() + keyFileLoc
rootcaFile = tools.GetModelPath() + rootcaFileLoc
//使用memcache保存access_token也可选择redis或自定义cache
memCache := NewGocache("_winxin_access")
//配置微信参数
cfg = wechat.Config{
AppID: wxInfo.APIKey,
AppSecret: wxInfo.AppSecret,
Token: wxInfo.Token,
EncodingAESKey: wxInfo.EncodingAESKey,
Cache: memCache,
}
client = wxpay.NewClient(wxInfo.AppID, wxInfo.MchID, wxInfo.APIKey)
client.WithCert(certFile, keyFile, rootcaFile)
}