云通讯发送短信的 Gem。
Add this line to your application's Gemfile:
gem 'cloopen'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cloopen
-
注册 云通讯 ,申请企业认证(只有企业帐号才可以发短信)。
-
在 这个页面 查看帐号的 account_sid, auth_token
-
在 这个页面 创建 App,获得 app_id
-
在 这里 创建你的短信模板,比如:
【薄荷网】您的的验证码是{1}
-
等待云通讯的管理员审核,大概需要 2 个小时的时间。
- App 通过审核
- 短信模板通过审核
-
执行
rails g cloopen
生成配置文件config/initialiers/cloopen_setup.rb
-
替换 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}
。
- Fork it ( https://github.com/xiaoronglv/cloopen/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request