File Coverage

blib/lib/Webqq/Client/Method/_send_discuss_message.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 16 0.0
condition 0 8 0.0
subroutine 3 5 60.0
pod n/a
total 12 66 18.1


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