|
@@ -35,40 +35,49 @@ func (this *SingleLogin) ShortUrl(key string) error {
|
|
|
return this.Redirect(redirectUrl)
|
|
|
}
|
|
|
|
|
|
-//是否关注处理
|
|
|
+//toHref 已关注跳转页面
|
|
|
+//unHref 为关注跳转页面,若无此字段会跳至关注二维码页面
|
|
|
+// *已有逻辑 1.线上课程推文,用户点击可登陆跳转;未关注扫码会回复课程链接
|
|
|
+// 2.文库赚积分
|
|
|
func (this *SingleLogin) SingleLogin() error {
|
|
|
- userid := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- toHref := this.GetString("toHref")
|
|
|
- if userid != "" { //已有session,直接跳转至结果页面
|
|
|
- return this.Redirect(toHref)
|
|
|
+ openid := qutil.ObjToString(this.Session().Get("s_m_openid"))
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "toHref": this.GetString("toHref"),
|
|
|
+ "unHref": this.GetString("unHref"),
|
|
|
}
|
|
|
- data := map[string]interface{}{}
|
|
|
- stateKey := this.GetString("state")
|
|
|
- if stateKey == "" { //公众号回调
|
|
|
- stateKey = getTmpKey()
|
|
|
- //暂存参数
|
|
|
- for k, v := range this.Request.Form {
|
|
|
- if len(v) > 0 {
|
|
|
- data[k] = v[0]
|
|
|
+ if openid == "" {
|
|
|
+ stateKey := this.GetString("state")
|
|
|
+ if stateKey == "" { //公众号回调
|
|
|
+ stateKey = getTmpKey()
|
|
|
+ //暂存参数
|
|
|
+ for k, v := range this.Request.Form {
|
|
|
+ if len(v) > 0 {
|
|
|
+ data[k] = v[0]
|
|
|
+ }
|
|
|
}
|
|
|
+ redis.Put("other", stateKey, data, 60*5) //存储信息
|
|
|
+ return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), stateKey), 302)
|
|
|
}
|
|
|
- redis.Put("other", stateKey, data, 60*5) //存储信息
|
|
|
- return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), stateKey), 302)
|
|
|
- }
|
|
|
- //获取wx跳转前参数
|
|
|
- if redisValue := redis.Get("other", stateKey); redisValue != nil {
|
|
|
- if param, ok := redisValue.(map[string]interface{}); ok {
|
|
|
- data = param
|
|
|
+ //获取wx跳转前参数
|
|
|
+ if redisValue := redis.Get("other", stateKey); redisValue != nil {
|
|
|
+ if param, ok := redisValue.(map[string]interface{}); ok {
|
|
|
+ data = param
|
|
|
+ }
|
|
|
}
|
|
|
+ //获取用户openid
|
|
|
+ openid = jyutil.Getopenid(this.GetString("code"))
|
|
|
}
|
|
|
- openid := jyutil.Getopenid(this.GetString("code")) //获取用户openid
|
|
|
- //登录成功跳转
|
|
|
- if loginCreateSess(openid, this.Session()) {
|
|
|
+ //判断是否关注
|
|
|
+ isSubscribe := CheckUserIsSubscribe(openid)
|
|
|
+ if isSubscribe { //关注跳转
|
|
|
+ if this.GetSession("userId") == nil {
|
|
|
+ loginCreateSess(openid, this.Session())
|
|
|
+ }
|
|
|
return this.Redirect(qutil.ObjToString(data["toHref"]))
|
|
|
}
|
|
|
//未关注跳转
|
|
|
if unHref := qutil.ObjToString(data["unHref"]); unHref != "" {
|
|
|
- return this.Render(unHref)
|
|
|
+ return this.Redirect(unHref)
|
|
|
}
|
|
|
//跳转二维码关注页面,关注回复链接
|
|
|
if data["toHref"] != nil && data["title"] != nil {
|