class Struggle::Getui
Constants
- AppID
- AppKey
- AppSecret
- MasterSecret
Public Class Methods
close()
click to toggle source
关闭签权,return bool,success true, error false
# File lib/struggle/getui.rb, line 28 def close command = <<EOF curl -H "authtoken: #{@@auth_token}" \ https://restapi.getui.com/v1/#{AppID}/auth_close \ -XPOST EOF r = JSON.parse `#{command}` r["result"] == "ok" end
manyPush(clients)
click to toggle source
多推 参数 clients: 客户信息数组格式[{cid: “xxx”, title: “xxx”, text: “xxx”, is_offline: false}],
具体组成 cid:client_id, title: 标题, text: 消息内容, is_offline是否离线默认否。
返回值 bool,success true, error false
# File lib/struggle/getui.rb, line 80 def manyPush(clients) if sign msg_list = [] clients.each do |c| requestid = Random.new.rand(1000000000000000000000..99999999999999999999999) msg_list << { "message": { "appkey": "#{AppKey}", "is_offline": c[:is_offline] || false, "offline_expire_time": 100000000, "msgtype": "notification" }, "notification": { "style": { "type": 0, "text": "#{c[:text]}", "title": "#{c[:title]}" }, "transmission_type": true, "transmission_content": "透传内容" }, "cid": "#{c[:cid]}", "requestid": "#{requestid}" } end command = <<EOF curl -H "Content-Type: application/json" \ -H "authtoken:#{@@auth_token}" \ https://restapi.getui.com/v1/#{AppID}/push_single_batch \ -XPOST -d '{ "msg_list": #{msg_list.to_json}, "need_detail":true }' EOF r = JSON.parse `#{command}` close return r["result"] == "ok" else return false end end
onePush(cid, title, text, is_offline = false)
click to toggle source
单推 参数 cid:client_id, title: 标题, text: 消息内容, is_offline是否离线默认否。 返回值 bool,success true, error false
# File lib/struggle/getui.rb, line 41 def onePush(cid, title, text, is_offline = false) if sign requestid = Random.new.rand(1000000000000000000000..99999999999999999999999) command = <<EOF curl -H "Content-Type: application/json" \ -H "authtoken:#{@@auth_token}" \ https://restapi.getui.com/v1/#{AppID}/push_single \ -XPOST -d '{ "message": { "appkey": "#{AppKey}", "is_offline": #{is_offline}, "offline_expire_time":100000000, "msgtype": "notification" }, "notification": { "style": { "type": 0, "text": "#{text}", "title": "#{title}" }, "transmission_type": true, "transmission_content": "透传内容" }, "cid": "#{cid}", "requestid": "#{requestid}" }' EOF r = JSON.parse `#{command}` close return r["result"] == "ok" else return false end end
sign()
click to toggle source
签权,获取权限。返回bool值,成功签权返回true,否则返回false。 @@auth_token 全局token
# File lib/struggle/getui.rb, line 11 def sign timestamp = "#{Time.now.to_i}000" sign = Digest::SHA256.hexdigest(AppKey + timestamp + MasterSecret) # sign = Digest::SHA256.base64digest sign command = <<EOF curl -H "Content-Type: application/json" \\ https://restapi.getui.com/v1/#{AppID}/auth_sign \\ -XPOST -d '{ "sign":"#{sign}", "timestamp":"#{timestamp}", "appkey":"#{AppKey}" }' EOF r = JSON.parse `#{command}` r["result"] == "ok" ? @@auth_token = r["auth_token"] : nil end