File Coverage

blib/lib/Webqq/Client/Method/_send_group_message.pm
Criterion Covered Total %
statement 9 39 23.0
branch 0 20 0.0
condition 0 5 0.0
subroutine 3 5 60.0
pod n/a
total 12 69 17.3


line stmt bran cond sub pod time code
1 1     1   4 use JSON;
  1         1  
  1         5  
2 1     1   92 use Encode;
  1         1  
  1         52  
3 1     1   4 use Storable qw(dclone);
  1         1  
  1         374  
4             sub Webqq::Client::_send_group_message{
5 0     0     my($self,$msg) = @_;
6             #将整个hash从UTF8还原回uincode编码
7 0           my $ua = $self->{asyn_ua};
8              
9             my $callback = sub{
10 0     0     my $response = shift;
11 0 0         print $response->content() if $self->{debug};
12 0           my $status = $self->parse_send_status_msg( $response->content() );
13 0 0 0       if(defined $status and $status->{is_success} ==0){
    0          
14 0           $self->send_group_message($msg);
15 0           return;
16             }
17             elsif(defined $status){
18 0 0         if(ref $msg->{cb} eq 'CODE'){
19 0           $msg->{cb}->(
20             $msg, #msg
21             $status->{is_success}, #is_success
22             $status->{status} #status
23             );
24             }
25 0 0         if(ref $self->{on_send_message} eq 'CODE'){
26 0           $self->{on_send_message}->(
27             $msg, #msg
28             $status->{is_success}, #is_success
29             $status->{status} #status
30             );
31             }
32             }
33 0           };
34            
35 0 0         my $api_url = ($self->{qq_param}{is_https}?'https':'http') . '://d.web2.qq.com/channel/send_qun_msg2';
36 0 0         my @headers = $self->{type} eq 'webqq'? (Referer =>'http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=3')
37             : (Referer =>'http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2')
38             ;
39 0           my $content = [decode("utf8",$msg->{content}),[]];
40 0           my %s = (
41             group_uin => $msg->{to_uin},
42             content => JSON->new->utf8->encode($content),
43             msg_id => $msg->{msg_id},
44             clientid => $self->{qq_param}{clientid},
45             psessionid => $self->{qq_param}{psessionid},
46             );
47 0           $s{content} = decode("utf8",$s{content});
48 0 0         if($self->{type} eq 'smartqq'){
49 0   0       $s{face} = $self->{qq_database}{user}{face} || "591";
50             }
51 0           my $post_content = [
52             r => JSON->new->utf8->encode(\%s),
53             ];
54 0 0         if($self->{type} eq 'webqq'){
55 0           push @$post_content,(
56             clientid => $self->{qq_param}{clientid},
57             psessionid => $self->{qq_param}{psessionid}
58             );
59             }
60 0 0         if($self->{debug}){
61 0           require URI;
62 0           my $uri = URI->new('http:');
63 0           $uri->query_form($post_content);
64 0           print $api_url,"\n";
65 0           print $uri->query(),"\n";
66             }
67              
68             $ua->post(
69 0           $api_url,
70             $post_content,
71             @headers,
72             $callback,
73             );
74             }
75             1;