zoukankan      html  css  js  c++  java
  • 极光推送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

  • 相关阅读:
    numpy的shuffle函数
    特征值、特征向量
    keras的Embedding层
    自己写着玩的一个天气APP
    使用mbed进行STM32板子的开发
    提高ListView的效率
    自定义ListView里面的Item的内容
    Android控件使用自定义字体
    使用Handler类来更新UI
    MongoDB在Java下的增删查改
  • 原文地址:https://www.cnblogs.com/itmangelihai/p/3161315.html
Copyright © 2011-2022 走看看