本文整理汇总了Golang中github.com/jsix/gof/web.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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)
}
开发者ID:zoe527,项目名称:go2o,代码行数:33,代码来源:main_c.go
示例2: 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("订单不存在"))
}
开发者ID:jackyan,项目名称:go2o,代码行数:35,代码来源:payment_c.go
示例3: 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
}
开发者ID:zoe527,项目名称:go2o,代码行数:30,代码来源:member.go
示例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)
}
开发者ID:zoe527,项目名称:go2o,代码行数:7,代码来源:base_c.go
示例5: releaseOrder
func (this *ShoppingC) releaseOrder(ctx *web.Context) {
s := ctx.Session()
s.Remove("shopping_lock")
s.Save()
//fmt.Println("REMOVED")
}
开发者ID:jackyan,项目名称:go2o,代码行数:7,代码来源:shopping_c.go
示例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)
}
开发者ID:zoe527,项目名称:go2o,代码行数:9,代码来源:base_c.go
示例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"))
}
}
开发者ID:zoe527,项目名称:go2o,代码行数:10,代码来源:main_c.go
示例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
}
开发者ID:zoe527,项目名称:go2o,代码行数:10,代码来源:base_c.go
示例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
}
开发者ID:zoe527,项目名称:go2o,代码行数:10,代码来源:base_c.go
示例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
}
开发者ID:jackyan,项目名称:go2o,代码行数:11,代码来源:order_c.go
示例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>"))
}
开发者ID:zoe527,项目名称:go2o,代码行数:35,代码来源:login_c.go
示例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),
)))
}
开发者ID:jackyan,项目名称:go2o,代码行数:12,代码来源:user_c.go
示例13: getPartner
func getPartner(ctx *web.Context) (*partner.ValuePartner, error) {
//todo: 缓存,用Member对应的Partner编号来查询缓存
var partnerId int = ctx.GetItem("partner_id").(int)
var err error
var pt *partner.ValuePartner = cache.GetValuePartnerCache(partnerId)
if pt == nil {
if pt, err = dps.PartnerService.GetPartner(getPartnerId(ctx)); err == nil {
cache.SetValuePartnerCache(partnerId, pt)
}
}
return pt, err
}
开发者ID:zoe527,项目名称:go2o,代码行数:12,代码来源:base_c.go
示例14: 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
}
开发者ID:jackyan,项目名称:go2o,代码行数:13,代码来源:shopping_c.go
示例15: 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
}
开发者ID:zoe527,项目名称:go2o,代码行数:13,代码来源:base_c.go
示例16: 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 + "'}"))
}
开发者ID:zoe527,项目名称:go2o,代码行数:14,代码来源:user_c.go
示例17: GetPartner
// 获取商户
func (this *baseC) GetPartner(ctx *web.Context) *partner.ValuePartner {
val := ctx.Session().Get("member:rel_partner")
if val != nil {
return cache.GetValuePartnerCache(val.(int))
} else {
m := this.GetMember(ctx)
if m != nil {
rel := dps.MemberService.GetRelation(m.Id)
ctx.Session().Set("member:rel_partner", rel.RegisterPartnerId)
ctx.Session().Save()
return cache.GetValuePartnerCache(rel.RegisterPartnerId)
}
}
return nil
}
开发者ID:zoe527,项目名称:go2o,代码行数:16,代码来源:base_c.go
示例18: member
//跳转到会员中心
// url : /user/jump_m
func (this *userC) member(ctx *web.Context) {
m := this.GetMember(ctx)
var location string
if m == nil {
location = "/login?return_url=/member"
} else {
location = fmt.Sprintf("http://%s.%s/login/partner_connect?sessionId=%s&mid=%d&token=%s",
variable.DOMAIN_PREFIX_MEMBER,
ctx.App.Config().GetString(variable.ServerDomain),
ctx.Session().GetSessionId(),
m.Id,
m.DynamicToken,
)
}
ctx.Response.Write([]byte("<script>window.parent.location.replace('" + location + "')</script>"))
}
开发者ID:zoe527,项目名称:go2o,代码行数:18,代码来源:user_c.go
示例19: File_upload
func (this *editorController) File_upload(ctx *web.Context) {
if ctx.Request().Method != "POST" {
return errors.New("error request method")
}
fileUrl, err := fileUpload(ctx.Request, "./uploads/", "http://img.abc.com/uploads/")
var hash map[string]interface{} = make(map[string]interface{})
if err == nil {
hash["error"] = 0
hash["url"] = fileUrl
} else {
hash["error"] = 1
hash["message"] = err.Error()
}
ctx.Response.Header().Add("Content-Type", "application/json")
d, _ := json.Marshal(hash)
ctx.Response.Write(d)
}
开发者ID:jsix,项目名称:go-kindeditor,代码行数:17,代码来源:demo.go
示例20: Return_alipay
func (this *PaymentC) Return_alipay(ctx *web.Context) {
//this.paymentFail(ctx,nil)
//return
aliPayObj := this.getAliPayment(ctx)
result := aliPayObj.Return(ctx.Request)
partnerId := this.GetPartnerId(ctx)
if len(result.OrderNo) == 0 {
result.OrderNo = ctx.Session().Get("current_payment").(string)
}
order := dps.ShoppingService.GetOrderByNo(partnerId, result.OrderNo)
if result.Status == payment.StatusTradeSuccess {
this.handleOrder(order, "alipay", &result)
this.paymentSuccess(ctx, order, &result)
return
}
this.paymentFail(ctx, order, &result)
}
开发者ID:jackyan,项目名称:go2o,代码行数:18,代码来源:payment_c.go
注:本文中的github.com/jsix/gof/web.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论