Skip to content

Commit 317b7a7

Browse files
feat: Support 云·绝区零 (#30)
* chore(version): Version code * feat: Support ZZZ * typo(user): For `PCWeb` of ZZZ * doc: Update README.md
1 parent 48f4aea commit 317b7a7

File tree

7 files changed

+54
-32
lines changed

7 files changed

+54
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
![Python](https://img.shields.io/pypi/pyversions/mhyy.py?style=flat-square)
77
![STARS](https://img.shields.io/github/stars/GuangChen2333/mhyy.py?style=flat-square)
88

9-
Python 米哈云游(云·原神、云·星穷铁道)签到功能与相关方法的API
9+
Python 米哈云游(云·原神、云·星穷铁道、云·绝区零)签到功能与相关方法的API
1010

1111
## 安装
1212

docs/reference/interface.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ _mhyy.Client()_
2626
2727
`get_wallet_data`(self, user: [User](#user))
2828

29-
> 获取指定用户的钱包数据。
29+
> 获取指定游戏类型的版本号,若未发送过请求,将会强制更新。
30+
> 若想获取字典类型的所有版本号,请使用 versions 属性。
3031
>
3132
> **形参:**
3233
>
@@ -72,6 +73,10 @@ _class mhyy.GameType_
7273

7374
> 云·星穹铁道。
7475
76+
`ZZZ` = 2
77+
78+
> 云·绝区零
79+
7580
## Notification {#notification}
7681

7782
> 通知类。

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mhyy.py"
7-
version = "2.1.5"
7+
version = "3.0.0"
88
authors = [
99
{ name = "GuangChen2333", email = "guangchenworks@outlook.com" },
1010
]

src/mhyy/_api.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,12 @@
22

33

44
class API:
5-
@staticmethod
6-
def get_launcher_key(game_type: GameType) -> str:
7-
return {
8-
GameType.GenshinImpact: "eYd89JmJ",
9-
GameType.StarRail: "6KcVuOkbcqjJomjZ"
10-
}[game_type]
11-
125
@staticmethod
136
def get_launcher_id(game_type: GameType) -> str:
147
return {
15-
GameType.GenshinImpact: "18",
16-
GameType.StarRail: "33"
17-
}[game_type]
18-
19-
@staticmethod
20-
def get_game_version_url(game_type: GameType) -> str:
21-
return {
22-
GameType.GenshinImpact: "https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource",
23-
GameType.StarRail: "https://api-launcher.mihoyo.com/hkrpg_cn/mdk/launcher/api/resource"
8+
GameType.GenshinImpact: "umfgRO5gh5",
9+
GameType.StarRail: "6P5gHMNyK3",
10+
GameType.ZZZ: "jGHBHlcOq1",
2411
}[game_type]
2512

2613
@staticmethod
@@ -29,6 +16,7 @@ def get_app_id(game_type: GameType, client_type: UserClientType) -> str:
2916
UserClientType.Android: {
3017
GameType.GenshinImpact: "1953439974",
3118
GameType.StarRail: "1953445976",
19+
GameType.ZZZ: "1953458679",
3220
},
3321
UserClientType.PCWeb: {
3422
GameType.GenshinImpact: "4",
@@ -42,6 +30,7 @@ def get_vendor_id(game_type: GameType, client_type: UserClientType) -> str:
4230
UserClientType.Android: {
4331
GameType.GenshinImpact: "1",
4432
GameType.StarRail: "2",
33+
GameType.ZZZ: "2",
4534
},
4635
UserClientType.PCWeb: {
4736
GameType.GenshinImpact: "2",
@@ -54,13 +43,15 @@ def get_cg_game_biz(game_type: GameType) -> str:
5443
return {
5544
GameType.GenshinImpact: "hk4e_cn",
5645
GameType.StarRail: "hkrpg_cn",
46+
GameType.ZZZ: "nap_cn",
5747
}[game_type]
5848

5949
@staticmethod
6050
def get_op_biz(game_type: GameType) -> str:
6151
return {
6252
GameType.GenshinImpact: "clgm_cn",
6353
GameType.StarRail: "clgm_hkrpg-cn",
54+
GameType.ZZZ: "clgm_nap-cn",
6455
}[game_type]
6556

6657
@staticmethod
@@ -69,6 +60,7 @@ def get_cps(game_type: GameType, client_type: UserClientType) -> str:
6960
UserClientType.Android: {
7061
GameType.GenshinImpact: "mihoyo",
7162
GameType.StarRail: "mihoyo",
63+
GameType.ZZZ: "oosnsdyu_C",
7264
},
7365
UserClientType.PCWeb: {
7466
GameType.GenshinImpact: "pc_default",
@@ -77,21 +69,27 @@ def get_cps(game_type: GameType, client_type: UserClientType) -> str:
7769
}[client_type][game_type]
7870

7971
@staticmethod
80-
def get_channel_id(user_channel: UserChannel) -> str:
72+
def get_channel_id(game_type: GameType, user_channel: UserChannel) -> str:
8173
return {
82-
UserChannel.Official: "mihoyo"
83-
}[user_channel]
74+
UserChannel.Official: {
75+
GameType.GenshinImpact: "mihoyo",
76+
GameType.StarRail: "mihoyo",
77+
GameType.ZZZ: "oosnsdyu_C",
78+
}
79+
}[user_channel][game_type]
8480

8581
@staticmethod
8682
def get_wallet_data_url(game_type: GameType) -> str:
8783
return {
8884
GameType.GenshinImpact: "https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get",
89-
GameType.StarRail: "https://cg-hkrpg-api.mihoyo.com/hkrpg_cn/cg/wallet/wallet/get"
85+
GameType.StarRail: "https://cg-hkrpg-api.mihoyo.com/hkrpg_cn/cg/wallet/wallet/get",
86+
GameType.ZZZ: "https://cg-nap-api.mihoyo.com/nap_cn/cg/wallet/wallet/get"
9087
}[game_type]
9188

9289
@staticmethod
9390
def get_notifications_url(game_type: GameType) -> str:
9491
return {
9592
GameType.GenshinImpact: "https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications",
96-
GameType.StarRail: "https://cg-hkrpg-api.mihoyo.com/hkrpg_cn/cg/gamer/api/listNotifications"
93+
GameType.StarRail: "https://cg-hkrpg-api.mihoyo.com/hkrpg_cn/cg/gamer/api/listNotifications",
94+
GameType.ZZZ: "https://cg-nap-api.mihoyo.com/nap_cn/cg/gamer/api/listNotifications"
9795
}[game_type]

src/mhyy/_client.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def __init__(self):
3333
# The version will be updated on the first request from the corresponding game.
3434
self._versions: dict = {
3535
GameType.GenshinImpact: None,
36-
GameType.StarRail: None
36+
GameType.StarRail: None,
37+
GameType.ZZZ: None
3738
}
3839

3940
def __enter__(self):
@@ -58,14 +59,13 @@ def _update_version(self, game_type: GameType) -> None:
5859
Args:
5960
game_type (GameType): 要更新的客户端类型。
6061
"""
61-
version_url = API.get_game_version_url(game_type)
62+
version_url = 'https://hyp-api.mihoyo.com/hyp/hyp-connect/api/getGamePackages'
6263

6364
resp = self._client.get(version_url, params={
64-
"key": API.get_launcher_key(game_type),
6565
"launcher_id": API.get_launcher_id(game_type)
6666
}).json()
6767

68-
self._versions[game_type] = resp["data"]["game"]["latest"]["version"]
68+
self._versions[game_type] = resp["data"]["game_packages"][0]["main"]["major"]["version"]
6969

7070
def _get_common_headers(self, game_type: GameType, client_type: UserClientType) -> dict:
7171
"""
@@ -119,7 +119,11 @@ def _user_web_get(self, user: User, url: str, params: Optional[dict] = None) ->
119119

120120
headers.update(user_headers)
121121

122-
headers["x-rpc-channel"] = API.get_channel_id(user.channel)
122+
headers["x-rpc-channel"] = API.get_channel_id(user.game_type, user.channel)
123+
124+
# ZZZ special header cg_game_id
125+
if user.game_type == GameType.ZZZ:
126+
headers['x-rpc-cg_game_id'] = '9000357'
123127

124128
resp = self._client.get(url, headers=headers, params=params)
125129

@@ -141,7 +145,10 @@ def get_wallet_data(self, user: User) -> WalletData:
141145
Returns:
142146
该用户的钱包数据。
143147
"""
144-
r = self._user_web_get(user, API.get_wallet_data_url(user.game_type)).json()
148+
r = self._user_web_get(
149+
user,
150+
API.get_wallet_data_url(user.game_type)
151+
).json()
145152
if r['retcode'] != 0:
146153
raise APIRequestError(r['message'], r['retcode'])
147154
return WalletData.from_dict(r['data'])
@@ -197,14 +204,18 @@ def get_notifications(
197204

198205
def get_client_version(self, game_type: GameType) -> str:
199206
"""
200-
获取指定游戏类型的版本号,若想获取字典类型的所有版本号,请使用 versions 属性。
207+
获取指定游戏类型的版本号,若未发送过请求,将会强制更新。
208+
若想获取字典类型的所有版本号,请使用 versions 属性。
201209
202210
Args:
203211
game_type (GameType): 游戏类型。
204212
205213
Returns:
206214
该游戏类型的版本号。
207215
"""
216+
if self._versions[game_type] is None:
217+
self._update_version(game_type)
218+
208219
return self._versions[game_type]
209220

210221
@property

src/mhyy/_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ class GameType(Enum):
99
Attributes:
1010
GenshinImpact: 云·原神。
1111
StarRail: 云·星穹铁道。
12+
ZZZ: 云·绝区零
1213
"""
1314
GenshinImpact = 0
1415
StarRail = 1
16+
ZZZ = 2
1517

1618

1719
class UserClientType(Enum):

src/mhyy/_user.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def __init__(
5555

5656
detected_game_type = {
5757
"hk4e_cn": GameType.GenshinImpact,
58-
"hkrpg_cn": GameType.StarRail
58+
"hkrpg_cn": GameType.StarRail,
59+
"nap_cn": GameType.ZZZ
5960
}[bi]
6061

6162
if self._game_type is None:
@@ -69,6 +70,11 @@ def __init__(
6970
SyntaxWarning
7071
)
7172

73+
# PCWeb for ZZZ
74+
75+
if self._game_type == GameType.ZZZ and self._client_type == UserClientType.PCWeb:
76+
raise NotImplementedError("ZZZ's PC Web is not supported. Use Android.")
77+
7278
def get_user_headers(self) -> dict:
7379
"""
7480
获取该用户的 headers。

0 commit comments

Comments
 (0)