Webqq/Message/Remote/_send_friend_message.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 10 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 / 45 CC 6 SCAR 37.4
CC
6
Cov
0%
Mojo::Webqq::_send_friend_message
42.0
CRAP 42.0
1 sub Mojo::Webqq::_send_friend_message{
2 my($self,$msg) = @_;
3 my $callback = sub{
4 my $json = shift;
5 $msg->parse_send_status_msg( $json );
6 if(!$msg->is_success and $msg->ttl > 0){
7 $self->debug("消息[ " .$msg->id . " ]发送失败,尝试重新发送,当前TTL: " . $msg->ttl);
8 $self->message_queue->put($msg);
9 return;
10 }
11 else{
12 if(ref $msg->cb eq 'CODE'){
13 $msg->cb->(
14 $self,
15 $msg,
16 );
17 }
18 $self->emit(send_message =>
19 $msg,
20 );
21 }
22 };
23 my $api_url = ($self->security?'https':'http') . '://d1.web2.qq.com/channel/send_buddy_msg2';
24 my $headers = {
25 Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
26 json => 1,
27 };
28 my @content = map {
29 if($_->{type} eq "txt"){$_->{content}}
30 elsif($_->{type} eq "face"){["face",0+$_->{id}]}
31 } @{$msg->raw_content};
32 #for(my $i=0;$i<@content;$i++){
33 # if(ref $content[$i] eq "ARRAY"){
34 # if(ref $content[$i] eq "ARRAY"){
35 # splice @content,$i+1,0," ";
36 # }
37 # else{
38 # $content[$i+1] = " " . $content[$i+1];
39 # }
40 # }
41 #}
42 my $content = [@content,["font",{name=>"宋体",size=>10,style=>[0,0,0],color=>"000000"}]];
43 my %s = (
44 to => $msg->receiver_id,
45 face => $self->user->face || 570,
46 content => $self->to_json($content),
47 msg_id => $msg->id,
48 clientid => $self->clientid,
49 psessionid => $self->psessionid,
50 );
51 $self->http_post(
52 $api_url,
53 $headers,
54 form=>{r=>$self->to_json(\%s)},
55 $callback,
56 );
57 }
58 1;