Class: Getui

Inherits:
Object
  • Object
show all
Defined in:
lib/struggle/getui.rb

Constant Summary collapse

AppID =
"XxESwIkfcwAKhgIcQ0iyl8"
AppKey =
"9WY9yq0cxj5O7kPJT72om9"
AppSecret =
"RkZ9pNxnXl7hHYG4NX1s19"
MasterSecret =
"ie5ftISOpv97cgTBsiigaA"

Class Method Summary collapse

Class Method Details

.closeObject

关闭签权,return bool,success true, error false



27
28
29
30
31
32
33
34
35
# File 'lib/struggle/getui.rb', line 27

def close
  command = "curl -H \"authtoken: \#{@@auth_token}\" \\\nhttps://restapi.getui.com/v1/\#{AppID}/auth_close \\\n-XPOST\n"
  r = JSON.parse `#{command}`
  r["result"] == "ok"
end

.manyPush(clients) ⇒ Object

多推参数 clients: 客户信息数组格式[“xxx”, title: “xxx”, text: “xxx”, is_offline: false],

返回值 bool,success true, error false



79
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
# File 'lib/struggle/getui.rb', line 79

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 = "curl -H \"Content-Type: application/json\"  \\\n -H \"authtoken:\#{@@auth_token}\" \\\n https://restapi.getui.com/v1/\#{AppID}/push_single_batch  \\\n -XPOST -d '{\n             \"msg_list\": \#{msg_list.to_json},\n             \"need_detail\":true\n        }'\n"
    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



40
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
# File 'lib/struggle/getui.rb', line 40

def onePush(cid, title, text, is_offline=false)
  if sign
    requestid = Random.new.rand(1000000000000000000000..99999999999999999999999)
    command = "curl -H \"Content-Type: application/json\" \\\n-H \"authtoken:\#{@@auth_token}\" \\\n https://restapi.getui.com/v1/\#{AppID}/push_single \\\n -XPOST -d '{\n               \"message\": {\n               \"appkey\": \"\#{AppKey}\",\n               \"is_offline\": \#{is_offline},\n               \"offline_expire_time\":100000000,\n               \"msgtype\": \"notification\"\n            },\n            \"notification\": {\n                \"style\": {\n                    \"type\": 0,\n                    \"text\": \"\#{text}\",\n                    \"title\": \"\#{title}\"\n                },\n                \"transmission_type\": true,\n                \"transmission_content\": \"\u900F\u4F20\u5185\u5BB9\"\n            },\n            \"cid\": \"\#{cid}\",\n            \"requestid\": \"\#{requestid}\"\n        }'\n"
    r = JSON.parse `#{command}`
    close
    return r["result"] == "ok"
  else
    return false
  end
end

.signObject

签权,获取权限。返回bool值,成功签权返回true,否则返回false。 @@auth_token 全局token



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/struggle/getui.rb', line 10

def sign
  timestamp = "#{Time.now.to_i}000"
  sign = Digest::SHA256.hexdigest(AppKey+timestamp+MasterSecret)
  # sign = Digest::SHA256.base64digest sign
  command = "curl -H \"Content-Type: application/json\" \\\\\nhttps://restapi.getui.com/v1/\#{AppID}/auth_sign \\\\\n-XPOST -d '{ \"sign\":\"\#{sign}\",\n\"timestamp\":\"\#{timestamp}\",\n\"appkey\":\"\#{AppKey}\"\n}'\n"
  r = JSON.parse `#{command}`
  r["result"] == "ok" ? @@auth_token = r["auth_token"] : nil
end