本文整理汇总了Golang中github.com/jsix/gof/web.Context.Session方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Session方法的具体用法?Golang Context.Session怎么用?Golang Context.Session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jsix/gof/web.Context
的用法示例。
在下文中一共展示了Context.Session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: releaseOrder
func (this *ShoppingC) releaseOrder(ctx *web.Context) {
s := ctx.Session()
s.Remove("shopping_lock")
s.Save()
//fmt.Println("REMOVED")
}
示例2: MemberHttpSessionConnect
// 会员Http请求会话链接
func MemberHttpSessionConnect(ctx *web.Context, call func(memberId int)) (ok bool, memberId int) {
//return true,30
// 如果传递会话参数正确,能存储到Session
form := ctx.Request.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
}
示例3: Create
func (this *PaymentC) Create(ctx *web.Context) {
r, w := ctx.Request, ctx.Response
qs := r.URL.Query()
partnerId := this.GetPartnerId(ctx)
orderNo := qs.Get("order_no")
paymentOpt := qs.Get("pay_opt")
var order *shopping.ValueOrder
if len(orderNo) > 0 {
order = dps.ShoppingService.GetOrderByNo(partnerId, orderNo)
}
if order != nil {
ctx.Session().Set("current_payment", orderNo)
ctx.Session().Save()
//order.PayFee = 0.01
if paymentOpt == "alipay" {
aliPayObj := this.getAliPayment(ctx)
domain := getDomain(ctx.Request)
returnUrl := fmt.Sprintf("%s/pay/return_alipay", domain)
notifyUrl := fmt.Sprintf("%s/pay/notify/%d_alipay", domain, partnerId)
gateway := aliPayObj.CreateGateway(orderNo, order.PayFee, "在线支付订单", "订单号:"+orderNo, notifyUrl, returnUrl)
html := "<html><head><meta charset=\"utf-8\"/></head><body>" + gateway + "</body></html>"
w.Write([]byte(html))
payment.Debug(" [ Submit] - %s - %s", orderNo, notifyUrl)
return
}
}
w.Write([]byte("订单不存在"))
}
示例4: chkLogin
func chkLogin(ctx *web.Context) (b bool, partnerId int) {
v := ctx.Session().Get("master_id")
if v == nil {
return false, -1
}
return true, v.(int)
}
示例5: Msc
// Member session connect
func (this *mainC) Msc(ctx *web.Context) {
form := ctx.Request.URL.Query()
util.SetDeviceByUrlQuery(ctx, &form)
ok, memberId := util.MemberHttpSessionConnect(ctx, func(memberId int) {
v := ctx.Session().Get("member")
var m *member.ValueMember
if v != nil {
m = v.(*member.ValueMember)
if m.Id != memberId { // 如果会话冲突
m = nil
}
}
if m == nil {
m = dps.MemberService.GetMember(memberId)
ctx.Session().Set("member", m)
ctx.Session().Save()
}
})
if ok {
ctx.Items["client_member_id"] = memberId
}
rtu := form.Get("return_url")
if len(rtu) == 0 {
rtu = "/"
}
ctx.Response.Header().Add("Location", rtu)
ctx.Response.WriteHeader(302)
}
示例6: GetPartnerId
// 获取商户编号
func (this *baseC) GetPartnerId(ctx *web.Context) int {
v := ctx.Session().Get("partner_id")
if v == nil {
this.Requesting(ctx)
return -1
}
return v.(int)
}
示例7: Msd
// Member session disconnect
func (this *mainC) Msd(ctx *web.Context) {
if util.MemberHttpSessionDisconnect(ctx) {
ctx.Session().Set("member", nil)
ctx.Session().Save()
ctx.Response.Write([]byte("disconnect success"))
} else {
ctx.Response.Write([]byte("disconnect fail"))
}
}
示例8: GetMember
// 获取会员
func (this *BaseC) GetMember(ctx *web.Context) *member.ValueMember {
memberIdObj := ctx.Session().Get("member")
if memberIdObj != nil {
if o, ok := memberIdObj.(*member.ValueMember); ok {
return o
}
}
return nil
}
示例9: CheckMemberLogin
// 检查会员是否登陆
func (this *BaseC) CheckMemberLogin(ctx *web.Context) bool {
if ctx.Session().Get("member") == nil {
ctx.Response.Header().Add("Location", "/user/login?return_url="+
url.QueryEscape(ctx.Request.RequestURI))
ctx.Response.WriteHeader(302)
return false
}
return true
}
示例10: lockOrder
// 锁定,防止重复下单,返回false,表示正在处理订单
func (this *orderC) lockOrder(ctx *web.Context) bool {
s := ctx.Session()
v := s.Get("pt_order_lock")
if v != nil {
return false
}
s.Set("pt_order_lock", "1")
s.Save()
return true
}
示例11: Partner_connect
//从partner登录过来的信息
func (this *loginC) Partner_connect(ctx *web.Context) {
r, w := ctx.Request, ctx.Response
sessionId := r.URL.Query().Get("sessionId")
var m *member.ValueMember
var err error
if sessionId == "" {
// 第三方连接,传入memberId 和 token
memberId, err := strconv.Atoi(r.URL.Query().Get("mid"))
token := r.URL.Query().Get("token")
if err == nil && token != "" {
m, err = goclient.Member.GetMember(memberId, token)
ctx.Session().Set("member", m)
}
} else {
// 从统一平台连接过来(标准版商户PC前端)
ctx.Session().UseInstead(sessionId)
m = ctx.Session().Get("member").(*member.ValueMember)
}
// 设置访问设备
util.SetBrownerDevice(ctx, ctx.Request.URL.Query().Get("device"))
if err == nil || m != nil {
rl := dps.MemberService.GetRelation(m.Id)
if rl.RegisterPartnerId > 0 {
ctx.Session().Set("member:rel_partner", rl.RegisterPartnerId)
ctx.Session().Save()
w.Write([]byte("<script>location.replace('/')</script>"))
return
}
}
w.Write([]byte("<script>location.replace('/login')</script>"))
}
示例12: Logout
// 退出
func (this *UserC) Logout(ctx *web.Context) {
ctx.Session().Set("member", nil)
ctx.Session().Save()
ctx.Response.Write([]byte(fmt.Sprintf(`<html><head><title>正在退出...</title></head><body>
3秒后将自动返回到首页... <br />
<iframe src="http://%s.%s/login/partner_disconnect" width="0" height="0" frameBorder="0"></iframe>
<script>window.onload=function(){location.replace('/')}</script></body></html>`,
variable.DOMAIN_PREFIX_MEMBER,
ctx.App.Config().GetString(variable.ServerDomain),
)))
}
示例13: lockOrder
// 锁定,防止重复下单,返回false,表示正在处理订单
func (this *ShoppingC) lockOrder(ctx *web.Context) bool {
s := ctx.Session()
v := s.Get("shopping_lock")
//fmt.Println(v)
if v != nil {
return false
}
s.Set("shopping_lock", "1")
s.Save()
return true
}
示例14: Requesting
func (this *baseC) Requesting(ctx *web.Context) bool {
//验证是否登陆
s := ctx.Session().Get("member")
if s != nil {
if m := s.(*member.ValueMember); m != nil {
ctx.Items["member"] = m
return true
}
}
ctx.Response.Write([]byte("<script>window.parent.location.href='/login?return_url=" +
url.QueryEscape(ctx.Request.URL.String()) + "'</script>"))
return false
}
示例15: Login_post
func (this *userC) Login_post(ctx *web.Context) {
r, w := ctx.Request, ctx.Response
r.ParseForm()
usr, pwd := r.Form.Get("usr"), r.Form.Get("pwd")
result, _ := goclient.Member.Login(usr, pwd)
if result.Result {
ctx.Session().Set("member", result.Member)
ctx.Session().Save()
w.Write([]byte("{result:true}"))
return
}
w.Write([]byte("{result:false,message:'" + result.Message + "'}"))
}