Class: QQBot::Api
- Inherits:
-
Object
- Object
- QQBot::Api
- Defined in:
- lib/qqbot/api.rb
Class Method Summary collapse
Instance Method Summary collapse
- #auth_options=(options = {}) ⇒ Object
- #get_account_info ⇒ Object
- #get_discuss_info(discuss_id) ⇒ Object
- #get_discuss_list ⇒ Object
- #get_friend_info(friend_id) ⇒ Object
- #get_friend_list ⇒ Object
- #get_group_info(group_code) ⇒ Object
- #get_group_list ⇒ Object
- #get_online_friends ⇒ Object
- #get_psessionid_and_uin(ptwebqq) ⇒ Object
- #get_ptwebqq(url) ⇒ Object
- #get_qq_by_id(id) ⇒ Object
- #get_qrcode ⇒ Object
- #get_recent_list ⇒ Object
- #get_vfwebqq(ptwebqq) ⇒ Object
- #hash ⇒ Object
-
#initialize ⇒ Api
constructor
A new instance of Api.
- #msg_id ⇒ Object
- #poll ⇒ Object
- #send_to_discuss(discuss_id, content) ⇒ Object
- #send_to_friend(friend_id, content) ⇒ Object
- #send_to_group(group_id, content) ⇒ Object
- #send_to_sess(sess_id, content) ⇒ Object
- #verify_qrcode ⇒ Object
Constructor Details
Class Method Details
.build_message(content) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/qqbot/api.rb', line 297 def self.(content) JSON.generate( [ content.force_encoding("UTF-8"), [ 'font', { name: '宋体', size: 10, style: [0, 0, 0], color: '000000' } ] ] ) end |
.hash(uin, ptwebqq) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/qqbot/api.rb', line 87 def self.hash(uin, ptwebqq) n = Array.new(4, 0) ptwebqq.chars.each_index { |i| n[i % 4] ^= ptwebqq[i].ord } u = ['EC', 'OK'] v = Array.new(4) v[0] = uin >> 24 & 255 ^ u[0][0].ord; v[1] = uin >> 16 & 255 ^ u[0][1].ord; v[2] = uin >> 8 & 255 ^ u[1][0].ord; v[3] = uin & 255 ^ u[1][1].ord; u = Array.new(8) (0...8).each { |i| u[i] = i.odd? ? v[i >> 1] : n[i >> 1] } n = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] v = '' u.each do |i| v << n[(i >> 4) & 15] v << n[i & 15] end v end |
Instance Method Details
#auth_options=(options = {}) ⇒ Object
11 12 13 |
# File 'lib/qqbot/api.rb', line 11 def ( = {}) @options = end |
#get_account_info ⇒ Object
208 209 210 211 212 213 214 215 216 |
# File 'lib/qqbot/api.rb', line 208 def get_account_info uri = URI('http://s.web2.qq.com/api/get_self_info2') uri.query = URI.encode_www_form( t: 0.1 ) @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') end |
#get_discuss_info(discuss_id) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/qqbot/api.rb', line 263 def get_discuss_info(discuss_id) uri = URI('http://d1.web2.qq.com/channel/get_discu_info') uri.query = URI.encode_www_form( did: discuss_id, vfwebqq: @options[:vfwebqq], clientid: QQBot::CLIENT_ID, psessionid: @options[:psessionid], t: 0.1 ) @client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2') end |
#get_discuss_list ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/qqbot/api.rb', line 144 def get_discuss_list uri = URI('http://s.web2.qq.com/api/get_discus_list') uri.query = URI.encode_www_form( clientid: QQBot::CLIENT_ID, psessionid: @options[:psessionid], vfwebqq: @options[:vfwebqq], t: 0.1 ) @client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2') end |
#get_friend_info(friend_id) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/qqbot/api.rb', line 276 def get_friend_info(friend_id) uri = URI('http://s.web2.qq.com/api/get_friend_info2') uri.query = URI.encode_www_form( tuin: friend_id, vfwebqq: @options[:vfwebqq], clientid: QQBot::CLIENT_ID, psessionid: @options[:psessionid], t: 0.1 ) @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') end |
#get_friend_list ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/qqbot/api.rb', line 135 def get_friend_list uri = URI('http://s.web2.qq.com/api/get_user_friends2') r = JSON.generate( vfwebqq: @options[:vfwebqq], hash: hash ) @client.post(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1', r: r) end |
#get_group_info(group_code) ⇒ Object
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/qqbot/api.rb', line 252 def get_group_info(group_code) uri = URI('http://s.web2.qq.com/api/get_group_info_ext2') uri.query = URI.encode_www_form( gcode: group_code, vfwebqq: @options[:vfwebqq], t: 0.1 ) @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') end |
#get_group_list ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/qqbot/api.rb', line 122 def get_group_list uri = URI('http://s.web2.qq.com/api/get_group_name_list_mask2') r = JSON.generate( vfwebqq: @options[:vfwebqq], hash: hash ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#get_online_friends ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/qqbot/api.rb', line 240 def get_online_friends uri = URI('http://d1.web2.qq.com/channel/get_online_buddies2') uri.query = URI.encode_www_form( vfwebqq: @options[:vfwebqq], clientid: QQBot::CLIENT_ID, psessionid: @options[:psessionid], t: 0.1 ) @client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2') end |
#get_psessionid_and_uin(ptwebqq) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/qqbot/api.rb', line 76 def get_psessionid_and_uin(ptwebqq) uri = URI('http://d1.web2.qq.com/channel/login2'); r = JSON.generate( ptwebqq: ptwebqq, clientid: QQBot::CLIENT_ID, psessionid: '', status: 'online' ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#get_ptwebqq(url) ⇒ Object
58 59 60 61 62 |
# File 'lib/qqbot/api.rb', line 58 def get_ptwebqq(url) uri = URI(url); code, body = @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') return code, @client.('ptwebqq') end |
#get_qq_by_id(id) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/qqbot/api.rb', line 228 def get_qq_by_id(id) uri = URI('http://s.web2.qq.com/api/get_friend_uin2') uri.query = URI.encode_www_form( tuin: id, type: 1, vfwebqq: @options[:vfwebqq], t: 0.1 ) @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') end |
#get_qrcode ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/qqbot/api.rb', line 15 def get_qrcode uri = URI('https://ssl.ptlogin2.qq.com/ptqrshow'); uri.query = URI.encode_www_form( appid: 501004106, e: 0, l: :M, s: 5, d: 72, v: 4, t: 0.1, ) @client.get(uri) end |
#get_recent_list ⇒ Object
218 219 220 221 222 223 224 225 226 |
# File 'lib/qqbot/api.rb', line 218 def get_recent_list uri = URI('http://d1.web2.qq.com/channel/get_recent_list2') r = JSON.generate( vfwebqq: @options[:vfwebqq], clientid: QQBot::CLIENT_ID, psessionid: '' ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#get_vfwebqq(ptwebqq) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/qqbot/api.rb', line 64 def get_vfwebqq(ptwebqq) uri = URI('http://s.web2.qq.com/api/getvfwebqq'); uri.query = URI.encode_www_form( ptwebqq: ptwebqq, clientid: QQBot::CLIENT_ID, psessionid: '', t: 0.1, ) @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') end |
#hash ⇒ Object
131 132 133 |
# File 'lib/qqbot/api.rb', line 131 def hash self.class.hash(@options[:uin], @options[:ptwebqq]) end |
#msg_id ⇒ Object
293 294 295 |
# File 'lib/qqbot/api.rb', line 293 def msg_id @msg_id += 1 end |
#poll ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/qqbot/api.rb', line 107 def poll uri = URI('http://d1.web2.qq.com/channel/poll2') r = JSON.generate( ptwebqq: @options[:ptwebqq], clientid: QQBot::CLIENT_ID, psessionid: @options[:psessionid], key: '' ) begin @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) rescue retry end end |
#send_to_discuss(discuss_id, content) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/qqbot/api.rb', line 182 def send_to_discuss(discuss_id, content) uri = URI('http://d1.web2.qq.com/channel/send_discu_msg2') r = JSON.generate( did: discuss_id, content: self.class.(content), face: 522, clientid: QQBot::CLIENT_ID, msg_id: msg_id, psessionid: @options[:psessionid] ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#send_to_friend(friend_id, content) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/qqbot/api.rb', line 156 def send_to_friend(friend_id, content) uri = URI('http://d1.web2.qq.com/channel/send_buddy_msg2') r = JSON.generate( to: friend_id, content: self.class.(content), face: 522, clientid: QQBot::CLIENT_ID, msg_id: msg_id, psessionid: @options[:psessionid] ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#send_to_group(group_id, content) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/qqbot/api.rb', line 169 def send_to_group(group_id, content) uri = URI('http://d1.web2.qq.com/channel/send_qun_msg2') r = JSON.generate( group_uin: group_id, content: self.class.(content), face: 522, clientid: QQBot::CLIENT_ID, msg_id: msg_id, psessionid: @options[:psessionid] ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#send_to_sess(sess_id, content) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/qqbot/api.rb', line 195 def send_to_sess(sess_id, content) uri = URI('http://d1.web2.qq.com/channel/send_sess_msg2') r = JSON.generate( to: sess_id, content: self.class.(content), face: 522, clientid: QQBot::CLIENT_ID, msg_id: msg_id, psessionid: @options[:psessionid] ) @client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r) end |
#verify_qrcode ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/qqbot/api.rb', line 30 def verify_qrcode uri = URI('https://ssl.ptlogin2.qq.com/ptqrlogin'); uri.query = URI.encode_www_form( webqq_type: 10, remember_uin: 1, login2qq: 1, aid: 501004106, u1: 'http://Fw.qq.com/proxy.html?login2qq=1&webqq_type=10', ptredirect: 0, ptlang: 2052, daid: 164, from_ui: 1, pttype: 1, dumy: '', fp: 'loginerroralert', action: '0-0-157510', mibao_css: 'm_webqq', t: 1, g: 1, js_type: 0, js_ver: 10143, login_sig: '', pt_randsalt: 0, ) @client.get(uri) end |