| 32 | } |
| 33 | |
| 34 | func GetWechatSessKey(appId, secret, code string) (sess *SessKey, err error) { |
| 35 | var resp string |
| 36 | api := fmt.Sprintf("https://api.weixin.qq.com/sns/jscode2session?appid=%v&secret=%v&js_code=%v&grant_type=authorization_code", appId, secret, code) |
| 37 | |
| 38 | resp, err = httplib.Get(api).SetTimeout(60*time.Second, 60*time.Second).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).String() |
| 39 | if err != nil { |
| 40 | beego.Error(err.Error()) |
| 41 | return |
| 42 | } |
| 43 | if beego.AppConfig.String("runmode") == "dev" { |
| 44 | beego.Debug(api, resp) |
| 45 | } |
| 46 | sess = &SessKey{} |
| 47 | json.Unmarshal([]byte(resp), sess) |
| 48 | return |
| 49 | } |