/cloopen

云通讯发送短信 Gem

Primary LanguageRubyMIT LicenseMIT

Cloopen

云通讯发送短信的 Gem。

Installation

Add this line to your application's Gemfile:

gem 'cloopen'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cloopen

Usage

申请云通讯的短信通道服务

  1. 注册 云通讯 ,申请企业认证(只有企业帐号才可以发短信)。

  2. 这个页面 查看帐号的 account_sid, auth_token

  3. 这个页面 创建 App,获得 app_id

  4. 这里 创建你的短信模板,比如:

    【薄荷网】您的的验证码是{1}

  5. 等待云通讯的管理员审核,大概需要 2 个小时的时间。

    • App 通过审核
    • 短信模板通过审核

生成配置文件

  1. 执行 rails g cloopen 生成配置文件 config/initialiers/cloopen_setup.rb

  2. 替换 sid、token、app_id、env

# config/initialiers/cloopen_setup.rb
Cloopen.account_sid = "Your Yuntongxun Account Sid"
Cloopen.auth_token  = "Your Yuntongxun Auth token"
Cloopen.app_id      = "Your Yuntongxun App id"
Cloopen.env         = "production" # 如果是测试环境,填写 "development"

发送验证码

  Cloopen::SMS.deliver(18668189884, 3127, ['a32d1k'])   # 短信形式
  Cloopen::Voice.deliver(18668189884, 3127, ['a32d1k']) # 语音形式
  • 第一个参数是手机号码

  • 第二个是模板id。只能使用已审通过核的模板发短信。

  • 第三个是模板中的变量的值。用于替换模板中的变量 1 【薄荷网】您的的验证码是{1}

荣耀归给仨小伙

Contributing

  1. Fork it ( https://github.com/xiaoronglv/cloopen/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request