|
@@ -229,7 +229,7 @@ type Result struct {
|
|
|
Result []interface{} `json:"result"`
|
|
Result []interface{} `json:"result"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//定义正确结果集
|
|
|
|
|
|
|
+// 定义正确结果集
|
|
|
func (self *BaseController) FormatResult(result []interface{}) *Result {
|
|
func (self *BaseController) FormatResult(result []interface{}) *Result {
|
|
|
return &Result{
|
|
return &Result{
|
|
|
Status: 200,
|
|
Status: 200,
|
|
@@ -243,8 +243,11 @@ func (self *BaseController) GetCurrentUserId() int64 {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (self *BaseController) GetCurrentUser(useCache bool) *user_model.User {
|
|
func (self *BaseController) GetCurrentUser(useCache bool) *user_model.User {
|
|
|
-
|
|
|
|
|
- id := self.GetCurrentWxUser(useCache).UserId
|
|
|
|
|
|
|
+ wxUser := self.GetCurrentWxUser(useCache)
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ id := wxUser.UserId
|
|
|
if id <= 0 {
|
|
if id <= 0 {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
@@ -267,12 +270,12 @@ func (self *BaseController) GetCurrentWxUser(useCache bool) *user_model.WxUser {
|
|
|
return u
|
|
return u
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//根据token解析userId
|
|
|
|
|
|
|
+// 根据token解析userId
|
|
|
func (self *BaseController) GetCurrentWxUserIdByToken() int64 {
|
|
func (self *BaseController) GetCurrentWxUserIdByToken() int64 {
|
|
|
return getCurrentUserIdByToken(self.Ctx)
|
|
return getCurrentUserIdByToken(self.Ctx)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//TODO校验是否微信客户端
|
|
|
|
|
|
|
+// TODO校验是否微信客户端
|
|
|
func getCurrentUserIdByToken(ctx *context.Context) int64 {
|
|
func getCurrentUserIdByToken(ctx *context.Context) int64 {
|
|
|
inputToken := ""
|
|
inputToken := ""
|
|
|
wxUserId := int64(0)
|
|
wxUserId := int64(0)
|
|
@@ -291,7 +294,7 @@ func getCurrentUserIdByToken(ctx *context.Context) int64 {
|
|
|
return wxUserId
|
|
return wxUserId
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//sceneId, 关注场景id
|
|
|
|
|
|
|
+// sceneId, 关注场景id
|
|
|
func (self *BaseController) CheckWxUserSubscribe(sceneId int64) {
|
|
func (self *BaseController) CheckWxUserSubscribe(sceneId int64) {
|
|
|
beego.BeeLogger.Info("check wx_user subscribe")
|
|
beego.BeeLogger.Info("check wx_user subscribe")
|
|
|
ctx := self.Ctx
|
|
ctx := self.Ctx
|
|
@@ -376,7 +379,7 @@ func checkWxUserLogin(ctx *context.Context) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//检查来自大后台的请求是否为服务器IP
|
|
|
|
|
|
|
+// 检查来自大后台的请求是否为服务器IP
|
|
|
func CheckIsInvokeFromRailsAdmin(ctx *context.Context) {
|
|
func CheckIsInvokeFromRailsAdmin(ctx *context.Context) {
|
|
|
s := strings.Split(ctx.Request.RemoteAddr, ":")
|
|
s := strings.Split(ctx.Request.RemoteAddr, ":")
|
|
|
ip := s[0]
|
|
ip := s[0]
|
|
@@ -423,7 +426,7 @@ type ErrCode struct {
|
|
|
Data map[string]string `json:"data"`
|
|
Data map[string]string `json:"data"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//定义返回错误信息
|
|
|
|
|
|
|
+// 定义返回错误信息
|
|
|
func (self *BaseController) ReturnError(status int, code []string, redirect string, data map[string]string) {
|
|
func (self *BaseController) ReturnError(status int, code []string, redirect string, data map[string]string) {
|
|
|
errCode := &ErrCode{
|
|
errCode := &ErrCode{
|
|
|
Status: status,
|
|
Status: status,
|
|
@@ -443,12 +446,12 @@ func (self *BaseController) ReturnError(status int, code []string, redirect stri
|
|
|
// self.ServeJson(status, string(jsonErrCode))
|
|
// self.ServeJson(status, string(jsonErrCode))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//TODO校验是否微信客户端
|
|
|
|
|
|
|
+// TODO校验是否微信客户端
|
|
|
func (self *BaseController) IsWxClient() bool {
|
|
func (self *BaseController) IsWxClient() bool {
|
|
|
return isWxClient(self.Ctx)
|
|
return isWxClient(self.Ctx)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//TODO校验是否微信客户端
|
|
|
|
|
|
|
+// TODO校验是否微信客户端
|
|
|
func isWxClient(ctx *context.Context) bool {
|
|
func isWxClient(ctx *context.Context) bool {
|
|
|
agent := ctx.Input.UserAgent()
|
|
agent := ctx.Input.UserAgent()
|
|
|
b := getRealBrowser(agent)
|
|
b := getRealBrowser(agent)
|