func (c *UserController) Users() {
	userId, _ := c.GetInt64(":id")
	var user, err = services.User(userId)
	if err != nil {
		c.Data["json"] = nil
	} else {
		c.Data["json"] = user
	}
	c.ServeJSON()
}
func (c *ArticleController) ArticleDetail() {

	id, _ := c.GetInt64(":id")
	ip := c.Ip()
	userId, _ := c.GetInt64(":userId")

	c.TplName = "article_detail.html"

	if id <= 0 {
		c.StringError("文章不存在")
		c.Ctx.Redirect(302, "/")
		return
	}

	host := c.Host()
	url := c.Ctx.Request.RequestURI

	reqUri := fmt.Sprintf("%s%s", host, url)

	c.Data["reqUri"] = reqUri

	article, error := services.ArticleById(id)

	if error == nil {
		writer, _ := services.User(article.UserId)
		article.User = writer
	}

	if userId > 0 {
		hasLike, err := services.HasLikeArticle(id, userId, db.NewDB())
		if nil == err {
			article.HasLike = hasLike
		}
	}

	if nil != error {
		c.StringError("文章不存在")
	} else {
		currUserId := c.CurrentUserId()
		success, _ := services.IncrViewCount(id, currUserId, ip)
		if success {
			article.ViewCount = article.ViewCount + 1
		}
		c.Data["article"] = article

		c.SetCategories(article.UserId)

		c.SetKeywords(article.Categories + "," + article.Tags)
		var subLength = services.ParameterIntValue("seo-description-length")
		c.SetDescription(article.ShortContent(subLength)).SetTitle(article.Title)
	}
}
func (c *OpenUserController) QqToken() {

	code := c.GetString("code")

	var loginPageUrl = "/users/login"
	//获取token
	tokenRes, err := services.QueryToken(code)
	beego.Debug("****************tokenRes:", tokenRes, "****************")
	if nil != err {
		c.Redirect(loginPageUrl, 302)
		return
	}

	accessToken := tokenRes["access_token"]
	beego.Debug("****************accessToken:", accessToken, "****************")
	if len(accessToken) <= 0 {
		c.Redirect(loginPageUrl, 302)
		return
	}

	//获取openid
	openIdRes, err := services.QueryOpenId(accessToken)
	beego.Debug("****************openIdRes:", openIdRes, "****************")
	if nil != err {
		beego.Error(err)
		c.Redirect("login.html", 302)
		return
	}

	openId := openIdRes["openid"]
	if len(openId) <= 0 {
		beego.Error(errors.New("openid[" + openId + "] error"))
		c.Redirect(loginPageUrl, 302)
		return
	}

	//获取user_info
	openUser, err := services.OpenUserInfo(accessToken, openId)
	beego.Debug("err:", err, "userInfoRes:", openUser)

	if nil != err {
		beego.Error(err)
		c.Redirect(loginPageUrl, 302)
		return
	}

	err = services.SaveOrUpdateOpenUser(openUser)
	if nil != err {
		beego.Error(err)
		c.Redirect(loginPageUrl, 302)
		return
	}

	openUser, _ = services.OpenUser(openId, entities.OPEN_USER_TYPE_QQ)
	beego.Debug("openUser:"******"user", user)
	} else {
		c.SetSession("openUser", openUser)
		c.Redirect("/users/oauth_register", 302)
		return
	}

	c.Redirect("/", 302)
}