class Struggle::Sms

Constants

URL

Public Class Methods

send(uid, pwd, mobile, content) click to toggle source
# 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) click to toggle source

腾讯短信单发接口 参数

1.sdkappid,请填写您在腾讯云上申请到的appid  示例:1400147773
2.appkey,sdkappid对应的的appkey          示例:f1c0cae4ee52489abe711d48a7e7789c
3.tpl_id,短信模板id                       示例:205045
4.sign,开通得短信的应用名称,一般是公司名称缩写。 示例:微象科技
5.mobile,接收短信的手机号码
6.content,发送的变量内容,对应模板中的变量{0},类型为string数组
# 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