mirror of
https://gitee.com/quecpython/helios-service.git
synced 2025-05-19 06:08:22 +08:00
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
from usr.bin.guard import GuardContext
|
|
|
|
# 刷新容器
|
|
guard_context = GuardContext()
|
|
guard_context.refresh()
|
|
|
|
|
|
def func(*args, **kwargs):
|
|
print(args, kwargs)
|
|
"""
|
|
|
|
:param args: ('anonymous',) 发送人, 默认是'anonymous'无需关心
|
|
:param kwargs: 格式如下
|
|
{
|
|
'message':{
|
|
'message_id':2, # 消息ID
|
|
'sender':'anonymous', # 发送人
|
|
'message': { # 来的消息
|
|
"sim_status": 1, # sim卡状态 1为正常0为异常
|
|
"net_status": 1, # 网络状态 1为正常0为异常
|
|
"datacall_status": 1, # 注网状态 1为正常0为异常, 一般只需关注拨号状态即可
|
|
"profile_id": 1, # pid
|
|
"ip_type": 0, # 0是ipv4, 1是ipv6
|
|
"IPv4": "xxxx",
|
|
"IPv4_DNS1": "xxxx",
|
|
"IPv4_DNS2": "xxxx",
|
|
"IPv6": "xxxx",
|
|
"IPv6_DNS1": "xxxx",
|
|
"IPv6_DNS2": "xxxx",
|
|
},
|
|
'from_event':'NET', # 从那个事件或服务来的
|
|
'msg_type':1 # 1代表来自有data call信息
|
|
}
|
|
}
|
|
:return:
|
|
"""
|
|
print(kwargs['message']['message'])
|
|
|
|
|
|
# 获取媒体服务
|
|
net_ser = guard_context.get_server("net")
|
|
# 获取并打印媒体服务
|
|
_net = net_ser.net
|
|
print("_net = {}".format(_net))
|
|
# 获取并打印sim卡原生对象
|
|
_sim = net_ser.sim
|
|
print("_sim = {}".format(_sim))
|
|
# 获取并打印dataCall原生对象
|
|
_data_call = net_ser.data_call
|
|
print("_data_call = {}".format(_data_call))
|
|
# 等待网络连接
|
|
net_ser.wait_connect(5)
|
|
# 获取网络状态, 返回值, 1网络正常, 0网络异常
|
|
net_ser.get_net_status()
|
|
# 订阅网络服务
|
|
net_ser.subscribe(func)
|