-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.py
More file actions
74 lines (62 loc) · 2.78 KB
/
demo.py
File metadata and controls
74 lines (62 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2025 Timandes White
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import argparse
from fnos import FnosClient
def on_message_handler(message):
"""消息回调处理函数"""
print(f"收到消息: {message}")
async def main():
"""主函数"""
# 解析命令行参数
parser = argparse.ArgumentParser(description='Fnos客户端')
parser.add_argument('--user', type=str, required=True, help='用户名')
parser.add_argument('--password', type=str, required=True, help='密码')
parser.add_argument('-e', '--endpoint', type=str, default='your-custom-endpoint.com:5666', help='服务器地址 (默认: your-custom-endpoint.com:5666)')
parser.add_argument('--use-ssl', action='store_true', help='使用 SSL/WSS 连接')
parser.add_argument('--skip-ssl-verify', type=lambda x: x.lower() == 'true', default=True, help='跳过 SSL 证书验证 (默认: True)')
args = parser.parse_args()
client = FnosClient()
# 设置消息回调
client.on_message(on_message_handler)
# 连接到服务器(必须指定endpoint)
await client.connect(args.endpoint, use_ssl=args.use_ssl, skip_ssl_verify=args.skip_ssl_verify)
if client.connected:
print("连接成功,尝试登录...")
try:
# 使用命令行参数中的用户名和密码
result = await client.login(args.user, args.password)
print("登录结果:", result)
# 获取解密后的secret
decrypted_secret = client.get_decrypted_secret()
if decrypted_secret:
print(f"保存的secret: {decrypted_secret}")
# 测试request方法
try:
await client.request_payload("user.info", {})
print("已发送请求,等待响应...")
# 等待一段时间以接收响应
await asyncio.sleep(5)
except Exception as e:
print(f"Request失败: {e}")
else:
print("未找到secret")
except Exception as e:
print(f"登录失败: {e}")
else:
print("连接失败")
# 关闭连接
await client.close()
if __name__ == "__main__":
asyncio.run(main())