Class: Struggle::Sms
- Inherits:
-
Object
- Object
- Struggle::Sms
- Defined in:
- lib/struggle/sms.rb
Constant Summary collapse
- URL =
"http://api.cnsms.cn/"
Class Method Summary collapse
- .send(uid, pwd, mobile, content) ⇒ Object
-
.tx_send(sdkappid, appkey, tpl_id, sign, mobile, content) ⇒ Object
腾讯短信单发接口 参数 1.sdkappid,请填写您在腾讯云上申请到的appid 示例:1400147773 2.appkey,sdkappid对应的的appkey 示例:f1c0cae4ee52489abe711d48a7e7789c 3.tpl_id,短信模板id 示例:205045 4.sign,开通得短信的应用名称,一般是公司名称缩写。 示例:微象科技 5.mobile,接收短信的手机号码 6.content,发送的变量内容,对应模板中的变量0,类型为string数组.
Class Method Details
.send(uid, pwd, mobile, content) ⇒ Object
7 8 9 10 |
# File 'lib/struggle/sms.rb', line 7 def Sms.send(uid, pwd, mobile, content) response = Http.post(URL, {'ac' => "send", 'uid' => uid, 'pwd' => pwd, 'mobile' => mobile, 'content' => content}) return response.body=="100" end |
.tx_send(sdkappid, appkey, tpl_id, sign, mobile, content) ⇒ Object
腾讯短信单发接口 参数
1.sdkappid,请填写您在腾讯云上申请到的appid 示例:1400147773
2.appkey,sdkappid对应的的appkey 示例:f1c0cae4ee52489abe711d48a7e7789c
3.tpl_id,短信模板id 示例:205045
4.sign,开通得短信的应用名称,一般是公司名称缩写。 示例:微象科技
5.mobile,接收短信的手机号码
6.content,发送的变量内容,对应模板中的变量{0},类型为string数组
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/struggle/sms.rb', line 20 def Sms.tx_send(sdkappid, appkey, tpl_id, sign, mobile, content) random = Random.new.rand(100000..999999) time = Time.now.to_i data = {:ext=>"", :extend=>"", :params=>content, :sig=>Digest::SHA256.hexdigest("appkey=#{appkey}&random=#{random}&time=#{time}&mobile=#{mobile}"), :sign=>sign, :tel=>{:mobile=>mobile, :nationcode=>"86"}, :time => time, :tpl_id=>tpl_id} url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=#{sdkappid}&random=#{random}" body = Http.new(url).post(data.to_json).body if !body.blank? result = eval body if result[:result] == 0 return {state: true} else return {state: false, msg: result[:errmsg]} end end return {state: false, msg:"腾讯短信平台无响应,发送失败。"} end |