`
鹤惊昆仑
  • 浏览: 229063 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ruby-sms

    博客分类:
  • ruby
阅读更多
出处:http://raa.ruby-lang.org/project/ruby-sms/
#!/usr/local/bin/ruby 

require "serialport.so"
require "socket"

class SMSController
  
  def initialize(bluetoothDevice,phoneNum,smsText)
    @@bluetoothDevice = bluetoothDevice
    @@phoneNum = phoneNum
    @@smsText = smsText
  end
  
  @@t_bin =  
    {
    "0000" => "0", 
    '0001' => '1', 
    '0010' => '2',
    '0011' => '3', 
    '0100' => '4', 
    '0101' => '5', 
    '0110' => '6', 
    '0111' => '7', 
    '1000' => '8', 
    '1001' => '9', 
    '1010' => 'A', 
    '1011' => 'B', 
    '1100' => 'C',  
    '1101' => 'D', 
    '1110' => 'E', 
    '1111' => 'F' 
    }
    
  @@bit7 = 
    {
      "0000000" => "@",
      "0000001" => "£",
      "0000010" => "$",
      "0000011" => "¥",
      "0000100" => "è",
      "0000101" => "é",
      "0000110" => "ù",
      "0000111" => "ì",
      "0001000" => "ò",
      "0001001" => "Ç",
      "0001010" => "\r",
      "0001011" => "Ø",
      "0001100" => "ø",
      "0001101" => "\n\r",
      "0001110" => "Å",
      "0001111" => "å",
      "0010000" => "∆",
      "0010001" => "_",
      "0010010" => "fi",
      "0010011" => "GAMMA",
      "0010100" => "LAMBDA",
      "0010101" => "Ω",
      "0010110" => "π",
      "0010111" => "PSI",
      "0011000" => "∑",
      "0011001" => "THETA",
      "0011010" => "XI",
      "0011011" => "\n",
      "0011100" => "Æ",
      "0011101" => "æ",
      "0011110" => "ß",
      "0011111" => "É",
      "0100000" => " ",
      "0100001" => "!",
      "0100010" => "\"",
      "0100011" => "#",
      "0100100" => "¢",
      "0100101" => "%",
      "0100110" => "&",
      "0100111" => "\'",
      "0101000" => "(",
      "0101001" => ")",
      "0101010" => "*",
      "0101011" => "+",
      "0101100" => ",",
      "0101101" => "-",
      "0101110" => ".",
      "0101111" => "/",
      "0110000" => "0",
      "0110001" => "1",
      "0110010" => "2",
      "0110011" => "3",
      "0110100" => "4",
      "0110101" => "5",
      "0110110" => "6",
      "0110111" => "7",
      "0111000" => "8",
      "0111001" => "9",
      "0111010" => ":",
      "0111011" => ",",
      "0111100" => "<",
      "0111101" => "=",
      "0111110" => ">",
      "0111111" => "?",
      "1000000" => "¡",
      "1000001" => "A",
      "1000010" => "B",
      "1000011" => "C",
      "1000100" => "D",
      "1000101" => "E",
      "1000110" => "F",
      "1000111" => "G",
      "1001000" => "H",
      "1001001" => "I",
      "1001010" => "J",
      "1001011" => "K",
      "1001100" => "L",
      "1001101" => "M",
      "1001110" => "N",
      "1001111" => "O",
      "1010000" => "P",
      "1010001" => "Q",
      "1010010" => "R",
      "1010011" => "S",
      "1010100" => "T",
      "1010101" => "U",
      "1010110" => "V",
      "1010111" => "W",
      "1011000" => "X",
      "1011001" => "Y",
      "1011010" => "Z",
      "1011011" => "Ä",
      "1011100" => "Ö",
      "1011101" => "N",
      "1011110" => "Ü",
      "1011111" => "§",
      "1100000" => "?",
      "1100001" => "a",
      "1100010" => "b",
      "1100011" => "c",
      "1100100" => "d",
      "1100101" => "e",
      "1100110" => "f",
      "1100111" => "g",
      "1101000" => "h",
      "1101001" => "i",
      "1101010" => "j",
      "1101011" => "k",
      "1101100" => "l",
      "1101101" => "m",
      "1101110" => "n",
      "1101111" => "o",
      "1110000" => "p",
      "1110001" => "q",
      "1110010" => "r",
      "1110011" => "s",
      "1110100" => "t",
      "1110101" => "u",
      "1110110" => "v",
      "1110111" => "w",
      "1111000" => "x",
      "1111001" => "y",
      "1111010" => "Z",
      "1111011" => "ä",
      "1111100" => "ö",
      "1111101" => "ñ",
      "1111110" => "ü",
      "1111111" => "à",
      }
      
   def sendSMS()
    	createSMS(@@phoneNum,@@smsText)
   end
   

   def nibble_swap(str)
       strLen = str.length
       swap_str = ""
       if strLen%2 != 0 then        
           str = str + "f"
       end
       i = 0
       while i < strLen
           swap_str = swap_str + str.slice(i..(i+1)).reverse
           i += 2
       end
       return swap_str
   end  
   
  def ascii2bin7bit(str)
      strLen = str.length
      binStr = ""
      i = 0
      while i < strLen
          char = str.slice(i..i)
          @@bit7.each do |k,v|
              if v == char then
                  binStr = binStr + k
              end
          end
          i += 1
      end
      return binStr
  end
  
  def code7bin2octet(septets)

      spLen = septets.length - 6
      octets = ""
      octets_n = ""
      oct = {}
      n = 0
      i = 0
      while i < spLen
          if (n <= 6) then
              sep = septets.slice((i)..(i+6))
              sep_n = septets.slice((i+7)..(i+13))
              if !(sep_n.length == 0) then
                  oct[n] = sep_n.slice((6-n)..6) + sep.slice(0..(6-n))
                  octets_n = octets_n + oct[n]
              else
                  oct[n] = sep.slice(0..(6-n))
                  while oct[n].length < 8
                      oct[n] = "0" + oct[n]
                  end
                  octets_n = octets_n + oct[n]
              end
              n += 1
          else
              n = 0
          end
          i += 7
      end
      hex = []
      j = 0   
      while j < octets_n.length
          bin = octets_n.slice(j..j+3)
          hex.insert(-1,@@t_bin["#{bin}"])
          j += 4
      end
      return hex.to_s
  end
  
  def createSMS(phoneNum,smsText)
    
      @sms_praefix = "001100"

      @phone_num = phoneNum
      @sms_msg = smsText
      @pn_len = @phone_num.length
      @pn_len = sprintf('%02X',@pn_len)
      @trp = "91"
      @phone_num = nibble_swap(@phone_num)
      @sms_infix = "0000FF"
      @msg_len = @sms_msg.length
      @msg_len = sprintf('%02X',@msg_len)
      @sms_msg = ascii2bin7bit(@sms_msg)
      @sms_msg = code7bin2octet(@sms_msg)
      @sms = @sms_praefix + @pn_len + @trp + @phone_num + @sms_infix + @msg_len + @sms_msg
      @sms_len = @sms.length/2 -1

      sp = SerialPort.new(@@bluetoothDevice, 9600,8,1,SerialPort::NONE)
      open(@@bluetoothDevice)

      sp.write( "at+cmgs=#{@sms_len}" + "\n\r")

      sleep 2

      sp.write( "#{@sms}" + "\032")

      sleep 2

      sp.close
  end  

end

#mySMS = SMSController.new("/dev/cu.Your_Paired_Bluetooth_Device","Number_Of_SMS_Receiver,"SMS_Message")
mySMS = SMSController.new("/dev/cu.W900i-SerialPort-1","43676844256222","hallo world!")

mySMS.sendSMS


分享到:
评论
1 楼 sevk 2010-08-03  
请问
mySMS = SMSController.new("/dev/cu.W900i-SerialPort-1","43676844256222","hallo world!") 

这里的号码怎么解析?

相关推荐

    Ruby-百度sms简单发送短信ruby代码

    本示例将详细介绍如何使用Ruby代码通过百度SMS接口实现短信发送功能。百度SMS服务提供了一个方便的方式来与用户进行实时通信,例如验证身份、通知重要事件等。在本文中,我们将探讨如何配置和使用这个服务,并分析...

    serverless-ruby-simple-sms:使用Ruby的jets框架创建无服务器SMS服务的简单应用程序

    无服务器短信服务这是在Ruby的...sudo apt install awscli$ aws configure第4步-克隆存储库$ git clone https://github.com/SystangoTechnologies/serverless-ruby-simple-sms.git$ cd serverless-ruby-simple-sms$

    Ruby - NetHTTP实现短信验证码注册登录完整示例:Ruby - NetHTTP.rb和附件说明.rar

    uri = URI.parse('https://sms-provider.com/send') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri) req.set_form_data('phone' =&gt; phone_number, 'key' =&gt; api_key, 'action' =&gt; '...

    Ruby-RopRuby是融数金服的ruby语言的SDK其支持的功能包括短信等

    然后,就可以调用相应的函数,如`send_sms`来发送短信,或者`verify_sms`来验证接收到的验证码。这些函数通常会返回一个包含操作结果的状态码或错误信息,帮助开发者判断操作是否成功。 在压缩包文件"rop-ruby-...

    Ruby-Rails的异常通知插件

    Exception Notification插件的核心功能是在Rack或Rails应用发生错误时,自动发送通知给指定的接收者,如开发团队的邮箱或者通过其他通信方式(如Slack、SMS等)。这样,即使应用在生产环境中遇到问题,开发者也能...

    Ruby-云片短息ruby服务器端api

    Ruby是面向对象的脚本语言,常用于Web开发和快速原型设计。云片(YunPian)是一家提供短信服务的公司,它们提供了各种API,让开发者能够方便地在自己的应用中集成短信发送功能。"云片短息Ruby服务器端API"就是针对...

    Laravel开发-sms

    在这个"SMS-master"项目中,我们可能看到以下几个关键组成部分: 1. **服务提供者配置**:Laravel允许我们注册自定义的服务提供者,这些提供者可以绑定到IoC容器,管理服务的生命周期。在`config/app.php`文件中,...

    sms-ruby-code:评估从短信服务收到的 ruby​​ 代码

    标题中的“sms-ruby-code”项目是一个专门为评估通过短信服务接收到的Ruby代码而设计的解决方案。这个项目可能被开发者用来安全地运行用户提交的代码片段,例如在竞赛、教育平台或者任何需要动态评估Ruby代码的场景...

    mobily-sms:允许与mobily.ws服务集成

    Mobily :: Sms mobily-sms gem,用于与 api集成。 mobilyws提供SMS网关服务“ SMS API”,使您可以轻松地将Send-SMS服务与您的应用程序,网站或任何类型的系统连接 这种宝石将与您的集成容易,为了使用mobily.ws ...

    vonage-ruby-sdk:针对Ruby的Vonage REST API客户端。 API支持短信,语音,文本语音转换,数字,验证(2FA)等

    Vonage Server SDK for Ruby 这是用于Vonage API的Ruby Server SDK。 要使用它,您需要一个Vonage帐户。...要求Vonage Ruby支持MRI / CRuby(2.5或更高版本),JRuby(9.2.x)和Truffleruby。... sms . send ( from : 'Rub

    ruby-smpp:SMPP协议的Ruby实现,基于EventMachine

    Ruby-SMPP是SMPP v3.4协议的Ruby实现。 它适用于编写与SMSC通信以发送和接收SMS消息的网关守护程序。 该实现基于Ruby / EventMachine库。 注意:中断更改从0.1.2到0.1.3 。 见下文。 如需帮助,请在此处使用...

    D7 SMS - Ruby SDK:用于通过 D7 SMS 发送 SMS 的 Ruby SDK-开源

    D7 SMS Ruby SDK 是一个专为 Ruby 开发者设计的工具包,允许他们方便地集成 D7 SMS 平台的功能,以便通过 SMS 方式与全球的客户进行沟通。这个 SDK 提供了丰富的功能,使开发者能够高效、稳定地发送短信,从而提升...

    ruby-library:适用于Urban Airship API的Ruby包装器

    关于urbanairship是一个Ruby库,用于使用 REST API来推送通知,消息中心消息,电子邮件和SMS。要求我们正式支持以下Ruby版本: 2.2.52.3.1较新的版本也应该工作。功能性5.0版是主要升级,因为已删除了早期版本中的...

    rapidpro-sms-manager:图表调查和管理由 Rapidpro webhooks 转发的谣言

    Rapidpro 短信管理器流可以配置 webhook,将 sms 响应的内容转发到 url。 此应用程序使用 ruby​​ on rails 开发,与 django 应用程序 Rapidpro 分开运行,旨在接收这些响应。 它们不需要在同一台服务器上运行。 ...

    marketing-notifications-rails:Ruby on Rails中的Sms通知应用程序

    Ruby on Rails和Twilio的SMS通知 关于 使用Twilio创建短信通知,以使您的订户保持循环。 ! 当地发展 该项目是使用和框架构建的。 首先克隆该存储库,然后将其cd入。 $ git clone git@github....

    sms-spec:一个用于使用RSpec和Cucumber测试SMS消息的Ruby库

    ## Setup将sms-spec gem添加到您的Gemfile中: group :test do gem 'sms-spec' end 规范 在您的spec_helper.rb文件中添加以下内容: require 'sms_spec' 如果要在所有示例组中都提供帮助程序,则可以将以下内容...

    ringcentral-sdk-ruby:Ruby 中的 RingCentral SDK (https)

    SMS 和 MMS 示例3.传真示例 高级用例 支持的 Ruby 版本 发布 版本控制 更改日志 链接 贡献 执照 概述 用于RingCentral REST API 的Ruby SDK。 重要笔记 2.0.0 版引入了以下向后突破性更改: 通过移动到基于块的...

    power-off-phone:Ruby脚本,可无限期关闭手机

    要运行这个名为“send-sms.rb”的Ruby脚本,首先你需要确保已经安装了Ruby环境,并且在项目目录下执行以下命令: ```bash ruby send-sms.rb ``` 在执行脚本之前,你还需要设置以下几项: 1. **Twilio账户**:你...

    sms-openapi:BlueHuseLab SMS OpenAPI for S.Korea

    청기와랩 SMS Open API v1.0 这是 BlueHouseLab S.Korean SMS OpenAPI 的官方... Ruby php 节点.js Java(安卓) C (libcurl) C++ (Qt5) C#(单声道/.NET) callback-api : 用于测试回调 API 的简单网络服务器

    smstools:一组Ruby和JavaScript类,以帮助进行SMS消息处理

    少量的Ruby和JavaScript类实现了处理SMS消息经常需要的功能。 该宝石还可以在Rails应用程序中用作引擎。 它与资产管道集成在一起,使您可以访问某些客户端SMS操作功能。 特征 服务器端和客户端都可以使用以下功能:...

Global site tag (gtag.js) - Google Analytics