Example #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))
}
Example #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)
}
Example #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))
}
Example #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))
}
Example #5
0
// @router /add-music_tag [post]
func (this *AdminController) AddMusicTag() {
	var msg string
	// var data = make(map[string]string)
	tag_name := this.GetString("tag_name")
	if tag_name == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		ret, err := models.AddMusicTag(tag_name)
		if err != nil {
			msg = common.Response(500, "插入数据库出错:"+err.Error(), nil)
		} else if ret == -1 {
			msg = common.Response(501, "已经存在这个标签了", nil)
		} else {
			// fmt.Println(ret)
			id := strconv.FormatInt(ret, 10)
			msg = common.Response(200, "插入第"+id+"个音乐标签`"+tag_name+"`成功", nil)
		}
	}
	this.Ctx.WriteString(msg)
}
Example #6
0
// @router /add-character [post]
func (this *AdminController) AddCharacter() {
	var msg string
	// var data = make(map[string]string)
	intro := this.GetString("intro")
	if intro == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		ret, err := models.AddCharacter(intro)
		if err != nil {
			msg = common.Response(500, "插入数据库出错:"+err.Error(), nil)
		} else if ret == -1 {
			msg = common.Response(501, "九型人格已经添加完成,不能继续添加了", nil)
		} else {
			// fmt.Println(ret)
			id := strconv.FormatInt(ret, 10)
			msg = common.Response(200, "插入第"+id+"型人格成功", nil)
		}
	}
	this.Ctx.WriteString(msg)
}
Example #7
0
// @router /add-app_key [post]
func (this *AdminController) AddDev() {
	var msg string
	content := make(map[string]string)
	// var data = make(map[string]string)
	// TODO 之后调用组件然后返回的时候添加一个app_key
	content["api_token"] = this.GetString("api_token")
	content["dev_name"] = this.GetString("dev_name")

	if content["api_token"] == "" || content["dev_name"] == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		ret, err := models.AddAppKey(content)
		if err != nil {
			msg = common.Response(500, "插入数据库出错:"+err.Error(), nil)
		} else if ret == -1 {
			msg = common.Response(501, "已经存在该开发者", nil)
		} else {
			// fmt.Println(ret)
			id := strconv.FormatInt(ret, 10)
			msg = common.Response(200, "插入第"+id+"个开发者信息成功", nil)
		}
	}
	this.Ctx.WriteString(msg)
}
Example #8
0
// @Title Dev.Register
// @Description 开发者注册
// @Param   the_id    query   string   true   "通过系统获取"
// @Param   password    query   string   true   "需要开发者输入密码验证身份"
// @Success 200 成功
// @Failure 401 参数不完整
// @router /register [post]
func (this *DevController) Register() {
	var msg string
	var data = make(map[string]string)
	data["the_id"] = this.GetString("api_token")
	data["password"] = this.GetString("password")
	if data["the_id"] == "" || data["password"] == "" {
		msg = common.Response(401, "参数不完整,请检查参数", nil)
	} else {
		url := beego.AppConfig.String("Component::DevRegister")
		res := common.Request(url, data, "")
		// fmt.Println("===res===")
		// fmt.Println(res)
		if res["code"] != "200" {
			// fmt.Println(res)
			msg = common.Response(500, res["msg"], nil)
		} else {
			// fmt.Println("===数据===")
			// fmt.Println(res["msg"])
			type Msg struct {
				Code string
				Msg  string
				Data map[string]string
			}
			var m Msg
			err := json.Unmarshal([]byte(res["msg"]), &m)
			if err != nil {
				// fmt.Println("===错误===")
				// fmt.Println(err)
				msg = common.Response(501, "服务器内部错误", nil)
			} else {
				if m.Code != "10003.201" {
					msg = common.Response(502, m.Msg, nil)
				} else {
					ret, err := models.AddAppKey(m.Data)
					if err != nil {
						msg = common.Response(503, "插入数据库出错:"+err.Error(), nil)
					} else if ret == -1 {
						msg = common.Response(504, "已经存在该开发者", nil)
					} else {
						// fmt.Println(ret)
						msg = common.Response(200, "恭喜您成功成为开发者!", nil)
					}
				}
				/**********涨姿势***********/
				// fmt.Println("===json 解析===")
				// t := reflect.TypeOf(m.Data)
				// v := reflect.ValueOf(m.Data)
				// fmt.Println(m)
				// fmt.Println(m.Code)
				// switch m.Data.(type) {
				// case string:
				// 	fmt.Println("yeah")
				// default:
				// 	fmt.Println("······")
				// }
				// fmt.Println("===类型===")
				// fmt.Println(t)
				// fmt.Println("===值===")
				// fmt.Println(m.Data)
				//

				//
				// for i := 0; i < t.NumField(); i++ {
				// 	f := t.Field(i)
				// 	val := v.Field(i).Interface()
				// 	fmt.Println(f)
				// 	fmt.Println(val)
				// }
				//

				//
				// switch v := m.(type) {
				// default:
				// 	fmt.Println("===switch===")
				// 	fmt.Println(reflect.TypeOf(v))
				// } // 接口的类型选择
				/***************************/
			}
		}
	}
	this.Ctx.WriteString(string(msg))
}