求助:如何使用python编程来获取到registration_id的列表?

btdan
2019-02-24 13:12 853 0

如题,我想利用python获取到当前可以推送消息的所有设备列表,这就需要有接口或者方法来获取到所有的registration_id列表,请教大侠我该如何实现?非常感谢。
目前我使用咱们极光网站提供的android app demo,然后使用下面的python程序可以向指定registrationid的设备发送消息,但是如何获取到所有设备的registrationid(而不是简单的通过jpush.all_来代替),因为后续我想针对不同的registrationid来发送不同的消息。 给指定registrationid的设备发送消息的代码如下:

coding=utf-8

import jpush

def push_msg(message,device_id):
app_key = 'appkey'
master_secret = 'master_secret '

_jpush = jpush.JPush(app_key, master_secret)
push = _jpush.create_push()
# push.audience = jpush.audience([{"registration_id":device_id}])
# push.audience = jpush.all_
# deviceList=jpush.device_regid()
# deviceList=jpush.all_
# print(deviceList)
push.audience = {'registration_id': [device_id]}
# push.audience = device_id
msg = jpush.android(
                    message,
                    None,
                    None,
                    {
                        "sn": message,      # 强行套用app中notification的相关格式
                        "type": "T4",
                        "url": "http://www.baidu.com"
                    }
                    )
push.notification = jpush.notification("hello jpush", None, msg, None) # 第一个值似乎没有什么用,另外这个push目前只发送至android
# push.options = {"time_to_live": 86400, "sendno": 12345, "apns_production":True}
push.options = {"time_to_live": 86400, "apns_production": True}
push.platform = jpush.platform("android")
try:
    response=push.send()
except:
    print ("Exception")

if name=="main":
device_id = '9e798e4793c90ba04815cf2d08fcfbfb' # device_id 需要事先获得
device_id = '18071adc034cfe36726' # device_id 需要事先获得
message = "This is a test"
push_msg(message,device_id)

1个回答

热门排序