qqbot 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -15
- data/Gemfile +4 -4
- data/README.md +84 -84
- data/lib/qqbot.rb +46 -46
- data/lib/qqbot/api.rb +314 -314
- data/lib/qqbot/bot.rb +504 -504
- data/lib/qqbot/client.rb +60 -60
- data/lib/qqbot/cookie.rb +28 -28
- data/lib/qqbot/error.rb +4 -4
- data/lib/qqbot/model.rb +57 -57
- data/lib/qqbot/version.rb +3 -3
- data/qqbot.gemspec +33 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3705c7042139eb9057765efc1a752e5832178078
|
4
|
+
data.tar.gz: bb2fe5f03e6f22448fa1c94bb4c5a43e190e2f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03fd72b1f4d26abecb697a71bda74f1a4ebb7387c190a93011c0a8eb7b261f838ed4351e05055e01320216f49d1fb5b95f0c4da5a9c72edde09cecf42b7fce49
|
7
|
+
data.tar.gz: fbb384a8f99e5b078035ca346c8271d2f17060a06e55625d49a36c423c0d636163025a55ec428e426311218330ec35165a94479a097fd36f418836a138d53728
|
data/.gitignore
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
|
11
|
-
lib/qqbot/qrcode.png
|
12
|
-
|
13
|
-
qqbot-0.1.0.gem
|
14
|
-
|
15
|
-
*.gem
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
lib/qqbot/qrcode.png
|
12
|
+
|
13
|
+
qqbot-0.1.0.gem
|
14
|
+
|
15
|
+
*.gem
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://ruby.taobao.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in qqbot.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://ruby.taobao.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in qqbot.gemspec
|
4
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,84 +1,84 @@
|
|
1
|
-
# QQBot
|
2
|
-
|
3
|
-
基于 Smart QQ(Web QQ)的 QQ 机器人
|
4
|
-
|
5
|
-
### 使用方法
|
6
|
-
|
7
|
-
安装这个 Gem :
|
8
|
-
|
9
|
-
```
|
10
|
-
gem install qqbot
|
11
|
-
```
|
12
|
-
|
13
|
-
`require 'qqbot'`并编写自己的业务逻辑,例如:
|
14
|
-
|
15
|
-
```
|
16
|
-
require 'qqbot'
|
17
|
-
|
18
|
-
qqbot = QQBot.new
|
19
|
-
|
20
|
-
# 在这里需要扫描二维码登录
|
21
|
-
|
22
|
-
# 打印出好友列表
|
23
|
-
qqbot.get_friend_list_with_category.each do |category|
|
24
|
-
puts category.name
|
25
|
-
category.friends.each do |friend|
|
26
|
-
puts "———— #{friend.nickname}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
```
|
30
|
-
|
31
|
-
### 示例代码
|
32
|
-
|
33
|
-
[在控制台打印接收到的所有消息][1]
|
34
|
-
|
35
|
-
效果:
|
36
|
-
|
37
|
-
![Console][2]
|
38
|
-
|
39
|
-
[通过 Tuling123 的 Api 实现自动回复功能][3]
|
40
|
-
|
41
|
-
效果:
|
42
|
-
|
43
|
-
![Tuling][4]
|
44
|
-
|
45
|
-
|
46
|
-
[1]: https://gist.github.com/ScienJus/f1ba1e5b1611cca662cc
|
47
|
-
[2]: http://www.scienjus.com/wp-content/uploads/2015/12/console.png
|
48
|
-
[3]: https://gist.github.com/ScienJus/26a341fda25d009acea1
|
49
|
-
[4]: http://www.scienjus.com/wp-content/uploads/2015/12/tuling.jpg
|
50
|
-
|
51
|
-
### Api 列表
|
52
|
-
|
53
|
-
- [x] 登录
|
54
|
-
- [x] 拉取消息
|
55
|
-
- [x] 获取群列表
|
56
|
-
- [x] 获取好友列表
|
57
|
-
- [x] 获取讨论组列表
|
58
|
-
- [x] 发送私聊消息
|
59
|
-
- [x] 发送群消息
|
60
|
-
- [x] 发送讨论组消息
|
61
|
-
- [x] 发送临时消息
|
62
|
-
- [x] 好友详细信息
|
63
|
-
- [x] 群详细信息
|
64
|
-
- [x] 讨论组详细信息
|
65
|
-
- [x] 获取在线好友
|
66
|
-
- [x] 获取最近会话
|
67
|
-
- [x] 获取登录用户信息
|
68
|
-
- [x] 查询用户 QQ 号
|
69
|
-
- [ ] 退出登录
|
70
|
-
|
71
|
-
|
72
|
-
### 拓展功能列表
|
73
|
-
|
74
|
-
- [x] 登录时保存二维码到本地
|
75
|
-
- [x] 登录时通过网页查看二维码
|
76
|
-
- [ ] 登录时发送二维码到指定邮箱
|
77
|
-
- [ ] 登录时将二维码打印到控制台
|
78
|
-
- [x] 掉线时尝试重新登录
|
79
|
-
- [ ] 登录失效后邮件推送信息
|
80
|
-
|
81
|
-
|
82
|
-
### 反馈
|
83
|
-
|
84
|
-
有问题或是建议可以提 Issues ,或是发邮件联系我,我的邮箱:`i@scienjus.com`
|
1
|
+
# QQBot
|
2
|
+
|
3
|
+
基于 Smart QQ(Web QQ)的 QQ 机器人
|
4
|
+
|
5
|
+
### 使用方法
|
6
|
+
|
7
|
+
安装这个 Gem :
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install qqbot
|
11
|
+
```
|
12
|
+
|
13
|
+
`require 'qqbot'`并编写自己的业务逻辑,例如:
|
14
|
+
|
15
|
+
```
|
16
|
+
require 'qqbot'
|
17
|
+
|
18
|
+
qqbot = QQBot.new
|
19
|
+
|
20
|
+
# 在这里需要扫描二维码登录
|
21
|
+
|
22
|
+
# 打印出好友列表
|
23
|
+
qqbot.get_friend_list_with_category.each do |category|
|
24
|
+
puts category.name
|
25
|
+
category.friends.each do |friend|
|
26
|
+
puts "———— #{friend.nickname}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### 示例代码
|
32
|
+
|
33
|
+
[在控制台打印接收到的所有消息][1]
|
34
|
+
|
35
|
+
效果:
|
36
|
+
|
37
|
+
![Console][2]
|
38
|
+
|
39
|
+
[通过 Tuling123 的 Api 实现自动回复功能][3]
|
40
|
+
|
41
|
+
效果:
|
42
|
+
|
43
|
+
![Tuling][4]
|
44
|
+
|
45
|
+
|
46
|
+
[1]: https://gist.github.com/ScienJus/f1ba1e5b1611cca662cc
|
47
|
+
[2]: http://www.scienjus.com/wp-content/uploads/2015/12/console.png
|
48
|
+
[3]: https://gist.github.com/ScienJus/26a341fda25d009acea1
|
49
|
+
[4]: http://www.scienjus.com/wp-content/uploads/2015/12/tuling.jpg
|
50
|
+
|
51
|
+
### Api 列表
|
52
|
+
|
53
|
+
- [x] 登录
|
54
|
+
- [x] 拉取消息
|
55
|
+
- [x] 获取群列表
|
56
|
+
- [x] 获取好友列表
|
57
|
+
- [x] 获取讨论组列表
|
58
|
+
- [x] 发送私聊消息
|
59
|
+
- [x] 发送群消息
|
60
|
+
- [x] 发送讨论组消息
|
61
|
+
- [x] 发送临时消息
|
62
|
+
- [x] 好友详细信息
|
63
|
+
- [x] 群详细信息
|
64
|
+
- [x] 讨论组详细信息
|
65
|
+
- [x] 获取在线好友
|
66
|
+
- [x] 获取最近会话
|
67
|
+
- [x] 获取登录用户信息
|
68
|
+
- [x] 查询用户 QQ 号
|
69
|
+
- [ ] 退出登录
|
70
|
+
|
71
|
+
|
72
|
+
### 拓展功能列表
|
73
|
+
|
74
|
+
- [x] 登录时保存二维码到本地
|
75
|
+
- [x] 登录时通过网页查看二维码
|
76
|
+
- [ ] 登录时发送二维码到指定邮箱
|
77
|
+
- [ ] 登录时将二维码打印到控制台
|
78
|
+
- [x] 掉线时尝试重新登录
|
79
|
+
- [ ] 登录失效后邮件推送信息
|
80
|
+
|
81
|
+
|
82
|
+
### 反馈
|
83
|
+
|
84
|
+
有问题或是建议可以提 Issues ,或是发邮件联系我,我的邮箱:`i@scienjus.com`
|
data/lib/qqbot.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'qqbot/version'
|
3
|
-
|
4
|
-
module QQBot
|
5
|
-
|
6
|
-
class Logger < Logger
|
7
|
-
|
8
|
-
def info(*args)
|
9
|
-
super && false if info?
|
10
|
-
end
|
11
|
-
|
12
|
-
def debug(*args)
|
13
|
-
super && false if debug?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
LOGGER = QQBot::Logger.new(STDOUT)
|
18
|
-
LOGGER.datetime_format = '%Y-%m-%d %H:%M:%S'
|
19
|
-
LOGGER.level = Logger::INFO
|
20
|
-
|
21
|
-
CLIENT_ID = 53999199
|
22
|
-
|
23
|
-
autoload :Cookie, 'qqbot/cookie'
|
24
|
-
autoload :Client, 'qqbot/client'
|
25
|
-
autoload :Api, 'qqbot/api'
|
26
|
-
autoload :Bot, 'qqbot/bot'
|
27
|
-
autoload :Group, 'qqbot/model'
|
28
|
-
autoload :Friend, 'qqbot/model'
|
29
|
-
autoload :Category, 'qqbot/model'
|
30
|
-
autoload :Discuss, 'qqbot/model'
|
31
|
-
autoload :Message, 'qqbot/model'
|
32
|
-
autoload :Font, 'qqbot/model'
|
33
|
-
autoload :UserInfo, 'qqbot/model'
|
34
|
-
autoload :Birthday, 'qqbot/model'
|
35
|
-
autoload :Recent, 'qqbot/model'
|
36
|
-
autoload :Online, 'qqbot/model'
|
37
|
-
autoload :GroupInfo, 'qqbot/model'
|
38
|
-
autoload :GroupMember, 'qqbot/model'
|
39
|
-
autoload :DiscussInfo, 'qqbot/model'
|
40
|
-
autoload :DiscussMember, 'qqbot/model'
|
41
|
-
autoload :Error, 'qqbot/error'
|
42
|
-
|
43
|
-
def self.new
|
44
|
-
QQBot::Bot.new
|
45
|
-
end
|
46
|
-
end
|
1
|
+
require 'logger'
|
2
|
+
require 'qqbot/version'
|
3
|
+
|
4
|
+
module QQBot
|
5
|
+
|
6
|
+
class Logger < Logger
|
7
|
+
|
8
|
+
def info(*args)
|
9
|
+
super && false if info?
|
10
|
+
end
|
11
|
+
|
12
|
+
def debug(*args)
|
13
|
+
super && false if debug?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
LOGGER = QQBot::Logger.new(STDOUT)
|
18
|
+
LOGGER.datetime_format = '%Y-%m-%d %H:%M:%S'
|
19
|
+
LOGGER.level = Logger::INFO
|
20
|
+
|
21
|
+
CLIENT_ID = 53999199
|
22
|
+
|
23
|
+
autoload :Cookie, 'qqbot/cookie'
|
24
|
+
autoload :Client, 'qqbot/client'
|
25
|
+
autoload :Api, 'qqbot/api'
|
26
|
+
autoload :Bot, 'qqbot/bot'
|
27
|
+
autoload :Group, 'qqbot/model'
|
28
|
+
autoload :Friend, 'qqbot/model'
|
29
|
+
autoload :Category, 'qqbot/model'
|
30
|
+
autoload :Discuss, 'qqbot/model'
|
31
|
+
autoload :Message, 'qqbot/model'
|
32
|
+
autoload :Font, 'qqbot/model'
|
33
|
+
autoload :UserInfo, 'qqbot/model'
|
34
|
+
autoload :Birthday, 'qqbot/model'
|
35
|
+
autoload :Recent, 'qqbot/model'
|
36
|
+
autoload :Online, 'qqbot/model'
|
37
|
+
autoload :GroupInfo, 'qqbot/model'
|
38
|
+
autoload :GroupMember, 'qqbot/model'
|
39
|
+
autoload :DiscussInfo, 'qqbot/model'
|
40
|
+
autoload :DiscussMember, 'qqbot/model'
|
41
|
+
autoload :Error, 'qqbot/error'
|
42
|
+
|
43
|
+
def self.new
|
44
|
+
QQBot::Bot.new
|
45
|
+
end
|
46
|
+
end
|
data/lib/qqbot/api.rb
CHANGED
@@ -1,314 +1,314 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
|
-
module QQBot
|
4
|
-
class Api
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@client = QQBot::Client.new
|
8
|
-
@msg_id = 1_000_000
|
9
|
-
end
|
10
|
-
|
11
|
-
def auth_options=(options = {})
|
12
|
-
@options = options
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_qrcode
|
16
|
-
uri = URI('https://ssl.ptlogin2.qq.com/ptqrshow');
|
17
|
-
uri.query =
|
18
|
-
URI.encode_www_form(
|
19
|
-
appid: 501004106,
|
20
|
-
e: 0,
|
21
|
-
l: :M,
|
22
|
-
s: 5,
|
23
|
-
d: 72,
|
24
|
-
v: 4,
|
25
|
-
t: 0.1,
|
26
|
-
)
|
27
|
-
@client.get(uri)
|
28
|
-
end
|
29
|
-
|
30
|
-
def verify_qrcode
|
31
|
-
uri = URI('https://ssl.ptlogin2.qq.com/ptqrlogin');
|
32
|
-
uri.query =
|
33
|
-
URI.encode_www_form(
|
34
|
-
webqq_type: 10,
|
35
|
-
remember_uin: 1,
|
36
|
-
login2qq: 1,
|
37
|
-
aid: 501004106,
|
38
|
-
u1: 'http://Fw.qq.com/proxy.html?login2qq=1&webqq_type=10',
|
39
|
-
ptredirect: 0,
|
40
|
-
ptlang: 2052,
|
41
|
-
daid: 164,
|
42
|
-
from_ui: 1,
|
43
|
-
pttype: 1,
|
44
|
-
dumy: '',
|
45
|
-
fp: 'loginerroralert',
|
46
|
-
action: '0-0-157510',
|
47
|
-
mibao_css: 'm_webqq',
|
48
|
-
t: 1,
|
49
|
-
g: 1,
|
50
|
-
js_type: 0,
|
51
|
-
js_ver: 10143,
|
52
|
-
login_sig: '',
|
53
|
-
pt_randsalt: 0,
|
54
|
-
)
|
55
|
-
@client.get(uri)
|
56
|
-
end
|
57
|
-
|
58
|
-
def get_ptwebqq(url)
|
59
|
-
uri = URI(url);
|
60
|
-
code, body = @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
61
|
-
return code, @client.get_cookie('ptwebqq')
|
62
|
-
end
|
63
|
-
|
64
|
-
def get_vfwebqq(ptwebqq)
|
65
|
-
uri = URI('http://s.web2.qq.com/api/getvfwebqq');
|
66
|
-
uri.query =
|
67
|
-
URI.encode_www_form(
|
68
|
-
ptwebqq: ptwebqq,
|
69
|
-
clientid: QQBot::CLIENT_ID,
|
70
|
-
psessionid: '',
|
71
|
-
t: 0.1,
|
72
|
-
)
|
73
|
-
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
74
|
-
end
|
75
|
-
|
76
|
-
def get_psessionid_and_uin(ptwebqq)
|
77
|
-
uri = URI('http://d1.web2.qq.com/channel/login2');
|
78
|
-
r = JSON.generate(
|
79
|
-
ptwebqq: ptwebqq,
|
80
|
-
clientid: QQBot::CLIENT_ID,
|
81
|
-
psessionid: '',
|
82
|
-
status: 'online'
|
83
|
-
)
|
84
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.hash(uin, ptwebqq)
|
88
|
-
n = Array.new(4, 0)
|
89
|
-
ptwebqq.chars.each_index { |i| n[i % 4] ^= ptwebqq[i].ord }
|
90
|
-
u = ['EC', 'OK']
|
91
|
-
v = Array.new(4)
|
92
|
-
v[0] = uin >> 24 & 255 ^ u[0][0].ord;
|
93
|
-
v[1] = uin >> 16 & 255 ^ u[0][1].ord;
|
94
|
-
v[2] = uin >> 8 & 255 ^ u[1][0].ord;
|
95
|
-
v[3] = uin & 255 ^ u[1][1].ord;
|
96
|
-
u = Array.new(8)
|
97
|
-
(0...8).each { |i| u[i] = i.odd? ? v[i >> 1] : n[i >> 1] }
|
98
|
-
n = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
|
99
|
-
v = ''
|
100
|
-
u.each do |i|
|
101
|
-
v << n[(i >> 4) & 15]
|
102
|
-
v << n[i & 15]
|
103
|
-
end
|
104
|
-
v
|
105
|
-
end
|
106
|
-
|
107
|
-
def poll
|
108
|
-
uri = URI('http://d1.web2.qq.com/channel/poll2')
|
109
|
-
r = JSON.generate(
|
110
|
-
ptwebqq: @options[:ptwebqq],
|
111
|
-
clientid: QQBot::CLIENT_ID,
|
112
|
-
psessionid: @options[:psessionid],
|
113
|
-
key: ''
|
114
|
-
)
|
115
|
-
begin
|
116
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
117
|
-
rescue
|
118
|
-
retry
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_group_list
|
123
|
-
uri = URI('http://s.web2.qq.com/api/get_group_name_list_mask2')
|
124
|
-
r = JSON.generate(
|
125
|
-
vfwebqq: @options[:vfwebqq],
|
126
|
-
hash: hash
|
127
|
-
)
|
128
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
129
|
-
end
|
130
|
-
|
131
|
-
def hash
|
132
|
-
self.class.hash(@options[:uin], @options[:ptwebqq])
|
133
|
-
end
|
134
|
-
|
135
|
-
def get_friend_list
|
136
|
-
uri = URI('http://s.web2.qq.com/api/get_user_friends2')
|
137
|
-
r = JSON.generate(
|
138
|
-
vfwebqq: @options[:vfwebqq],
|
139
|
-
hash: hash
|
140
|
-
)
|
141
|
-
@client.post(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1', r: r)
|
142
|
-
end
|
143
|
-
|
144
|
-
def get_discuss_list
|
145
|
-
uri = URI('http://s.web2.qq.com/api/get_discus_list')
|
146
|
-
uri.query =
|
147
|
-
URI.encode_www_form(
|
148
|
-
clientid: QQBot::CLIENT_ID,
|
149
|
-
psessionid: @options[:psessionid],
|
150
|
-
vfwebqq: @options[:vfwebqq],
|
151
|
-
t: 0.1
|
152
|
-
)
|
153
|
-
@client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
|
154
|
-
end
|
155
|
-
|
156
|
-
def send_to_friend(friend_id, content)
|
157
|
-
uri = URI('http://d1.web2.qq.com/channel/send_buddy_msg2')
|
158
|
-
r = JSON.generate(
|
159
|
-
to: friend_id,
|
160
|
-
content: self.class.build_message(content),
|
161
|
-
face: 522,
|
162
|
-
clientid: QQBot::CLIENT_ID,
|
163
|
-
msg_id: msg_id,
|
164
|
-
psessionid: @options[:psessionid]
|
165
|
-
)
|
166
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
167
|
-
end
|
168
|
-
|
169
|
-
def send_to_group(group_id, content)
|
170
|
-
uri = URI('http://d1.web2.qq.com/channel/send_qun_msg2')
|
171
|
-
r = JSON.generate(
|
172
|
-
group_uin: group_id,
|
173
|
-
content: self.class.build_message(content),
|
174
|
-
face: 522,
|
175
|
-
clientid: QQBot::CLIENT_ID,
|
176
|
-
msg_id: msg_id,
|
177
|
-
psessionid: @options[:psessionid]
|
178
|
-
)
|
179
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
180
|
-
end
|
181
|
-
|
182
|
-
def send_to_discuss(discuss_id, content)
|
183
|
-
uri = URI('http://d1.web2.qq.com/channel/send_discu_msg2')
|
184
|
-
r = JSON.generate(
|
185
|
-
did: discuss_id,
|
186
|
-
content: self.class.build_message(content),
|
187
|
-
face: 522,
|
188
|
-
clientid: QQBot::CLIENT_ID,
|
189
|
-
msg_id: msg_id,
|
190
|
-
psessionid: @options[:psessionid]
|
191
|
-
)
|
192
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
193
|
-
end
|
194
|
-
|
195
|
-
def send_to_sess(sess_id, content)
|
196
|
-
uri = URI('http://d1.web2.qq.com/channel/send_sess_msg2')
|
197
|
-
r = JSON.generate(
|
198
|
-
to: sess_id,
|
199
|
-
content: self.class.build_message(content),
|
200
|
-
face: 522,
|
201
|
-
clientid: QQBot::CLIENT_ID,
|
202
|
-
msg_id: msg_id,
|
203
|
-
psessionid: @options[:psessionid]
|
204
|
-
)
|
205
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
206
|
-
end
|
207
|
-
|
208
|
-
def get_account_info
|
209
|
-
uri = URI('http://s.web2.qq.com/api/get_self_info2')
|
210
|
-
uri.query =
|
211
|
-
URI.encode_www_form(
|
212
|
-
t: 0.1
|
213
|
-
)
|
214
|
-
|
215
|
-
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
216
|
-
end
|
217
|
-
|
218
|
-
def get_recent_list
|
219
|
-
uri = URI('http://d1.web2.qq.com/channel/get_recent_list2')
|
220
|
-
r = JSON.generate(
|
221
|
-
vfwebqq: @options[:vfwebqq],
|
222
|
-
clientid: QQBot::CLIENT_ID,
|
223
|
-
psessionid: ''
|
224
|
-
)
|
225
|
-
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
226
|
-
end
|
227
|
-
|
228
|
-
def get_qq_by_id(id)
|
229
|
-
uri = URI('http://s.web2.qq.com/api/get_friend_uin2')
|
230
|
-
uri.query =
|
231
|
-
URI.encode_www_form(
|
232
|
-
tuin: id,
|
233
|
-
type: 1,
|
234
|
-
vfwebqq: @options[:vfwebqq],
|
235
|
-
t: 0.1
|
236
|
-
)
|
237
|
-
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
238
|
-
end
|
239
|
-
|
240
|
-
def get_online_friends
|
241
|
-
uri = URI('http://d1.web2.qq.com/channel/get_online_buddies2')
|
242
|
-
uri.query =
|
243
|
-
URI.encode_www_form(
|
244
|
-
vfwebqq: @options[:vfwebqq],
|
245
|
-
clientid: QQBot::CLIENT_ID,
|
246
|
-
psessionid: @options[:psessionid],
|
247
|
-
t: 0.1
|
248
|
-
)
|
249
|
-
@client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
|
250
|
-
end
|
251
|
-
|
252
|
-
def get_group_info(group_code)
|
253
|
-
uri = URI('http://s.web2.qq.com/api/get_group_info_ext2')
|
254
|
-
uri.query =
|
255
|
-
URI.encode_www_form(
|
256
|
-
gcode: group_code,
|
257
|
-
vfwebqq: @options[:vfwebqq],
|
258
|
-
t: 0.1
|
259
|
-
)
|
260
|
-
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
261
|
-
end
|
262
|
-
|
263
|
-
def get_discuss_info(discuss_id)
|
264
|
-
uri = URI('http://d1.web2.qq.com/channel/get_discu_info')
|
265
|
-
uri.query =
|
266
|
-
URI.encode_www_form(
|
267
|
-
did: discuss_id,
|
268
|
-
vfwebqq: @options[:vfwebqq],
|
269
|
-
clientid: QQBot::CLIENT_ID,
|
270
|
-
psessionid: @options[:psessionid],
|
271
|
-
t: 0.1
|
272
|
-
)
|
273
|
-
@client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
|
274
|
-
end
|
275
|
-
|
276
|
-
def get_friend_info(friend_id)
|
277
|
-
uri = URI('http://s.web2.qq.com/api/get_friend_info2')
|
278
|
-
uri.query =
|
279
|
-
URI.encode_www_form(
|
280
|
-
tuin: friend_id,
|
281
|
-
vfwebqq: @options[:vfwebqq],
|
282
|
-
clientid: QQBot::CLIENT_ID,
|
283
|
-
psessionid: @options[:psessionid],
|
284
|
-
t: 0.1
|
285
|
-
)
|
286
|
-
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
287
|
-
end
|
288
|
-
|
289
|
-
def hash
|
290
|
-
self.class.hash(@options[:uin], @options[:ptwebqq])
|
291
|
-
end
|
292
|
-
|
293
|
-
def msg_id
|
294
|
-
@msg_id += 1
|
295
|
-
end
|
296
|
-
|
297
|
-
def self.build_message(content)
|
298
|
-
JSON.generate(
|
299
|
-
[
|
300
|
-
content.force_encoding("UTF-8"),
|
301
|
-
[
|
302
|
-
'font',
|
303
|
-
{
|
304
|
-
name: '宋体',
|
305
|
-
size: 10,
|
306
|
-
style: [0, 0, 0],
|
307
|
-
color: '000000'
|
308
|
-
}
|
309
|
-
]
|
310
|
-
]
|
311
|
-
)
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module QQBot
|
4
|
+
class Api
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@client = QQBot::Client.new
|
8
|
+
@msg_id = 1_000_000
|
9
|
+
end
|
10
|
+
|
11
|
+
def auth_options=(options = {})
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_qrcode
|
16
|
+
uri = URI('https://ssl.ptlogin2.qq.com/ptqrshow');
|
17
|
+
uri.query =
|
18
|
+
URI.encode_www_form(
|
19
|
+
appid: 501004106,
|
20
|
+
e: 0,
|
21
|
+
l: :M,
|
22
|
+
s: 5,
|
23
|
+
d: 72,
|
24
|
+
v: 4,
|
25
|
+
t: 0.1,
|
26
|
+
)
|
27
|
+
@client.get(uri)
|
28
|
+
end
|
29
|
+
|
30
|
+
def verify_qrcode
|
31
|
+
uri = URI('https://ssl.ptlogin2.qq.com/ptqrlogin');
|
32
|
+
uri.query =
|
33
|
+
URI.encode_www_form(
|
34
|
+
webqq_type: 10,
|
35
|
+
remember_uin: 1,
|
36
|
+
login2qq: 1,
|
37
|
+
aid: 501004106,
|
38
|
+
u1: 'http://Fw.qq.com/proxy.html?login2qq=1&webqq_type=10',
|
39
|
+
ptredirect: 0,
|
40
|
+
ptlang: 2052,
|
41
|
+
daid: 164,
|
42
|
+
from_ui: 1,
|
43
|
+
pttype: 1,
|
44
|
+
dumy: '',
|
45
|
+
fp: 'loginerroralert',
|
46
|
+
action: '0-0-157510',
|
47
|
+
mibao_css: 'm_webqq',
|
48
|
+
t: 1,
|
49
|
+
g: 1,
|
50
|
+
js_type: 0,
|
51
|
+
js_ver: 10143,
|
52
|
+
login_sig: '',
|
53
|
+
pt_randsalt: 0,
|
54
|
+
)
|
55
|
+
@client.get(uri)
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_ptwebqq(url)
|
59
|
+
uri = URI(url);
|
60
|
+
code, body = @client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
61
|
+
return code, @client.get_cookie('ptwebqq')
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_vfwebqq(ptwebqq)
|
65
|
+
uri = URI('http://s.web2.qq.com/api/getvfwebqq');
|
66
|
+
uri.query =
|
67
|
+
URI.encode_www_form(
|
68
|
+
ptwebqq: ptwebqq,
|
69
|
+
clientid: QQBot::CLIENT_ID,
|
70
|
+
psessionid: '',
|
71
|
+
t: 0.1,
|
72
|
+
)
|
73
|
+
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_psessionid_and_uin(ptwebqq)
|
77
|
+
uri = URI('http://d1.web2.qq.com/channel/login2');
|
78
|
+
r = JSON.generate(
|
79
|
+
ptwebqq: ptwebqq,
|
80
|
+
clientid: QQBot::CLIENT_ID,
|
81
|
+
psessionid: '',
|
82
|
+
status: 'online'
|
83
|
+
)
|
84
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.hash(uin, ptwebqq)
|
88
|
+
n = Array.new(4, 0)
|
89
|
+
ptwebqq.chars.each_index { |i| n[i % 4] ^= ptwebqq[i].ord }
|
90
|
+
u = ['EC', 'OK']
|
91
|
+
v = Array.new(4)
|
92
|
+
v[0] = uin >> 24 & 255 ^ u[0][0].ord;
|
93
|
+
v[1] = uin >> 16 & 255 ^ u[0][1].ord;
|
94
|
+
v[2] = uin >> 8 & 255 ^ u[1][0].ord;
|
95
|
+
v[3] = uin & 255 ^ u[1][1].ord;
|
96
|
+
u = Array.new(8)
|
97
|
+
(0...8).each { |i| u[i] = i.odd? ? v[i >> 1] : n[i >> 1] }
|
98
|
+
n = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
|
99
|
+
v = ''
|
100
|
+
u.each do |i|
|
101
|
+
v << n[(i >> 4) & 15]
|
102
|
+
v << n[i & 15]
|
103
|
+
end
|
104
|
+
v
|
105
|
+
end
|
106
|
+
|
107
|
+
def poll
|
108
|
+
uri = URI('http://d1.web2.qq.com/channel/poll2')
|
109
|
+
r = JSON.generate(
|
110
|
+
ptwebqq: @options[:ptwebqq],
|
111
|
+
clientid: QQBot::CLIENT_ID,
|
112
|
+
psessionid: @options[:psessionid],
|
113
|
+
key: ''
|
114
|
+
)
|
115
|
+
begin
|
116
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
117
|
+
rescue
|
118
|
+
retry
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_group_list
|
123
|
+
uri = URI('http://s.web2.qq.com/api/get_group_name_list_mask2')
|
124
|
+
r = JSON.generate(
|
125
|
+
vfwebqq: @options[:vfwebqq],
|
126
|
+
hash: hash
|
127
|
+
)
|
128
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
129
|
+
end
|
130
|
+
|
131
|
+
def hash
|
132
|
+
self.class.hash(@options[:uin], @options[:ptwebqq])
|
133
|
+
end
|
134
|
+
|
135
|
+
def get_friend_list
|
136
|
+
uri = URI('http://s.web2.qq.com/api/get_user_friends2')
|
137
|
+
r = JSON.generate(
|
138
|
+
vfwebqq: @options[:vfwebqq],
|
139
|
+
hash: hash
|
140
|
+
)
|
141
|
+
@client.post(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1', r: r)
|
142
|
+
end
|
143
|
+
|
144
|
+
def get_discuss_list
|
145
|
+
uri = URI('http://s.web2.qq.com/api/get_discus_list')
|
146
|
+
uri.query =
|
147
|
+
URI.encode_www_form(
|
148
|
+
clientid: QQBot::CLIENT_ID,
|
149
|
+
psessionid: @options[:psessionid],
|
150
|
+
vfwebqq: @options[:vfwebqq],
|
151
|
+
t: 0.1
|
152
|
+
)
|
153
|
+
@client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
|
154
|
+
end
|
155
|
+
|
156
|
+
def send_to_friend(friend_id, content)
|
157
|
+
uri = URI('http://d1.web2.qq.com/channel/send_buddy_msg2')
|
158
|
+
r = JSON.generate(
|
159
|
+
to: friend_id,
|
160
|
+
content: self.class.build_message(content),
|
161
|
+
face: 522,
|
162
|
+
clientid: QQBot::CLIENT_ID,
|
163
|
+
msg_id: msg_id,
|
164
|
+
psessionid: @options[:psessionid]
|
165
|
+
)
|
166
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
167
|
+
end
|
168
|
+
|
169
|
+
def send_to_group(group_id, content)
|
170
|
+
uri = URI('http://d1.web2.qq.com/channel/send_qun_msg2')
|
171
|
+
r = JSON.generate(
|
172
|
+
group_uin: group_id,
|
173
|
+
content: self.class.build_message(content),
|
174
|
+
face: 522,
|
175
|
+
clientid: QQBot::CLIENT_ID,
|
176
|
+
msg_id: msg_id,
|
177
|
+
psessionid: @options[:psessionid]
|
178
|
+
)
|
179
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
180
|
+
end
|
181
|
+
|
182
|
+
def send_to_discuss(discuss_id, content)
|
183
|
+
uri = URI('http://d1.web2.qq.com/channel/send_discu_msg2')
|
184
|
+
r = JSON.generate(
|
185
|
+
did: discuss_id,
|
186
|
+
content: self.class.build_message(content),
|
187
|
+
face: 522,
|
188
|
+
clientid: QQBot::CLIENT_ID,
|
189
|
+
msg_id: msg_id,
|
190
|
+
psessionid: @options[:psessionid]
|
191
|
+
)
|
192
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
193
|
+
end
|
194
|
+
|
195
|
+
def send_to_sess(sess_id, content)
|
196
|
+
uri = URI('http://d1.web2.qq.com/channel/send_sess_msg2')
|
197
|
+
r = JSON.generate(
|
198
|
+
to: sess_id,
|
199
|
+
content: self.class.build_message(content),
|
200
|
+
face: 522,
|
201
|
+
clientid: QQBot::CLIENT_ID,
|
202
|
+
msg_id: msg_id,
|
203
|
+
psessionid: @options[:psessionid]
|
204
|
+
)
|
205
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
206
|
+
end
|
207
|
+
|
208
|
+
def get_account_info
|
209
|
+
uri = URI('http://s.web2.qq.com/api/get_self_info2')
|
210
|
+
uri.query =
|
211
|
+
URI.encode_www_form(
|
212
|
+
t: 0.1
|
213
|
+
)
|
214
|
+
|
215
|
+
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
216
|
+
end
|
217
|
+
|
218
|
+
def get_recent_list
|
219
|
+
uri = URI('http://d1.web2.qq.com/channel/get_recent_list2')
|
220
|
+
r = JSON.generate(
|
221
|
+
vfwebqq: @options[:vfwebqq],
|
222
|
+
clientid: QQBot::CLIENT_ID,
|
223
|
+
psessionid: ''
|
224
|
+
)
|
225
|
+
@client.post(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2', r: r)
|
226
|
+
end
|
227
|
+
|
228
|
+
def get_qq_by_id(id)
|
229
|
+
uri = URI('http://s.web2.qq.com/api/get_friend_uin2')
|
230
|
+
uri.query =
|
231
|
+
URI.encode_www_form(
|
232
|
+
tuin: id,
|
233
|
+
type: 1,
|
234
|
+
vfwebqq: @options[:vfwebqq],
|
235
|
+
t: 0.1
|
236
|
+
)
|
237
|
+
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
238
|
+
end
|
239
|
+
|
240
|
+
def get_online_friends
|
241
|
+
uri = URI('http://d1.web2.qq.com/channel/get_online_buddies2')
|
242
|
+
uri.query =
|
243
|
+
URI.encode_www_form(
|
244
|
+
vfwebqq: @options[:vfwebqq],
|
245
|
+
clientid: QQBot::CLIENT_ID,
|
246
|
+
psessionid: @options[:psessionid],
|
247
|
+
t: 0.1
|
248
|
+
)
|
249
|
+
@client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
|
250
|
+
end
|
251
|
+
|
252
|
+
def get_group_info(group_code)
|
253
|
+
uri = URI('http://s.web2.qq.com/api/get_group_info_ext2')
|
254
|
+
uri.query =
|
255
|
+
URI.encode_www_form(
|
256
|
+
gcode: group_code,
|
257
|
+
vfwebqq: @options[:vfwebqq],
|
258
|
+
t: 0.1
|
259
|
+
)
|
260
|
+
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
261
|
+
end
|
262
|
+
|
263
|
+
def get_discuss_info(discuss_id)
|
264
|
+
uri = URI('http://d1.web2.qq.com/channel/get_discu_info')
|
265
|
+
uri.query =
|
266
|
+
URI.encode_www_form(
|
267
|
+
did: discuss_id,
|
268
|
+
vfwebqq: @options[:vfwebqq],
|
269
|
+
clientid: QQBot::CLIENT_ID,
|
270
|
+
psessionid: @options[:psessionid],
|
271
|
+
t: 0.1
|
272
|
+
)
|
273
|
+
@client.get(uri, 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2')
|
274
|
+
end
|
275
|
+
|
276
|
+
def get_friend_info(friend_id)
|
277
|
+
uri = URI('http://s.web2.qq.com/api/get_friend_info2')
|
278
|
+
uri.query =
|
279
|
+
URI.encode_www_form(
|
280
|
+
tuin: friend_id,
|
281
|
+
vfwebqq: @options[:vfwebqq],
|
282
|
+
clientid: QQBot::CLIENT_ID,
|
283
|
+
psessionid: @options[:psessionid],
|
284
|
+
t: 0.1
|
285
|
+
)
|
286
|
+
@client.get(uri, 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
|
287
|
+
end
|
288
|
+
|
289
|
+
def hash
|
290
|
+
self.class.hash(@options[:uin], @options[:ptwebqq])
|
291
|
+
end
|
292
|
+
|
293
|
+
def msg_id
|
294
|
+
@msg_id += 1
|
295
|
+
end
|
296
|
+
|
297
|
+
def self.build_message(content)
|
298
|
+
JSON.generate(
|
299
|
+
[
|
300
|
+
content.force_encoding("UTF-8"),
|
301
|
+
[
|
302
|
+
'font',
|
303
|
+
{
|
304
|
+
name: '宋体',
|
305
|
+
size: 10,
|
306
|
+
style: [0, 0, 0],
|
307
|
+
color: '000000'
|
308
|
+
}
|
309
|
+
]
|
310
|
+
]
|
311
|
+
)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|