|
|
@@ -7,23 +7,44 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/silenceper/wechat"
|
|
|
+ "github.com/silenceper/wechat/oauth"
|
|
|
"github.com/silenceper/wechat/cache"
|
|
|
)
|
|
|
|
|
|
var wc *wechat.Wechat
|
|
|
+var wxoauth *oauth.Oauth
|
|
|
+
|
|
|
+var wxConfig struct {
|
|
|
+ WxPayCallback string // 完整微信支付回调url,
|
|
|
+ AppId string // 公众号appid
|
|
|
+ AppSecret string // 公众号appsecret
|
|
|
+ Token string // 设置token
|
|
|
+ EncodingAseKey string // ase key
|
|
|
+ PayMchId string // 商户号id
|
|
|
+ PayKey string // 商户支付设置的key
|
|
|
+ RedirectUrl string // 微信Oauth完整跳转uri
|
|
|
+ Scope string // 微信Oauth的scope
|
|
|
+ ResponseType string // 微信oauth的response type
|
|
|
+ State string // 微信oauth的state
|
|
|
+}
|
|
|
|
|
|
func init() {
|
|
|
c := &LocalCache{}
|
|
|
- wxpayCallback := config.AppConfig.GetKey("wxpay_callback") // 完整微信回调url,
|
|
|
- appId := config.AppConfig.GetKey("app_id") // 公众号appid
|
|
|
- appSecret := config.AppConfig.GetKey("app_secret") // 公众号app secret
|
|
|
- token := config.AppConfig.GetKey("token")
|
|
|
- encodingAseKey := config.AppConfig.GetKey("encoding_aes_key")
|
|
|
- payMchId := config.AppConfig.GetKey("mch_id") // 商户号id
|
|
|
- payKey := config.AppConfig.GetKey("pay_key") // 商户支付设置的key
|
|
|
-
|
|
|
- config := &wechat.Config{appId, appSecret, token, encodingAseKey, payMchId, wxpayCallback, payKey, c}
|
|
|
+ wxConfig.WxPayCallback = config.AppConfig.GetKey("wxpay_callback") // 完整微信回调url,
|
|
|
+ wxConfig.AppId = config.AppConfig.GetKey("appid") // 公众号appid
|
|
|
+ wxConfig.AppSecret = config.AppConfig.GetKey("appsecret") // 公众号appsecret
|
|
|
+ wxConfig.Token = config.AppConfig.GetKey("token")
|
|
|
+ wxConfig.EncodingAseKey = config.AppConfig.GetKey("encoding_aes_key")
|
|
|
+ wxConfig.PayMchId = config.AppConfig.GetKey("mch_id") // 商户号id
|
|
|
+ wxConfig.PayKey = config.AppConfig.GetKey("pay_key") // 商户支付设置的key
|
|
|
+ wxConfig.RedirectUrl = config.AppConfig.GetKey("redirect_url")
|
|
|
+ wxConfig.Scope = config.AppConfig.GetKey("scope")
|
|
|
+ wxConfig.ResponseType = config.AppConfig.GetKey("response_type")
|
|
|
+ wxConfig.State = config.AppConfig.GetKey("state")
|
|
|
+
|
|
|
+ config := &wechat.Config{wxConfig.AppId, wxConfig.AppSecret, wxConfig.Token, wxConfig.EncodingAseKey, wxConfig.PayMchId, wxConfig.WxPayCallback, wxConfig.PayKey, c}
|
|
|
wc = wechat.NewWechat(config)
|
|
|
+ wxoauth = wc.GetOauth()
|
|
|
}
|
|
|
|
|
|
/*********************local cache*************************/
|
|
|
@@ -89,3 +110,16 @@ type PayParams struct{
|
|
|
PaySign string `json:"paySign"`
|
|
|
OutTradeNo string `json:"outTradeNo"`
|
|
|
}
|
|
|
+
|
|
|
+// 微信oauth跳转信息,
|
|
|
+type WxOAuthConfig struct {
|
|
|
+ AuthUrl string `json:"auth_url"`
|
|
|
+ AppId string `json:"app_id"`
|
|
|
+ // 给微信跳转的url
|
|
|
+ RedirectUrl string `json:"redirect_url"`
|
|
|
+ ResponseType string `json:"response_type"`
|
|
|
+ Scope string `json:"scope"`
|
|
|
+ State string `json:"state"`
|
|
|
+ // 完整的微信Oauth的url
|
|
|
+ OAuthRedirectUrl string `json:"oauth_redirect_url"`
|
|
|
+}
|