Browse Source

Merge branch 'master' of http://git.ycjcjy.com/default/wechat-conf

胡轶钦 6 years ago
parent
commit
f5b0cd9454
2 changed files with 10 additions and 6 deletions
  1. 1
    1
      controllers/component.go
  2. 9
    5
      models/wechat.go

+ 1
- 1
controllers/component.go View File

204
 
204
 
205
 // GetPreAuthCode 获取预授权码
205
 // GetPreAuthCode 获取预授权码
206
 func (c *WechatController) GetPreAuthCode() {
206
 func (c *WechatController) GetPreAuthCode() {
207
-	utils.LogError(utils.Component.GetToken())
207
+	beego.Error(utils.Component.GetToken())
208
 	code, err := utils.Component.GetPreAuthCode()
208
 	code, err := utils.Component.GetPreAuthCode()
209
 	if err != nil {
209
 	if err != nil {
210
 		utils.LogError("获取预授权码错误: " + err.Error())
210
 		utils.LogError("获取预授权码错误: " + err.Error())

+ 9
- 5
models/wechat.go View File

25
 	d := "0"
25
 	d := "0"
26
 	if !conf.ExpiresDate.IsZero() {
26
 	if !conf.ExpiresDate.IsZero() {
27
 		now := time.Now()
27
 		now := time.Now()
28
-		d = string(conf.ExpiresDate.Sub(now))
28
+		subd := conf.ExpiresDate.Sub(now)
29
+		beego.Error(d)
30
+		d = string(subd)
29
 	}
31
 	}
30
 
32
 
33
+	beego.Error("过期时间:", d)
31
 	var cert = map[string]string{
34
 	var cert = map[string]string{
32
 		"appid":                 conf.Appid,
35
 		"appid":                 conf.Appid,
33
 		"aeskey":                conf.Aeskey,
36
 		"aeskey":                conf.Aeskey,
51
 		Token: token["accessToken"].(string),
54
 		Token: token["accessToken"].(string),
52
 	}
55
 	}
53
 
56
 
54
-	expires := token["expire_in"].(int)
55
-	beego.Error(expires)
56
-	if expires > 0 {
57
-		expriesTime := time.Now().Local().Add(time.Duration(expires))
57
+	expire := token["expire_in"].(int64)
58
+	if expire > 0 {
59
+		beego.Error(time.Now())
60
+		expriesTime := time.Now().Local().Add(time.Duration(expire) * time.Second)
61
+		beego.Error(expriesTime)
58
 		conf.ExpiresDate = expriesTime
62
 		conf.ExpiresDate = expriesTime
59
 		sql := `update sys_component_conf set token=?,expires_date=?`
63
 		sql := `update sys_component_conf set token=?,expires_date=?`
60
 		_, err := DBEngine.Exec(sql, conf.Token, conf.ExpiresDate)
64
 		_, err := DBEngine.Exec(sql, conf.Token, conf.ExpiresDate)