func QueryToken(authCode string) (map[string]string, error) {
	params := make(map[string]string)
	params["grant_type"] = "authorization_code"
	params["client_id"] = AuthConfig.String("app_id")
	params["client_secret"] = AuthConfig.String("app_key")
	params["code"] = authCode
	params["redirect_uri"] = AuthConfig.String("token_redirect_uri")

	var baseUrl = AuthConfig.String("access_token_url")

	subUrl := utils.BuildQueryString(params)

	var fullRequestStr = baseUrl + subUrl

	resp, err := http.Get(fullRequestStr)
	if nil != err {
		beego.Error(err)
		return nil, err
	}

	paramMap, err := utils.ExtractResponse(resp.Body)

	defer resp.Body.Close()

	return paramMap, err
}
func (c *OpenUserController) QqAuth() {
	params := make(map[string]string)
	params["client_id"] = services.AuthConfig.String("app_id")
	params["redirect_uri"] = services.AuthConfig.String("auth_redirect_uri")
	params["response_type"] = "code"
	var state = "111"
	params["state"] = state
	params["scope"] = services.AuthConfig.String("scope")

	var baseUrl = services.AuthConfig.String("authorize_url")

	subUrl := utils.BuildQueryString(params)

	var fullRequestStr = baseUrl + subUrl
	c.Redirect(fullRequestStr, 302)
}
func OpenUserInfo(accessToken string, openId string) (*entities.OpenUser, error) {
	var baseUrl = AuthConfig.String("get_user_info_url")
	params := make(map[string]string)
	params["access_token"] = accessToken
	params["openid"] = openId
	params["oauth_consumer_key"] = AuthConfig.String("app_id")

	subUrl := utils.BuildQueryString(params)

	var fullRequestStr = baseUrl + subUrl

	resp, err := http.Get(fullRequestStr)
	if nil != err {
		beego.Error(err)
		return nil, err
	}

	result, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()

	if nil != err {
		beego.Error(err)
		return nil, err
	}

	content := string(result)
	if len(content) == 0 {
		beego.Error(err)
		return nil, err
	}

	beego.Debug("******************OpenUserInfo", content)

	var paramMap map[string]interface{}

	err = json.Unmarshal([]byte(content), &paramMap)

	if len(paramMap) == 0 {
		return nil, errors.New("open_user_info get fail")
	}

	city, _ := paramMap["city"].(string)
	province, _ := paramMap["province"].(string)
	nick, _ := paramMap["nickname"].(string)
	gender, _ := paramMap["gender"].(string)
	head, _ := paramMap["figureurl_qq_1"].(string)
	year, _ := paramMap["year"].(string)
	sex := 1
	if "女" == gender {
		sex = 2
	}
	age := 0
	if len(year) > 0 {
		yearInt, err := strconv.Atoi(year)
		if nil != err {
			currYear := time.Now().Year()
			age = currYear - yearInt + 1
		}
	}

	openUser := new(entities.OpenUser)

	openUser.OpenId = openId
	openUser.Nick = nick
	openUser.Age = age
	openUser.City = city
	openUser.Province = province
	openUser.Sex = sex
	openUser.Type = entities.OPEN_USER_TYPE_QQ
	openUser.Head = head

	return openUser, err
}