• 极光推送API简易rails版本


      研究了下极光推送写了个rails版本封装http接口的文件,上代码

    # -*- encoding : utf-8 -*-
    require 'digest/md5'
    require 'json'
    require 'rest_client'
    
    module NotificationPush
    
      def push_message(opts ={})
    
          sendno = opts[:sendno] || 1
    
          app_key = opts[:app_key] || '.....'
    
          receiver_type = opts[:receiver_type] || 2
    
          receiver_value = opts[:receiver_value] || '1'
    
          master_secret = opts[:master_secret] || '......'
    
          title = opts[:title] || '通知'
    
          message = opts[:message]
    
          n_extras_type = opts[:n_extras_type] || '1'
    
          n_extras_id = opts[:n_extras_id] || '1'
          
          mixstring = sendno.to_s + receiver_type.to_s + receiver_value + master_secret
          
          md5string = Digest::MD5.hexdigest(mixstring)
          
          msg_content = {  "n_title" => title, "n_content" =>  message,  "n_extras" => {"ios" => {"badge" => 1, "sound" => "happy"},"type" => n_extras_type, "id" => n_extras_id }}.to_json
          
          response = RestClient.post 'http://api.jpush.cn:8800/sendmsg/v2/sendmsg', 
                                { 
                                  :sendno => sendno, 
                                  :app_key => app_key, 
                                  :receiver_type => receiver_type, 
                                  :receiver_value => receiver_value,
                                  :verification_code => md5string, 
                                  :msg_type => 1, 
                                  :msg_content => msg_content, 
                                  :platform => 'ios,android'  
                                }                
      end
    end

    参数说明在api中都有说明我就不多说了,easy

  • 相关阅读:
    Java中获取键盘输入值的三种方法
    java多线程处理与数据集合
    Apachetomcat学习
    Java之枚举
    多例设计模式与枚举
    权限管理(数据库部分)
    hdu 2458(最大独立集)
    hdu 1507(最大匹配)
    hdu 1350+hdu 1960(最小路径覆盖)
    hdu 1845(最大匹配)
  • 原文地址:https://www.cnblogs.com/itmangelihai/p/3161315.html
Copyright © 2020-2023  润新知