diff --git a/server/api/api/member/member.go b/server/api/api/member/member.go index 8816592..d335001 100644 --- a/server/api/api/member/member.go +++ b/server/api/api/member/member.go @@ -1,16 +1,15 @@ -// Package member -// @Link https://github.com/bufanyun/hotgo -// @Copyright Copyright (c) 2023 HotGo CLI -// @Author Ms <133814250@qq.com> -// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + package member -import "github.com/gogf/gf/v2/frame/g" +import ( + "context" -// GetIdByCodeReq 通过邀请码获取用户ID -type GetIdByCodeReq struct { - g.Meta `path:"/member/getIdByCode" method:"post" tags:"用户" summary:"通过邀请码获取用户ID"` - Code string `json:"code" dc:"邀请码"` + "hotgo/api/api/member/v1" +) + +type IMemberV1 interface { + GetIdByCode(ctx context.Context, req *v1.GetIdByCodeReq) (res *v1.GetIdByCodeRes, err error) } - -type GetIdByCodeRes struct{} diff --git a/server/api/api/member/v1/member.go b/server/api/api/member/v1/member.go new file mode 100644 index 0000000..0ed4bb6 --- /dev/null +++ b/server/api/api/member/v1/member.go @@ -0,0 +1,16 @@ +// Package member +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +package v1 + +import "github.com/gogf/gf/v2/frame/g" + +// GetIdByCodeReq 通过邀请码获取用户ID +type GetIdByCodeReq struct { + g.Meta `path:"/member/getIdByCode" method:"post" tags:"用户" summary:"通过邀请码获取用户ID"` + Code string `json:"code" dc:"邀请码"` +} + +type GetIdByCodeRes struct{} diff --git a/server/api/api/pay/pay.go b/server/api/api/pay/pay.go new file mode 100644 index 0000000..654099c --- /dev/null +++ b/server/api/api/pay/pay.go @@ -0,0 +1,17 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package pay + +import ( + "context" + + "hotgo/api/api/pay/v1" +) + +type IPayV1 interface { + NotifyAliPay(ctx context.Context, req *v1.NotifyAliPayReq) (res *v1.NotifyAliPayRes, err error) + NotifyWxPay(ctx context.Context, req *v1.NotifyWxPayReq) (res *v1.NotifyWxPayRes, err error) + NotifyQQPay(ctx context.Context, req *v1.NotifyQQPayReq) (res *v1.NotifyQQPayRes, err error) +} diff --git a/server/api/api/pay/notify.go b/server/api/api/pay/v1/notify.go similarity index 98% rename from server/api/api/pay/notify.go rename to server/api/api/pay/v1/notify.go index bd0448e..8ac343b 100644 --- a/server/api/api/pay/notify.go +++ b/server/api/api/pay/v1/notify.go @@ -3,11 +3,12 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -package pay +package v1 import ( - "github.com/gogf/gf/v2/frame/g" "hotgo/internal/model/input/payin" + + "github.com/gogf/gf/v2/frame/g" ) // NotifyAliPayReq 支付宝回调 diff --git a/server/hack/config.yaml b/server/hack/config.yaml index 3e75ed9..80b369d 100644 --- a/server/hack/config.yaml +++ b/server/hack/config.yaml @@ -38,4 +38,10 @@ gfcli: # srcFolder: "internal/logic" # dstFolder: "internal/service" # dstFileNameCase: "CamelLower" -# clear: true \ No newline at end of file +# clear: true + ctrl: + # api/api下的接口可以使用gf gen ctrl自动生成控制器相关代码 + srcFolder: "api/api" + dstFolder: "internal/controller/api" + clear: true + merge: false diff --git a/server/internal/controller/admin/common/site.go b/server/internal/controller/admin/common/site.go index 7b5c2f9..da3462d 100644 --- a/server/internal/controller/admin/common/site.go +++ b/server/internal/controller/admin/common/site.go @@ -45,7 +45,12 @@ func (c *cSite) Config(ctx context.Context, _ *common.SiteConfigReq) (res *commo func (c *cSite) getWsAddr(ctx context.Context, request *ghttp.Request) string { // 如果是本地IP访问,则认为是调试模式,走实际请求地址,否则走配置中的地址 + // 尝试读取hostname,兼容本地运行模式 ip := ghttp.RequestFromCtx(ctx).GetHeader("hostname") + if len(ip) == 0 { + ip = ghttp.RequestFromCtx(ctx).GetHost() + } + if validate.IsLocalIPAddr(ip) { return "ws://" + ip + ":" + gstr.StrEx(request.Host, ":") + g.Cfg().MustGet(ctx, "router.websocket.prefix").String() } @@ -59,7 +64,12 @@ func (c *cSite) getWsAddr(ctx context.Context, request *ghttp.Request) string { func (c *cSite) getDomain(ctx context.Context, request *ghttp.Request) string { // 如果是本地IP访问,则认为是调试模式,走实际请求地址,否则走配置中的地址 - ip := request.GetHeader("hostname") + // 尝试读取hostname,兼容本地运行模式 + ip := ghttp.RequestFromCtx(ctx).GetHeader("hostname") + if len(ip) == 0 { + ip = ghttp.RequestFromCtx(ctx).GetHost() + } + if validate.IsLocalIPAddr(ip) { return "http://" + ip + ":" + gstr.StrEx(request.Host, ":") } diff --git a/server/internal/controller/api/member/member.go b/server/internal/controller/api/member/member.go index 9599400..6fe3c71 100644 --- a/server/internal/controller/api/member/member.go +++ b/server/internal/controller/api/member/member.go @@ -1,23 +1,5 @@ -// Package member -// @Link https://github.com/bufanyun/hotgo -// @Copyright Copyright (c) 2023 HotGo CLI -// @Author Ms <133814250@qq.com> -// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + package member - -import ( - "context" - "github.com/gogf/gf/v2/frame/g" - "hotgo/api/api/member" -) - -var ( - Member = cMember{} -) - -type cMember struct{} - -func (c *cMember) GetIdByCode(ctx context.Context, _ *member.GetIdByCodeReq) (res *member.GetIdByCodeRes, err error) { - g.RequestFromCtx(ctx).Response.Writeln("Hello World api member!") - return -} diff --git a/server/internal/controller/api/member/member_new.go b/server/internal/controller/api/member/member_new.go new file mode 100644 index 0000000..dfb4e71 --- /dev/null +++ b/server/internal/controller/api/member/member_new.go @@ -0,0 +1,15 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package member + +import ( + "hotgo/api/api/member" +) + +type ControllerV1 struct{} + +func NewV1() member.IMemberV1 { + return &ControllerV1{} +} diff --git a/server/internal/controller/api/member/member_v1_get_id_by_code.go b/server/internal/controller/api/member/member_v1_get_id_by_code.go new file mode 100644 index 0000000..42010d3 --- /dev/null +++ b/server/internal/controller/api/member/member_v1_get_id_by_code.go @@ -0,0 +1,14 @@ +package member + +import ( + "context" + + v1 "hotgo/api/api/member/v1" + + "github.com/gogf/gf/v2/frame/g" +) + +func (c *ControllerV1) GetIdByCode(ctx context.Context, req *v1.GetIdByCodeReq) (res *v1.GetIdByCodeRes, err error) { + g.RequestFromCtx(ctx).Response.Writeln("Hello World api member!") + return +} diff --git a/server/internal/controller/api/pay/notify.go b/server/internal/controller/api/pay/notify.go deleted file mode 100644 index cd05f28..0000000 --- a/server/internal/controller/api/pay/notify.go +++ /dev/null @@ -1,57 +0,0 @@ -// Package pay -// @Link https://github.com/bufanyun/hotgo -// @Copyright Copyright (c) 2023 HotGo CLI -// @Author Ms <133814250@qq.com> -// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -package pay - -import ( - "context" - "github.com/gogf/gf/v2/frame/g" - "hotgo/api/api/pay" - "hotgo/internal/consts" - "hotgo/internal/library/response" - "hotgo/internal/model/input/payin" - "hotgo/internal/service" -) - -var ( - Notify = cNotify{} -) - -type cNotify struct{} - -// AliPay 支付宝回调 -func (c *cNotify) AliPay(ctx context.Context, _ *pay.NotifyAliPayReq) (res *pay.NotifyAliPayRes, err error) { - if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeAliPay}); err != nil { - return nil, err - } - - response.RText(g.RequestFromCtx(ctx), "success") - return -} - -// WxPay 微信支付回调 -func (c *cNotify) WxPay(ctx context.Context, _ *pay.NotifyWxPayReq) (res *pay.NotifyWxPayRes, err error) { - if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeWxPay}); err != nil { - return - } - - response.CustomJson(g.RequestFromCtx(ctx), `{"code": "SUCCESS","message": "收单成功"}`) - return -} - -// QQPay QQ支付回调 -func (c *cNotify) QQPay(ctx context.Context, _ *pay.NotifyQQPayReq) (res *pay.NotifyQQPayRes, err error) { - if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeQQPay}); err != nil { - return - } - - r := g.RequestFromCtx(ctx) - r.Response.ClearBuffer() - r.Response.Write(``) - r.Response.WriteXml(g.Map{ - "return_code": "SUCCESS", - }) - return -} diff --git a/server/internal/controller/api/pay/pay.go b/server/internal/controller/api/pay/pay.go new file mode 100644 index 0000000..cc269a0 --- /dev/null +++ b/server/internal/controller/api/pay/pay.go @@ -0,0 +1,5 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package pay diff --git a/server/internal/controller/api/pay/pay_new.go b/server/internal/controller/api/pay/pay_new.go new file mode 100644 index 0000000..53eb435 --- /dev/null +++ b/server/internal/controller/api/pay/pay_new.go @@ -0,0 +1,15 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package pay + +import ( + "hotgo/api/api/pay" +) + +type ControllerV1 struct{} + +func NewV1() pay.IPayV1 { + return &ControllerV1{} +} diff --git a/server/internal/controller/api/pay/pay_v1_notify_ali_pay.go b/server/internal/controller/api/pay/pay_v1_notify_ali_pay.go new file mode 100644 index 0000000..5e22899 --- /dev/null +++ b/server/internal/controller/api/pay/pay_v1_notify_ali_pay.go @@ -0,0 +1,22 @@ +package pay + +import ( + "context" + + v1 "hotgo/api/api/pay/v1" + "hotgo/internal/consts" + "hotgo/internal/library/response" + "hotgo/internal/model/input/payin" + "hotgo/internal/service" + + "github.com/gogf/gf/v2/frame/g" +) + +func (c *ControllerV1) NotifyAliPay(ctx context.Context, req *v1.NotifyAliPayReq) (res *v1.NotifyAliPayRes, err error) { + if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeAliPay}); err != nil { + return nil, err + } + + response.RText(g.RequestFromCtx(ctx), "success") + return +} diff --git a/server/internal/controller/api/pay/pay_v1_notify_qq_pay.go b/server/internal/controller/api/pay/pay_v1_notify_qq_pay.go new file mode 100644 index 0000000..6c93b03 --- /dev/null +++ b/server/internal/controller/api/pay/pay_v1_notify_qq_pay.go @@ -0,0 +1,26 @@ +package pay + +import ( + "context" + + v1 "hotgo/api/api/pay/v1" + "hotgo/internal/consts" + "hotgo/internal/model/input/payin" + "hotgo/internal/service" + + "github.com/gogf/gf/v2/frame/g" +) + +func (c *ControllerV1) NotifyQQPay(ctx context.Context, req *v1.NotifyQQPayReq) (res *v1.NotifyQQPayRes, err error) { + if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeQQPay}); err != nil { + return + } + + r := g.RequestFromCtx(ctx) + r.Response.ClearBuffer() + r.Response.Write(``) + r.Response.WriteXml(g.Map{ + "return_code": "SUCCESS", + }) + return +} diff --git a/server/internal/controller/api/pay/pay_v1_notify_wx_pay.go b/server/internal/controller/api/pay/pay_v1_notify_wx_pay.go new file mode 100644 index 0000000..e871910 --- /dev/null +++ b/server/internal/controller/api/pay/pay_v1_notify_wx_pay.go @@ -0,0 +1,22 @@ +package pay + +import ( + "context" + + v1 "hotgo/api/api/pay/v1" + "hotgo/internal/consts" + "hotgo/internal/library/response" + "hotgo/internal/model/input/payin" + "hotgo/internal/service" + + "github.com/gogf/gf/v2/frame/g" +) + +func (c *ControllerV1) NotifyWxPay(ctx context.Context, req *v1.NotifyWxPayReq) (res *v1.NotifyWxPayRes, err error) { + if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeWxPay}); err != nil { + return + } + + response.CustomJson(g.RequestFromCtx(ctx), `{"code": "SUCCESS","message": "收单成功"}`) + return +} diff --git a/server/internal/logic/pay/create.go b/server/internal/logic/pay/create.go index ded2fa5..c75c598 100644 --- a/server/internal/logic/pay/create.go +++ b/server/internal/logic/pay/create.go @@ -10,13 +10,7 @@ package pay import ( "context" "fmt" - "github.com/gogf/gf/v2/encoding/gjson" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/net/ghttp" - "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/v2/util/gmeta" - "hotgo/api/api/pay" + v1 "hotgo/api/api/pay/v1" "hotgo/internal/consts" "hotgo/internal/library/contexts" "hotgo/internal/library/location" @@ -25,6 +19,13 @@ import ( "hotgo/internal/model/input/payin" "hotgo/internal/service" "hotgo/utility/validate" + + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/util/gmeta" ) // Create 创建支付订单和日志 @@ -127,11 +128,11 @@ func (s *sPay) GenNotifyURL(ctx context.Context, in payin.PayCreateInp) (notifyU var object interface{} switch in.PayType { case consts.PayTypeAliPay: - object = pay.NotifyAliPayReq{} + object = v1.NotifyAliPayReq{} case consts.PayTypeWxPay: - object = pay.NotifyWxPayReq{} + object = v1.NotifyWxPayReq{} case consts.PayTypeQQPay: - object = pay.NotifyQQPayReq{} + object = v1.NotifyQQPayReq{} default: err = gerror.Newf("未被支持的支付方式:%v", in.PayType) return diff --git a/server/internal/router/api.go b/server/internal/router/api.go index f5be5ea..27b2980 100644 --- a/server/internal/router/api.go +++ b/server/internal/router/api.go @@ -7,23 +7,24 @@ package router import ( "context" - "github.com/gogf/gf/v2/net/ghttp" "hotgo/internal/consts" "hotgo/internal/controller/api/member" "hotgo/internal/controller/api/pay" "hotgo/internal/service" "hotgo/utility/simple" + + "github.com/gogf/gf/v2/net/ghttp" ) // Api 前台路由 func Api(ctx context.Context, group *ghttp.RouterGroup) { group.Group(simple.RouterPrefix(ctx, consts.AppApi), func(group *ghttp.RouterGroup) { group.Bind( - pay.Notify, // 支付异步通知 + pay.NewV1(), // 支付异步通知 ) group.Middleware(service.Middleware().ApiAuth) group.Bind( - member.Member, // 管理员 + member.NewV1(), // 管理员 ) }) }