Weixin/Message/Remote/_send_media_message.pm

filter: Statementstmt 14.2% 7 / 49 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 33.3% 2 / 6 Podpod n/a totaltotal 8.0% 9 / 112 CC 21 SCAR 47.9
CC
21
Cov
7%
__ANON__
210.0
_send_media_message
20.0
__ANON__
20.0
CRAP 119.8
« Weixin/User.pm ↑ Summary Weixin/Model/Remote/_webwxbatchgetcontact_group_member.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use Mojo::Weixin::Const ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶sub Mojo::Weixin::_send_media_message {
Subroutine _send_media_message: not called CC=4 SCAR=30.0
4 0 my $self = shift;
5 0 my $msg = shift;
6 0 ▶ if($msg->format ne "media" or (!defined $msg->media_path and !defined $msg->media_id) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->format ne "media" or not defined $msg->media_path || defined $msg->media_id) 0 0 0
Condition0%0/6
$msg->format ne "media" or not defined $msg->media_path || defined $msg->media_id
l!l&&r!l&&!r
000
defined $msg->media_path || defined $msg->media_id
l!l&&r!l&&!r
000
MC/DC0%0/3
$msg->format ne "media" or not defined $msg->media_path || defined $msg->media_id
$msg->format ne "media" defined $msg->media_path defined $msg->media_id
Truth table0%0/4
A or not(B || C)
A= $msg->format ne "media"B= defined $msg->media_pathC= defined $msg->media_id
ABCresult
1XX1
0001
01X0
0010
7 0 $self->error("无效的 media msg");
8 0 return;
9 }
10 0 ▶ my $callback = sub{
Subroutine __ANON__: not called CC=4 SCAR=30.0
11 0 my $json = shift;
12 0 $msg->_parse_send_status_data($json);
13 0 ▶ if(!$msg->is_success and $msg->ttl > 0){
Branch: 1 branch
BranchTrueFalseTotal
if (not $msg->is_success and $msg->ttl > 0) { } 0 0 0
Condition0%0/3
not $msg->is_success and $msg->ttl > 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $msg->is_success and $msg->ttl > 0
not $msg->is_success $msg->ttl > 0
Truth table0%0/3
not(A) and B
A= not $msg->is_successB= $msg->ttl > 0
ABresult
0X0
100
111
14 0 $self->debug("消息[ " . $msg->id . " ]发送失败,尝试重新发送,当前TTL: " . $msg->ttl);
15 0 $self->message_queue->put($msg);
16 0 return;
17 }
18 else{
19 0 ▶ if(ref $msg->cb eq 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msg->cb eq "CODE") 0 0 0
20 0 $msg->cb->($self, $msg);
21 }
22 0 $self->emit(send_media => $msg->media_path,$msg->media_data,$msg);
23 0 $self->emit(send_message => $msg);
24 }
25 0 };
26 $self->steps(
27 0 ▶ sub{
Subroutine __ANON__: not called CC=2 SCAR=17.9
28 0 my $delay = shift;
29 0 ▶ defined $msg->media_id ? $delay->begin(0)->($msg): $self->_upload_media($msg,$delay->begin(0,));
Branch: 1 branch
BranchTrueFalseTotal
defined $msg->media_id ? : 0 0 0
30 },
31 0 ▶ sub{
Subroutine __ANON__: not called CC=14 SCAR=53.5
32 0 my($delay,$msg,$error) = @_;
33 0 ▶ if(!defined $msg->media_id or $error){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $msg->media_id or $error) 0 0 0
Condition0%0/3
not defined $msg->media_id or $error
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $msg->media_id or $error
not defined $msg->media_id $error
Truth table0%0/3
not(A) or B
A= not defined $msg->media_idB= $error
ABresult
1X1
011
000
34 0 $msg->send_status(code=>-1,msg=>"发送失败",info=>$error);
35 0 ▶ if(ref $msg->cb eq 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msg->cb eq "CODE") 0 0 0
36 0 $msg->cb->($self, $msg);
37 }
38 0 $self->emit(send_message => $msg);
39 0 return;
40 }
41 0 my $api;
42 0 ▶ my @query_string = (
Branch: 1 branch
BranchTrueFalseTotal
$self->pass_ticket ? : 0 0 0
43 fun => 'async',
44 f => 'json',
45 $self->pass_ticket?(pass_ticket => $self->url_escape($self->pass_ticket)):()
46 );
47 my $post = {
48 BaseRequest => {
49 DeviceID => $self->deviceid,
50 Sid => $self->wxsid,
51 Skey => $self->skey,
52 Uin => $self->wxuin,
53 },
54 Msg => {
55 ClientMsgId => $msg->uid,
56 FromUserName => $msg->sender_id,
57 MediaId => (split ":",$msg->media_id)[0],
58 LocalID => $msg->uid,
59 ToUserName => ($msg->type eq "group_message"?$msg->group_id:$msg->receiver_id),
60 #Type => $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type} || 6,
61 0 ▶ Type => $msg->media_code || $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type} || 6,
Branch: 1 branch
BranchTrueFalseTotal
$msg->type eq 'group_message' ? : 0 0 0
Condition0%0/5
$msg->media_code || $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type} || 6
l!l
00
$msg->media_code or $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type}
l!l&&r!l&&!r
000
MC/DC0%0/2
$msg->media_code || $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type} || 6
$msg->media_code $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type}
Truth table0%0/3
A or B
A= $msg->media_codeB= $Mojo::Weixin::Const::KEY_MAP_MEDIA_CODE{$msg->media_type}
ABresult
1X1
011
000
62 },
63 Scene => 0,
64 };
65 0 ▶ if($msg->media_type eq "image"){
Branch: 3 branches
BranchTrueFalseTotal
if ($msg->media_type eq 'image') { } 0 0 0
elsif ($msg->media_type eq 'video' or $msg->media_type eq 'microvideo') { } 0 0 0
elsif ($msg->media_type eq 'emoticon') { } 0 0 0
66 0 $api = 'https://' . $self->domain . '/cgi-bin/mmwebwx-bin/webwxsendmsgimg';
67 }
68 ▶ elsif($msg->media_type eq "video" or $msg->media_type eq "microvideo"){
Condition0%0/3
$msg->media_type eq "video" or $msg->media_type eq "microvideo"
l!l&&r!l&&!r
000
MC/DC0%0/2
$msg->media_type eq "video" or $msg->media_type eq "microvideo"
$msg->media_type eq "video" $msg->media_type eq "microvideo"
Truth table0%0/3
A or B
A= $msg->media_type eq "video"B= $msg->media_type eq "microvideo"
ABresult
1X1
011
000
69 0 $api = 'https://' . $self->domain . '/cgi-bin/mmwebwx-bin/webwxsendvideomsg';
70 }
71 #elsif($msg->media_type eq "voice"){
72 #
73 #}
74 elsif($msg->media_type eq "emoticon"){
75 0 $api = 'https://' . $self->domain . '/cgi-bin/mmwebwx-bin/webwxsendemoticon';
76 0 ▶ @query_string = (
Branch: 1 branch
BranchTrueFalseTotal
$self->pass_ticket ? : 0 0 0
77 fun=>'sys',
78 $self->pass_ticket?(pass_ticket => $self->url_escape($self->pass_ticket)):()
79 );
80 0 $post->{Msg}{EmojiFlag} = 2;
81 }
82 else{
83 0 $api = 'https://' . $self->domain . '/cgi-bin/mmwebwx-bin/webwxsendappmsg';
84 0 my $content =
85 "<appmsg appid='wxeb7ec651dd0aefa9' sdkver=''>" .
86 "<title>" . $msg->media_name . "</title>" .
87 "<des></des>" .
88 "<action></action>" .
89 "<type>6</type>" .
90 "<content></content>" .
91 "<url></url>" .
92 "<lowurl></lowurl>" .
93 "<appattach>" .
94 "<totallen>" . $msg->media_size . "</totallen>" .
95 "<attachid>" . (split ":",$msg->media_id)[0] . "</attachid>" .
96 "<fileext>" . $msg->media_ext ."</fileext>" .
97 "</appattach>" .
98 "<extinfo></extinfo>" .
99 "</appmsg>";
100 0 $post->{Msg}{Content} = $content;
101 }
102 0 ▶ $post->{Msg}{Content} =~ s#/#__SLASH__#g if exists $post->{Msg}{Content};
Branch: 1 branch
BranchTrueFalseTotal
if exists $post->{"Msg"}{"Content"} 0 0 0
103 0 my $json = $self->to_json($post);
104 0 $json =~ s#__SLASH__#/#g;
105 0 $self->http_post(
106 $self->gen_url($api,@query_string),
107 {json=>1,Referer=>'https://' . $self->domain . '/','Content-Type'=>'application/json'},
108 $json,
109 $callback
110 );
111 },
112 0 );
113 }
114 1 1;
« Weixin/User.pm ↑ Summary Weixin/Model/Remote/_webwxbatchgetcontact_group_member.pm »