Overhaul [1/n]

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-01-29 02:42:28 +08:00
parent 989acd6ff1
commit c77241a883
2267 changed files with 7158 additions and 5583 deletions
+33
View File
@@ -0,0 +1,33 @@
package basic
import (
"encoding/json"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func getCode(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
codeArray := `{"codeArray":[{"btntext":"好的","code":"-10264022","msg_from":2,"text":"","title":"短信验证码被阻止","type":1},{"btntext":"","code":"-10869623","msg_from":2,"text":"","title":"网络连接失败,无法一键登录","type":2},{"btntext":"","code":"10298300","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298311","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298312","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298313","msg_from":2,"text":"","title":"","type":1},{"btntext":"","code":"10298321","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298322","msg_from":2,"text":"","title":"","type":3}],"codeVersion":"1.0.5"}`
getCodeData := map[string]any{}
err := json.Unmarshal([]byte(codeArray), &getCodeData)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.GetCodeResp{
Code: 0,
Msg: "ok",
Data: getCodeData,
})
}
func init() {
router.AddHandler("v1", "GET", "/basic/getcode", getCode)
router.AddHandler("v1", "POST", "/basic/getcode", getCode)
}
@@ -0,0 +1,29 @@
package basic
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func getProductList(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
getProductListData := ghome.GetProductListData{
Message: []string{},
Result: 0,
}
ss.Respond(ghome.GetProductListResp{
Code: 1,
Msg: "ok",
Data: getProductListData,
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/getProductList", getProductList)
}
+60
View File
@@ -0,0 +1,60 @@
package basic
import (
"encoding/base64"
"fmt"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"honoka-chan/pkg/db"
"honoka-chan/pkg/encrypt"
honokautils "honoka-chan/pkg/utils"
"net/url"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-think/openssl"
)
func handshake(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
if ss.CheckErr(err) {
return
}
data, err = base64.StdEncoding.DecodeString(string(data))
if ss.CheckErr(err) {
return
}
decryptedData := encrypt.RSADecrypt(data)
params, _ := url.ParseQuery(string(decryptedData))
randKey := []byte(params.Get("randkey"))
deviceID := ss.GetDeviceID()
err = db.Ldb.Set([]byte(deviceID), randKey)
if ss.CheckErr(err) {
return
}
token := fmt.Sprintf(`{"message":"ok","result":0,"token":"%s"}`, strings.ToUpper(honokautils.RandomStr(33)))
encryptedToken, err := openssl.Des3ECBEncrypt([]byte(token), randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.HandshakeResp{
Code: 0,
Msg: "ok",
Data: base64.StdEncoding.EncodeToString(encryptedToken),
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/handshake", handshake)
}
+26
View File
@@ -0,0 +1,26 @@
package basic
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func loginArea(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
ss.Respond(ghome.LoginAreaResp{
Code: 0,
Msg: "ok",
Data: ghome.LoginAreaData{
UserID: ctx.PostForm("userid"),
},
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/loginarea", loginArea)
}
+45
View File
@@ -0,0 +1,45 @@
package basic
import (
"encoding/base64"
"encoding/pem"
"honoka-chan/config"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
honokautils "honoka-chan/pkg/utils"
"github.com/gin-gonic/gin"
)
func publicKey(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
publicKeyCode := 0
publicKeyMsg := "ok"
publicKeyData := ghome.PublicKeyData{
Result: publicKeyCode,
Message: publicKeyMsg,
}
publicKey := honokautils.ReadAllText(config.PublicKeyPath)
block, _ := pem.Decode([]byte(publicKey))
if block == nil || block.Type != "PUBLIC KEY" {
publicKeyMsg = "公钥读取失败!"
publicKeyCode = 31
} else {
publicKeyData.Key = base64.StdEncoding.EncodeToString(block.Bytes)
publicKeyData.Method = "rsa"
}
ss.Respond(ghome.PublicKeyResp{
Code: publicKeyCode,
Msg: publicKeyMsg,
Data: publicKeyData,
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/publickey", publicKey)
}