zoukankan      html  css  js  c++  java
  • python 调用jpush推送消息

    使用jpush的python方式, 做为邮件,短信之后的另一种提醒方式,同时还有微信方式可以研究下

    # coding=utf-8
    import jpush
    
    
    def push_msg(message,device_id):
        app_key = 'app_key'
        master_secret = 'master_key'
    
        _jpush = jpush.JPush(app_key, master_secret)
        push = _jpush.create_push()
        # push.audience = jpush.audience([{"registration_id":device_id}])
        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")
        push.send()
    
    if __name__=="__main__":
        device_id = '001023123123'  # device_id 需要事先获得
        message = "This is a test"
        push_msg(message,device_id)
  • 相关阅读:
    python 协程之Greenlet
    python 协程
    python 多进程通信之Manger
    python 多线程通信之Queue
    python 多进程
    python threading之queue
    python threading之同步条件(Event)
    python threading之条件变量同步(condition)
    python之字符串常用方法
    python之字典操作
  • 原文地址:https://www.cnblogs.com/yeyong/p/4598245.html
Copyright © 2011-2022 走看看