You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.4 KiB
79 lines
2.4 KiB
package mihoyo
|
|
|
|
import (
|
|
"GenshinImpact/global"
|
|
"GenshinImpact/utils"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type GameRoleList struct {
|
|
List []GameRole `json:"list"`
|
|
}
|
|
type GameRole struct {
|
|
Uid string `json:"game_uid"`
|
|
NickName string `json:"nickname"`
|
|
Region string `json:"region"`
|
|
RegionName string `json:"region_name"`
|
|
}
|
|
|
|
func GetUserGameRoles(cookie string) ([]GameRole, error) {
|
|
mr := NewMiyoRequest("https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn")
|
|
mr.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/2.11.1")
|
|
mr.SetHeader("Referer", "https://webstatic.mihoyo.com/app/community-game-records/index.html?v=6")
|
|
mr.SetHeader("Cookie", cookie)
|
|
mr.SetHeader("X-Requested-With", "com.mihoyo.hyperion")
|
|
data, err := mr.Execute()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
roleList := GameRoleList{}
|
|
json.Unmarshal(data, &roleList)
|
|
if len(roleList.List) == 0 {
|
|
return nil, errors.New("没有找到绑定的角色")
|
|
}
|
|
return roleList.List, nil
|
|
}
|
|
|
|
func GetUserGameRoleByUid(cookie string, uid string) (*GameRole, error) {
|
|
roles, err := GetUserGameRoles(cookie)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for i := range roles {
|
|
if roles[i].Uid == uid {
|
|
return &roles[i], nil
|
|
}
|
|
}
|
|
return nil, errors.New("没有找到UID为" + uid + "的角色")
|
|
}
|
|
|
|
func GetGenshinDailyNote(cookie, uid, server string) (*GenshinDailyNote, error) {
|
|
dailyNoteApi := func(useOld string) string {
|
|
if strings.EqualFold(useOld, "yes") {
|
|
return "https://api-takumi.mihoyo.com/game_record/app/genshin/api/dailyNote"
|
|
} else {
|
|
return "https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/dailyNote"
|
|
}
|
|
}(global.UseOldApi)
|
|
url := fmt.Sprintf("%s?server=%s&role_id=%s", dailyNoteApi, server, uid)
|
|
mr := NewMiyoRequest(url)
|
|
mr.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/2.11.1")
|
|
mr.SetHeader("Referer", "https://webstatic.mihoyo.com/app/community-game-records/index.html?v=6")
|
|
mr.SetHeader("Cookie", cookie)
|
|
mr.SetHeader("X-Requested-With", "com.mihoyo.hyperion")
|
|
appType, appVersion, DS := utils.GetDS(mr.url, "")
|
|
mr.SetHeader("x-rpc-client_type", appType)
|
|
mr.SetHeader("x-rpc-app_version", appVersion)
|
|
mr.SetHeader("DS", DS)
|
|
data, err := mr.Execute()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
dailyNote := GenshinDailyNote{}
|
|
json.Unmarshal(data, &dailyNote)
|
|
return &dailyNote, nil
|
|
}
|