|
@@ -53,7 +53,7 @@ var DefaultKey = "zcmRedis"
|
|
|
|
|
|
// GetAccessToken 获取accessToken
|
|
// GetAccessToken 获取accessToken
|
|
func (wechat WechatAccessToken) GetAccessToken() (accessToken string, err error) {
|
|
func (wechat WechatAccessToken) GetAccessToken() (accessToken string, err error) {
|
|
- accessToken, err = utils.Redis.Get(context.TODO(), utils.CACHE_WX_ACCESS_TOKEN_HZ).Result()
|
|
|
|
|
|
+ accessToken, err = utils.Redis.Get(context.TODO(), utils.CACHE_WX_ACCESS_TOKEN_DW).Result()
|
|
// wxToken, err := models.GetWxTokenById()
|
|
// wxToken, err := models.GetWxTokenById()
|
|
if err != nil && err != redis.Nil {
|
|
if err != nil && err != redis.Nil {
|
|
return
|
|
return
|
|
@@ -67,11 +67,11 @@ func (wechat WechatAccessToken) GetAccessToken() (accessToken string, err error)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
redisTimeExpire := time.Duration(expires-600) * time.Second
|
|
redisTimeExpire := time.Duration(expires-600) * time.Second
|
|
- err = utils.Redis.SetEX(context.TODO(), utils.CACHE_WX_ACCESS_TOKEN_HZ, tmpAccessToken, redisTimeExpire).Err()
|
|
|
|
|
|
+ err = utils.Redis.SetEX(context.TODO(), utils.CACHE_WX_ACCESS_TOKEN_DW, tmpAccessToken, redisTimeExpire).Err()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- err = utils.Redis.HSet(context.TODO(), DefaultKey, utils.CACHE_WX_ACCESS_TOKEN_HZ, true).Err()
|
|
|
|
|
|
+ err = utils.Redis.HSet(context.TODO(), DefaultKey, utils.CACHE_WX_ACCESS_TOKEN_DW, true).Err()
|
|
// err = utils.Redis.Put(utils.CACHE_WX_ACCESS_TOKEN_HZ, tmpAccessToken, redisTimeExpire)
|
|
// err = utils.Redis.Put(utils.CACHE_WX_ACCESS_TOKEN_HZ, tmpAccessToken, redisTimeExpire)
|
|
if err != nil {
|
|
if err != nil {
|
|
err = errors.New("更新微信token失败")
|
|
err = errors.New("更新微信token失败")
|
|
@@ -144,11 +144,7 @@ type WxUserInfo struct {
|
|
func GetWxUserInfo(code string) (info *WxUserInfo, err error) {
|
|
func GetWxUserInfo(code string) (info *WxUserInfo, err error) {
|
|
httpUrl := `https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code`
|
|
httpUrl := `https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code`
|
|
|
|
|
|
- confMap, err := models.GetMiniConf()
|
|
|
|
- if err != nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- httpUrl = fmt.Sprintf(httpUrl, confMap["WxAppId"], confMap["WxAppSecret"], code)
|
|
|
|
|
|
+ httpUrl = fmt.Sprintf(httpUrl, utils.DW_WX_APPID, utils.DW_WX_APP_SECRET, code)
|
|
|
|
|
|
client := http.Client{}
|
|
client := http.Client{}
|
|
wxReq, err := http.NewRequest("GET", httpUrl, nil)
|
|
wxReq, err := http.NewRequest("GET", httpUrl, nil)
|