diff --git a/handler/api.go b/handler/api.go index d37afaf..d1a290f 100644 --- a/handler/api.go +++ b/handler/api.go @@ -896,20 +896,27 @@ func ApiHandler(ctx *gin.Context) { CheckErr(err) } else if v.Action == "profileInfo" { // key = "profile_info_result" + pref := tools.UserPref{} + exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Get(&pref) + CheckErr(err) + if !exists { + ctx.String(http.StatusForbidden, ErrorMsg) + return + } profileResp := tools.ProfileResp{ Result: tools.ProfileResult{ UserInfo: tools.UserInfo{ - UserID: 9999999, // 3241988 - Name: "\u68a6\u8def @\u65c5\u7acb\u3061\u306e\u65e5\u306b", - Level: 1028, + UserID: pref.UserID, + Name: pref.UserName, + Level: pref.UserLevel, CostMax: 100, UnitMax: 5000, - EnergyMax: 417, + EnergyMax: 1000, FriendMax: 99, UnitCnt: 3898, - InviteCode: "377385143", + InviteCode: strconv.Itoa(pref.UserID), ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d", - Introduction: "\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d \u65f6\u5149\u4ece\u4e0d\u505c\u7559\\n\u5982\u4eca\u7684\u6211\u4eec \u6bd5\u4e1a\u518d\u56de\u9996\\n\u8ffd\u68a6\u7684\u670b\u53cb\u4eec\u4e00\u540c \u8e0f\u4e0a\u4e86\u65b0\u7684\u5f81\u9014\\n\u5728\u4e0d\u4e45\u7684\u4eca\u540e \u5728\u672a\u77e5\u7684\u67d0\u5904\\n \u6211\u4eec\u4e00\u5b9a\u4f1a\u518d\u4e00\u6b21\u9082\u9005\\n \u8bf7\u4e0d\u8981\u5fd8\u8bb0\u6211\u4eec \u66fe\u7ecf\u7684\u7b11\u5bb9\r", + Introduction: pref.UserDesc, }, CenterUnitInfo: tools.CenterUnitInfo{ UnitOwningUserID: 41674, diff --git a/handler/award.go b/handler/award.go new file mode 100644 index 0000000..09c2e35 --- /dev/null +++ b/handler/award.go @@ -0,0 +1,40 @@ +package handler + +import ( + "encoding/base64" + "encoding/json" + "fmt" + "honoka-chan/encrypt" + "honoka-chan/model" + "honoka-chan/tools" + "net/http" + "time" + + "github.com/gin-gonic/gin" + "github.com/tidwall/gjson" +) + +func AwardSet(ctx *gin.Context) { + req := gjson.Parse(ctx.PostForm("request_data")) + pref := tools.UserPref{ + AwardID: int(req.Get("award_id").Int()), + } + _, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) + CheckErr(err) + awardResp := model.AwardSetResp{ + ResponseData: []interface{}{}, + ReleaseInfo: []interface{}{}, + StatusCode: 200, + } + resp, err := json.Marshal(awardResp) + CheckErr(err) + + nonce := ctx.GetInt("nonce") + nonce++ + + ctx.Header("user_id", ctx.GetString("userid")) + ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time"))) + ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSA_Sign_SHA1(resp, "privatekey.pem"))) + + ctx.String(http.StatusOK, string(resp)) +} diff --git a/handler/background.go b/handler/background.go new file mode 100644 index 0000000..9fdd45f --- /dev/null +++ b/handler/background.go @@ -0,0 +1,40 @@ +package handler + +import ( + "encoding/base64" + "encoding/json" + "fmt" + "honoka-chan/encrypt" + "honoka-chan/model" + "honoka-chan/tools" + "net/http" + "time" + + "github.com/gin-gonic/gin" + "github.com/tidwall/gjson" +) + +func BackgroundSet(ctx *gin.Context) { + req := gjson.Parse(ctx.PostForm("request_data")) + pref := tools.UserPref{ + BackgroundID: int(req.Get("background_id").Int()), + } + _, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) + CheckErr(err) + backgroundResp := model.BackgroundSetResp{ + ResponseData: []interface{}{}, + ReleaseInfo: []interface{}{}, + StatusCode: 200, + } + resp, err := json.Marshal(backgroundResp) + CheckErr(err) + + nonce := ctx.GetInt("nonce") + nonce++ + + ctx.Header("user_id", ctx.GetString("userid")) + ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time"))) + ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSA_Sign_SHA1(resp, "privatekey.pem"))) + + ctx.String(http.StatusOK, string(resp)) +} diff --git a/handler/profile.go b/handler/profile.go new file mode 100644 index 0000000..35f0157 --- /dev/null +++ b/handler/profile.go @@ -0,0 +1,40 @@ +package handler + +import ( + "encoding/base64" + "encoding/json" + "fmt" + "honoka-chan/encrypt" + "honoka-chan/model" + "honoka-chan/tools" + "net/http" + "time" + + "github.com/gin-gonic/gin" + "github.com/tidwall/gjson" +) + +func ProfileRegister(ctx *gin.Context) { + req := gjson.Parse(ctx.PostForm("request_data")) + pref := tools.UserPref{ + UserDesc: req.Get("introduction").String(), + } + _, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) + CheckErr(err) + profileResp := model.ProfileRegisterResp{ + ResponseData: []interface{}{}, + ReleaseInfo: []interface{}{}, + StatusCode: 200, + } + resp, err := json.Marshal(profileResp) + CheckErr(err) + + nonce := ctx.GetInt("nonce") + nonce++ + + ctx.Header("user_id", ctx.GetString("userid")) + ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time"))) + ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSA_Sign_SHA1(resp, "privatekey.pem"))) + + ctx.String(http.StatusOK, string(resp)) +} diff --git a/handler/user.go b/handler/user.go index 6e72aef..bfa8964 100644 --- a/handler/user.go +++ b/handler/user.go @@ -5,10 +5,13 @@ import ( "encoding/json" "fmt" "honoka-chan/encrypt" + "honoka-chan/model" + "honoka-chan/tools" "net/http" "time" "github.com/gin-gonic/gin" + "github.com/tidwall/gjson" ) type NotificationResp struct { @@ -37,12 +40,54 @@ func SetNotificationTokenHandler(ctx *gin.Context) { } func ChangeNaviHandler(ctx *gin.Context) { - notifResp := NotificationResp{ + req := gjson.Parse(ctx.PostForm("request_data")) + pref := tools.UserPref{ + UnitOwningUserID: int(req.Get("unit_owning_user_id").Int()), + } + _, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) + CheckErr(err) + naviResp := model.UserNaviChangeResp{ ResponseData: []interface{}{}, ReleaseInfo: []interface{}{}, StatusCode: 200, } - resp, err := json.Marshal(notifResp) + resp, err := json.Marshal(naviResp) + CheckErr(err) + + nonce := ctx.GetInt("nonce") + nonce++ + + ctx.Header("user_id", ctx.GetString("userid")) + ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time"))) + ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSA_Sign_SHA1(resp, "privatekey.pem"))) + + ctx.String(http.StatusOK, string(resp)) +} + +func ChangeNameHandler(ctx *gin.Context) { + req := gjson.Parse(ctx.PostForm("request_data")) + var oldName string + exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("user_name").Get(&oldName) + CheckErr(err) + if !exists { + ctx.String(http.StatusForbidden, ErrorMsg) + return + } + pref := tools.UserPref{ + UserName: req.Get("name").String(), + } + _, err = UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) + CheckErr(err) + nameResp := model.UserNameChangeResp{ + ResponseData: model.UserNameChangeRes{ + BeforeName: oldName, + AfterName: req.Get("name").String(), + ServerTimestamp: time.Now().Unix(), + }, + ReleaseInfo: []interface{}{}, + StatusCode: 200, + } + resp, err := json.Marshal(nameResp) CheckErr(err) nonce := ctx.GetInt("nonce") diff --git a/main.go b/main.go index bf75ca2..8d31800 100644 --- a/main.go +++ b/main.go @@ -48,42 +48,46 @@ func main() { // Server APIs m := r.Group("main.php").Use(middleware.Common) { - m.POST("/login/authkey", middleware.AuthKey, handler.AuthKey) - m.POST("/login/login", middleware.Login, handler.Login) - m.POST("/user/userInfo", handler.UserInfoHandler) - m.POST("/gdpr/get", handler.GdprHandler) - m.POST("/personalnotice/get", handler.PersonalNoticeHandler) - m.POST("/tos/tosCheck", handler.TosCheckHandler) + m.POST("/album/seriesAll", handler.AlbumSeriesAllHandler) + m.POST("/announce/checkState", handler.AnnounceCheckStateHandler) + m.POST("/api", handler.ApiHandler) + m.POST("/award/set", handler.AwardSet) + m.POST("/background/set", handler.BackgroundSet) m.POST("/download/additional", handler.DownloadAdditionalHandler) m.POST("/download/batch", handler.DownloadBatchHandler) + m.POST("/download/event", handler.DownloadEventHandler) m.POST("/download/getUrl", handler.DownloadUrlHandler) m.POST("/download/update", handler.DownloadUpdateHandler) - m.POST("/download/event", handler.DownloadEventHandler) - m.POST("/lbonus/execute", handler.LBonusExecuteHandler) - m.POST("/api", handler.ApiHandler) - m.POST("/announce/checkState", handler.AnnounceCheckStateHandler) - m.POST("/scenario/startup", handler.ScenarioStartupHandler) - m.POST("/scenario/reward", handler.ScenarioRewardHandler) - m.POST("/user/setNotificationToken", handler.SetNotificationTokenHandler) - m.POST("/user/changeNavi", handler.SetNotificationTokenHandler) m.POST("/event/eventList", handler.EventListHandler) - m.POST("/payment/productList", handler.ProductListHandler) + m.POST("/gdpr/get", handler.GdprHandler) + m.POST("/lbonus/execute", handler.LBonusExecuteHandler) + m.POST("/live/gameover", handler.GameOverHandler) m.POST("/live/partyList", handler.PartyListHandler) m.POST("/live/play", handler.PlayLiveHandler) m.POST("/live/preciseScore", handler.PlayScoreHandler) m.POST("/live/reward", handler.PlayRewardHandler) - m.POST("/live/gameover", handler.GameOverHandler) - m.POST("/unit/setDisplayRank", handler.SetDisplayRankHandler) - m.POST("/unit/favorite", handler.SetDisplayRankHandler) + m.POST("/login/authkey", middleware.AuthKey, handler.AuthKey) + m.POST("/login/login", middleware.Login, handler.Login) + m.POST("/multiunit/scenarioStartup", handler.MultiUnitStartUpHandler) + m.POST("/notice/noticeFriendGreeting", handler.NoticeFriendGreetingHandler) + m.POST("/notice/noticeFriendVariety", handler.NoticeFriendVarietyHandler) + m.POST("/notice/noticeUserGreetingHistory", handler.NoticeUserGreetingHandler) + m.POST("/payment/productList", handler.ProductListHandler) + m.POST("/personalnotice/get", handler.PersonalNoticeHandler) + m.POST("/profile/profileRegister", handler.ProfileRegister) + m.POST("/scenario/reward", handler.ScenarioRewardHandler) + m.POST("/scenario/startup", handler.ScenarioStartupHandler) + m.POST("/subscenario/reward", handler.SubScenarioStartupHandler) + m.POST("/subscenario/startup", handler.SubScenarioStartupHandler) + m.POST("/tos/tosCheck", handler.TosCheckHandler) m.POST("/unit/deck", handler.SetDeckHandler) m.POST("/unit/deckName", handler.SetDeckNameHandler) - m.POST("/subscenario/startup", handler.SubScenarioStartupHandler) - m.POST("/subscenario/reward", handler.SubScenarioStartupHandler) - m.POST("/album/seriesAll", handler.AlbumSeriesAllHandler) - m.POST("/notice/noticeFriendVariety", handler.NoticeFriendVarietyHandler) - m.POST("/notice/noticeFriendGreeting", handler.NoticeFriendGreetingHandler) - m.POST("/notice/noticeUserGreetingHistory", handler.NoticeUserGreetingHandler) - m.POST("/multiunit/scenarioStartup", handler.MultiUnitStartUpHandler) + m.POST("/unit/favorite", handler.SetDisplayRankHandler) + m.POST("/unit/setDisplayRank", handler.SetDisplayRankHandler) + m.POST("/user/changeName", handler.ChangeNameHandler) + m.POST("/user/changeNavi", handler.ChangeNaviHandler) + m.POST("/user/setNotificationToken", handler.SetNotificationTokenHandler) + m.POST("/user/userInfo", handler.UserInfoHandler) } r.GET("/webview.php/announce/index", handler.AnnounceIndexHandler) // Server APIs diff --git a/model/award.go b/model/award.go new file mode 100644 index 0000000..d396b26 --- /dev/null +++ b/model/award.go @@ -0,0 +1,8 @@ +package model + +// AwardSetResp ... +type AwardSetResp struct { + ResponseData []interface{} `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} diff --git a/model/background.go b/model/background.go new file mode 100644 index 0000000..da06818 --- /dev/null +++ b/model/background.go @@ -0,0 +1,8 @@ +package model + +// BackgroundSetResp ... +type BackgroundSetResp struct { + ResponseData []interface{} `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} diff --git a/model/profile.go b/model/profile.go new file mode 100644 index 0000000..99a8ed6 --- /dev/null +++ b/model/profile.go @@ -0,0 +1,8 @@ +package model + +// AwardSetResp ... +type ProfileRegisterResp struct { + ResponseData []interface{} `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} diff --git a/model/user.go b/model/user.go new file mode 100644 index 0000000..69dde13 --- /dev/null +++ b/model/user.go @@ -0,0 +1,22 @@ +package model + +// UserNaviResp ... +type UserNaviChangeResp struct { + ResponseData []interface{} `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} + +// UserNameChangeResp ... +type UserNameChangeResp struct { + ResponseData UserNameChangeRes `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} + +// UserNameChangeRes ... +type UserNameChangeRes struct { + BeforeName string `json:"before_name"` + AfterName string `json:"after_name"` + ServerTimestamp int64 `json:"server_timestamp"` +} diff --git a/tools/init.go b/tools/init.go index a6f0f3d..fb899cc 100644 --- a/tools/init.go +++ b/tools/init.go @@ -40,6 +40,10 @@ func InitUserData(userId int) { session := UserEng.NewSession() defer session.Close() + if err := session.Begin(); err != nil { + panic(err) + } + for _, user := range userList { // 检查用户配置 exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", user.UserID).Exist() @@ -61,13 +65,9 @@ func InitUserData(userId int) { UserDesc: "你好。", UpdateTime: time.Now().Unix(), } - _, err = UserEng.Table("user_preference_m").Insert(&userPref) + _, err = session.Table("user_preference_m").Insert(&userPref) CheckErr(err) fmt.Println("UserPref ID", userPref.ID) - } else { - userPref := UserPref{} - _, err = UserEng.Table("user_preference_m").Where("user_id = ?", user.UserID).Get(&userPref) - CheckErr(err) } // 检查用户卡组配置 @@ -84,10 +84,6 @@ func InitUserData(userId int) { InsertDate: time.Now().Unix(), } - if err = session.Begin(); err != nil { - panic(err) - } - // 默认队伍 _, err = session.Table("user_deck_m").Insert(&userDeck) if err != nil {