Class: Struggle::Getui
- Inherits:
-
Object
- Object
- Struggle::Getui
- Defined in:
- lib/struggle/getui.rb
Constant Summary collapse
- AppID =
"XxESwIkfcwAKhgIcQ0iyl8"
- AppKey =
"9WY9yq0cxj5O7kPJT72om9"
- AppSecret =
"RkZ9pNxnXl7hHYG4NX1s19"
- MasterSecret =
"ie5ftISOpv97cgTBsiigaA"
Class Method Summary collapse
-
.close ⇒ Object
关闭签权,return bool,success true, error false.
-
.manyPush(clients) ⇒ Object
多推 参数 clients: 客户信息数组格式[“xxx”, title: “xxx”, text: “xxx”, is_offline: false], 具体组成 cid:client_id, title: 标题, text: 消息内容, is_offline是否离线默认否。 返回值 bool,success true, error false.
-
.onePush(cid, title, text, is_offline = false) ⇒ Object
单推 参数 cid:client_id, title: 标题, text: 消息内容, is_offline是否离线默认否。 返回值 bool,success true, error false.
-
.sign ⇒ Object
签权,获取权限。返回bool值,成功签权返回true,否则返回false。 @@auth_token 全局token.
Class Method Details
.close ⇒ Object
关闭签权,return bool,success true, error false
28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Object
多推 参数 clients: 客户信息数组格式[“xxx”, title: “xxx”, text: “xxx”, is_offline: false],
具体组成 cid:client_id, title: 标题, text: 消息内容, is_offline是否离线默认否。
返回值 bool,success true, error false
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# 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) ⇒ Object
单推 参数 cid:client_id, title: 标题, text: 消息内容, is_offline是否离线默认否。 返回值 bool,success true, error false
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
签权,获取权限。返回bool值,成功签权返回true,否则返回false。 @@auth_token 全局token
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/struggle/getui.rb', line 11 def sign = "#{Time.now.to_i}000" sign = Digest::SHA256.hexdigest(AppKey + + 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":"#{}", "appkey":"#{AppKey}" }' EOF r = JSON.parse `#{command}` r["result"] == "ok" ? @@auth_token = r["auth_token"] : nil end |