zoukankan      html  css  js  c++  java
  • Django 通过APNS推送消息

      最近手上一个项目需要通过APNS向app推送消息,由于后端采用drf框架,在github上找了好多模块,最终发现pzanitti大神的推送模块 django-push-notifications 比较好用,特此感谢pzanitti大神,也像大家推荐使用。下面是我的配置流程仅供参考,大家可以根据需求进行修改。

    1.模块Dependencies

      Python 2.7 or 3.4+

      Django 1.11+

      For the API module, Django REST Framework 3.7+ is required.

    2. Setup

      pip install django-push-notifications

    3. settings.py 配置

      # 将模块导入

      INSTALLED_APPS = ( ... "push_notifications" )

      # 推送消息配置

    PUSH_NOTIFICATIONS_SETTINGS = {
      # pem文件的绝对路径
        "APNS_CERTIFICATE": r"/path/to/xxx.pem",
      # 在apns服务中心配置,配置文档地址后面贴上 "APNS_TOPIC": "xxx.xxx.xxxApp",
      # 这个端口号不需要改了 "APNS_USE_ALTERNATIVE_PORT": 2197, "UPDATE_ON_DUPLICATE_REG_ID": False,
      # 我的配置使用的是沙箱环境,生产环境的配置类似 "CONFIG": "push_notifications.conf.AppConfig", "APNS_USE_SANDBOX": "api.development.push.apple.com", "APPLICATIONS": {
        # 下面的xxx.xxx.xxxApp是上面的APNS_TOPIC,由于不方便写真实的TOPIC,大家见谅,注意修改成自己配置好的 "xxx.xxx.xxxApp": { # PLATFORM (required) determines what additional settings are required. "PLATFORM": "APNS", # required APNS setting
           #下面的是证书的绝对路径,跟上面的配置"APNS_CERTIFICATE": r"/path/to/xxx.pem"一致 "CERTIFICATE": r"/path/to/xxx.pem",, "USE_SANDBOX": True, }, }, }

    4 urls.py 配置

      router.register(r'api/v1/device/apns', APNSDeviceAuthorizedViewSet)  # 注册设备的

    5. 注册设备参数说明

      通过第四步配置的路由添加设备时,几个参数和大家说一下。

      Application ID : 上面配置的APNS_TOPIC

      Registration ID:  device token

      Device ID : UDID

    6.证书生成

      IOS生成pem 方法: https://blog.csdn.net/lgm252008/article/details/11201467

      注意生成pem一定要no key

    7. 总结

      按照上面流程配置好,就可以推送消息了,希望对大家有所帮助,少踩一些坑。最后再次感谢pzanitti大神。

    文档地址:

      https://github.com/jazzband/django-push-notifications

  • 相关阅读:
    创建进程
    进程
    操作系统历史
    socket
    网络基础
    常用模块二:hashlib、configparser、logging
    常见正则匹配
    类中的内置方法(魔法方法、双下方法)
    反射、isinstance和issubclass
    封装、继承、多态
  • 原文地址:https://www.cnblogs.com/0x0101010/p/9707343.html
Copyright © 2011-2022 走看看