Example #1
0
// 会员Http请求会话链接
func MemberHttpSessionConnect(ctx *echox.Context, call func(memberId int)) (ok bool, memberId int) {
	//return true,30
	// 如果传递会话参数正确,能存储到Session
	form := ctx.HttpRequest().URL.Query()
	if memberId, err := strconv.Atoi(form.Get("member_id")); err == nil {
		var token string = form.Get("token")
		if CompareMemberApiToken(ctx.App.Storage(), memberId, token) {
			if call != nil {
				call(memberId)
			}
			ctx.Session.Set("client_member_id", memberId)
			ctx.Session.Save()
			return true, memberId
		}
	} else {
		// 如果没有传递参数从会话中获取
		if v := ctx.Session.Get("client_member_id"); v != nil {
			memberId = v.(int)
			return true, memberId
		}
	}

	//http://zs.ts.com/main/msc?device=1&return_url=/list/all_cate&member_id=30&token=25245e2640232df15db617473f59159c9d3d7c300ce349cb9a953b
	//SetMemberApiToken(ctx.App.Storage(),30,"f22e180335baf50c134ea5c1093de0a6")
	//fmt.Println(GetMemberApiToken(ctx.App.Storage(),30))

	return false, memberId
}
Example #2
0
// 会员Http请求会话链接
func MemberHttpSessionDisconnect(ctx *echox.Context) bool {
	form := ctx.HttpRequest().URL.Query()
	if memberId, err := strconv.Atoi(form.Get("member_id")); err == nil {
		var token string = form.Get("token")
		return RemoveMemberApiToken(ctx.App.Storage(), memberId, token)
	}
	return false
}
Example #3
0
// 断开
func (this *MemberC) Disconnect(ctx *echox.Context) error {
	var result gof.Message
	if util.MemberHttpSessionDisconnect(ctx) {
		result.Result = true
	} else {
		result.Message = "disconnect fail"
	}
	return ctx.JSON(http.StatusOK, result)
}