first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

View File

@ -0,0 +1,225 @@
package client_game_wz
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"servicebase/pkg/utils"
"github.com/anxpp/common-utils/logg"
"github.com/anxpp/common-utils/str"
)
const WZYD_TOKEN = "SZN62jr4"
const WZYD_UID = "1702857155"
func RoleInfo(targetUid string) (targetRole map[string]interface{}, e error) {
if len(targetUid) == 0 {
e = errors.New("参数不足")
return
}
apiUrl := "https://kohcamp.qq.com/game/koh/profile"
token := WZYD_TOKEN // 登录王者营地的token
uid := WZYD_UID // 营地ID
headerMap := make(map[string]string, 0)
headerMap["Content-Type"] = "application/json"
headerMap["userId"] = uid
headerMap["cCurrentGameId"] = "20001"
headerMap["Accept-Language"] = "zh-Hans-CN;q=1, en-CN;q=0.9"
headerMap["token"] = token
paraMap := make(map[string]string, 4)
paraMap["CampPreloadHTTPHandledIdentifier"] = "2"
paraMap["targetUserId"] = targetUid
resStr, err2 := utils.HttpDo(http.MethodPost, apiUrl, headerMap, str.ToJsonString(paraMap))
if err2 != nil {
logg.Info("调用王者营地数据查询失败", err2.Error())
e = fmt.Errorf("调用王者营地数据查询失败: %v", err2.Error())
return
}
logg.Info(resStr)
resMap := make(map[string]interface{}, 0)
json.Unmarshal([]byte(resStr), &resMap)
if resMap["returnCode"].(float64) != 0 {
e = fmt.Errorf("调用王者营地数据查询失败2: %v", resMap["returnMsg"])
return
}
// 获取成功
data := resMap["data"].(map[string]interface{})
// 默认角色ID
targetRoleId := data["targetRoleId"].(string)
//角色列表
roleList := data["roleList"].([]interface{})
// 匹配默认角色
for _, item := range roleList {
m := item.(map[string]interface{})
if m["roleId"].(string) == targetRoleId {
targetRole = m
}
}
if targetRole == nil {
e = errors.New("未找到角色信息")
return
}
// 其他数据
head := data["head"].(map[string]interface{})
mods := head["mods"].([]interface{})
//targetRole["mods"] = mods
for _, item := range mods {
mod := item.(map[string]interface{})
modId := mod["modId"].(float64)
if modId == 401 {
// 总场次
targetRole["totalPlayCount"] = mod["content"].(string)
} else if modId == 408 {
// MVP
targetRole["mvpCount"] = mod["content"].(string)
} else if modId == 409 {
// 胜率
targetRole["winRate"] = mod["content"].(string)
} else if modId == 201 {
// 英雄数
targetRole["heroCount"] = mod["content"].(string)
} else if modId == 202 {
// 皮肤数
targetRole["skinCount"] = mod["content"].(string)
} else if modId == 702 {
// 巅峰赛
targetRole["topScore"] = mod["content"].(string)
} else if modId == 304 {
// 战力
targetRole["battleScore"] = mod["content"].(string)
}
}
return
}
func RoleSkinList(roleId string) (result map[string][]interface{}, e error) {
apiUrl := "https://kohcamp.qq.com/game/itempage/skinlist"
token := WZYD_TOKEN // 登录王者营地的token
uid := WZYD_UID // 营地ID
if len(roleId) == 0 {
e = errors.New("参数不足")
return
}
headerMap := make(map[string]string, 0)
headerMap["Content-Type"] = "application/json"
headerMap["userId"] = uid
headerMap["cCurrentGameId"] = "20001"
headerMap["Accept-Language"] = "zh-Hans-CN;q=1, en-CN;q=0.9"
headerMap["token"] = token
paraMap := make(map[string]string, 4)
paraMap["roleId"] = roleId
resStr, err2 := utils.HttpDo(http.MethodPost, apiUrl, headerMap, str.ToJsonString(paraMap))
if err2 != nil {
logg.Info("调用王者营地数据查询失败", err2.Error())
e = fmt.Errorf("调用王者营地数据查询失败:%v", err2)
return
}
resMap := make(map[string]interface{}, 0)
json.Unmarshal([]byte(resStr), &resMap)
if _, ok := resMap["returnCode"]; ok {
e = fmt.Errorf("调用王者营地数据查询失败2: %v", resMap["returnMsg"])
return
}
//全部皮肤
allSkin := resMap["allSkinConf"].([]interface{})
// 用户的皮肤
userSkinList := resMap["skinData"].([]interface{})
resultList := []interface{}{}
rongyaoList := []interface{}{} // 荣耀典藏
xiandingList := []interface{}{} // 限定
shishiList := []interface{}{} // 史诗级
chuanshuoList := []interface{}{} // 传说
wushuangList := []interface{}{} //无双
for _, item := range userSkinList {
skinMap := item.(map[string]interface{})
userSkinId := skinMap["skinId"].(float64)
mySkin := getSkinModel(allSkin, userSkinId)
mySkin["acquireTime"] = skinMap["acquireTime"].(string)
// 去掉隐藏的皮肤
if mySkin["isHidden"].(float64) == 1 {
continue
}
// 去掉原皮
if int64(userSkinId)%100 == 0 {
continue
}
// 等级处理
classTypeName := mySkin["classTypeName"].([]interface{})
nameList := []string{}
for _, name := range classTypeName {
nameList = append(nameList, name.(string))
}
str := fmt.Sprintf("%s(%s)", mySkin["skinName"].(string), mySkin["heroName"].(string))
if utils.IsInStringList("荣耀典藏", nameList) {
rongyaoList = append(rongyaoList, str)
}
if utils.IsInStringList("限定", nameList) {
xiandingList = append(xiandingList, str)
}
if utils.IsInStringList("史诗品质", nameList) {
shishiList = append(shishiList, str)
}
if utils.IsInStringList("传说品质", nameList) {
chuanshuoList = append(chuanshuoList, str)
}
if utils.IsInStringList("无双", nameList) {
wushuangList = append(wushuangList, str)
}
resultList = append(resultList, mySkin)
}
logg.Info("皮肤数量", len(resultList))
result = make(map[string][]interface{}, 0)
// result["totalCount"] = len(resultList)
result["allSkin"] = resultList
result["荣耀典藏"] = rongyaoList
result["限定"] = xiandingList
result["史诗品质"] = shishiList
result["传说品质"] = chuanshuoList
result["无双"] = wushuangList
return
}
func getSkinModel(allSkin []interface{}, userSkinId float64) (result map[string]interface{}) {
for _, item := range allSkin {
skin := item.(map[string]interface{})
skinId := skin["skinId"].(float64)
if skinId == userSkinId {
result = skin
break
}
}
return
}