Weixin/Message/Handle.pm

filter: Statementstmt 9.3% 40 / 428 Branchbran 0.0% 0 / 282 Conditioncond 0.0% 0 / 85 MC/DCmcdc 0.0% 0 / 52 Subroutinesub 40.0% 12 / 30 Podpod n/a totaltotal 5.9% 52 / 877 CC 185 SCAR 85.1
CC
185
Cov
5%
_parse_sync_data
10302.0
send_media
702.0
__ANON__
240.0
CRAP 4982.6
« Weixin/Plugin/IRCShell.pm ↑ Summary Weixin/Plugin/KnowledgeBase.pm »
1 package Mojo::Weixin;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Mojo::Weixin::Const qw(%KEY_MAP_USER %KEY_MAP_GROUP %KEY_MAP_GROUP_MEMBER %KEY_MAP_FRIEND %KEY_MAP_MEDIA_CODE);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Weixin::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mojo::Weixin::Const;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Mojo::Weixin::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Mojo::Weixin::Message::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Mojo::Weixin::Message::Remote::_upload_media;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Mojo::Weixin::Message::Remote::_get_media;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Mojo::Weixin::Message::Remote::_send_media_message;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Mojo::Weixin::Message::Remote::_send_text_message;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Mojo::Weixin::Message::Remote::_revoke_message;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 $Mojo::Weixin::Message::LAST_DISPATCH_TIME = undef;
15 1 $Mojo::Weixin::Message::SEND_INTERVAL = 3;
16  
17 0 ▶sub gen_message_queue{
Subroutine gen_message_queue: not called CC=1 SCAR=6.9
18 0 my $self = shift;
19 0 ▶ Mojo::Weixin::Message::Queue->new(callback_for_get=>sub{
Subroutine __ANON__: not called CC=15 SCAR=54.8
20 0 my $msg = shift;
21 0 ▶ return if $self->is_stop;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_stop 0 0 0
22 0 ▶ if($msg->class eq "recv"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->class eq 'recv') { } 0 0 0
elsif ($msg->class eq 'send') { } 0 0 0
23 0 ▶ if($msg->format eq "media"){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->format eq 'media') { } 0 0 0
24 0 ▶ if($self->download_media){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->download_media) { } 0 0 0
25 0 ▶ $self->_get_media($msg,sub{
Subroutine __ANON__: not called CC=3 SCAR=24.8
26 0 my ($path,$data,$msg) = @_;
27 0 ▶ if($msg->media_size == 0 and $msg->media_type eq 'emoticon'){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->media_size == 0 and $msg->media_type eq 'emoticon') { } 0 0 0
Condition0%0/3
$msg->media_size == 0 and $msg->media_type eq "emoticon"
!ll&&!rl&&r
000
MC/DC0%0/2
$msg->media_size == 0 and $msg->media_type eq "emoticon"
$msg->media_size == 0 $msg->media_type eq "emoticon"
Truth table0%0/3
A and B
A= $msg->media_size == 0B= $msg->media_type eq "emoticon"
ABresult
0X0
100
111
28 0 $msg->content("[表情](获取数据为空,可能需要手机查看)");
29 }
30 else{
31 0 $msg->content( $msg->content. "(". $msg->media_path . ")");
32 }
33 0 $self->emit(receive_media=>$path,$data,$msg);
34 0 $self->emit(receive_message=>$msg);
35 0 });
36 }
37 else{
38 0 $self->emit(receive_message=>$msg);
39 }
40 }
41 0 else{ $self->emit(receive_message=>$msg);}
42 }
43 elsif($msg->class eq "send"){
44 0 ▶ if($msg->source ne "local"){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->source ne "local") 0 0 0
45 0 $msg->send_status(code=>0,msg=>"发送成功",info=>"来自其他设备");
46 0 ▶ if($msg->format eq "media"){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->format eq 'media') { } 0 0 0
47 0 ▶ if($self->download_media){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->download_media) { } 0 0 0
48 0 ▶ $self->_get_media($msg,sub{
Subroutine __ANON__: not called CC=4 SCAR=30.0
49 0 my ($path,$data,$msg) = @_;
50 0 ▶ if($msg->media_size == 0 and $msg->media_type eq 'emoticon'){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->media_size == 0 and $msg->media_type eq 'emoticon') { } 0 0 0
Condition0%0/3
$msg->media_size == 0 and $msg->media_type eq "emoticon"
!ll&&!rl&&r
000
MC/DC0%0/2
$msg->media_size == 0 and $msg->media_type eq "emoticon"
$msg->media_size == 0 $msg->media_type eq "emoticon"
Truth table0%0/3
A and B
A= $msg->media_size == 0B= $msg->media_type eq "emoticon"
ABresult
0X0
100
111
51 0 $msg->content("[表情](获取数据为空,可能需要手机查看)");
52 }
53 else{
54 0 $msg->content( $msg->content. "(". $msg->media_path . ")");
55 }
56 0 ▶ $msg->cb->($self,$msg) if ref $msg->cb eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg->cb eq "CODE" 0 0 0
57 0 $self->emit(send_media=>$path,$data,$msg);
58 0 $self->emit(send_message=>$msg);
59 0 });
60 }
61 else{
62 0 ▶ $msg->cb->($self,$msg) if ref $msg->cb eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg->cb eq "CODE" 0 0 0
63 0 $self->emit(send_message=>$msg);
64 }
65 }
66 else{
67 0 ▶ $msg->cb->($self,$msg) if ref $msg->cb eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg->cb eq "CODE" 0 0 0
68 0 $self->emit(send_message=>$msg);
69 }
70 0 return;
71 }
72 #消息的ttl值减少到0则丢弃消息
73 0 ▶ if($msg->ttl <= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->ttl <= 0) 0 0 0
74 0 $self->debug("消息[ " . $msg->id. " ]已被消息队列丢弃,当前TTL: ". $msg->ttl);
75 0 $msg->send_status(code=>-5,msg=>"发送失败",info=>"TTL失效");
76 0 ▶ if(ref $msg->cb eq 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msg->cb eq "CODE") 0 0 0
77 0 $msg->cb->(
78 $self,
79 $msg,
80 );
81 }
82 0 $self->emit(send_message=>
83 $msg,
84 );
85 0 return;
86 }
87 0 my $ttl = $msg->ttl;
88 0 $msg->ttl(--$ttl);
89  
90 0 my $delay = 0;
91 0 my $now = time;
92 0 ▶ if(defined $Mojo::Weixin::Message::LAST_DISPATCH_TIME){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Mojo::Weixin::Message::LAST_DISPATCH_TIME) 0 0 0
93 0 ▶ $delay = $now<$Mojo::Weixin::Message::LAST_DISPATCH_TIME+$Mojo::Weixin::Message::SEND_INTERVAL?
Branch: 1 branch
BranchTrueFalseTotal
$now < $Mojo::Weixin::Message::LAST_DISPATCH_TIME + $Mojo::Weixin::Message::SEND_INTERVAL ? : 0 0 0
94 $Mojo::Weixin::Message::LAST_DISPATCH_TIME+$Mojo::Weixin::Message::SEND_INTERVAL-$now
95 : 0;
96 }
97 0 ▶ $self->timer($delay,sub{
Subroutine __ANON__: not called CC=3 SCAR=24.8
98 0 $msg->time(time);
99 0 ▶ if($msg->format eq "text"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->format eq 'text') { } 0 0 0
elsif ($msg->format eq 'media') { } 0 0 0
100 0 $self->_send_text_message($msg);
101 }
102 elsif($msg->format eq "media"){
103 0 $self->_send_media_message($msg);
104 }
105 0 });
106 0 $Mojo::Weixin::Message::LAST_DISPATCH_TIME = $now+$delay;
107 }
108 0 });
109 }
110 0 ▶sub _parse_synccheck_data{
Subroutine _parse_synccheck_data: not called CC=11 SCAR=48.8
111 0 my @logout_code = qw(1100 1101 1102 1205);
112 0 my $self = shift;
113 0 my($retcode,$selector) = @_;
114 0 ▶ if(defined $retcode and defined $selector){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $retcode and defined $selector) 0 0 0
Condition0%0/3
defined $retcode and defined $selector
!ll&&!rl&&r
000
MC/DC0%0/2
defined $retcode and defined $selector
defined $retcode defined $selector
Truth table0%0/3
A and B
A= defined $retcodeB= defined $selector
ABresult
0X0
100
111
115 0 ▶ if($retcode == 0 and $selector != 0){
Branch: 5 branches
BranchTrueFalseTotal
if ($retcode == 0 and $selector != 0) { } 0 0 0
elsif ($retcode == 0 and $selector == 0) { } 0 0 0
elsif ($retcode == 1101 and $self->stop_with_mobile) { } 0 0 0
elsif (&first(sub { $retcode == $_; } , @logout_code)) { } 0 0 0
elsif ($self->_synccheck_error_count <= 10) { } 0 0 0
Condition0%0/3
$retcode == 0 and $selector != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$retcode == 0 and $selector != 0
$retcode == 0 $selector != 0
Truth table0%0/3
A and B
A= $retcode == 0B= $selector != 0
ABresult
0X0
100
111
116 0 $self->_synccheck_error_count(0);
117 0 $self->_sync();
118 }
119 ▶ elsif($retcode == 0 and $selector == 0){
Condition0%0/3
$retcode == 0 and $selector == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$retcode == 0 and $selector == 0
$retcode == 0 $selector == 0
Truth table0%0/3
A and B
A= $retcode == 0B= $selector == 0
ABresult
0X0
100
111
120 0 $self->_synccheck_error_count(0);
121 }
122 ▶ elsif($retcode == 1101 and $self->stop_with_mobile){
Condition0%0/3
$retcode == 1101 and $self->stop_with_mobile
!ll&&!rl&&r
000
MC/DC0%0/2
$retcode == 1101 and $self->stop_with_mobile
$retcode == 1101 $self->stop_with_mobile
Truth table0%0/3
A and B
A= $retcode == 1101B= $self->stop_with_mobile
ABresult
0X0
100
111
123 0 $self->stop();
124 }
125 0 ▶ elsif(first {$retcode == $_} @logout_code){
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 $self->relogin($retcode);
127 0 return;
128 }
129 elsif($self->_synccheck_error_count <= 10){
130 0 my $c = $self->_synccheck_error_count;
131 0 $self->_synccheck_error_count(++$c);
132 }
133 else{
134 0 $self->relogin();
135 0 return;
136 }
137 }
138 }
139 0 ▶sub _parse_sync_data {
Subroutine _parse_sync_data: not called CC=101 SCAR=92.4
140 0 my $self = shift;
141 0 my $json = shift;
142 0 ▶ return if not defined $json;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $json 0 0 0
143 0 my @logout_code = qw(1100 1102 1205);
144 0 ▶ if($json->{BaseResponse}{Ret} == 1101){#手机端强制下线 或 其他设备登录Web微信
Branch: 3 branches
BranchTrueFalseTotal
if ($json->{'BaseResponse'}{'Ret'} == 1101) { } 0 0 0
elsif (&first(sub { $json->{'BaseResponse'}{'Ret'} == $_; } , @logout_code)) { } 0 0 0
elsif ($json->{'BaseResponse'}{'Ret'} != 0) { } 0 0 0
145 0 $self->info("收到下线通知");
146 0 $self->logout($json->{BaseResponse}{Ret});
147 0 $self->stop();
148 }
149 0 ▶ elsif(first {$json->{BaseResponse}{Ret} == $_} @logout_code ){
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 0 $self->relogin($json->{BaseResponse}{Ret});
151 0 return;
152 }
153 elsif($json->{BaseResponse}{Ret} !=0){
154 0 $self->warn("收到无法识别消息代码[$json->{BaseResponse}{Ret}],已将其忽略");
155 0 $self->emit(unknown_retcode=>$json->{BaseResponse}{Ret});
156 0 return;
157 }
158 0 ▶ $self->sync_key($json->{SyncKey}) if $json->{SyncKey}{Count}!=0;
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"SyncKey"}{"Count"} != 0 0 0 0
159 0 ▶ $self->synccheck_key($json->{SyncCheckKey}) if $json->{SyncCheckKey}{Count}!=0;
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"SyncCheckKey"}{"Count"} != 0 0 0 0
160 0 ▶ $self->skey($json->{SKey}) if $json->{SKey};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"SKey"} 0 0 0
161  
162  
163 #群组或联系人变更
164 0 ▶ if($json->{ModContactCount}!=0){
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"ModContactCount"} != 0) 0 0 0
165 0 for my $e (@{$json->{ModContactList}}){
166 0 ▶ if($self->is_group_id($e->{UserName})){#群组
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_group_id($e->{'UserName'})) { } 0 0 0
167 0 my $group = {member=>[]};
168 0 for(keys %KEY_MAP_GROUP){
169 0 ▶ $group->{$_} = $e->{$KEY_MAP_GROUP{$_}} // "";
Condition0%0/2
$$e{$Mojo::Weixin::KEY_MAP_GROUP{$_}} // ""
l!l
00
MC/DC0%0/1
$$e{$Mojo::Weixin::KEY_MAP_GROUP{$_}} // ""
$$e{$Mojo::Weixin::KEY_MAP_GROUP{$_}}
Truth table0%0/2
A
A= $$e{$Mojo::Weixin::KEY_MAP_GROUP{$_}}
Aresult
11
00
170 }
171 0 ▶ if($e->{MemberCount} != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"MemberCount"} != 0) 0 0 0
172 0 for my $m (@{$e->{MemberList}}){
173 0 my $member = {};
174 0 for(keys %KEY_MAP_GROUP_MEMBER){
175 0 ▶ $member->{$_} = $m->{$KEY_MAP_GROUP_MEMBER{$_}} // "";
Condition0%0/2
$$m{$Mojo::Weixin::KEY_MAP_GROUP_MEMBER{$_}} // ""
l!l
00
MC/DC0%0/1
$$m{$Mojo::Weixin::KEY_MAP_GROUP_MEMBER{$_}} // ""
$$m{$Mojo::Weixin::KEY_MAP_GROUP_MEMBER{$_}}
Truth table0%0/2
A
A= $$m{$Mojo::Weixin::KEY_MAP_GROUP_MEMBER{$_}}
Aresult
11
00
176 }
177 0 push @{ $group->{member} }, $member;
178 }
179 }
180 0 my $g = $self->search_group(id=>$group->{id});
181 0 ▶ if(not defined $g){#新增群组
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $g) { } 0 0 0
182 0 ▶ if(not $self->update_group($group->{id},1)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update_group($group->{"id"}, 1)) 0 0 0
183 0 $self->add_group(Mojo::Weixin::Group->new($group));
184 }
185 }
186 else{#更新已有联系人
187 0 $g->update($group);
188 }
189 }
190 else{#联系人
191 0 my $friend = {};
192 0 for(keys %KEY_MAP_FRIEND){
193 0 ▶ $friend->{$_} = $e->{$KEY_MAP_FRIEND{$_}} if defined $e->{$KEY_MAP_FRIEND{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e{$Mojo::Weixin::KEY_MAP_FRIEND{$_}} 0 0 0
194 }
195 0 my $f = $self->search_friend(id=>$friend->{id});
196 0 ▶ if(not defined $f){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $f) { } 0 0 0
197 0 $self->add_friend(Mojo::Weixin::Friend->new($friend));
198 }
199 0 else{$f->update($friend)}
200 }
201 }
202 }
203  
204 0 ▶ if($json->{ModChatRoomMemberCount}!=0){
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"ModChatRoomMemberCount"} != 0) 0 0 0
205
206 }
207  
208 0 ▶ if($json->{DelContactCount}!=0){
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"DelContactCount"} != 0) 0 0 0
209 0 for my $e (@{$json->{DelContactList}}){
210 0 ▶ if($self->is_group_id($e->{UserName})){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_group_id($e->{'UserName'})) { } 0 0 0
211 0 my $g = $self->search_group(id=>$e->{UserName});
212 0 ▶ $self->remove_group($g) if defined $g;
Branch: 1 branch
BranchTrueFalseTotal
if defined $g 0 0 0
213 }
214 else{
215 0 my $f = $self->search_friend(id=>$e->{UserName});
216 0 ▶ $self->remove_friend($f) if defined $f;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f 0 0 0
217 }
218 }
219 }
220  
221 #有新消息
222 0 ▶ if($json->{AddMsgCount} != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"AddMsgCount"} != 0) 0 0 0
223 0 for my $e (@{$json->{AddMsgList}}){
224 0 my $msg = {};
225 0 for(keys %KEY_MAP_MESSAGE){
226 0 ▶ $msg->{$_} = $e->{$KEY_MAP_MESSAGE{$_}} // "";
Condition0%0/2
$$e{$Mojo::Weixin::KEY_MAP_MESSAGE{$_}} // ""
l!l
00
MC/DC0%0/1
$$e{$Mojo::Weixin::KEY_MAP_MESSAGE{$_}} // ""
$$e{$Mojo::Weixin::KEY_MAP_MESSAGE{$_}}
Truth table0%0/2
A
A= $$e{$Mojo::Weixin::KEY_MAP_MESSAGE{$_}}
Aresult
11
00
227 }
228 0 ▶ if($e->{MsgType} == 1){#好友消息或群消息
Branch: 14 branches
BranchTrueFalseTotal
if ($e->{'MsgType'} == 1) { } 0 0 0
elsif ($e->{'MsgType'} == 3) { } 0 0 0
elsif ($e->{'MsgType'} == 47) { } 0 0 0
elsif ($e->{'MsgType'} == 62) { } 0 0 0
elsif ($e->{'MsgType'} == 43) { } 0 0 0
elsif ($e->{'MsgType'} == 34) { } 0 0 0
elsif ($e->{'MsgType'} == 37) { } 0 0 0
elsif ($e->{'MsgType'} == 10000) { } 0 0 0
elsif ($e->{'MsgType'} == 10002) { } 0 0 0
elsif ($e->{'MsgType'} == 49 and $e->{'AppMsgType'} == 6) { } 0 0 0
elsif ($e->{'MsgType'} == 49 and $e->{'AppMsgType'} == 5) { } 0 0 0
elsif ($e->{'MsgType'} == 49 and $e->{'AppMsgType'} == 2000) { } 0 0 0
elsif ($e->{'MsgType'} == 42) { } 0 0 0
elsif ($e->{'MsgType'} == 51) { } 0 0 0
229 0 $msg->{format} = "text";
230 }
231 elsif($e->{MsgType} == 3){#图片消息
232 0 $msg->{format} = "media";
233 0 $msg->{media_type} = "image";
234 0 $msg->{media_code} = $e->{MsgType};
235 0 $msg->{media_id} = $msg->{id} . ":" . $msg->{media_code};
236 }
237 elsif($e->{MsgType} == 47){#表情或gif图片
238 0 $msg->{format} = "media";
239 0 $msg->{media_type} = "emoticon";
240 0 $msg->{media_code} = $e->{MsgType};
241 0 $msg->{media_id} = $msg->{id} . ":" . $msg->{media_code};
242 }
243 elsif($e->{MsgType} == 62){#小视频
244 0 $msg->{format} = "media";
245 0 $msg->{media_type} = "microvideo";
246 0 $msg->{media_code} = $e->{MsgType};
247 0 $msg->{media_id} = $msg->{id} . ":" . $msg->{media_code};
248 }
249 elsif($e->{MsgType} == 43){#视频
250 0 $msg->{format} = "media";
251 0 $msg->{media_type} = "video";
252 0 $msg->{media_code} = $e->{MsgType};
253 0 $msg->{media_id} = $msg->{id} . ":" . $msg->{media_code};
254 }
255 elsif($e->{MsgType} == 34){#语音
256 0 $msg->{format} = "media";
257 0 $msg->{media_type} = "voice";
258 0 $msg->{media_code} = $e->{MsgType};
259 0 $msg->{media_id} = $msg->{id} . ":" . $msg->{media_code};
260 }
261 elsif($e->{MsgType} == 37){#好友推荐消息
262 0 $msg->{format} = "text";
263 #$msg->{class} = "recv";
264 #$msg->{type} = "friend_message";
265 #$msg->{receiver_id} = $self->user->id;
266 #$msg->{sender_id} = $e->{FromUserName};
267 0 my $id = $e->{RecommendInfo}{UserName};
268 0 my $displayname = $e->{RecommendInfo}{NickName};
269 0 my $verify = $e->{RecommendInfo}{Content};
270 0 my $ticket = $e->{RecommendInfo}{Ticket};
271 #$msg->data({id=>$id,verify=>$verify,ticket=>$ticket,displayname=>$displayname});
272 #$msg->{content} = "收到[ " . $displayname . " ]好友验证请求:" . ($verify?$verify:"(验证内容为空)");
273 0 $self->_webwxstatusnotify($e->{FromUserName},1);
274 0 $self->emit("friend_request",$id,$displayname,$verify,$ticket);
275 0 next;
276 }
277 elsif($e->{MsgType} == 10000){#群提示消息
278 0 $msg->{format} = "text";
279 }
280 elsif($e->{MsgType} == 10002){#撤回消息
281 0 $msg->{format} = "revoke";
282 }
283 ▶ elsif($e->{MsgType} == 49 and $e->{AppMsgType} == 6) {#文件分享
Condition0%0/3
$e->{"MsgType"} == 49 and $e->{"AppMsgType"} == 6
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{"MsgType"} == 49 and $e->{"AppMsgType"} == 6
$e->{"MsgType"} == 49 $e->{"AppMsgType"} == 6
Truth table0%0/3
A and B
A= $e->{"MsgType"} == 49B= $e->{"AppMsgType"} == 6
ABresult
0X0
100
111
284 0 $msg->{format} = "media";
285 0 $msg->{media_type} = "file";
286 0 $msg->{media_code} = $e->{AppMsgType};
287 0 $msg->{media_id} = $e->{MediaId} . ":" . $e->{AppMsgType};
288 0 $msg->{media_name} = $e->{FileName};
289 0 $msg->{media_size} = $e->{FileSize};
290 }
291 ▶ elsif($e->{MsgType} == 49 and $e->{AppMsgType} == 5) {#应用分享
Condition0%0/3
$e->{"MsgType"} == 49 and $e->{"AppMsgType"} == 5
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{"MsgType"} == 49 and $e->{"AppMsgType"} == 5
$e->{"MsgType"} == 49 $e->{"AppMsgType"} == 5
Truth table0%0/3
A and B
A= $e->{"MsgType"} == 49B= $e->{"AppMsgType"} == 5
ABresult
0X0
100
111
292 0 $msg->{format} = "app";
293 0 $msg->{app_title} = $e->{FileName};
294 0 $msg->{app_url} = $e->{Url};
295 }
296 ▶ elsif($e->{MsgType} == 49 and $e->{AppMsgType} == 2000){#转账信息
Condition0%0/3
$e->{"MsgType"} == 49 and $e->{"AppMsgType"} == 2000
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{"MsgType"} == 49 and $e->{"AppMsgType"} == 2000
$e->{"MsgType"} == 49 $e->{"AppMsgType"} == 2000
Truth table0%0/3
A and B
A= $e->{"MsgType"} == 49B= $e->{"AppMsgType"} == 2000
ABresult
0X0
100
111
297 0 $msg->{format} = "payment";
298 }
299 elsif($e->{MsgType} == 42){#名片消息
300 0 $msg->{format} = "card";
301 0 $msg->{card_name} = $e->{RecommendInfo}{NickName};
302 0 $msg->{card_id} = $e->{RecommendInfo}{UserName};
303 0 $msg->{card_province} = $e->{RecommendInfo}{Province};
304 0 $msg->{card_city} = $e->{RecommendInfo}{City};
305 0 $msg->{card_account} = $e->{RecommendInfo}{Alias};
306 0 $msg->{card_sex} = $self->code2sex($e->{RecommendInfo}{Sex});
307 #$msg->{card_avatar} = '';
308 }
309 elsif($e->{MsgType} == 51){#会话、联系人信息同步
310 0 ▶ if($e->{StatusNotifyCode} == 4 or $e->{StatusNotifyCode} == 2){#联系人、群组信息需要同步
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"StatusNotifyCode"} == 4 or $e->{"StatusNotifyCode"} == 2) 0 0 0
Condition0%0/3
$e->{"StatusNotifyCode"} == 4 or $e->{"StatusNotifyCode"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$e->{"StatusNotifyCode"} == 4 or $e->{"StatusNotifyCode"} == 2
$e->{"StatusNotifyCode"} == 4 $e->{"StatusNotifyCode"} == 2
Truth table0%0/3
A or B
A= $e->{"StatusNotifyCode"} == 4B= $e->{"StatusNotifyCode"} == 2
ABresult
1X1
011
000
311 0 my @id = split /,/,$e->{StatusNotifyUserName};
312 0 my @group_ids;
313 my @friend_ids;
314 0 for (@id){
315 0 ▶ next if $_ eq $self->user->id;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $self->user->id 0 0 0
316 0 ▶ if($self->is_group_id($_)){push @group_ids,$_ if not $self->search_group(id=>$_);}
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_group_id($_)) { } 0 0 0
unless $self->search_group("id", $_) 0 0 0
317 0 ▶ else{push @friend_ids,$_ if not $self->search_friend(id=>$_);}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->search_friend("id", $_) 0 0 0
318 }
319 0 ▶ $self->update_group(@group_ids) if @group_ids;
Branch: 1 branch
BranchTrueFalseTotal
if @group_ids 0 0 0
320 0 ▶ $self->update_friend(@friend_ids) if @friend_ids;
Branch: 1 branch
BranchTrueFalseTotal
if @friend_ids 0 0 0
321 }
322 0 next;
323 }
324 0 else{next;}
325 0 ▶ if($e->{FromUserName} eq $self->user->id){#发送的消息
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{'FromUserName'} eq $self->user->id) { } 0 0 0
326 0 $msg->{source} = 'outer';
327 0 $msg->{class} = "send";
328 0 $msg->{sender_id} = $self->user->id;
329 0 ▶ if($self->is_group_id($e->{ToUserName})){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_group_id($e->{'ToUserName'})) { } 0 0 0
330 0 $msg->{type} = "group_message";
331 0 $msg->{group_id} = $e->{ToUserName};
332 }
333 else{
334 0 $msg->{type} = "friend_message";
335 0 $msg->{receiver_id} = $e->{ToUserName};
336 }
337 }
338 #elsif($e->{ToUserName} eq $self->user->id){#接收的消息
339 else{#接收的消息
340 0 $msg->{class} = "recv";
341 0 $msg->{receiver_id} = $self->user->id;
342 0 $msg->{type} = "group_message";
343 0 ▶ if($self->is_group_id($e->{FromUserName})){#接收到群组消息
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_group_id($e->{'FromUserName'})) { } 0 0 0
344 0 $msg->{group_id} = $e->{FromUserName};
345 0 ▶ if($e->{MsgType} == 10000){#群提示信息
Branch: 2 branches
BranchTrueFalseTotal
if ($e->{'MsgType'} == 10000) { } 0 0 0
elsif ($msg->{'content'} =~ m[^(\@.+?):<br/>(.*)$]s) { } 0 0 0
346 0 $msg->{type} = "group_notice";
347 }
348 elsif( $msg->{content}=~/^(\@.+?):<br\/>(.*)$/s ){
349 0 my ($member_id,$content) = ($1,$2);
350 0 ▶ if(defined $member_id and defined $content){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $member_id and defined $content) 0 0 0
Condition0%0/3
defined $member_id and defined $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $member_id and defined $content
defined $member_id defined $content
Truth table0%0/3
A and B
A= defined $member_idB= defined $content
ABresult
0X0
100
111
351 0 $msg->{sender_id} = $member_id;
352 0 $msg->{content} = $content;
353 }
354 }
355 }
356 else{#接收到的好友消息
357 0 $msg->{type} = "friend_message";
358 0 $msg->{sender_id} = $e->{FromUserName};
359 }
360 }
361 0 ▶ if($msg->{format} eq "media"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->{'format'} eq 'media') { } 0 0 0
elsif (defined $msg->{'content'}) { } 0 0 0
362 0 ▶ $msg->{content} = '[图片]' if $msg->{media_type} eq "image";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->{"media_type"} eq "image" 0 0 0
363 0 ▶ $msg->{content} = '[语音]' if $msg->{media_type} eq "voice";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->{"media_type"} eq "voice" 0 0 0
364 0 ▶ $msg->{content} = '[视频]' if $msg->{media_type} eq "video";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->{"media_type"} eq "video" 0 0 0
365 0 ▶ $msg->{content} = '[小视频]' if $msg->{media_type} eq "microvideo";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->{"media_type"} eq "microvideo" 0 0 0
366 0 ▶ $msg->{content} = '[表情]' if $msg->{media_type} eq "emoticon";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->{"media_type"} eq "emoticon" 0 0 0
367 0 ▶ $msg->{content} = '[文件]' if $msg->{media_type} eq "file";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->{"media_type"} eq "file" 0 0 0
368 }
369 elsif(defined $msg->{content}){
370 0 eval{$msg->{content} = Mojo::Util::html_unescape($msg->{content});};
371 0 ▶ $self->warn("html entities unescape fail: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
372 }
373 0 ▶ if($msg->{format} eq "app"){
Branch: 4 branches
BranchTrueFalseTotal
if ($msg->{'format'} eq 'app') { } 0 0 0
elsif ($msg->{'format'} eq 'revoke') { } 0 0 0
elsif ($msg->{'format'} eq 'card') { } 0 0 0
elsif ($msg->{'format'} eq 'payment') { } 0 0 0
374 0 eval{
375 0 $msg->{content}=~s/<br\/>/\n/g;
376 0 require Mojo::DOM;
377 0 my $dom = Mojo::DOM->new($msg->{content});
378 0 ▶ if( $dom->at('msg > appmsg > type')->content != 5){
Branch: 1 branch
BranchTrueFalseTotal
if ($dom->at("msg > appmsg > type")->content != 5) 0 0 0
379 0 $msg->{content} = "[应用分享]标题:$msg->{app_title}\n[应用分享]链接:$msg->{app_url}";
380 0 return;
381 }
382 0 $msg->{app_id} = $dom->at('msg > appmsg')->attr->{appid};
383 0 $msg->{app_title} = $dom->at('msg > appmsg > title')->content;
384 0 $msg->{app_name} = $dom->at('msg > appinfo > appname')->content;
385 0 $msg->{app_url} = $dom->at('msg > appmsg > url')->content;
386 0 $msg->{app_desc} = $dom->at('msg > appmsg > des')->content;
387 0 for( ($msg->{app_title},$msg->{app_desc},$msg->{app_url},$msg->{app_name}) ){
388 0 s/<!\[CDATA\[(.*?)\]\]>/$1/sg;
389 }
390 0 $msg->{app_url} = Mojo::Util::html_unescape($msg->{app_url});
391 0 ▶ $msg->{content} = "[应用分享]标题:@{[$msg->{app_title} || '未知']}\n[应用分享]描述:@{[$msg->{app_desc} || '未知']}\n[应用分享]应用:@{[$msg->{app_name} || '未知']}\n[应用分享]链接:@{[$msg->{app_url} || '未知']}";
Condition0%0/8
$msg->{'app_title'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'app_desc'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'app_name'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'app_url'} || "\346\234\252\347\237\245"
l!l
00
MC/DC0%0/1
$msg->{'app_title'} || "\346\234\252\347\237\245"
$msg->{'app_title'}
MC/DC0%0/1
$msg->{'app_desc'} || "\346\234\252\347\237\245"
$msg->{'app_desc'}
MC/DC0%0/1
$msg->{'app_name'} || "\346\234\252\347\237\245"
$msg->{'app_name'}
MC/DC0%0/1
$msg->{'app_url'} || "\346\234\252\347\237\245"
$msg->{'app_url'}
Truth table0%0/2
A
A= $msg->{'app_title'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'app_desc'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'app_name'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'app_url'}
Aresult
11
00
392 };
393 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
394 0 ▶ $self->warn("app message xml parse fail: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
395 0 $msg->{content} = "[应用分享]标题:$msg->{app_title}\n[应用分享]链接:$msg->{app_url}";
396 }
397 }
398 elsif($msg->{format} eq "revoke"){
399 #<sysmsg type=\"revokemsg\"><revokemsg><session>wxid_8mn2bmkx40so22</session><oldmsgid>1072643834</oldmsgid><msgid>4835386562261263795</msgid><replacemsg><![CDATA[你撤回了一条消息]]></replacemsg></revokemsg></sysmsg>
400 0 eval{
401 0 require Mojo::DOM;
402 0 my $dom = Mojo::DOM->new($msg->{content});
403 0 ▶ return if $dom->at('sysmsg')->attr->{type} ne 'revokemsg';
Branch: 1 branch
BranchTrueFalseTotal
if $dom->at("sysmsg")->attr->{"type"} ne "revokemsg" 0 0 0
404 #$msg->{revoke_session} = $dom->at('sysmsg > revokemsg > session')->content;
405 0 $msg->{revoke_id} = $dom->at('sysmsg > revokemsg > msgid')->content;
406 0 $msg->{content} = $dom->at('sysmsg > revokemsg > replacemsg')->content;
407 0 $msg->{content}=~s/<!\[CDATA\[(.*?)\]\]>/$1/g;
408  
409 #纠正自己撤回消息时,消息类型错乱的问题
410 0 ▶ if($msg->{content} eq '你撤回了一条消息' and $msg->{class} eq 'recv'){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->{"content"} eq "\344\275\240\346\222\244\345\233\236\344\272\206\344\270\200\346\235\241\346\266\210\346\201\257" and $msg->{"class"} eq "recv") 0 0 0
Condition0%0/3
$msg->{"content"} eq "\344\275\240\346\222\244\345\233\236\344\272\206\344\270\200\346\235\241\346\266\210\346\201\257" and $msg->{"class"} eq "recv"
!ll&&!rl&&r
000
MC/DC0%0/2
$msg->{"content"} eq "\344\275\240\346\222\244\345\233\236\344\272\206\344\270\200\346\235\241\346\266\210\346\201\257" and $msg->{"class"} eq "recv"
$msg->{"content"} eq "\344\275\240\346\222\244\345\233\236\344\272\206\344\270\200\346\235\241\346\266\210\346\201\257" $msg->{"class"} eq "recv"
Truth table0%0/3
A and B
A= $msg->{"content"} eq "\344\275\240\346\222\244\345\233\236\344\272\206\344\270\200\346\235\241\346\266\210\346\201\257"B= $msg->{"class"} eq "recv"
ABresult
0X0
100
111
411 0 $msg->{class} = 'send';
412 0 $msg->{source} = 'outer';
413 0 ▶ if($msg->{type} eq "group_message"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->{'type'} eq 'group_message') { } 0 0 0
elsif ($msg->{'type'} eq 'friend_message') { } 0 0 0
414 0 $msg->{sender_id} = $msg->{receiver_id};
415 0 delete $msg->{receiver_id};
416 }
417 elsif($msg->{type} eq "friend_message"){
418 0 ($msg->{sender_id},$msg->{receiver_id}) = ($msg->{receiver_id},$msg->{sender_id});
419 }
420 }
421 0 $msg->{content} = "[撤回消息](" . $msg->{content} . ")";
422 };
423 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
424 0 ▶ $self->warn("app message xml parse fail: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
425 0 $msg->{content} = "[撤回消息]";
426 }
427 }
428 elsif($msg->{format} eq "card"){
429 #<msg bigheadimgurl="http://wx.qlogo.cn/mmhead/ver_1/k99g2RHrEeib9KMhGmXZGSIGDjgnmiaX2acT2wl04so2ibsq8ysVPRkRRNQyRLmUVptBpcHt6lvUZym5JgOSd4fug/0" smallheadimgurl="http://wx.qlogo.cn/mmhead/ver_1/k99g2RHrEeib9KMhGmXZGSIGDjgnmiaX2acT2wl04so2ibsq8ysVPRkRRNQyRLmUVptBpcHt6lvUZym5JgOSd4fug/132" username="xxx" nickname="xxx" shortpy="" alias="" imagestatus="3" scene="17" province="xxx" city="xxx" sign="" sex="1" certflag="0" certinfo="" brandIconUrl="" brandHomeUrl="" brandSubscriptConfigUrl="" brandFlags="0" regionCode="CN_Shanghai_Pudong New District" />
430 0 $msg->{content}=~s/<br\/>/\n/g;
431 0 eval{
432 0 require Mojo::DOM;
433 0 my $dom = Mojo::DOM->new($msg->{content});
434 0 $msg->{card_avatar} = $dom->at('msg')->attr->{bigheadimgurl};
435 0 $msg->{card_name} = $dom->at('msg')->attr->{nickname};
436 0 $msg->{card_account} = $dom->at('msg')->attr->{alias};
437 0 $msg->{card_province} = $dom->at('msg')->attr->{province};
438 0 $msg->{card_city} = $dom->at('msg')->attr->{city};
439 0 $msg->{card_sex} = $self->code2sex($dom->at('msg')->attr->{sex});
440 };
441 0 ▶ $self->warn("app message xml parse fail: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
442 0 ▶ $msg->{content} = "[名片]昵称:@{[$msg->{card_name} || '未知']}\n[名片]性别:@{[$msg->{card_sex} || '未知']}\n[名片]位置:@{[$msg->{card_province} || '未知']} @{[$msg->{card_city} || '未知']}\n[名片]头像:@{[$msg->{card_avatar} || '未知']}";
Condition0%0/10
$msg->{'card_name'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'card_sex'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'card_province'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'card_city'} || "\346\234\252\347\237\245"
l!l
00
$msg->{'card_avatar'} || "\346\234\252\347\237\245"
l!l
00
MC/DC0%0/1
$msg->{'card_name'} || "\346\234\252\347\237\245"
$msg->{'card_name'}
MC/DC0%0/1
$msg->{'card_sex'} || "\346\234\252\347\237\245"
$msg->{'card_sex'}
MC/DC0%0/1
$msg->{'card_province'} || "\346\234\252\347\237\245"
$msg->{'card_province'}
MC/DC0%0/1
$msg->{'card_city'} || "\346\234\252\347\237\245"
$msg->{'card_city'}
MC/DC0%0/1
$msg->{'card_avatar'} || "\346\234\252\347\237\245"
$msg->{'card_avatar'}
Truth table0%0/2
A
A= $msg->{'card_name'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'card_sex'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'card_province'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'card_city'}
Aresult
11
00
Truth table0%0/2
A
A= $msg->{'card_avatar'}
Aresult
11
00
443 }
444 elsif($msg->{format} eq 'payment'){
445 #<msg><br/><appmsg appid=\"\" sdkver=\"\"><br/><title><![CDATA[微信转账]]></title><br/><des><![CDATA[X向你转账0.10元。如需收钱,请点此升级至最新版本]]></des><br/><action></action><br/><type>2000</type><br/><content><![CDATA[]]></content><br/><url><![CDATA[https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&text=text001&btn_text=btn_text_0]]></url><br/><thumburl><![CDATA[https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&text=text001&btn_text=btn_text_0]]></thumburl><br/><lowurl></lowurl><br/><extinfo><br/></extinfo><br/><wcpayinfo><br/><paysubtype>1</paysubtype><br/><feedesc><![CDATA[¥0.10]]></feedesc><br/><transcationid><![CDATA[100005020117111600024321086800000000]]></transcationid><br/><transferid><![CDATA[1000050201201711160100300000000]]></transferid><br/><invalidtime><![CDATA[1510910500]]></invalidtime><br/><begintransfertime><![CDATA[1510818700]]></begintransfertime><br/><effectivedate><![CDATA[1]]></effectivedate><br/><pay_memo><![CDATA[]]></pay_memo><br/><br/></wcpayinfo><br/></appmsg><br/></msg>
446 0 $msg->{content}=~s/<br\/>/\n/g;
447 0 eval{
448 0 require Mojo::DOM;
449 0 my $dom = Mojo::DOM->new($msg->{content});
450 0 $msg->{content} = $dom->at('msg > appmsg > des')->content;
451 0 $msg->{content}=~s/<!\[CDATA\[(.*?)\]\]>/$1/g;
452 };
453 0 ▶ $self->warn("payment message xml parse fail: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
454 0 $msg->{content} = "[转账](" . $msg->{content} . ")";
455 }
456 0 $self->message_queue->put(Mojo::Weixin::Message->new($msg));
457 }
458 }
459  
460 0 ▶ if($json->{ContinueFlag}!=0){
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"ContinueFlag"} != 0) 0 0 0
461 0 $self->_sync();
462 0 return;
463 }
464 }
465  
466 0 ▶sub send_message{
Subroutine send_message: not called CC=7 SCAR=40.3
467 0 my $self = shift;
468 0 my $object = shift;
469 0 my $content = shift;
470 0 my $callback = shift;
471 0 ▶ if( ref($object) ne "Mojo::Weixin::Friend" and ref($object) ne "Mojo::Weixin::Group") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group") 0 0 0
Condition0%0/3
ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group"
ref $object ne "Mojo::Weixin::Friend" ref $object ne "Mojo::Weixin::Group"
Truth table0%0/3
A and B
A= ref $object ne "Mojo::Weixin::Friend"B= ref $object ne "Mojo::Weixin::Group"
ABresult
0X0
100
111
472 0 $self->error("无效的发送消息对象");
473 0 return;
474 }
475 0 ▶ my $id = sub{my $r = sprintf "%.3f", rand();$r=~s/\.//g;my $t = $self->now() . $r;return $t}->();
Subroutine __ANON__: not called CC=1 SCAR=6.9
476 0 ▶ my $msg = Mojo::Weixin::Message->new(
Branch: 3 branches
BranchTrueFalseTotal
ref $object eq 'Mojo::Weixin::Friend' ? : 0 0 0
ref $object eq 'Mojo::Weixin::Group' ? : 0 0 0
ref $object eq 'Mojo::Weixin::Group' ? : 0 0 0
477 id => $id,
478 uid=> $id,
479 content => $content,
480 sender_id => $self->user->id,
481 receiver_id => (ref $object eq "Mojo::Weixin::Friend"?$object->id : undef),
482 group_id =>(ref $object eq "Mojo::Weixin::Group"?$object->id : undef),
483 type => (ref $object eq "Mojo::Weixin::Group"?"group_message":"friend_message"),
484 class => "send",
485 format => "text",
486 from => "code",
487 );
488  
489 0 ▶ $callback->($self,$msg) if ref $callback eq "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback eq "CODE" 0 0 0
490 0 $self->emit(before_send_message=>$msg);
491 0 $self->message_queue->put($msg);
492  
493 }
494 1 my %KEY_MAP_MEDIA_TYPE = reverse %KEY_MAP_MEDIA_CODE;
495 0 ▶sub send_media {
Subroutine send_media: not called CC=26 SCAR=65.5
496 0 my $self = shift;
497 0 my $object = shift;
498 0 my $media = shift;
499 0 my $callback = shift;
500 0 ▶ if( ref($object) ne "Mojo::Weixin::Friend" and ref($object) ne "Mojo::Weixin::Group") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group") 0 0 0
Condition0%0/3
ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group"
ref $object ne "Mojo::Weixin::Friend" ref $object ne "Mojo::Weixin::Group"
Truth table0%0/3
A and B
A= ref $object ne "Mojo::Weixin::Friend"B= ref $object ne "Mojo::Weixin::Group"
ABresult
0X0
100
111
501 0 $self->error("无效的发送消息对象");
502 0 return;
503 }
504 0 my $media_info = {};
505 0 ▶ if(ref $media eq ""){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $media eq '') { } 0 0 0
elsif (ref $media eq 'HASH') { } 0 0 0
506 0 $media_info->{media_path} = $media;
507 }
508 elsif(ref $media eq "HASH"){
509 0 $media_info = $media;
510 0 ▶ if(defined $media_info->{media_id}){#定义了media_id意味着不会上传文件,忽略media_path
Branch: 1 branch
BranchTrueFalseTotal
if (defined $media_info->{"media_id"}) 0 0 0
511 0 my ($id,$code) = split(/:/,$media_info->{media_id},2);
512 0 ▶ $media_info->{media_id} = $id if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 0 0
513 0 ▶ $media_info->{media_code} = $code if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
514 0 ▶ if(!defined $media_info->{media_code} and defined $media_info->{media_type}){
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $media_info->{'media_code'} and defined $media_info->{'media_type'}) { } 0 0 0
elsif (not defined $media_info->{'media_code'}) { } 0 0 0
Condition0%0/3
not defined $media_info->{"media_code"} and defined $media_info->{"media_type"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $media_info->{"media_code"} and defined $media_info->{"media_type"}
not defined $media_info->{"media_code"} defined $media_info->{"media_type"}
Truth table0%0/3
not(A) and B
A= not defined $media_info->{"media_code"}B= defined $media_info->{"media_type"}
ABresult
0X0
100
111
515 0 ▶ $media_info->{media_code} = $KEY_MAP_MEDIA_CODE{$media_info->{media_type}} // 6;
Condition0%0/2
$Mojo::Weixin::KEY_MAP_MEDIA_CODE{$media_info->{"media_type"}} // 6
l!l
00
MC/DC0%0/1
$Mojo::Weixin::KEY_MAP_MEDIA_CODE{$media_info->{"media_type"}} // 6
$Mojo::Weixin::KEY_MAP_MEDIA_CODE{$media_info->{"media_type"}}
Truth table0%0/2
A
A= $Mojo::Weixin::KEY_MAP_MEDIA_CODE{$media_info->{"media_type"}}
Aresult
11
00
516 }
517 elsif(!defined $media_info->{media_code}){
518 0 $media_info->{media_code} = 6;
519 }
520 }
521 0 ▶ if(defined $media_info->{media_code} and !defined $media_info->{media_type}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $media_info->{"media_code"} and not defined $media_info->{"media_type"}) 0 0 0
Condition0%0/3
defined $media_info->{"media_code"} and not defined $media_info->{"media_type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $media_info->{"media_code"} and not defined $media_info->{"media_type"}
defined $media_info->{"media_code"} not defined $media_info->{"media_type"}
Truth table0%0/3
A and not(B)
A= defined $media_info->{"media_code"}B= not defined $media_info->{"media_type"}
ABresult
0X0
100
111
522 0 ▶ $media_info->{media_type} = $KEY_MAP_MEDIA_TYPE{$media_info->{media_code}} || 'file';
Condition0%0/2
$KEY_MAP_MEDIA_TYPE{$media_info->{'media_code'}} || 'file'
l!l
00
MC/DC0%0/1
$KEY_MAP_MEDIA_TYPE{$media_info->{'media_code'}} || 'file'
$KEY_MAP_MEDIA_TYPE{$media_info->{'media_code'}}
Truth table0%0/2
A
A= $KEY_MAP_MEDIA_TYPE{$media_info->{'media_code'}}
Aresult
11
00
523 }
524  
525 }
526  
527 my $media_type = $media_info->{media_type} eq "image" ? "[图片]"
528 : $media_info->{media_type} eq "emoticon" ? "[表情]"
529 : $media_info->{media_type} eq "video" ? "[视频]"
530 : $media_info->{media_type} eq "microvideo"? "[小视频]"
531 : $media_info->{media_type} eq "voicce" ? "[语音]"
532 0 ▶ : $media_info->{media_type} eq "file" ? "[文件]"
Branch: 6 branches
BranchTrueFalseTotal
$media_info->{'media_type'} eq 'image' ? : 0 0 0
$media_info->{'media_type'} eq 'emoticon' ? : 0 0 0
$media_info->{'media_type'} eq 'video' ? : 0 0 0
$media_info->{'media_type'} eq 'microvideo' ? : 0 0 0
$media_info->{'media_type'} eq 'voicce' ? : 0 0 0
$media_info->{'media_type'} eq 'file' ? : 0 0 0
533 : "[文件]"
534 ;
535
536 0 ▶ my $id = sub{my $r = sprintf "%.3f", rand();$r=~s/\.//g;my $t = $self->now() . $r;return $t}->();
Subroutine __ANON__: not called CC=1 SCAR=6.9
537 my $msg = Mojo::Weixin::Message->new(
538 id => $id,
539 uid=> $id,
540 media_id => $media_info->{media_id},
541 media_name => $media_info->{media_name},
542 media_type => $media_info->{media_type},
543 media_code => $media_info->{media_code},
544 media_path => $media_info->{media_path},
545 media_data => $media_info->{media_data},
546 media_mime => $media_info->{media_mime},
547 media_size => $media_info->{media_size},
548 media_mtime => $media_info->{media_mtime},
549 media_ext => $media_info->{media_ext},
550 0 ▶ content => "$media_type(" . ($media_info->{media_path} || $media_info->{media_id}) . ")",
Branch: 3 branches
BranchTrueFalseTotal
ref $object eq 'Mojo::Weixin::Friend' ? : 0 0 0
ref $object eq 'Mojo::Weixin::Group' ? : 0 0 0
ref $object eq 'Mojo::Weixin::Group' ? : 0 0 0
Condition0%0/3
$media_info->{'media_path'} || $media_info->{'media_id'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$media_info->{'media_path'} || $media_info->{'media_id'}
$media_info->{'media_path'} $media_info->{'media_id'}
Truth table0%0/3
A || B
A= $media_info->{'media_path'}B= $media_info->{'media_id'}
ABresult
1X1
011
000
551 sender_id => $self->user->id,
552 receiver_id => (ref $object eq "Mojo::Weixin::Friend"?$object->id : undef),
553 group_id =>(ref $object eq "Mojo::Weixin::Group"?$object->id : undef),
554 type => (ref $object eq "Mojo::Weixin::Group"?"group_message":"friend_message"),
555 class => "send",
556 format => "media",
557 );
558  
559 0 ▶ $callback->($self,$msg) if ref $callback eq "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback eq "CODE" 0 0 0
560 0 $self->message_queue->put($msg);
561 }
562  
563 0 ▶sub upload_media {
Subroutine upload_media: not called CC=1 SCAR=6.9
564 0 my $self = shift;
565 0 my $opt = shift;
566 0 my $callback = pop;
567 0 my $msg = Mojo::Weixin::Message->new(%$opt);
568 0 ▶ $self->_upload_media($msg,sub{
Subroutine __ANON__: not called CC=2 SCAR=17.9
569 0 my($msg,$json) = @_;
570 0 ▶ $callback->({
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback eq "CODE" 0 0 0
571 media_id => $msg->media_id,
572 media_code => $msg->media_code,
573 media_type => $msg->media_type,
574 media_path => $msg->media_path,
575 media_name => $msg->media_name,
576 media_size => $msg->media_size,
577 media_mime => $msg->media_mime,
578 media_mtime => $msg->media_mtime,
579 media_ext => $msg->media_ext,
580 }) if ref $callback eq "CODE";
581 0 });
582 }
583 0 ▶sub reply_message{
Subroutine reply_message: not called CC=7 SCAR=40.3
584 0 my $self = shift;
585 0 my $msg = shift;
586 0 my $content = shift;
587 0 my $callback = shift;
588 0 ▶ if($msg->class eq "recv"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->class eq 'recv') { } 0 0 0
elsif ($msg->class eq 'send') { } 0 0 0
589 0 ▶ if($msg->type eq "group_message"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->type eq 'group_message') { } 0 0 0
elsif ($msg->type eq 'friend_message') { } 0 0 0
590 0 $self->send_message($msg->group,$content,$callback);
591 }
592 elsif($msg->type eq "friend_message"){
593 0 $self->send_message($msg->sender,$content,$callback);
594 }
595 }
596 elsif($msg->class eq "send"){
597 0 ▶ if($msg->type eq "group_message"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->type eq 'group_message') { } 0 0 0
elsif ($msg->type eq 'friend_message') { } 0 0 0
598 0 $self->send_message($msg->group,$content,$callback);
599 }
600 elsif($msg->type eq "friend_message"){
601 0 $self->send_message($msg->receiver,$content,$callback);
602 }
603  
604 }
605 }
606  
607 0 ▶sub reply_media_message {
Subroutine reply_media_message: not called CC=7 SCAR=40.3
608 0 my $self = shift;
609 0 my $msg = shift;
610 0 my $media = shift;
611 0 my $callback = shift;
612 0 ▶ if($msg->class eq "recv"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->class eq 'recv') { } 0 0 0
elsif ($msg->class eq 'send') { } 0 0 0
613 0 ▶ if($msg->type eq "group_message"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->type eq 'group_message') { } 0 0 0
elsif ($msg->type eq 'friend_message') { } 0 0 0
614 0 $self->send_media($msg->group,$media,$callback);
615 }
616 elsif($msg->type eq "friend_message"){
617 0 $self->send_media($msg->sender,$media,$callback);
618 }
619 }
620 elsif($msg->class eq "send"){
621 0 ▶ if($msg->type eq "group_message"){
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->type eq 'group_message') { } 0 0 0
elsif ($msg->type eq 'friend_message') { } 0 0 0
622 0 $self->send_media($msg->group,$media,$callback);
623 }
624 elsif($msg->type eq "friend_message"){
625 0 $self->send_media($msg->receiver,$callback);
626 }
627  
628 }
629 }
630 0 ▶sub revoke_message {
Subroutine revoke_message: not called CC=10 SCAR=47.0
631 0 my $self = shift;
632 0 my ($msg_id, $receiver_id);
633 0 ▶ if(not $_[0]){
Branch: 2 branches
BranchTrueFalseTotal
if (not $_[0]) { } 0 0 0
elsif (ref $_[0] eq 'Mojo::Weixin::Message') { } 0 0 0
634 0 $self->error("撤回消息失败: 无效的msg对象或者msg_id");
635 0 return;
636 }
637 elsif(ref $_[0] eq "Mojo::Weixin::Message"){
638 0 ▶ if( not $_[0]->is_success){
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]->is_success) 0 0 0
639 0 $self->error("撤回消息失败: 无法撤回未成功发送的消息");
640 0 return;
641 }
642 0 $_[0]->dump;
643 0 $msg_id = $_[0]->id;
644 0 ▶ $receiver_id = $_[0]->type eq 'group_message'?$_[0]->group_id:$_[0]->receiver_id;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->type eq 'group_message' ? : 0 0 0
645 0 ▶ if(not defined $msg_id or not defined $receiver_id){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $msg_id and defined $receiver_id) 0 0 0
Condition0%0/3
defined $msg_id and defined $receiver_id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $msg_id and defined $receiver_id
defined $msg_id defined $receiver_id
Truth table0%0/3
A and B
A= defined $msg_idB= defined $receiver_id
ABresult
0X0
100
111
646 0 $self->error("撤回消息失败: msg对象中包含无效的msg_id");
647 0 return;
648 }
649 }
650 else{
651 0 ($msg_id, $receiver_id) = $_[0] =~ /^([^:]+):(.+)$/;
652 0 ▶ if(not defined $msg_id or not defined $receiver_id){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $msg_id and defined $receiver_id) 0 0 0
Condition0%0/3
defined $msg_id and defined $receiver_id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $msg_id and defined $receiver_id
defined $msg_id defined $receiver_id
Truth table0%0/3
A and B
A= defined $msg_idB= defined $receiver_id
ABresult
0X0
100
111
653 0 $self->error("撤回消息失败: 无效的msg_id");
654 0 return;
655 }
656 }
657 0 my $ret = $self->_revoke_message($msg_id,$receiver_id);
658 0 ▶ if($ret){
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 0 0 0
659 0 $self->debug("消息[$msg_id]撤回成功");
660 }
661 else{
662 0 $self->debug("消息[$msg_id]撤回失败");
663 }
664 0 return $ret;
665 }
666  
667  
668 1 1;
« Weixin/Plugin/IRCShell.pm ↑ Summary Weixin/Plugin/KnowledgeBase.pm »