Webqq/Message/Remote/_send_sess_message.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 1 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 57 CC 9 SCAR 45.0
CC
9
Cov
0%
Mojo::Webqq::_send_sess_message
90.0
CRAP 90.0
1 sub Mojo::Webqq::_send_sess_message{
2 my($self,$msg) = @_;
3 if(not defined $msg->sess_sig){
4 $msg->send_status(code=>-5,msg=>"发送失败",info=>'无法获取到sess_sig');
5 if(ref $msg->cb eq 'CODE'){
6 $msg->cb->(
7 $self,
8 $msg,
9 );
10 }
11 $self->emit(send_message =>
12 $msg,
13 );
14 return;
15 }
16 my $callback = sub{
17 my $json = shift;
18 $msg->parse_send_status_msg( $json );
19 if(!$msg->is_success and $msg->ttl > 0){
20 $self->debug("消息[ " .$msg->id . " ]发送失败,尝试重新发送,当前TTL: " . $msg->ttl);
21 $self->message_queue->put($msg);
22 return;
23 }
24 else{
25 if(ref $msg->cb eq 'CODE'){
26 $msg->cb->(
27 $self,
28 $msg,
29 );
30 }
31 $self->emit(send_message =>
32 $msg,
33 );
34 }
35 };
36  
37 my $api_url = ($self->security?'https':'http') . '://d1.web2.qq.com/channel/send_sess_msg2';
38 my $headers = {
39 Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
40 json => 1,
41 };
42 my @content = map {
43 if($_->{type} eq "txt"){$_->{content}}
44 elsif($_->{type} eq "face"){["face",0+$_->{id}]}
45 } @{$msg->raw_content};
46 #for(my $i=0;$i<@content;$i++){
47 # if(ref $content[$i] eq "ARRAY"){
48 # if(ref $content[$i] eq "ARRAY"){
49 # splice @content,$i+1,0," ";
50 # }
51 # else{
52 # $content[$i+1] = " " . $content[$i+1];
53 # }
54 # }
55 #}
56 my $content = [@content,["font",{name=>"宋体",size=>10,style=>[0,0,0],color=>"000000"}]];
57 my %s = (
58 to => $msg->receiver_id ,
59 group_sig => $msg->sess_sig ,
60 face => $self->user->face || 591,
61 content => $self->to_json($content),
62 msg_id => $msg->id,
63 service_type => $msg->via eq "group"?0:1,
64 clientid => $self->clientid,
65 psessionid => $self->psessionid,
66 );
67 $self->http_post(
68 $api_url,
69 $headers,
70 form=>{r=>$self->to_json(\%s)},
71 $callback,
72 );
73 }
74 1;