Jpush极光推送

require 'jpush'
class SidkiqJpushWorker
  include Sidekiq::Worker

  #  args[0] msg  ; args[1] region_id ; args[2]: 设备 1 Android 2 ios
  # SidkiqJpushWorker.perform_async("张三你好","140fe1da9e9010a3725")
  def perform(*args)
    #msg = args[0]
    msg,registration_ids = args[0], args[1]

    # audience = JPush::Push::Audience.new.set_registration_id(registration_ids)
    #  #client = JPush::Client.new(JpushConfig::APP_KEY, JpushConfig::MASTER_SECRET)

    # app_key = "59bb23b8250c779fa0035af0"
    # master_secret = "5903bd6524c89970f3f8266c"
    # jpush = JPush::Client.new(app_key, master_secret)

    # #pusher = client.pusher
    # push_payload = JPush::Push::PushPayload.new(
    #     platform: 'all',
    #     audience: 'all',
    #     notification: 'hello jpush',
    #     message: msg
    # )
    # #pusher.push(payload1)
    # jpush.pusher.push(push_payload)

    app_key = "59bb23b8250c779fa0035af0"
    master_secret = "5903bd6524c89970f3f8266c"
    # reg_id = '190e35f7e044c642639'  JPushClient
    client = JPush::Client.new(app_key, master_secret)
    #client = JPush::Client.new(JpushConfig::APP_KEY, JpushConfig::MASTER_SECRET)

    playload1=JPush::PushPayload.build(
        #"cid": "8103a4c628a0b98974ec1949-711261d4-5f17-4d2f-a855-5e5a8909b26e",
        :platform => Jpush::Platform.all,
        :audience => Jpush::Audience.build(:registration_id => registration_ids),

        :notification =>Jpush::Notification.build(
          :android => JPush::AndroidNotification.build(
              :alert => "服务单01201607122395,分派给了你。",
              :title => "您有新的分配单!"
              # :builder_id => 1,
              # :extras => {:key1 => 'value1', :key2 => 'value2'})
              )


        # :message => JPush::Message.build(
        #     :msg_content => "message content test",
        #     :title => "message title test",
        #     # :content_type => "message content type test",
        #     # :extras => {:key1 => "value1", :key2 => "value2"}
        #     ),

        #   :options => {
        #     "time_to_live": 60,
        #     "apns_production": false,
        #     "apns_collapse_id":"jiguang_test_201706011100"
        # }    
      )
    )
       client.sendPush(playload1)





  end

end

  

 
posted @ 2017-12-11 12:36  lmg6406  阅读(328)  评论(0编辑  收藏  举报