Răsfoiți Sursa

基础go后端代码提交

gujiheimao 1 an în urmă
comite
26fd0be80c

+ 12 - 0
ahttp/req.http

@@ -0,0 +1,12 @@
+POST http://localhost:9777/ark/timedPointsReward/group
+Content-Type: application/json
+auth-sign: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjI0MTcxOTgsImlzcyI6ImFkbWluIn0.oMvc0eKZ3D3EPQM6IWoaPWMaP5Ukte0XZd3_xmVdAFg
+
+{
+  "group": {
+    "name": "VIP01",
+    "amount": 1000
+  }
+}
+
+###

+ 88 - 0
configs/config.go

@@ -0,0 +1,88 @@
+package configs
+
+import (
+	"fmt"
+	_ "github.com/glebarez/sqlite"
+	"github.com/spf13/cast"
+	"github.com/spf13/viper"
+
+	"os"
+	"xorm.io/xorm"
+)
+
+var (
+	Server  ServerConfiguration
+	Manager ServerManager
+	Engine  *xorm.Engine
+	//RedisDb *redis.Client
+)
+
+type ServerConfiguration struct {
+	Port string `mapstructure:"port"`
+	Host string `mapstructure:"host"`
+}
+
+type ServerManager struct {
+	Username string `json:"username"`
+	Password string `json:"password"`
+}
+
+func init() {
+	LoadServerConfiguration()
+	ConfigInit()
+}
+
+func LoadServerConfiguration() {
+	//获取项目的执行路径
+	path, err := os.Getwd()
+	if err != nil {
+		panic(err)
+	}
+	config := viper.New()
+
+	config.AddConfigPath(path + "/configs") //设置读取的文件路径
+	config.SetConfigName("config")          //设置读取的文件名
+	config.SetConfigType("yaml")            //设置文件的类型
+	if err := config.ReadInConfig(); err != nil {
+		panic(err)
+	}
+	portString := config.Get("server.port")
+	if cast.ToString(portString) == "" {
+		portString = "9777"
+	}
+	host := config.Get("server.host")
+
+	Server = ServerConfiguration{
+		Port: cast.ToString(portString),
+		Host: cast.ToString(host),
+	}
+	//用户账号密码获取
+	username := config.Get("server.manager.username")
+	password := config.Get("server.manager.password")
+	Manager = ServerManager{
+		Username: cast.ToString(username),
+		Password: cast.ToString(password),
+	}
+}
+
+func ConfigInit() {
+	//获取项目的执行路径
+	path, err := os.Getwd()
+	if err != nil {
+		panic(err)
+	}
+	config := viper.New()
+	config.AddConfigPath(path + "/configs") //设置读取的文件路径
+	config.SetConfigName("config")          //设置读取的文件名
+	config.SetConfigType("yaml")            //设置文件的类型
+	//尝试进行配置读取
+	if err := config.ReadInConfig(); err != nil {
+		panic(err)
+	}
+	Engine, err = xorm.NewEngine("sqlite", "./file/ark-tools.db")
+	Engine.Ping() //连接测试
+	//TODO  显示sql
+	Engine.ShowSQL(true)
+	Engine.Logger().ShowSQL(true)
+	fmt.Println("xorm 数据库orm框架初始化成功")
+}

+ 5 - 0
configs/config.yaml

@@ -0,0 +1,5 @@
+server:
+  port: 9777
+  manager:
+    username: "admin"
+    password: "123456"

+ 1 - 0
dao/GeneralDao.go

@@ -0,0 +1 @@
+package dao

+ 15 - 0
dao/MysqlDao.go

@@ -0,0 +1,15 @@
+package dao
+
+import (
+	"ARKItems/entity/ark"
+	"ARKItems/router"
+)
+
+// GetMysqlInfo 获取配置mysql项目
+func GetMysqlInfo() ark.Mysql {
+	return router.ARKConfig.Mysql
+}
+
+func SetMysqlInfo(mysql ark.Mysql) {
+	router.ARKConfig.Mysql = mysql
+}

+ 29 - 0
entity/Domain.go

@@ -0,0 +1,29 @@
+package entity
+
+type Group struct {
+	Name   string `json:"Name"`
+	Amount int    `json:"Amount"`
+}
+
+type ArkItemInfo struct {
+	Id        string `xorm:"id" json:"id"`
+	Name      string `xorm:"name" json:"name"`
+	Label     string `xorm:"label" json:"label"`
+	ImgUrl    string `xorm:"img_url" json:"imgUrl"`
+	Category  string `xorm:"category" json:"category"`
+	StackSize int    `xorm:"stack_size" json:"stackSize"`
+	ItemId    string `xorm:"item_id" json:"itemId"`
+	ClassName string `xorm:"class_name" json:"className"`
+	Blueprint string `xorm:"blueprint" json:"blueprint"`
+}
+
+type ArkDinoInfo struct {
+	Id        string `xorm:"id" json:"id"`
+	Name      string `xorm:"name" json:"name"`
+	Label     string `xorm:"label" json:"label"`
+	NameTag   string `xorm:"name_tag" json:"nameTag"`
+	ImgUrl    string `xorm:"img_url" json:"imgUrl"`
+	Category  string `xorm:"category" json:"category"`
+	Entity    string `xorm:"entity_id" json:"entityId"`
+	Blueprint string `xorm:"blueprint" json:"blueprint"`
+}

+ 7 - 0
entity/Response.go

@@ -0,0 +1,7 @@
+package entity
+
+type Response struct {
+	Code    int         `json:"code"`
+	Message string      `json:"message"`
+	Data    interface{} `json:"data"`
+}

+ 149 - 0
entity/ark/Config.go

@@ -0,0 +1,149 @@
+package ark
+
+// ARKShopConfig  总配置
+
+type Config struct {
+	Mysql     Mysql                  `json:"Mysql"`     //数据库
+	General   General                `json:"General"`   //概述
+	Kits      map[string]Kit         `json:"Kits"`      //礼包?
+	ShopItems map[string]interface{} `json:"ShopItems"` //商品
+	SellItems map[string]SellItem    `json:"SellItems"` //回收
+	Messages  Messages               `json:"Messages"`  //消息
+}
+
+type Mysql struct {
+	UseMysql  bool   `json:"UseMysql"`  //是否使用mysql
+	MysqlHost string `json:"MysqlHost"` //mysql地址
+	MysqlUser string `json:"MysqlUser"` //mysql用户名
+	MysqlPass string `json:"MysqlPass"` //mysql密码
+	MysqlDB   string `json:"MysqlDB"`   //mysql数据库
+	MysqlPort int    `json:"MysqlPort"` //mysql端口
+}
+
+// General 概述
+type General struct {
+	Discord                       Discord           `json:"Discord"`           //联系方式
+	TimedPointsReward             TimedPointsReward `json:"TimedPointsReward"` //计时积分奖励
+	UseOriginalTradeCommandWithUI bool              `json:"UseOriginalTradeCommandWithUI"`
+	ItemsPerPage                  int               `json:"ItemsPerPage"`        //每页项目数
+	ShopDisplayTime               float64           `json:"ShopDisplayTime"`     //店铺展示时间
+	ShopTextSize                  float64           `json:"ShopTextSize"`        //店铺文字大小
+	DbPathOverride                string            `json:"DbPathOverride"`      //db文件位置
+	DefaultKit                    string            `json:"DefaultKit"`          //默认礼包?
+	GiveDinosInCryopods           bool              `json:"GiveDinosInCryopods"` //在低温仓给恐龙
+	UseSoulTraps                  bool              `json:"UseSoulTraps"`        //使用灵魂陷阱?
+	CryoLimitedTime               bool              `json:"CryoLimitedTime"`     //低温仓有限时间?
+}
+
+type Discord struct {
+	Enabled    bool   `json:"Enabled"`    //启用
+	SenderName string `json:"SenderName"` //发件人
+	URL        string `json:"URL"`        //地址
+}
+
+type TimedPointsReward struct {
+	Enabled      bool             `json:"Enabled"`      //启用
+	Interval     int              `json:"Interval"`     //间隔(应该是分钟为单位)
+	StackRewards bool             `json:"StackRewards"` //堆栈奖励
+	Groups       map[string]Group `json:"Groups"`       //vip 组(key: vip名称(英文),金额)
+}
+
+type Group struct {
+	Amount int `json:"Amount"` //金额
+}
+
+type Messages struct {
+	Sender                 string `json:"Sender"`                 //发件人
+	BoughtItem             string `json:"BoughtItem"`             //已购买商品
+	BoughtDino             string `json:"BoughtDino"`             //已购买恐龙
+	BoughtBeacon           string `json:"BoughtBeacon"`           //已购买信标?
+	BoughtExp              string `json:"BoughtExp"`              //已购买经验
+	ReceivedPoints         string `json:"ReceivedPoints"`         //已获得积分
+	HavePoints             string `json:"HavePoints"`             //拥有积分
+	NoPoints               string `json:"NoPoints"`               //没有积分
+	WrongId                string `json:"WrongId"`                //错误的id
+	NoPermissionsKit       string `json:"NoPermissionsKit"`       //没有权限
+	CantBuyKit             string `json:"CantBuyKit"`             //无法购买
+	BoughtKit              string `json:"BoughtKit"`              //已购买礼包
+	AvailableKits          string `json:"AvailableKits"`          //可用礼包
+	NoKits                 string `json:"NoKits"`                 //没有礼包
+	KitsLeft               string `json:"KitsLeft"`               //礼包剩余
+	NoKitsLeft             string `json:"NoKitsLeft"`             //没有礼包
+	CantGivePoints         string `json:"CantGivePoints"`         //无法发送积分
+	RidingDino             string `json:"RidingDino"`             //正在骑乘恐龙
+	SentPoints             string `json:"SentPoints"`             //已发送积分
+	GotPoints              string `json:"GotPoints"`              //已获得积分
+	NoPlayer               string `json:"NoPlayer"`               //没有玩家
+	FoundMorePlayers       string `json:"FoundMorePlayers"`       //找到多个玩家
+	BuyUsage               string `json:"BuyUsage"`               //购买命令
+	ShopUsage              string `json:"ShopUsage"`              //商店命令
+	KitUsage               string `json:"KitUsage"`               //交易命令
+	BuyKitUsage            string `json:"BuyKitUsage"`            //购买礼包命令
+	TradeUsage             string `json:"TradeUsage"`             //交易命令
+	PointsCmd              string `json:"PointsCmd"`              //积分命令
+	TradeCmd               string `json:"TradeCmd"`               //交易命令
+	BuyCmd                 string `json:"BuyCmd"`                 //购买命令
+	ShopCmd                string `json:"ShopCmd"`                //商店命令
+	KitCmd                 string `json:"KitCmd"`                 //交易命令
+	BuyKitCmd              string `json:"BuyKitCmd"`              //购买礼包命令
+	SellCmd                string `json:"SellCmd"`                //出售命令
+	ShopSellCmd            string `json:"ShopSellCmd"`            //商店出售命令
+	SellUsage              string `json:"SellUsage"`              //出售命令
+	NotEnoughItems         string `json:"NotEnoughItems"`         //没有足够的物品
+	SoldItems              string `json:"SoldItems"`              //已出售物品
+	BadLevel               string `json:"BadLevel"`               //错误的等级
+	KitsListPrice          string `json:"KitsListPrice"`          //礼包列表价格
+	KitsListFormat         string `json:"KitsListFormat"`         //礼包列表格式
+	StoreListDino          string `json:"StoreListDino"`          //商店列表恐龙
+	StoreListItem          string `json:"StoreListItem"`          //商店列表物品
+	StoreListFormat        string `json:"StoreListFormat"`        //商店列表格式
+	OnlyOnSpawnKit         string `json:"OnlyOnSpawnKit"`         //只能购买在出生点礼包
+	HelpCmd                string `json:"HelpCmd"`                //帮助命令
+	ShopMessage            string `json:"ShopMessage"`            //商店消息
+	HelpMessage            string `json:"HelpMessage"`            //帮助消息
+	RefundError            string `json:"RefundError"`            //退款错误
+	ShopFindCmd            string `json:"ShopFindCmd"`            //商店查找命令
+	ShopFindUsage          string `json:"ShopFindUsage"`          //商店查找用法
+	ShopFindNotFound       string `json:"ShopFindNotFound"`       //商店查找不存在
+	ShopFindTooManyResults string `json:"ShopFindTooManyResults"` //商店发现太多结果
+	NoPermissionsStore     string `json:"NoPermissionsStore"`     //没有权限
+}
+
+// SellItem 允许玩家出售物资,以换取积分
+type SellItem struct {
+	Type        string `json:"Type"`        //类型,item
+	Description string `json:"Description"` //描述
+	Price       int    `json:"Price"`       //价格
+	Amount      int    `json:"Amount"`      //数量
+	Blueprint   string `json:"Blueprint"`   //图纸
+}
+
+// Kit 礼包
+type Kit struct {
+	DefaultAmount int       `json:"DefaultAmount"` //数量?
+	Price         int       `json:"Price"`         //价格
+	Description   string    `json:"Description"`   //描述
+	Permissions   string    `json:"Permissions"`   //购买权限,例如"Admins,VIP1"
+	Dinos         []Dino    `json:"Dinos"`         //恐龙
+	Items         []Item    `json:"Items"`
+	Commands      []Command `json:"Commands"`
+}
+
+// Item 物品信息
+type Item struct {
+	Amount         int     `json:"Amount"`         //金额
+	Blueprint      string  `json:"Blueprint"`      //图纸
+	Fixed          bool    `json:"Fixed"`          //固定
+	ForceBlueprint bool    `json:"ForceBlueprint"` //
+	Quality        float64 `json:"Quality"`        //质量
+}
+type Dino struct {
+	Level     int    `json:"Level"`     //等级
+	Neutered  bool   `json:"Neutered"`  //是否绝育
+	Blueprint string `json:"Blueprint"` //指令?
+}
+
+type Command struct {
+	Command   string `json:"Command"`
+	DisplayAs string `json:"DisplayAs"`
+}

+ 66 - 0
entity/ark/Item.go

@@ -0,0 +1,66 @@
+package ark
+
+// ShopItem 类型
+type ShopItem struct {
+	Type        string `json:"Type"`
+	Description string `json:"Description"`
+	Price       int    `json:"Price"`
+
+	Items []Item `json:"Items,omitempty"`
+}
+
+// ShopDino  类型
+type ShopDino struct {
+	Type        string `json:"Type"`
+	Description string `json:"Description"`
+	Price       int    `json:"Price"`
+
+	Level           int    `json:"Level"`
+	MinLevel        int    `json:"MinLevel,omitempty"`
+	MaxLevel        int    `json:"MaxLevel,omitempty"`
+	Neutered        bool   `json:"Neutered,omitempty"`
+	Gender          string `json:"Gender,omitempty"`
+	SaddleBlueprint string `json:"SaddleBlueprint,omitempty"`
+	Blueprint       string `json:"Blueprint"`
+}
+
+// ShopBeacon 类型
+type ShopBeacon struct {
+	Type        string `json:"Type"`
+	Description string `json:"Description"`
+	Price       int    `json:"Price"`
+
+	ClassName string `json:"ClassName"`
+}
+
+// ShopExperience 类型
+type ShopExperience struct {
+	Type        string `json:"Type"`
+	Description string `json:"Description"`
+	Price       int    `json:"Price"`
+
+	GiveToDino bool    `json:"GiveToDino"`
+	Amount     float64 `json:"Amount"`
+}
+
+// ShopUnlockengram 类型
+type ShopUnlockengram struct {
+	Type        string `json:"Type"`
+	Description string `json:"Description"`
+	Price       int    `json:"Price"`
+	Items       []struct {
+		Blueprint string `json:"Blueprint"`
+	}
+}
+
+// ShopCommand  类型
+type ShopCommand struct {
+	Type        string `json:"Type"`
+	Description string `json:"Description"`
+	Price       int    `json:"Price"`
+
+	Items []struct {
+		Command   string `json:"Command"`
+		DisplayAs string `json:"DisplayAs"`
+	} `json:"Items"`
+}

+ 264 - 0
entity/demo/Command.go

@@ -0,0 +1,264 @@
+package demo
+
+type T struct {
+	Mysql struct {
+		UseMysql  bool   `json:"UseMysql"`
+		MysqlHost string `json:"MysqlHost"`
+		MysqlUser string `json:"MysqlUser"`
+		MysqlPass string `json:"MysqlPass"`
+		MysqlDB   string `json:"MysqlDB"`
+		MysqlPort int    `json:"MysqlPort"`
+	} `json:"Mysql"`
+	General struct {
+		Discord struct {
+			Enabled    bool   `json:"Enabled"`
+			SenderName string `json:"SenderName"`
+			URL        string `json:"URL"`
+		} `json:"Discord"`
+		TimedPointsReward struct {
+			Enabled      bool `json:"Enabled"`
+			StackRewards bool `json:"StackRewards"`
+			Interval     int  `json:"Interval"`
+			Groups       struct {
+				DonatorDiamond struct {
+					Amount int `json:"Amount"`
+				} `json:"Donator-Diamond"`
+				DonatorPlatinum struct {
+					Amount int `json:"Amount"`
+				} `json:"Donator-Platinum"`
+				DonatorGold struct {
+					Amount int `json:"Amount"`
+				} `json:"Donator-Gold"`
+				Verified struct {
+					Amount int `json:"Amount"`
+				} `json:"Verified"`
+				Default struct {
+					Amount int `json:"Amount"`
+				} `json:"Default"`
+			} `json:"Groups"`
+		} `json:"TimedPointsReward"`
+		UseOriginalTradeCommandWithUI bool   `json:"UseOriginalTradeCommandWithUI"`
+		GiveDinosInCryopods           bool   `json:"GiveDinosInCryopods"`
+		UseSoulTraps                  bool   `json:"UseSoulTraps"`
+		CryoLimitedTime               bool   `json:"CryoLimitedTime"`
+		CryoItemPath                  string `json:"CryoItemPath"`
+		ItemsPerPage                  int    `json:"ItemsPerPage"`
+		ShopDisplayTime               int    `json:"ShopDisplayTime"`
+		ShopTextSize                  int    `json:"ShopTextSize"`
+		DbPathOverride                string `json:"DbPathOverride"`
+		DefaultKit                    string `json:"DefaultKit"`
+	} `json:"General"`
+	Kits struct {
+		Starter struct {
+			DefaultAmount int    `json:"DefaultAmount"`
+			Price         int    `json:"Price"`
+			Description   string `json:"Description"`
+			OnlyFromSpawn bool   `json:"OnlyFromSpawn"`
+			Items         []struct {
+				Amount         int    `json:"Amount"`
+				Quality        int    `json:"Quality"`
+				ForceBlueprint bool   `json:"ForceBlueprint"`
+				Armor          int    `json:"Armor"`
+				Blueprint      string `json:"Blueprint"`
+			} `json:"Items"`
+			Dinos []struct {
+				Level     int    `json:"Level"`
+				Blueprint string `json:"Blueprint"`
+			} `json:"Dinos"`
+		} `json:"starter"`
+		Vip struct {
+			DefaultAmount int    `json:"DefaultAmount"`
+			Description   string `json:"Description"`
+			Permissions   string `json:"Permissions"`
+			Dinos         []struct {
+				Level     int    `json:"Level"`
+				Neutered  bool   `json:"Neutered"`
+				Blueprint string `json:"Blueprint"`
+			} `json:"Dinos"`
+			Commands []struct {
+				Command   string `json:"Command"`
+				DisplayAs string `json:"DisplayAs"`
+			} `json:"Commands"`
+		} `json:"vip"`
+		Tools struct {
+			DefaultAmount int    `json:"DefaultAmount"`
+			Price         int    `json:"Price"`
+			MinLevel      int    `json:"MinLevel"`
+			MaxLevel      int    `json:"MaxLevel"`
+			Description   string `json:"Description"`
+			Items         []struct {
+				Amount         int    `json:"Amount"`
+				Quality        int    `json:"Quality"`
+				Damage         int    `json:"Damage,omitempty"`
+				ForceBlueprint bool   `json:"ForceBlueprint"`
+				Blueprint      string `json:"Blueprint"`
+				Durability     int    `json:"Durability,omitempty"`
+			} `json:"Items"`
+		} `json:"tools"`
+	} `json:"Kits"`
+	ShopItems struct {
+		Ingots100 struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			Items       []struct {
+				Quality        int    `json:"Quality"`
+				ForceBlueprint bool   `json:"ForceBlueprint"`
+				Amount         int    `json:"Amount"`
+				Blueprint      string `json:"Blueprint"`
+			} `json:"Items"`
+		} `json:"ingots100"`
+		Tools struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			Items       []struct {
+				Quality        int    `json:"Quality"`
+				ForceBlueprint bool   `json:"ForceBlueprint"`
+				Amount         int    `json:"Amount"`
+				Blueprint      string `json:"Blueprint"`
+			} `json:"Items"`
+		} `json:"tools"`
+		Para struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Level       int    `json:"Level"`
+			Price       int    `json:"Price"`
+			MinLevel    int    `json:"MinLevel"`
+			MaxLevel    int    `json:"MaxLevel"`
+			Blueprint   string `json:"Blueprint"`
+		} `json:"para"`
+		Carno struct {
+			Type            string `json:"Type"`
+			Description     string `json:"Description"`
+			Level           int    `json:"Level"`
+			Price           int    `json:"Price"`
+			Neutered        bool   `json:"Neutered"`
+			Gender          string `json:"Gender"`
+			SaddleBlueprint string `json:"SaddleBlueprint"`
+			Blueprint       string `json:"Blueprint"`
+		} `json:"carno"`
+		Carno2 struct {
+			Type            string `json:"Type"`
+			Description     string `json:"Description"`
+			Level           int    `json:"Level"`
+			Price           int    `json:"Price"`
+			Neutered        bool   `json:"Neutered"`
+			Gender          string `json:"Gender"`
+			SaddleBlueprint string `json:"SaddleBlueprint"`
+			Blueprint       string `json:"Blueprint"`
+		} `json:"carno2"`
+		Carno3 struct {
+			Type            string `json:"Type"`
+			Description     string `json:"Description"`
+			Level           int    `json:"Level"`
+			Price           int    `json:"Price"`
+			Neutered        bool   `json:"Neutered"`
+			Gender          string `json:"Gender"`
+			SaddleBlueprint string `json:"SaddleBlueprint"`
+			Blueprint       string `json:"Blueprint"`
+		} `json:"carno3"`
+		Crate25 struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			ClassName   string `json:"ClassName"`
+		} `json:"crate25"`
+		Crate2 struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			ClassName   string `json:"ClassName"`
+		} `json:"crate2"`
+		Exp1000 struct {
+			Type        string  `json:"Type"`
+			Description string  `json:"Description"`
+			GiveToDino  bool    `json:"GiveToDino"`
+			Price       int     `json:"Price"`
+			Amount      float64 `json:"Amount"`
+		} `json:"exp1000"`
+		Tekengram struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			Items       []struct {
+				Blueprint string `json:"Blueprint"`
+			} `json:"Items"`
+		} `json:"tekengram"`
+		Allengrams struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			Items       []struct {
+				Command   string `json:"Command"`
+				DisplayAs string `json:"DisplayAs"`
+			} `json:"Items"`
+		} `json:"allengrams"`
+	} `json:"ShopItems"`
+	SellItems struct {
+		Metal struct {
+			Type        string `json:"Type"`
+			Description string `json:"Description"`
+			Price       int    `json:"Price"`
+			Amount      int    `json:"Amount"`
+			Blueprint   string `json:"Blueprint"`
+		} `json:"metal"`
+	} `json:"SellItems"`
+	Messages struct {
+		Sender                 string `json:"Sender"`
+		BoughtItem             string `json:"BoughtItem"`
+		BoughtDino             string `json:"BoughtDino"`
+		BoughtBeacon           string `json:"BoughtBeacon"`
+		BoughtExp              string `json:"BoughtExp"`
+		ReceivedPoints         string `json:"ReceivedPoints"`
+		HavePoints             string `json:"HavePoints"`
+		NoPoints               string `json:"NoPoints"`
+		WrongId                string `json:"WrongId"`
+		NoPermissionsKit       string `json:"NoPermissionsKit"`
+		CantBuyKit             string `json:"CantBuyKit"`
+		BoughtKit              string `json:"BoughtKit"`
+		AvailableKits          string `json:"AvailableKits"`
+		NoKits                 string `json:"NoKits"`
+		KitsLeft               string `json:"KitsLeft"`
+		NoKitsLeft             string `json:"NoKitsLeft"`
+		CantGivePoints         string `json:"CantGivePoints"`
+		RidingDino             string `json:"RidingDino"`
+		SentPoints             string `json:"SentPoints"`
+		GotPoints              string `json:"GotPoints"`
+		NoPlayer               string `json:"NoPlayer"`
+		FoundMorePlayers       string `json:"FoundMorePlayers"`
+		BuyUsage               string `json:"BuyUsage"`
+		ShopUsage              string `json:"ShopUsage"`
+		KitUsage               string `json:"KitUsage"`
+		BuyKitUsage            string `json:"BuyKitUsage"`
+		TradeUsage             string `json:"TradeUsage"`
+		PointsCmd              string `json:"PointsCmd"`
+		TradeCmd               string `json:"TradeCmd"`
+		BuyCmd                 string `json:"BuyCmd"`
+		ShopCmd                string `json:"ShopCmd"`
+		KitCmd                 string `json:"KitCmd"`
+		BuyKitCmd              string `json:"BuyKitCmd"`
+		SellCmd                string `json:"SellCmd"`
+		ShopSellCmd            string `json:"ShopSellCmd"`
+		SellUsage              string `json:"SellUsage"`
+		NotEnoughItems         string `json:"NotEnoughItems"`
+		SoldItems              string `json:"SoldItems"`
+		BadLevel               string `json:"BadLevel"`
+		KitsListPrice          string `json:"KitsListPrice"`
+		KitsListFormat         string `json:"KitsListFormat"`
+		StoreListDino          string `json:"StoreListDino"`
+		StoreListItem          string `json:"StoreListItem"`
+		StoreListFormat        string `json:"StoreListFormat"`
+		OnlyOnSpawnKit         string `json:"OnlyOnSpawnKit"`
+		HelpCmd                string `json:"HelpCmd"`
+		ShopMessage            string `json:"ShopMessage"`
+		HelpMessage            string `json:"HelpMessage"`
+		RefundError            string `json:"RefundError"`
+		ShopFindCmd            string `json:"ShopFindCmd"`
+		ShopFindUsage          string `json:"ShopFindUsage"`
+		ShopFindNotFound       string `json:"ShopFindNotFound"`
+		ShopFindTooManyResults string `json:"ShopFindTooManyResults"`
+		NoPermissionsStore     string `json:"NoPermissionsStore"`
+		InventoryIsFull        string `json:"InventoryIsFull"`
+	} `json:"Messages"`
+}

+ 72 - 0
go.mod

@@ -0,0 +1,72 @@
+module ARKItems
+
+go 1.22.0
+
+require (
+	github.com/PuerkitoBio/goquery v1.9.2
+	github.com/dgrijalva/jwt-go v3.2.0+incompatible
+	github.com/gin-gonic/gin v1.10.0
+	github.com/spf13/cast v1.6.0
+	github.com/spf13/viper v1.19.0
+	xorm.io/xorm v1.3.9
+)
+
+require (
+	filippo.io/edwards25519 v1.1.0 // indirect
+	github.com/andybalholm/cascadia v1.3.2 // indirect
+	github.com/bytedance/sonic v1.11.6 // indirect
+	github.com/bytedance/sonic/loader v0.1.1 // indirect
+	github.com/cloudwego/base64x v0.1.4 // indirect
+	github.com/cloudwego/iasm v0.2.0 // indirect
+	github.com/dustin/go-humanize v1.0.1 // indirect
+	github.com/fsnotify/fsnotify v1.7.0 // indirect
+	github.com/gabriel-vasile/mimetype v1.4.3 // indirect
+	github.com/gin-contrib/sse v0.1.0 // indirect
+	github.com/glebarez/go-sqlite v1.21.2 // indirect
+	github.com/glebarez/sqlite v1.11.0 // indirect
+	github.com/go-playground/locales v0.14.1 // indirect
+	github.com/go-playground/universal-translator v0.18.1 // indirect
+	github.com/go-playground/validator/v10 v10.20.0 // indirect
+	github.com/goccy/go-json v0.10.2 // indirect
+	github.com/golang/snappy v0.0.4 // indirect
+	github.com/google/uuid v1.4.0 // indirect
+	github.com/hashicorp/hcl v1.0.0 // indirect
+	github.com/jinzhu/inflection v1.0.0 // indirect
+	github.com/jinzhu/now v1.1.5 // indirect
+	github.com/json-iterator/go v1.1.12 // indirect
+	github.com/klauspost/cpuid/v2 v2.2.7 // indirect
+	github.com/leodido/go-urn v1.4.0 // indirect
+	github.com/magiconair/properties v1.8.7 // indirect
+	github.com/mattn/go-isatty v0.0.20 // indirect
+	github.com/mitchellh/mapstructure v1.5.0 // indirect
+	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+	github.com/modern-go/reflect2 v1.0.2 // indirect
+	github.com/pelletier/go-toml/v2 v2.2.2 // indirect
+	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
+	github.com/sagikazarmark/locafero v0.4.0 // indirect
+	github.com/sagikazarmark/slog-shim v0.1.0 // indirect
+	github.com/sourcegraph/conc v0.3.0 // indirect
+	github.com/spf13/afero v1.11.0 // indirect
+	github.com/spf13/pflag v1.0.5 // indirect
+	github.com/subosito/gotenv v1.6.0 // indirect
+	github.com/syndtr/goleveldb v1.0.0 // indirect
+	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
+	github.com/ugorji/go/codec v1.2.12 // indirect
+	go.uber.org/atomic v1.9.0 // indirect
+	go.uber.org/multierr v1.9.0 // indirect
+	golang.org/x/arch v0.8.0 // indirect
+	golang.org/x/crypto v0.23.0 // indirect
+	golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
+	golang.org/x/net v0.25.0 // indirect
+	golang.org/x/sys v0.20.0 // indirect
+	golang.org/x/text v0.15.0 // indirect
+	google.golang.org/protobuf v1.34.1 // indirect
+	gopkg.in/ini.v1 v1.67.0 // indirect
+	gopkg.in/yaml.v3 v3.0.1 // indirect
+	gorm.io/gorm v1.25.7 // indirect
+	modernc.org/libc v1.22.5 // indirect
+	modernc.org/mathutil v1.5.0 // indirect
+	modernc.org/memory v1.5.0 // indirect
+	modernc.org/sqlite v1.23.1 // indirect
+	xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
+)

+ 51 - 0
main.go

@@ -0,0 +1,51 @@
+package main
+
+import (
+	_ "ARKItems/configs"
+	configs "ARKItems/configs"
+	"ARKItems/entity"
+	"ARKItems/router"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"net/http"
+	"strings"
+)
+
+func main() {
+	//Get()
+	RunGin()
+}
+
+func Get() {
+	for i := 0; i < 240; i++ {
+		sprintf := fmt.Sprintf("IedServer_updateInt32AttributeValue(iedServer, IEDMODEL_ateway_GGIO1_AnIn%d_mag_i, all_data[%d]);", i+1, i)
+		fmt.Println(sprintf)
+	}
+
+}
+
+func RunGin() {
+	engine := gin.Default()
+	engine.StaticFS("/static", http.Dir("file"))
+	router.LoadRouter(engine)
+	engine.Run(configs.Server.Host + ":" + configs.Server.Port)
+}
+func ResetTek() {
+	var items []entity.ArkDinoInfo
+	_, err := configs.Engine.Table("ark_dino_info").FindAndCount(&items)
+	if err != nil {
+		panic(err)
+	}
+	for i := range items {
+		blueprint := items[i].Blueprint
+		if strings.Index(blueprint, "\"") == 0 && strings.LastIndex(blueprint, "\"") == len(blueprint)-1 {
+			blueprint = blueprint[1 : len(blueprint)-1]
+		}
+		_, err := configs.Engine.Table("ark_dino_info").Where("id = ?", items[i].Id).
+			Update(map[string]interface{}{"blueprint": blueprint})
+		if err != nil {
+			panic(err)
+		}
+	}
+
+}

+ 166 - 0
router/ArkItemRouter.go

@@ -0,0 +1,166 @@
+package router
+
+import (
+	"ARKItems/configs"
+	"ARKItems/entity"
+	"fmt"
+	"github.com/gin-gonic/gin"
+)
+
+func ArkItemRouter(api *gin.RouterGroup) {
+	api.GET("/arkItems", GetArkItems)
+	api.GET("/arkDinos", GetArkDinos)
+
+	api.POST("/arkItems", PostArkItemList)
+	api.POST("/arkDinos", PostArkDinoList)
+
+	api.PUT("/arkItem", UpdateArkItem)
+	api.PUT("/arkDino", UpdateArkDino)
+}
+func GetArkItems(c *gin.Context) {
+	var items []entity.ArkItemInfo
+	count, err := configs.Engine.Table("ark_item_info").FindAndCount(&items)
+	if err != nil {
+		c.JSON(200, CreateResultError(500, err.Error()))
+		return
+	}
+	c.JSON(200, gin.H{
+		"code":    200,
+		"message": "success",
+		"data": gin.H{
+			"list":  items,
+			"total": count,
+		},
+	})
+}
+
+func GetArkDinos(c *gin.Context) {
+	var items []entity.ArkDinoInfo
+	count, err := configs.Engine.Table("ark_dino_info").FindAndCount(&items)
+	if err != nil {
+		c.JSON(200, CreateResultError(500, err.Error()))
+		return
+	}
+
+	c.JSON(200, gin.H{
+		"code":    200,
+		"message": "success",
+		"data": gin.H{
+			"list":  items,
+			"total": count,
+		},
+	})
+}
+
+type ReqArkItem struct {
+	PageNum  int    `json:"pageNum"`
+	PageSize int    `json:"pageSize"`
+	Name     string `json:"name"`
+	Category string `json:"category"`
+	Label    string `json:"label"`
+	AllLike  string `json:"allLike"`
+}
+
+func PostArkItemList(c *gin.Context) {
+	var item ReqArkItem
+	err := c.BindJSON(&item)
+	if err != nil {
+		c.JSON(200, CreateResultError(500, err.Error()))
+		return
+	}
+	var items []entity.ArkItemInfo
+	session := configs.Engine.Table("ark_item_info")
+	if item.Name != "" {
+		session.Where("name like ?", "%"+item.Name+"%")
+	}
+	if item.Category != "" {
+		session.Where("category like ?", "%"+item.Category+"%")
+	}
+	if item.Label != "" {
+		session.Where("label like ?", "%"+item.Label+"%")
+	}
+	if item.AllLike != "" {
+		session.Where("name like ? or category like ? or label like ?", "%"+item.AllLike+"%", "%"+item.AllLike+"%", "%"+item.AllLike+"%")
+	}
+	count, err := session.Limit(item.PageSize, (item.PageNum-1)*item.PageSize).FindAndCount(&items)
+	if err != nil {
+		c.JSON(200, CreateResultError(500, err.Error()))
+		return
+	}
+	c.JSON(200, gin.H{
+		"code":    200,
+		"message": "success",
+		"data": gin.H{
+			"list":     items,
+			"total":    count,
+			"pageNum":  item.PageNum,
+			"pageSize": item.PageSize,
+		},
+	})
+}
+
+func PostArkDinoList(c *gin.Context) {
+	var item ReqArkItem
+	err := c.BindJSON(&item)
+	if err != nil {
+		c.JSON(200, CreateResultError(500, err.Error()))
+		return
+	}
+	var items []entity.ArkDinoInfo
+	session := configs.Engine.Table("ark_dino_info")
+	if item.Name != "" {
+		session.Where("name like ?", "%"+item.Name+"%")
+	}
+	if item.Category != "" {
+		session.Where("category like ?", "%"+item.Category+"%")
+	}
+	if item.Label != "" {
+		session.Where("label like ?", "%"+item.Label+"%")
+	}
+	if item.AllLike != "" {
+		session.Where("name like ? or category like ? or label like ?", "%"+item.AllLike+"%", "%"+item.AllLike+"%", "%"+item.AllLike+"%")
+	}
+	count, err := session.Limit(item.PageSize, (item.PageNum-1)*item.PageSize).FindAndCount(&items)
+	if err != nil {
+		c.JSON(200, CreateResultError(500, err.Error()))
+		return
+	}
+	c.JSON(200, gin.H{
+		"code":    200,
+		"message": "success",
+		"data": gin.H{
+			"list":     items,
+			"total":    count,
+			"pageNum":  item.PageNum,
+			"pageSize": item.PageSize,
+		},
+	})
+
+}
+
+func UpdateArkItem(c *gin.Context) {
+	info := entity.ArkItemInfo{}
+	err := c.BindJSON(&info)
+	if err != nil {
+		fmt.Println(err)
+		c.JSON(200, CreateResultError(500, err.Error()))
+	}
+	if info.Id == "" {
+		_, err = configs.Engine.Insert(&info)
+	} else {
+		_, err = configs.Engine.Where("id = ?", info.Id).Update(&info)
+	}
+}
+func UpdateArkDino(c *gin.Context) {
+	info := entity.ArkDinoInfo{}
+	err := c.BindJSON(&info)
+	if err != nil {
+		fmt.Println(err)
+		c.JSON(200, CreateResultError(500, err.Error()))
+	}
+	if info.Id == "" {
+		_, err = configs.Engine.Insert(&info)
+	} else {
+		_, err = configs.Engine.Where("id = ?", info.Id).Update(&info)
+	}
+}

+ 58 - 0
router/Router.go

@@ -0,0 +1,58 @@
+package router
+
+import (
+	"ARKItems/configs"
+	"ARKItems/entity/ark"
+	"ARKItems/util"
+	"github.com/gin-gonic/gin"
+	"github.com/spf13/cast"
+)
+
+var ARKConfig ark.Config
+
+func LoadRouter(router *gin.Engine) {
+	router.POST("/login", Login)
+	group := router.Group("/ark")
+	ArkItemRouter(group)
+}
+
+func Login(c *gin.Context) {
+	param := util.GetJsonAnyParam(c)
+	username, _ := param("username")
+	password, _ := param("password")
+	if username == configs.Manager.Username && password == configs.Manager.Password {
+		token, err := util.GenerateToken(cast.ToString(username))
+		if err != nil {
+			c.JSON(200, CreateResultError(500, "token生成失败"))
+			return
+		}
+		c.JSON(200, CreateResultData(gin.H{
+			"token": token,
+		}))
+		return
+	}
+	c.JSON(200, CreateResultError(500, "用户名或密码错误"))
+}
+
+//===============================================================
+
+func CreateResult() gin.H {
+	return gin.H{
+		"code": 200,
+		"msg":  "success",
+	}
+}
+func CreateResultData(Data any) gin.H {
+	return gin.H{
+		"code": 200,
+		"msg":  "success",
+		"data": Data,
+	}
+}
+
+func CreateResultError(errCode int, errMsg string) gin.H {
+	return gin.H{
+		"code": errCode,
+		"msg":  errMsg,
+	}
+}

Fișier diff suprimat deoarece este prea mare
+ 43 - 0
tools/ark-tools.sql


+ 10 - 0
tools/buildGo.bat

@@ -0,0 +1,10 @@
+@ECHO off
+cd ..
+echo %~dp0
+echo %cd%
+set GOARCH=amd64
+go env -w GOARCH=amd64
+set GOOS=windows
+go env -w GOOS=windows
+go build
+@ECHO on

+ 29 - 0
tools/saveSql.bat

@@ -0,0 +1,29 @@
+@ECHO off
+chcp 65001
+echo 启动sql控制脚本
+
+echo "1| 保存sql   2| 运行sql覆盖数据库"
+
+
+set /p var="请输入控制指令 :"
+echo  %~dp0
+C:
+cd C:\Program Files\MySQL\MySQL Server 5.7\bin\
+SET dbhost=127.0.0.1
+SET dbuser=root
+SET dbpasswd=root
+SET dbName=ark-tools
+
+echo 当前控制的mysql和数据库是 :[%dbhost%]%dbuser%@%dbpasswd%/%dbName%
+echo "code %var%"
+
+if %var% == 1 (
+echo [%time%] [保存sql]
+mysqldump -h%dbhost% -u%dbuser% -p%dbpasswd% %dbName% > %~dp0\ark-tools.sql
+) else if %var% == 2 (
+echo [%time%] [运行sql]
+mysql -h%dbhost% -u%dbuser% -p%dbpasswd% %dbName% < %~dp0\ark-tools.sql
+) else (
+echo "运行错误 未知代码:%var%"
+)
+@echo on

+ 80 - 0
util/ChatGptUtil.go

@@ -0,0 +1,80 @@
+package util
+
+import (
+	"bytes"
+	"encoding/json"
+	"errors"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"net/url"
+)
+
+type Message struct {
+	Role    string `json:"role"`
+	Content string `json:"content"`
+}
+
+type RequestBody struct {
+	Model    string    `json:"model"`
+	Messages []Message `json:"messages"`
+}
+
+const ChatGptUrl = "https://api.openai.com/v1/chat/completions"
+const ApiKey = "sk-proj-gmxWE5taNAc3blthTDOrT3BlbkFJa2ZkQJAoqdjNSRihG4ZY"
+
+func SendOpenAIRequest(Query string) (string, error) {
+	requestBody := RequestBody{
+		Model: "gpt-4o-mini",
+		Messages: []Message{
+			{
+				Role:    "system",
+				Content: "下面单词来自方舟ARk,将他们翻译成中文。提问格式为:'item,item2,item3'。要求返回格式为:'物品1,物品2,物品3'",
+			},
+			{
+				Role:    "user",
+				Content: Query,
+			},
+		},
+	}
+	body, err := json.Marshal(requestBody)
+	if err != nil {
+		log.Fatalf("封发请求正文失败: %v", err)
+		return "", err
+	}
+	req, err := http.NewRequest("POST", ChatGptUrl, bytes.NewBuffer(body))
+	if err != nil {
+		log.Fatalf("创建请求失败: %v", err)
+		return "", err
+	}
+	req.Header.Set("Content-Type", "application/json")
+	req.Header.Set("Authorization", "Bearer "+ApiKey)
+	// Set up proxy
+	proxy, err := url.Parse(ProxyHost)
+	if err != nil {
+		log.Fatalf("Failed to parse proxy URL: %v", err)
+		return "", err
+	}
+	transport := &http.Transport{
+		Proxy: http.ProxyURL(proxy),
+	}
+
+	client := &http.Client{Transport: transport}
+	resp, err := client.Do(req)
+	if err != nil {
+		log.Fatalf("发送请求失败: %v", err)
+		return "", err
+	}
+	defer resp.Body.Close()
+
+	responseBody, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		log.Fatalf("读取响应正文失败: %v", err)
+		return "", err
+	}
+	if resp.StatusCode != http.StatusOK {
+		return "", errors.New("web status error")
+	} else {
+		return string(responseBody), nil
+	}
+}

+ 92 - 0
util/ReadARKID.go

@@ -0,0 +1,92 @@
+package util
+
+import (
+	"bytes"
+	"fmt"
+	"github.com/PuerkitoBio/goquery"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"net/url"
+)
+
+var BaseHost = "https://arkids.net/items"
+
+const ProxyHost = "http://127.0.0.1:7890"
+
+var ArkItemIDs = make([]ArkItemID, 0)
+
+func GetArkIds(u string, page int) error {
+	fmt.Println("page:", u)
+	req, err := http.NewRequest("GET", u, nil)
+	if err != nil {
+		log.Fatalf("创建请求失败: %v", err)
+		return err
+	}
+	proxy, err := url.Parse(ProxyHost)
+	if err != nil {
+		log.Fatalf("Failed to parse proxy URL: %v", err)
+		return err
+	}
+	transport := &http.Transport{
+		Proxy: http.ProxyURL(proxy),
+	}
+
+	client := &http.Client{Transport: transport}
+	resp, err := client.Do(req)
+	if err != nil {
+		log.Fatalf("发送请求失败: %v", err)
+		return err
+	}
+	defer resp.Body.Close()
+
+	responseBody, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		log.Fatalf("读取响应正文失败: %v", err)
+		return err
+	}
+
+	// 使用 goquery 解析 HTML 内容
+	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(responseBody))
+	if err != nil {
+		log.Fatalf("解析 HTML 失败: %v", err)
+		return err
+	}
+	var sign = 0
+	// 查找所有 <h1> 标签并打印内容
+	doc.Find("tr").Each(func(index int, item *goquery.Selection) {
+		sign += 1
+		aii := ArkItemID{}
+		//ret, _ := item.Html()
+		item.Find("img").Each(func(index int, img *goquery.Selection) {
+			if img.AttrOr("data-src", "") != "" {
+				aii.ImageURL = img.AttrOr("data-src", "")
+			}
+		})
+		item.Find(".w-25 a").Each(func(index int, name *goquery.Selection) {
+			aii.Name = name.Text()
+		})
+		item.Find(".ts.cbl").Each(func(index int, name *goquery.Selection) {
+			aii.ID = name.Text()
+		})
+		item.Find(".cbl").Each(func(index int, name *goquery.Selection) {
+			aii.Command = name.Text()
+		})
+		aii.Page = page
+		ArkItemIDs = append(ArkItemIDs, aii)
+		//fmt.Println(aii.String())
+	})
+	return nil
+}
+
+type ArkItemID struct {
+	ID       string `json:"id"`        // id
+	Name     string `json:"name"`      // 名称
+	ImageURL string `json:"image_url"` // 图片地址
+	Command  string `json:"command"`   // 命令
+	Page     int    `json:"page"`      // 页码
+}
+
+func (a ArkItemID) String() string {
+	return fmt.Sprint("ID:", a.ID, " Name:", a.Name, " Img:", a.ImageURL, " Command:", a.Command, " Page:", a.Page)
+}

+ 101 - 0
util/ReadARKShopConfig.go

@@ -0,0 +1,101 @@
+package util
+
+import (
+	"ARKItems/entity/ark"
+	"encoding/json"
+	"fmt"
+	"io"
+	"os"
+	"strings"
+)
+
+//读取ark shop配置
+
+func LoadArkShopConfig(url string) (
+	ark.Config, map[string]ark.ShopItem, map[string]ark.ShopDino,
+	map[string]ark.ShopBeacon, map[string]ark.ShopExperience,
+	map[string]ark.ShopUnlockengram, map[string]ark.ShopCommand) {
+	file, err := os.OpenFile(url, os.O_RDWR, 0666)
+	if err != nil {
+		panic(err)
+	}
+	defer file.Close()
+	all, err := io.ReadAll(file)
+	if err != nil {
+		panic(err)
+	}
+	index := strings.Index(string(all), "{")
+	all = []byte(string(all)[index:])
+
+	return LoadArkShopConfigByString(all)
+}
+
+func LoadArkShopConfigByString(jsonContent []byte) (
+	ark.Config, map[string]ark.ShopItem, map[string]ark.ShopDino,
+	map[string]ark.ShopBeacon, map[string]ark.ShopExperience,
+	map[string]ark.ShopUnlockengram, map[string]ark.ShopCommand) {
+	var config ark.Config
+
+	var ARKShopItems = make(map[string]ark.ShopItem)
+	var ARKShopDines = make(map[string]ark.ShopDino)
+	var ARKShopBeacons = make(map[string]ark.ShopBeacon)
+	var ARKShopExperiences = make(map[string]ark.ShopExperience)
+	var ARKShopUnlockengram = make(map[string]ark.ShopUnlockengram)
+	var ARKShopCommands = make(map[string]ark.ShopCommand)
+
+	err := json.Unmarshal(jsonContent, &config)
+	if err != nil {
+		panic(err)
+	}
+	//接卸shopItems内容
+	var m map[string]interface{}
+	err = json.Unmarshal(jsonContent, &m)
+	if err != nil {
+		panic(err)
+	}
+	ShopItems, ok := m["ShopItems"].(map[string]interface{})
+	if ok {
+		for key := range ShopItems {
+			item := ShopItems[key].(map[string]interface{})
+			t := item["Type"]
+
+			switch t {
+			case "item":
+				var obj ark.ShopItem
+				DataToObject(item, &obj)
+				ARKShopItems[key] = obj
+				continue
+			case "dino":
+				var obj ark.ShopDino
+				DataToObject(item, &obj)
+				ARKShopDines[key] = obj
+				continue
+			case "beacon":
+				var obj ark.ShopBeacon
+				DataToObject(item, &obj)
+				ARKShopBeacons[key] = obj
+				continue
+			case "experience":
+				var obj ark.ShopExperience
+				DataToObject(item, &obj)
+				ARKShopExperiences[key] = obj
+				continue
+			case "unlockengram":
+				var obj ark.ShopUnlockengram
+				DataToObject(item, &obj)
+				ARKShopUnlockengram[key] = obj
+				continue
+			case "command":
+				var obj ark.ShopCommand
+				DataToObject(item, &obj)
+				ARKShopCommands[key] = obj
+				continue
+			default:
+				fmt.Println("=================>", t)
+			}
+		}
+	} else {
+		panic("ShopItems is not a map")
+	}
+	return config, ARKShopItems, ARKShopDines, ARKShopBeacons, ARKShopExperiences, ARKShopUnlockengram, ARKShopCommands
+}

+ 119 - 0
util/RequestHandler.go

@@ -0,0 +1,119 @@
+package util
+
+import (
+	"ARKItems/configs"
+	"crypto/rand"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/dgrijalva/jwt-go"
+	"github.com/gin-gonic/gin"
+	"math/big"
+	"time"
+)
+
+const (
+	SECRETKEY = "996icu12345611" //私钥
+)
+
+type CustomClaims struct {
+	UserId int64
+	jwt.StandardClaims
+}
+
+func GetJsonAnyParam(c *gin.Context) func(param string) (interface{}, error) {
+	jsonData := map[string]interface{}{}
+	err := c.BindJSON(&jsonData)
+
+	return func(param string) (interface{}, error) {
+		if err != nil {
+			return nil, err
+		}
+		value, err := func() (interface{}, error) {
+
+			i, exists := jsonData[param]
+			if !exists {
+				return nil, errors.New("缺少" + param + "字段")
+			}
+
+			return i, nil
+		}()
+		if err != nil {
+			return nil, err
+		}
+		return value, err
+	}
+}
+
+func GenerateToken(userId string) (string, error) {
+	maxAge := 60 * 60 * 24
+	// Create the Claims
+	claims := &jwt.StandardClaims{
+		ExpiresAt: time.Now().Add(time.Duration(maxAge) * time.Second).Unix(), // 过期时间,必须设置,
+		Issuer:    userId,                                                     // 非必须,也可以填充用户名,
+	}
+
+	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
+	tokenString, err := token.SignedString([]byte(SECRETKEY))
+	if err != nil {
+		fmt.Println(err)
+	}
+	return tokenString, err
+}
+
+func ParseToken(tokenString string) (jwt.MapClaims, error) {
+	token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
+		// Don't forget to validate the alg is what you expect:
+		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
+			return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
+		}
+
+		// hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key")
+		return []byte(SECRETKEY), nil
+	})
+	if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
+		return claims, nil
+	} else {
+		return nil, err
+	}
+}
+
+func JudgmentUserInfo(info jwt.MapClaims) bool {
+	i, ok := info["iss"].(string)
+	if ok {
+		return i == configs.Manager.Username
+	}
+	return false
+}
+
+func RandomInt(min, max *big.Int) *big.Int {
+	// 读取密码学安全的随机比特
+	byteLen := (max.BitLen() + 7) / 8
+	b := make([]byte, byteLen)
+	rand.Read(b)
+
+	// 将字节转换为大整数
+	r := new(big.Int).SetBytes(b)
+
+	// 需要将生成的大整数范围限制在[min,max]
+	r.Rem(r, new(big.Int).Sub(max, min)).Add(r, min)
+	return r
+}
+
+// DataToObject json转对象
+func DataToObject(data interface{}, obj interface{}) error {
+	marshal, err := json.Marshal(data)
+	if err != nil {
+		return err
+	}
+	return json.Unmarshal(marshal, obj)
+}
+func DataToMap(data interface{}) map[string]interface{} {
+	marshal, err := json.Marshal(data)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var obj map[string]interface{}
+	json.Unmarshal(marshal, &obj)
+	return obj
+}

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff