极光

require 'jpush'

master_secret = '7f4f6c4afa1c070f40e54'
app_key = 'e9a794f8d1a4d88204ab'

jpush = JPush::Client.new(app_key, master_secret)

pusher = jpush.pusher

push_payload = JPush::Push::PushPayload.new(
  platform: 'all',
  audience: 'all',
  notification: 'hello jpush',  #字符串设置最基本的'alert'属性
  message: 'hello world'
)

pusher.push(push_payload)

##Report API
reporter = jpush.reporter
##
########################################################
##构建audience
##如果要发送广播,不需要构建Audience对象。
##在新建PushPayload对象的时候,给'audience'参数传'all'即可。
##在广播之外还可以选择4种类型
#tag
#tag_and
#alias
#registration_id
#几种类型并存的时候隐含关系是AND
audience = JPush::Push::Audience.new
audience.set_tag(tag)             #最多包含20个有效的标签字符串的数组
audience.set_tag_and(tag_and)      #最多包含20个有效的标签字符串的数组
audience.set_alias(alias)         #最多包含1000个有效的别名字符串的数组
audience.set_registration_id(registration_ids) #最多包含1000个有效的registration id字符串数组
##上面可以 链式调用
########################################################

#若通知的内容在各个平台上,都只有 'alert'基本属性。
#不需要构建Notification,在新建PushPayload对象时,给'notification'直接传'alert'字符串
#属性包含3种,2个平台,以及一个'alert'属性

notification = JPush::Push::Notification.new

notification.set_alert(alert)
#Android
notification.set_android(
  alert: alert, #通知栏,可以为空字符串
  title: title, #通知标题,会替换通知里原来展示App名称的地方
  builder_id: builder_id, #通知栏样式ID
  extras: extras  #扩展字段,接受一个Hash对象,以供业务使用
)
#IOS
notification.set_ios(
  alert: alert,
  sound: sound, #是否设置提示声音
  badge: badge, #把角标设置为指定数字
  available: available,#表示推送唤醒
  category: category, #IOS8才支持,设置APNS payload中的'category'字段值
  extras: extras
)
########################################################

你可能感兴趣的:(极光)