Files
public/weixin/init.go
xiexiaojun 2ace0bade5 new
new
2019-03-07 21:30:01 +08:00

61 lines
1.5 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 (
"data/config"
"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 pay_appId string // 微信公众平台应用ID
var mchId string // 微信支付商户平台商户号
var apiKey string // 微信支付商户平台API密钥
var secret string
var notify_url string
var token string
var encodingAESKey string
var certFile string // 微信支付商户平台证书路径
var keyFile string
var rootcaFile string
func init() {
wx_info := config.GetWxInfo()
//配置微信支付参数
pay_appId = wx_info.AppID
mchId = wx_info.MchId
apiKey = wx_info.Key
secret = wx_info.AppSecret
notify_url = wx_info.NotifyUrl
token = wx_info.Token
encodingAESKey = wx_info.EncodingAESKey
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: pay_appId,
AppSecret: secret,
Token: token,
EncodingAESKey: encodingAESKey,
Cache: memCache,
}
client = wxpay.NewClient(pay_appId, mchId, apiKey)
client.WithCert(certFile, keyFile, rootcaFile)
}