add swagger demo

This commit is contained in:
wangchuxiao
2022-06-24 17:45:33 +08:00
parent db7ef3ac4b
commit 99062805ec
16 changed files with 367 additions and 50 deletions
+9
View File
@@ -195,6 +195,14 @@ func GetUsersInfo(c *gin.Context) {
c.JSON(http.StatusOK, resp)
}
// @Summary 更新用户信息
// @Description 向你说Hello
// @Tags 测试
// @Accept json
// @Param who query string true "人名"
// @Success 200 {string} string "{"msg": "hello Razeen"}"
// @Failure 400 {string} string "{"msg": "who are you"}"
// @Router /update_user_info [post]
func UpdateUserInfo(c *gin.Context) {
params := api.UpdateSelfUserInfoReq{}
if err := c.BindJSON(&params); err != nil {
@@ -233,6 +241,7 @@ func UpdateUserInfo(c *gin.Context) {
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
c.JSON(http.StatusOK, resp)
}
func SetGlobalRecvMessageOpt(c *gin.Context) {
params := api.SetGlobalRecvMessageOptReq{}
if err := c.BindJSON(&params); err != nil {
+2 -1
View File
@@ -20,6 +20,7 @@ type ParamsLogin struct {
Password string `json:"password"`
Platform int32 `json:"platform"`
OperationID string `json:"operationID" binding:"required"`
AreaCode string `json:"areaCode"`
}
func Login(c *gin.Context) {
@@ -35,7 +36,7 @@ func Login(c *gin.Context) {
account = params.PhoneNumber
}
r, err := im_mysql_model.GetRegister(account)
r, err := im_mysql_model.GetRegister(account, params.AreaCode)
if err != nil {
log.NewError(params.OperationID, "user have not register", params.Password, account, err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "Mobile phone number is not registered"})
+3 -2
View File
@@ -16,6 +16,7 @@ type resetPasswordRequest struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
NewPassword string `json:"newPassword" binding:"required"`
AreaCode string `json:"areaCode"`
OperationID string `json:"operationID"`
}
@@ -34,7 +35,7 @@ func ResetPassword(c *gin.Context) {
account = req.PhoneNumber
}
if req.VerificationCode != config.Config.Demo.SuperCode {
accountKey := account + "_" + constant.VerificationCodeForResetSuffix
accountKey := req.AreaCode + account + "_" + constant.VerificationCodeForResetSuffix
v, err := db.DB.GetAccountCode(accountKey)
if err != nil || v != req.VerificationCode {
log.NewError(req.OperationID, "password Verification code error", account, req.VerificationCode, v)
@@ -42,7 +43,7 @@ func ResetPassword(c *gin.Context) {
return
}
}
user, err := im_mysql_model.GetRegister(account)
user, err := im_mysql_model.GetRegister(account, req.AreaCode)
if err != nil || user.Account == "" {
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get register error", err.Error())
+7 -6
View File
@@ -22,6 +22,7 @@ type paramsVerificationCode struct {
PhoneNumber string `json:"phoneNumber"`
OperationID string `json:"operationID" binding:"required"`
UsedFor int `json:"usedFor"`
AreaCode string `json:"areaCode"`
}
func SendVerificationCode(c *gin.Context) {
@@ -37,28 +38,28 @@ func SendVerificationCode(c *gin.Context) {
} else {
account = params.PhoneNumber
}
var accountKey string
var accountKey = params.AreaCode + account
if params.UsedFor == 0 {
params.UsedFor = constant.VerificationCodeForRegister
}
switch params.UsedFor {
case constant.VerificationCodeForRegister:
_, err := im_mysql_model.GetRegister(account)
_, err := im_mysql_model.GetRegister(account, params.AreaCode)
if err == nil {
log.NewError(params.OperationID, "The phone number has been registered", params)
c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": "The phone number has been registered"})
return
}
ok, err := db.DB.JudgeAccountEXISTS(account)
ok, err := db.DB.JudgeAccountEXISTS(accountKey)
if ok || err != nil {
log.NewError(params.OperationID, "The phone number has been registered", params)
c.JSON(http.StatusOK, gin.H{"errCode": constant.RepeatSendCode, "errMsg": "The phone number has been registered"})
return
}
accountKey = account + "_" + constant.VerificationCodeForRegisterSuffix
accountKey += "_" + constant.VerificationCodeForRegisterSuffix
case constant.VerificationCodeForReset:
accountKey = account + "_" + constant.VerificationCodeForResetSuffix
accountKey += "_" + constant.VerificationCodeForResetSuffix
}
rand.Seed(time.Now().UnixNano())
code := 100000 + rand.Intn(900000)
@@ -90,7 +91,7 @@ func SendVerificationCode(c *gin.Context) {
}
sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
PhoneNumbers: tea.String(account),
PhoneNumbers: tea.String(accountKey),
SignName: tea.String(config.Config.Demo.AliSMSVerify.SignName),
TemplateCode: tea.String(config.Config.Demo.AliSMSVerify.VerificationCodeTemplateCode),
TemplateParam: tea.String(fmt.Sprintf("{\"code\":\"%d\"}", code)),
+2 -1
View File
@@ -27,6 +27,7 @@ type ParamsSetPassword struct {
Ex string `json:"ex"`
FaceURL string `json:"faceURL"`
OperationID string `json:"operationID" binding:"required"`
AreaCode string `json:"areaCode"`
}
func SetPassword(c *gin.Context) {
@@ -88,7 +89,7 @@ func SetPassword(c *gin.Context) {
return
}
log.Info(params.OperationID, "begin store mysql", account, params.Password, "info", params.FaceURL, params.Nickname)
err = im_mysql_model.SetPassword(account, params.Password, params.Ex, userID)
err = im_mysql_model.SetPassword(account, params.Password, params.Ex, userID, params.AreaCode)
if err != nil {
log.NewError(params.OperationID, "set phone number password error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
+2 -1
View File
@@ -16,6 +16,7 @@ type paramsCertification struct {
VerificationCode string `json:"verificationCode"`
OperationID string `json:"operationID" binding:"required"`
UsedFor int `json:"usedFor"`
AreaCode string `json:"areaCode"`
}
func Verify(c *gin.Context) {
@@ -31,7 +32,7 @@ func Verify(c *gin.Context) {
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
account = params.AreaCode + params.PhoneNumber
}
if params.VerificationCode == config.Config.Demo.SuperCode {