File Coverage

blib/lib/Webqq/Client/Method/_send_sess_message.pm
Criterion Covered Total %
statement 6 35 17.1
branch 0 20 0.0
condition 0 5 0.0
subroutine 2 4 50.0
pod n/a
total 8 64 12.5


line stmt bran cond sub pod time code
1 1     1   6 use JSON;
  1         29  
  1         6  
2 1     1   113 use Encode;
  1         1  
  1         525  
3             sub Webqq::Client::_send_sess_message{
4 0     0     my($self,$msg) = @_;
5 0 0         return unless defined $msg->{group_sig};
6 0           my $ua = $self->{asyn_ua};
7             my $callback = sub{
8 0     0     my $response = shift;
9 0 0         print $response->content() if $self->{debug};
10 0           my $status = $self->parse_send_status_msg( $response->content() );
11 0 0 0       if(defined $status and $status->{is_success}==0){
    0          
12 0           $self->send_sess_message($msg);
13 0           return;
14             }
15             elsif(defined $status){
16 0 0         if(ref $msg->{cb} eq 'CODE'){
17 0           $msg->{cb}->(
18             $msg, #msg
19             $status->{is_success}, #is_success
20             $status->{status} #status
21             );
22             }
23 0 0         if(ref $self->{on_send_message} eq 'CODE'){
24 0           $self->{on_send_message}->(
25             $msg, #msg
26             $status->{is_success}, #is_success
27             $status->{status} #status
28             );
29             }
30             }
31 0           };
32              
33 0 0         my $api_url = ($self->{is_https}?'https':'http') . '://d.web2.qq.com/channel/send_sess_msg2';
34 0 0         my @headers = $self->{type} eq 'webqq'? (Referer => 'http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=3')
35             : (Referer => 'http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2')
36             ;
37 0           my $content = [decode("utf8",$msg->{content}),[]];
38 0   0       my %s = (
39             to => $msg->{to_uin},
40             group_sig => $msg->{group_sig},
41             face => $self->{qq_database}{user}{face} || 591,
42             content => JSON->new->utf8->encode($content),
43             msg_id => $msg->{msg_id},
44             service_type => $msg->{service_type},
45             clientid => $self->{qq_param}{clientid},
46             psessionid => $self->{qq_param}{psessionid},
47             );
48 0           $s{content} = decode("utf8",$s{content});
49 0           my $post_content = [
50             r => JSON->new->utf8->encode(\%s),
51             ];
52              
53 0 0         if($self->{type} eq 'webqq'){
54 0           push @$post_content,(
55             clientid => $self->{qq_param}{clientid},
56             psessionid => $self->{qq_param}{psessionid},
57             );
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;