Beispiel #1
0
// @Title User.Login
// @Description 用户登录
// @Param   email   query   string    true   "用户邮箱"
// @Param   password    query   string  true  "用户密码"
// @Success 200 成功
// @Failure 401 参数不完整
// @Failure 402 邮箱有误
// @router /login [post]
func (this *UserController) Login() {
	var msg string
	var data = make(map[string]string)
	data["email"] = this.GetString("email")
	data["password"] = this.GetString("password")
	api_token := this.GetString("api_token")
	if data["email"] == "" || data["password"] == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		check := common.IsEmail(data["email"])
		if check {
			app_key, _ := models.GetAppKey(api_token)
			url := beego.AppConfig.String("Component::UserLogin")
			res := common.Request(url, data, app_key["app_key"])
			if res["code"] != "200" {
				// fmt.Println(res)
				msg = common.Response(500, res["msg"], nil)
			} else {
				msg = common.Response(200, "成功", res["msg"])
			}
		} else {
			msg = common.Response(402, "邮箱有误", nil)
		}
	}
	// ret, _ := common.EncodeData([]byte(msg))
	// common.WriteLog("加密消息@User.Register.EncodeData:" + string(msg))
	// if ret == nil {
	// 	msg = common.Response(505, "服务器内部错误")
	// 	this.Ctx.WriteString(msg)
	// }
	this.Ctx.WriteString(string(msg))
}
Beispiel #2
0
// @router /getone [post]
func (this *CharacterController) GetOne() {
	var msg string
	var data = make(map[string]string)
	id := this.GetString("id")
	api_token := this.GetString("api_token")
	if id == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		character_id, _ := strconv.ParseInt(id, 10, 64)
		ret, err := models.GetOneCharacter(character_id)
		if err != nil {
			msg = common.Response(500, "查询数据库出错:"+err.Error(), nil)
		} else {
			// fmt.Println(ret)
			app_key, _ := models.GetAppKey(api_token)
			key := strconv.FormatInt(ret.Id, 10)
			data[key] = ret.Introduction
			jsonbyte, _ := json.Marshal(data)
			encode_data, err := common.EncodeData(jsonbyte, app_key["app_key"])
			if err != nil {
				msg = common.Response(200, "查询错误:"+err.Error(), nil)
			} else {
				msg = common.Response(200, "成功", string(encode_data))
			}
		}
	}
	this.Ctx.WriteString(msg)
}
Beispiel #3
0
// @Title Dev.GetAppKey
// @Description 开发者获取appkey
// @Param   api_token    query   string   true   "开发者在注册的时候获取的api_token"
// @Success 200 成功
// @Failure 401 参数不完整
// @Failure 403 不存在该api_token
// @router /get-app-key [post]
func (this *DevController) GetAppKey() {
	var msg string
	var data = make(map[string]string)
	data["api_token"] = this.GetString("api_token")
	if data["api_token"] == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		app_key, err := models.GetAppKey(data["api_token"])
		if err != nil || app_key == nil {
			msg = common.Response(403, "查询失败,api_token不存在", nil)
		} else {
			timenow := time.Now().Unix()
			expire_time, _ := strconv.ParseInt(app_key["expire_time"], 10, 64)
			if expire_time < timenow {
				//app_key过期,去update一个新的出来
				// fmt.Println("【@#==========是update的==========#@】")
				app_key, err = models.UpdateAppKey(data["api_token"])
			}
			if err != nil {
				msg = common.Response(500, "服务器内部错误", nil)
			} else {
				// jsonbyte, _ := json.Marshal(app_key)
				// encode_data, _ := common.EncodeData(jsonbyte)
				msg = common.Response(200, "成功", app_key)
			}
		}
	}
	// ret, _ := common.EncodeData([]byte(msg))
	// common.WriteLog("加密消息@User.Register.EncodeData:" + string(msg))
	// if ret == nil {
	// 	msg = common.Response(505, "服务器内部错误")
	// 	this.Ctx.WriteString(msg)
	// }
	this.Ctx.WriteString(string(msg))
}
Beispiel #4
0
// @Title Music.GetAllTags
// @Description 获取所有音乐的标签
// @Success 200 成功
// @Failure 401 参数不完整
// @Failure 402 邮箱有误
// @router /get-all-tags [post]
func (this *MusicController) GetAllTags() {
	var msg string
	var data = make(map[string]string)
	data["page"] = this.GetString("page")
	data["count"] = this.GetString("count")
	api_token := this.GetString("api_token")
	if data["page"] == "" {
		data["page"] = "1"
	}
	if data["count"] == "" {
		data["count"] = "10"
	}
	page, _ := strconv.Atoi(data["page"])
	count, _ := strconv.Atoi(data["count"])
	if page < 1 || count < 1 || count > 20 {
		msg = common.Response(401, "参数中page不应该小于1,count不应该大于20小于1,请检查参数", nil)
	} else {
		limit := count
		offset := (page - 1) * count
		var opts = make(map[string]int)
		// opts["limit"] = strconv.Itoa(limit)
		// opts["offset"] = strconv.Itoa(offset)
		opts["limit"] = limit
		opts["offset"] = offset
		res, err := models.GetAllMusicTag(opts)
		if err != nil {
			msg = common.Response(500, "查询数据库出错", nil)
		} else {
			app_key, _ := models.GetAppKey(api_token)
			jsonbyte, _ := json.Marshal(res)
			// fmt.Println("===jsonbyte===")
			// fmt.Println(reflect.TypeOf(res))
			// fmt.Println(jsonbyte)
			encode_data, e := common.EncodeData(jsonbyte, app_key["app_key"])
			if e != nil {
				msg = common.Response(501, "服务器内部错误", nil)
			} else {
				msg = common.Response(200, "成功", string(encode_data))
			}
		}
	}
	this.Ctx.WriteString(string(msg))
}
Beispiel #5
0
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
	// "net/http"
)

// var r *http.Request //加了星号会爆出一个恐慌
var check = func(ctx *context.Context) {
	form := ctx.Request.Form
	if form["api_token"] == nil || form["sign"] == nil || form["timestamp"] == nil {
		ctx.WriteString("请求不合法")
	} else {
		check := make(map[string]string)
		api_token := form["api_token"][0]
		check["sign"] = form["sign"][0]
		check["timestamp"] = form["timestamp"][0]
		app_key, err := models.GetAppKey(api_token)
		if err != nil {
			ctx.WriteString("没有查询到开发者信息") //查询出错
		} else {
			ret := common.CheckSign(check, app_key)
			switch ret {
			// case 1:
			// 	ctx.WriteString("签名检查成功")
			case 0:
				ctx.WriteString("签名不匹配")
			case -1:
				ctx.WriteString("app_key过期")
			}
		}
	}
}