File Coverage

blib/lib/Webqq/Message.pm
Criterion Covered Total %
statement 18 374 4.8
branch 0 164 0.0
condition 0 36 0.0
subroutine 6 61 9.8
pod 0 8 0.0
total 24 643 3.7


line stmt bran cond sub pod time code
1             package Webqq::Message;
2 1     1   391 use Webqq::Message::Face;
  1         2  
  1         42  
3 1     1   5 use JSON;
  1         0  
  1         8  
4 1     1   110 use Encode;
  1         1  
  1         64  
5 1     1   380 use Webqq::Client::Util qw(console code2client);
  1         3  
  1         85  
6 1     1   9 use Scalar::Util qw(blessed);
  1         6  
  1         2861  
7             sub reply_message{
8 0     0 0   my $client = shift;
9 0           my $msg = shift;
10 0           my $content = shift;
11 0 0         unless(blessed($msg)){
12 0           console "输入的msg数据非法\n";
13 0           return 0;
14             }
15 0 0         if($msg->{type} eq 'message'){
    0          
    0          
    0          
16 0           $client->send_message(
17             $client->create_msg(to_uin=>$msg->{from_uin},content=>$content)
18             );
19             }
20             elsif($msg->{type} eq 'group_message'){
21 0           $client->send_group_message(
22             $client->create_group_msg(
23             to_uin=>$msg->{from_uin},
24             content=>$content,
25             group_code=>$msg->{group_code}
26             )
27             );
28             }
29             elsif($msg->{type} eq 'discuss_message'){
30 0   0       $client->send_discuss_message(
31             $client->create_discuss_msg(
32             to_uin =>$msg->{did} || $msg->{from_uin},
33             content =>$content,
34             )
35             );
36             }
37             elsif($msg->{type} eq 'sess_message'){
38             #群临时消息
39 0 0         if($msg->{via} eq 'group'){
    0          
40 0           $client->send_sess_message(
41             $client->create_sess_msg(
42             to_uin => $msg->{from_uin},
43             content => $content,
44             group_code => $msg->{group_code},
45             gid => $msg->{gid},
46             )
47             );
48             }
49             #讨论组临时消息
50             elsif($msg->{via} eq 'discuss'){
51 0           $client->send_sess_message(
52             $client->create_sess_msg(
53             to_uin => $msg->{from_uin},
54             content => $content,
55             did => $msg->{did},
56             )
57             );
58             }
59             }
60            
61             }
62             sub create_sess_msg{
63 0     0 0   my $client = shift;
64 0           return $client->_create_msg(@_,type=>'sess_message');
65             }
66             sub create_group_msg{
67 0     0 0   my $client = shift;
68 0           return $client->_create_msg(@_,type=>'group_message');
69             }
70             sub create_msg{
71 0     0 0   my $client = shift;
72 0           return $client->_create_msg(@_,type=>'message');
73             }
74             sub create_discuss_msg{
75 0     0 0   my $client = shift;
76 0           return $client->_create_msg(@_,type=>'discuss_message');
77             }
78             sub _create_msg {
79 0     0     my $client = shift;
80 0           my %p = @_;
81 0           $p{content} =~s/\r|\n/\n/g;
82 0   0       my %msg = (
      0        
83             type => $p{type},
84             msg_id => $p{msg_id} || ++$client->{qq_param}{send_msg_id},
85             from_uin => $p{from_uin} || $client->{qq_param}{from_uin},
86             to_uin => $p{to_uin},
87             content => $p{content},
88             msg_class => "send",
89             msg_time => time,
90             cb => $p{cb},
91             ttl => 5,
92             allow_plugin => 1,
93             client => $client,
94             );
95 0 0         if($p{type} eq 'sess_message'){
    0          
    0          
96 0 0         if(defined $p{group_code}){
    0          
    0          
97 0           $msg{group_code} = $p{group_code};
98 0           $msg{service_type} = 0;
99 0           $msg{via} = 'group';
100 0 0         my $id = defined $p{gid}?$p{gid}:$client->search_group($p{group_code})->{gid};
101 0           $msg{group_sig} = $client->_get_group_sig($id,$p{to_uin},$msg{service_type});
102             }
103             elsif(defined $p{gid}){
104 0           $msg{group_code} = $client->get_group_code_from_gid($p{gid});
105 0           $msg{service_type} = 0;
106 0           $msg{via} = 'group';
107 0           my $id = $p{gid};
108 0           $msg{group_sig} = $client->_get_group_sig($id,$p{to_uin},$msg{service_type});
109             }
110             elsif(defined $p{did}){
111 0           $msg{did} = $p{did};
112 0           $msg{service_type} = 1;
113 0           $msg{via} = 'discuss';
114 0           $msg{group_sig} = $client->_get_group_sig($p{did},$p{to_uin},$msg{service_type});
115             }
116             else{
117 0           console "create_sess_msg()必须设置group_code或者did\n";
118 0           return ;
119             }
120             }
121             elsif($p{type} eq 'group_message'){
122 0   0       $msg{group_code} = $p{group_code}||$client->get_group_code_from_gid($p{to_uin});
123 0           $msg{send_uin} = $msg{from_uin};
124             }
125             elsif($p{type} eq 'discuss_message'){
126 0   0       $msg{did} = $p{did} || $p{to_uin};
127 0           $msg{send_uin} = $msg{from_uin};
128             }
129 0           my $msg_pkg = "\u$p{type}::Send";
130 0           $msg_pkg=~s/_(.)/\u$1/g;
131 0           return $client->_mk_ro_accessors(\%msg,$msg_pkg);
132            
133             }
134              
135             sub _load_extra_accessor {
136             *Webqq::Message::DiscussMessage::Recv::discuss_name = sub{
137 0     0     my $msg = shift;
138 0           my $client = $msg->{client};
139 0           my $d = $client->search_discuss($msg->{did});
140 0 0         return defined $d?$d->{name}:undef ;
141 0     0     };
142             *Webqq::Message::DiscussMessage::Recv::from_dname = sub{
143 0     0     my $msg = shift;
144 0           my $client = $msg->{client};
145 0           my $d = $client->search_discuss($msg->{did});
146 0 0         return defined $d?$d->{name}:undef ;
147 0           };
148             *Webqq::Message::DiscussMessage::Recv::from_qq = sub{
149 0     0     my $msg = shift;
150 0           my $client = $msg->{client};
151 0           my $m = $client->search_member_in_discuss($msg->{did},$msg->{send_uin});
152 0 0         return defined $m?$m->{ruin}:$client->get_qq_from_uin($msg->{send_uin});
153 0           };
154             *Webqq::Message::DiscussMessage::Recv::from_nick = sub{
155 0     0     my $msg = shift;
156 0           my $client = $msg->{client};
157 0           my $m = $client->search_member_in_discuss($msg->{did},$msg->{send_uin});
158 0 0         return defined $m?$m->{nick}:undef;
159 0           };
160            
161             *Webqq::Message::DiscussMessage::Send::discuss_name = sub{
162 0     0     my $msg = shift;
163 0           my $client = $msg->{client};
164 0           my $d = $client->search_discuss($msg->{did});
165 0 0         return defined $d?$d->{name}:undef;
166 0           };
167             *Webqq::Message::DiscussMessage::Send::to_dname = sub{
168 0     0     my $msg = shift;
169 0           my $client = $msg->{client};
170 0           my $d = $client->search_discuss($msg->{did});
171 0 0         return defined $d?$d->{name}:undef;
172 0           };
173             *Webqq::Message::DiscussMessage::Send::from_qq = sub{
174 0     0     my $msg = shift;
175 0           my $client = $msg->{client};
176 0           return $client->{qq_param}{qq};
177 0           };
178             *Webqq::Message::DiscussMessage::Send::from_nick = sub{
179 0     0     return "我";
180 0           };
181              
182             *Webqq::Message::GroupMessage::Recv::group_name = sub{
183 0     0     my $msg = shift;
184 0           my $client = $msg->{client};
185 0           my $g = $client->search_group($msg->{group_code});
186 0 0         return defined $g?$g->{name}:undef ;
187 0           };
188             *Webqq::Message::GroupMessage::Recv::from_gname = sub{
189 0     0     my $msg = shift;
190 0           my $client = $msg->{client};
191 0           my $g = $client->search_group($msg->{group_code});
192 0 0         return defined $g?$g->{name}:undef ;
193 0           };
194             *Webqq::Message::GroupMessage::Recv::from_qq = sub{
195 0     0     my $msg = shift;
196 0           my $client = $msg->{client};
197 0           return $client->get_qq_from_uin($msg->{send_uin});
198 0           };
199             *Webqq::Message::GroupMessage::Recv::from_nick = sub{
200 0     0     my $msg = shift;
201 0           my $client = $msg->{client};
202 0           my $m = $client->search_member_in_group($msg->{group_code},$msg->{send_uin});
203 0 0         return defined $m?$m->{nick}:undef;
204 0           };
205             *Webqq::Message::GroupMessage::Recv::from_card = sub{
206 0     0     my $msg = shift;
207 0           my $client = $msg->{client};
208 0           my $m = $client->search_member_in_group($msg->{group_code},$msg->{send_uin});
209 0 0         return defined $m?$m->{card}:undef;
210 0           };
211             *Webqq::Message::GroupMessage::Recv::from_city = sub{
212 0     0     my $msg = shift;
213 0           my $client = $msg->{client};
214 0           my $m = $client->search_member_in_group($msg->{group_code},$msg->{send_uin});
215 0 0         return defined $m?$m->{city}:undef;
216 0           };
217              
218             *Webqq::Message::GroupMessage::Send::group_name = sub{
219 0     0     my $msg = shift;
220 0           my $client = $msg->{client};
221 0           my $g = $client->search_group($msg->{group_code});
222 0 0         return defined $g?$g->{name}:undef;
223 0           };
224             *Webqq::Message::GroupMessage::Send::to_gname = sub{
225 0     0     my $msg = shift;
226 0           my $client = $msg->{client};
227 0           my $g = $client->search_group($msg->{group_code});
228 0 0         return defined $g?$g->{name}:undef;
229 0           };
230             *Webqq::Message::GroupMessage::Send::from_qq = sub{
231 0     0     my $msg = shift;
232 0           my $client = $msg->{client};
233 0           return $client->{qq_param}{qq};
234 0           };
235             *Webqq::Message::GroupMessage::Send::from_nick = sub{
236 0     0     return "我";
237 0           };
238              
239              
240             *Webqq::Message::SessMessage::Recv::from_nick = sub{
241 0     0     my $msg = shift;
242 0           my $client = $msg->{client};
243 0 0         if($msg->{via} eq 'group'){
    0          
244 0           my $m = $client->search_member_in_group($msg->{group_code},$msg->{from_uin});
245 0 0         return defined $m?$m->{nick}:undef;
246             }
247 0           elsif($msg->{via} eq 'discuss'){
248 0           my $m = $client->search_member_in_discuss($msg->{did},$msg->{from_uin});
249 0 0         return defined $m?$m->{nick}:undef;
250             }
251             else{return undef}
252 0           };
253             *Webqq::Message::SessMessage::Recv::from_qq = sub {
254 0     0     my $msg = shift;
255 0           my $client = $msg->{client};
256 0           return $msg->{ruin};
257 0           };
258             *Webqq::Message::SessMessage::Recv::to_nick = sub{
259 0     0     return "我";
260 0           };
261             *Webqq::Message::SessMessage::Recv::to_qq = sub {
262 0     0     my $msg = shift;
263 0           my $client = $msg->{client};
264 0           return $client->{qq_param}{qq};
265 0           };
266              
267             *Webqq::Message::SessMessage::Recv::via_type = sub {
268 0     0     my $msg = shift;
269 0           my $client = $msg->{client};
270 0 0         return $msg->{via} eq 'group' ? "群"
    0          
271             : $msg->{via} eq 'discuss' ? "讨论组"
272             : undef
273             ;
274 0           };
275             *Webqq::Message::SessMessage::Recv::via_name = sub {
276 0     0     my $msg = shift;
277 0           my $client = $msg->{client};
278 0 0         if($msg->{via} eq 'group'){
    0          
279 0           my $g = $client->search_group($msg->{group_code});
280 0 0         return defined $g?$g->{name}:undef;
281             }
282 0           elsif($msg->{via} eq 'discuss'){
283 0           my $d = $client->search_discuss($msg->{did});
284 0 0         return defined $d?$d->{name}:undef;
285             }
286             else{return }
287 0           };
288              
289              
290             *Webqq::Message::SessMessage::Send::from_nick = sub{
291 0     0     return "我";
292 0           };
293             *Webqq::Message::SessMessage::Send::from_qq = sub {
294 0     0     my $msg = shift;
295 0           my $client = $msg->{client};
296 0           return $client->{qq_param}{qq};
297 0           };
298             *Webqq::Message::SessMessage::Send::to_nick = sub{
299 0     0     my $msg = shift;
300 0           my $client = $msg->{client};
301 0 0         if($msg->{via} eq 'group'){
    0          
302 0           my $m = $client->search_member_in_group($msg->{group_code},$msg->{to_uin});
303 0 0         return defined $m?$m->{nick}:undef;
304             }
305 0           elsif($msg->{via} eq 'discuss'){
306 0           my $m = $client->search_member_in_discuss($msg->{did},$msg->{to_uin});
307 0 0         return defined $m?$m->{nick}:undef;
308             }
309             else{return }
310 0           };
311             *Webqq::Message::SessMessage::Send::to_qq = sub{
312 0     0     my $msg = shift;
313 0           my $client = $msg->{client};
314 0           return $client->get_qq_from_uin($msg->{to_uin});
315 0           };
316             *Webqq::Message::SessMessage::Send::via_name = sub{
317 0     0     my $msg = shift;
318 0           my $client = $msg->{client};
319 0 0         if($msg->{via} eq 'group'){
    0          
320 0           my $g = $client->search_group($msg->{group_code});
321 0 0         return defined $g?$g->{name}:undef;
322             }
323 0           elsif($msg->{via} eq 'discuss'){
324 0           my $d = $client->search_discuss($msg->{did});
325 0 0         return defined $d?$d->{name}:undef;
326             }
327             else{return}
328 0           };
329              
330             *Webqq::Message::SessMessage::Send::via_type = sub {
331 0     0     my $msg = shift;
332 0           my $client = $msg->{client};
333 0 0         return $msg->{via} eq 'group' ? "群"
    0          
334             : $msg->{via} eq 'discuss' ? "讨论组"
335             : undef
336             ;
337 0           };
338             *Webqq::Message::Message::Recv::from_nick = sub{
339 0     0     my $msg = shift;
340 0           my $client = $msg->{client};
341 0           my $f = $client->search_friend($msg->{from_uin});
342 0 0         return defined $f?$f->{nick}:undef;
343 0           };
344             *Webqq::Message::Message::Recv::from_qq = sub{
345 0     0     my $msg = shift;
346 0           my $client = $msg->{client};
347 0           return $client->get_qq_from_uin($msg->{from_uin});
348 0           };
349             *Webqq::Message::Message::Recv::from_markname = sub{
350 0     0     my $msg = shift;
351 0           my $client = $msg->{client};
352 0           my $f = $client->search_friend($msg->{from_uin});
353 0 0         return defined $f?$f->{markname}:undef;
354 0           };
355             *Webqq::Message::Message::Recv::from_categories = sub {
356 0     0     my $msg = shift;
357 0           my $client = $msg->{client};
358 0           my $f = $client->search_friend($msg->{from_uin});
359 0 0         return defined $f?$f->{categories}:undef;
360 0           };
361              
362             *Webqq::Message::Message::Recv::from_city = sub {
363 0     0     my $msg = shift;
364 0           my $client = $msg->{client};
365 0           my $f = $client->search_friend($msg->{from_uin});
366 0 0         return defined $f?$f->{city}:undef;
367 0           };
368            
369             *Webqq::Message::Message::Recv::to_nick = sub{
370 0     0     return "我";
371 0           };
372             *Webqq::Message::Message::Recv::to_qq = sub {
373 0     0     my $msg = shift;
374 0           my $client = $msg->{client};
375 0           return $client->{qq_param}{qq};
376 0           };
377              
378              
379             *Webqq::Message::Message::Send::from_nick = sub{
380 0     0     return "我";
381 0           };
382             *Webqq::Message::Message::Send::from_qq = sub{
383 0     0     my $msg = shift;
384 0           my $client = $msg->{client};
385 0           return $client->{qq_param}{qq};
386 0           };
387             *Webqq::Message::Message::Send::to_nick = sub{
388 0     0     my $msg = shift;
389 0           my $client = $msg->{client};
390 0           my $f = $client->search_friend($msg->{to_uin});
391 0 0         return defined $f?$f->{nick}:undef;
392 0           };
393             *Webqq::Message::Message::Send::to_qq = sub{
394 0     0     my $msg = shift;
395 0           my $client = $msg->{client};
396 0           return $client->get_qq_from_uin($msg->{to_uin});
397 0           };
398             *Webqq::Message::Message::Send::to_markname = sub{
399 0     0     my $msg = shift;
400 0           my $client = $msg->{client};
401 0           my $f = $client->search_friend($msg->{to_uin});
402 0 0         return defined $f?$f->{markname}:undef;
403 0           };
404             *Webqq::Message::Message::Send::to_categories = sub{
405 0     0     my $msg = shift;
406 0           my $client = $msg->{client};
407 0           my $f = $client->search_friend($msg->{to_uin});
408 0 0         return defined $f?$f->{categories}:undef;
409 0           };
410              
411             }
412              
413             sub _mk_ro_accessors {
414 0     0     my $client = shift;
415 0           my $msg =shift;
416 0           my $msg_pkg = shift;
417 1     1   16 no strict 'refs';
  1         2  
  1         1213  
418 0           for my $field (keys %$msg){
419 0           *{"Webqq::Message::${msg_pkg}::$field"} = sub{
420 0     0     my $self = shift;
421 0           my $pkg = ref $self;
422 0 0         die "the value of \"$field\" in $pkg is read-only\n" if @_!=0;
423 0           return $self->{$field};
424 0           };
425             }
426            
427 0           $msg = bless $msg,"Webqq::Message::$msg_pkg";
428 0           return $msg;
429             }
430              
431             sub parse_send_status_msg{
432 0     0 0   my $client = shift;
433 0           my ($json_txt) = @_;
434 0           my $json = undef;
435 0           eval{$json = JSON->new->utf8->decode($json_txt)};
  0            
436 0 0 0       console "解析消息失败: $@ 对应的消息内容为: $json_txt\n" if $@ and $client->{debug};
437 0 0 0       if(ref $json eq 'HASH' and $json->{retcode}==0){
438 0           return {is_success=>1,status=>"发送成功"};
439             }
440             else{
441 0           return {is_success=>0,status=>"发送失败"};
442             }
443             }
444             #消息的后期处理
445             sub msg_put{
446 0     0 0   my $client = shift;
447 0           my $msg = shift;
448 0           $msg->{raw_content} = [];
449 0           my $msg_content;
450 0           shift @{ $msg->{content} };
  0            
451 0           for my $c (@{ $msg->{content} }){
  0            
452 0 0         if(ref $c eq 'ARRAY'){
    0          
453 0 0         if($c->[0] eq 'cface'){
    0          
    0          
454 0           push @{$msg->{raw_content}},{
  0            
455             type => 'cface',
456             content => '[图片]',
457             name => $c->[1]{name},
458             file_id => $c->[1]{file_id},
459             key => $c->[1]{key},
460             server => $c->[1]{server},
461             };
462 0           $c="[图片]";
463             }
464             elsif($c->[0] eq 'offpic'){
465 0           push @{$msg->{raw_content}},{
  0            
466             type => 'offpic',
467             content => '[图片]',
468             file_path => $c->[1]{file_path},
469             };
470 0           $c="[图片]";
471             }
472             elsif($c->[0] eq 'face'){
473 0           push @{$msg->{raw_content}},{
  0            
474             type => 'face',
475             content => face_to_txt($c),
476             id => $c->[1],
477             };
478 0           $c=face_to_txt($c);
479             }
480             else{
481 0           push @{$msg->{raw_content}},{
  0            
482             type => 'unknown',
483             content => '[未识别内容]',
484             };
485 0           $c = "[未识别内容]";
486             }
487             }
488             elsif($c eq " "){
489 0           next;
490             }
491             else{
492 0           $c=encode("utf8",$c);
493 0           $c=~s/ $//;
494 0           $c=~s/\r|\n/\n/g;
495             #{"retcode":0,"result":[{"poll_type":"group_message","value":{"msg_id":538,"from_uin":2859929324,"to_uin":3072574066,"msg_id2":545490,"msg_type":43,"reply_ip":182424361,"group_code":2904892801,"send_uin":1951767953,"seq":3024,"time":1418955773,"info_seq":390179723,"content":[["font",{"size":12,"color":"000000","style":[0,0,0],"name":"\u5FAE\u8F6F\u96C5\u9ED1"}],"[\u50BB\u7B11]\u0001 "]}}]}
496             #if($c=~/\[[^\[\]]+?\]\x{01}/)
497 0           push @{$msg->{raw_content}},{
  0            
498             type => 'txt',
499             content => $c,
500             };
501             }
502 0           $msg_content .= $c;
503             }
504 0           $msg->{content} = $msg_content;
505 0           $msg->{client} = $client;
506             #将整个hash从unicode转为UTF8编码
507             #$msg->{$_} = encode("utf8",$msg->{$_} ) for grep {$_ ne 'raw_content'} keys %$msg;
508             #$msg->{content}=~s/\r|\n/\n/g;
509 0 0 0       if($msg->{content}=~/\(\d+\) 被管理员禁言\d+(分钟|小时|天)$/ or $msg->{content}=~/\(\d+\) 被管理员解除禁言$/){
510 0           $msg->{type} = "sys_g_msg";
511 0           return;
512             }
513 0           my $msg_pkg = "\u$msg->{type}::Recv"; $msg_pkg=~s/_(.)/\u$1/g;
  0            
514 0           $msg = $client->_mk_ro_accessors($msg,$msg_pkg) ;
515 0           $client->{receive_message_queue}->put($msg);
516             }
517              
518             sub parse_receive_msg{
519 0     0 0   my $client = shift;
520 0 0         return if $client->{is_stop} ;
521 0           my ($json_txt) = @_;
522 0           my $json = undef;
523 0           eval{$json = JSON->new->utf8->decode($json_txt)};
  0            
524 0 0 0       console "解析消息失败: $@ 对应的消息内容为: $json_txt\n" if $@ and $client->{debug};
525 0 0         if($json){
526             #一个普通的消息
527 0 0 0       if($json->{retcode}==0){
    0 0        
    0 0        
    0          
    0          
528 0           $client->{poll_failure_count} = 0;
529 0           for my $m (@{ $json->{result} }){
  0            
530             #收到群临时消息
531 0 0         if($m->{poll_type} eq 'sess_message'){
    0          
    0          
    0          
    0          
    0          
    0          
532 0           my $msg = {
533             type => 'sess_message',
534             msg_id => $m->{value}{msg_id},
535             from_uin => $m->{value}{from_uin},
536             to_uin => $m->{value}{to_uin},
537             msg_time => $m->{value}{'time'},
538             content => $m->{value}{content},
539             service_type=> $m->{value}{service_type},
540             ruin => $m->{value}{ruin},
541             msg_class => "recv",
542             ttl => 5,
543             allow_plugin => 1,
544             };
545             #service_type =0 表示群临时消息,1 表示讨论组临时消息
546 0 0         if($m->{value}{service_type} == 0){
    0          
547 0           $msg->{gid} = $m->{value}{id};
548 0           $msg->{group_code} = $client->get_group_code_from_gid($m->{value}{id}),
549             $msg->{via} = 'group';
550             }
551 0           elsif($m->{value}{service_type} == 1){
552 0           $msg->{did} = $m->{value}{id};
553 0           $msg->{via} = 'discuss';
554             }
555             else{return}
556 0           $client->msg_put($msg);
557             }
558             #收到的消息是普通消息
559             elsif($m->{poll_type} eq 'message'){
560 0           my $msg = {
561             type => 'message',
562             msg_id => $m->{value}{msg_id},
563             from_uin => $m->{value}{from_uin},
564             to_uin => $m->{value}{to_uin},
565             msg_time => $m->{value}{'time'},
566             content => $m->{value}{content},
567             msg_class => "recv",
568             ttl => 5,
569             allow_plugin => 1,
570             };
571 0           $client->msg_put($msg);
572             }
573             #收到的消息是群消息
574             elsif($m->{poll_type} eq 'group_message'){
575 0           my $msg = {
576             type => 'group_message',
577             msg_id => $m->{value}{msg_id},
578             from_uin => $m->{value}{from_uin},
579             to_uin => $m->{value}{to_uin},
580             msg_time => $m->{value}{'time'},
581             content => $m->{value}{content},
582             send_uin => $m->{value}{send_uin},
583             group_code => $m->{value}{group_code},
584             msg_class => "recv",
585             ttl => 5,
586             allow_plugin => 1,
587             };
588 0           $client->msg_put($msg);
589             }
590             #收到讨论组消息
591             elsif($m->{poll_type} eq 'discu_message'){
592 0           my $msg = {
593             type => 'discuss_message',
594             did => $m->{value}{did},
595             from_uin => $m->{value}{from_uin},
596             msg_id => $m->{value}{msg_id},
597             send_uin => $m->{value}{send_uin},
598             msg_time => $m->{value}{'time'},
599             to_uin => $m->{value}{'to_uin'},
600             content => $m->{value}{content},
601             msg_class => "recv",
602             ttl => 5,
603             allow_plugin => 1,
604             };
605 0           $client->msg_put($msg);
606             }
607             elsif($m->{poll_type} eq 'buddies_status_change'){
608 0           my $msg = {
609             type => 'buddies_status_change',
610             uin => $m->{value}{uin},
611             state => $m->{value}{status},
612             client_type => code2client($m->{value}{client_type}),
613             };
614 0           $client->msg_put($msg);
615             }
616             #收到系统消息
617             elsif($m->{poll_type} eq 'sys_g_msg'){
618             #my $msg = {
619             # type => 'sys_g_msg',
620             # msg_id => $m->{value}{msg_id},
621             # from_uin => $m->{value}{from_uin},
622             # to_uin => $m->{value}{to_uin},
623             #
624             #};
625             #$client->msg_put($msg);
626             }
627             #收到强制下线消息
628             elsif($m->{poll_type} eq 'kick_message'){
629 0 0         if($m->{value}{show_reason} ==1){
  0            
630 0           my $reason = encode("utf8",$m->{value}{reason});
631 0           console "$reason\n";
632 0           $client->stop();
633             }
634 0           else {console "您已被迫下线\n";$client->stop(); }
635             }
636             #还未识别和处理的消息
637             else{
638              
639             }
640             }
641             }
642             #可以忽略的消息,暂时不做任何处理
643 0           elsif($json->{retcode} == 102 or $json->{retcode} == 109 or $json->{retcode} == 110 ){
644 0           $client->{poll_failure_count} = 0;
645             }
646             #更新客户端ptwebqq值
647             elsif($json->{retcode} == 116){$client->{qq_param}{ptwebqq} = $json->{p};}
648             #未重新登录
649             elsif($json->{retcode} ==100){
650 0           console "因网络或其他原因与服务器失去联系,客户端需要重新登录...\n";
651 0           $client->relogin();
652             }
653             #重新连接失败
654             elsif($json->{retcode} ==120 or $json->{retcode} ==121 ){
655 0           console "因网络或其他原因与服务器失去联系,客户端需要重新连接...\n";
656 0           $client->_relink();
657             }
658             #其他未知消息
659             else{
660 0           $client->{poll_failure_count}++;
661 0           console "获取消息失败,当前失败次数: $client->{poll_failure_count}\n";
662 0 0         if($client->{poll_failure_count} > $client->{poll_failure_count_max}){
663 0           console "接收消息失败次数超过最大值,尝试进行重新连接...\n";
664 0           $client->{poll_failure_count} = 0;
665 0           $client->_relink();
666             }
667             }
668             }
669             }
670             1;
671