line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Weixin::Message::Base; |
2
|
1
|
|
|
1
|
|
7
|
use Mojo::Weixin::Base 'Mojo::EventEmitter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
3
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
7
|
use Mojo::Util qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1461
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub client { |
8
|
0
|
|
|
0
|
0
|
|
return $Mojo::Weixin::_CLIENT; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
sub is_success{ |
11
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
12
|
0
|
0
|
0
|
|
|
|
return (defined $self->code and $self->code == 0)?1:0; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
sub send_status{ |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
0
|
|
|
|
|
|
my %opt = @_; |
17
|
0
|
|
|
|
|
|
$self->code($opt{code})->msg($opt{msg})->info($opt{info}); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
sub _parse_send_status_data { |
20
|
0
|
|
|
0
|
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
my $json = shift; |
22
|
0
|
0
|
|
|
|
|
if(defined $json){ |
23
|
0
|
0
|
|
|
|
|
if($json->{MsgID}){ |
24
|
0
|
0
|
|
|
|
|
my $id = $json->{MsgID} . ":" . ($self->type eq 'group_message'?$self->group_id : $self->receiver_id); |
25
|
0
|
|
|
|
|
|
$self->{id} = $id; |
26
|
|
|
|
|
|
|
} |
27
|
0
|
0
|
|
|
|
|
if($json->{BaseResponse}{Ret}!=0){ |
28
|
|
|
|
|
|
|
$self->send_status( |
29
|
|
|
|
|
|
|
code=>$json->{BaseResponse}{Ret}, |
30
|
|
|
|
|
|
|
msg=>"发送失败", |
31
|
0
|
|
0
|
|
|
|
info=>($json->{BaseResponse}{ErrMsg}||"unknown error"), |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else{ |
35
|
0
|
|
|
|
|
|
$self->send_status(code=>0,msg=>"发送成功",info=>"success"); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else{ |
39
|
0
|
|
|
|
|
|
$self->send_status(code=>-1,msg=>"发送失败",info=>"unknown data"); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
sub to_json_hash{ |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $json = {}; |
45
|
0
|
|
|
|
|
|
for my $key ( ( (keys %$self),qw(sender receiver group ) ) ){ |
46
|
0
|
0
|
|
|
|
|
next if substr($key,0,1) eq "_"; |
47
|
0
|
0
|
|
|
|
|
if($key eq "sender"){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
next if $self->type eq "group_notice"; |
49
|
0
|
|
|
|
|
|
$json->{sender} = $self->sender->displayname; |
50
|
0
|
|
|
|
|
|
$json->{sender_account} = $self->sender->account; |
51
|
0
|
|
|
|
|
|
$json->{sender_uid} = $self->sender->uid; |
52
|
0
|
|
|
|
|
|
$json->{sender_name} = $self->sender->name; |
53
|
0
|
|
|
|
|
|
$json->{sender_markname} = $self->sender->markname; |
54
|
0
|
0
|
|
|
|
|
$json->{sender_category} = $self->sender->category if $self->sender->type eq 'friend'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif($key eq "receiver"){ |
57
|
0
|
0
|
0
|
|
|
|
next if $self->type eq 'group_message' and $self->class eq 'send'; |
58
|
0
|
|
|
|
|
|
$json->{receiver} = $self->receiver->displayname; |
59
|
0
|
|
|
|
|
|
$json->{receiver_account} = $self->receiver->account; |
60
|
0
|
|
|
|
|
|
$json->{receiver_uid} = $self->receiver->uid; |
61
|
0
|
|
|
|
|
|
$json->{receiver_name} = $self->receiver->name; |
62
|
0
|
|
|
|
|
|
$json->{receiver_markname} = $self->receiver->markname; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif($key eq "group"){ |
65
|
0
|
0
|
0
|
|
|
|
next if ($self->type ne "group_message" and $self->type ne "group_notice"); |
66
|
0
|
|
|
|
|
|
$json->{group} = $self->group->displayname; |
67
|
0
|
|
|
|
|
|
$json->{group_uid} = $self->group->uid; |
68
|
0
|
|
|
|
|
|
$json->{group_name} = $self->group->name; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif($key eq "media_data"){ |
71
|
0
|
0
|
|
|
|
|
$json->{$key} = defined $self->{$key}?Mojo::Util::b64_encode($self->{$key}):""; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
elsif($key eq 'events'){next} |
74
|
|
|
|
|
|
|
elsif(ref $self->{$key} eq ""){ |
75
|
0
|
|
0
|
|
|
|
$json->{$key} = $self->{$key} || ""; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
return $json; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub is_at{ |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
0
|
0
|
|
|
|
|
return if not $self->content; |
84
|
0
|
|
|
|
|
|
my $object; |
85
|
|
|
|
|
|
|
my $displayname; |
86
|
0
|
0
|
|
|
|
|
if($self->class eq "recv"){ |
|
|
0
|
|
|
|
|
|
87
|
0
|
|
0
|
|
|
|
$object = shift || $self->receiver; |
88
|
0
|
|
|
|
|
|
$displayname = $object->displayname; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif($self->class eq "send"){ |
91
|
0
|
0
|
|
|
|
|
if($self->type eq "group_message"){ |
|
|
0
|
|
|
|
|
|
92
|
0
|
|
0
|
|
|
|
$object = shift || $self->group->me; |
93
|
0
|
|
|
|
|
|
$displayname = $object->displayname; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif($self->type=~/^friend_message$/){ |
96
|
0
|
|
0
|
|
|
|
$object = shift || $self->receiver; |
97
|
0
|
|
|
|
|
|
$displayname = $object->displayname; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
0
|
|
|
|
|
return if not $displayname; |
101
|
0
|
|
|
|
|
|
return $self->content =~/\@\Q$displayname\E( |"\xe2\x80\x85"|)/; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub remove_at{ |
105
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
106
|
0
|
|
|
|
|
|
my $object; |
107
|
|
|
|
|
|
|
my $displayname; |
108
|
0
|
0
|
|
|
|
|
if($self->class eq "recv"){ |
|
|
0
|
|
|
|
|
|
109
|
0
|
|
0
|
|
|
|
$object = shift || $self->receiver; |
110
|
0
|
|
|
|
|
|
$displayname = $object->displayname; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif($self->class eq "send"){ |
113
|
0
|
0
|
|
|
|
|
if($self->type eq "group_message"){ |
|
|
0
|
|
|
|
|
|
114
|
0
|
|
0
|
|
|
|
$object = shift || $self->group->me; |
115
|
0
|
|
|
|
|
|
$displayname = $object->displayname; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif($self->type=~/^friend_message$/){ |
118
|
0
|
|
0
|
|
|
|
$object = shift || $self->receiver; |
119
|
0
|
|
|
|
|
|
$displayname = $object->displayname; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
my $content = $self->content; |
123
|
0
|
|
|
|
|
|
$content=~s/\@\Q$displayname\E( |"\xe2\x80\x85"|)//g; |
124
|
0
|
|
|
|
|
|
$self->content($content); |
125
|
0
|
|
|
|
|
|
return $self; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub dump{ |
129
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
130
|
0
|
|
|
|
|
|
my $clone = {}; |
131
|
0
|
|
|
|
|
|
my $obj_name = blessed($self); |
132
|
0
|
|
|
|
|
|
for(keys %$self){ |
133
|
0
|
0
|
0
|
|
|
|
if(my $n=blessed($self->{$_})){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$clone->{$_} = "Object($n)"; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
elsif($_ eq "member" and ref($self->{$_}) eq "ARRAY"){ |
137
|
0
|
|
|
|
|
|
my $member_count = @{$self->{$_}}; |
|
0
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$clone->{$_} = [ "$member_count of Object(${obj_name}::Member)" ]; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif($_ eq 'media_data'){ |
141
|
0
|
|
|
|
|
|
$clone->{$_} = '[binary data not shown]'; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
elsif($_ eq 'events'){ |
144
|
0
|
|
|
|
|
|
next; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else{ |
147
|
0
|
|
|
|
|
|
$clone->{$_} = $self->{$_}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 1; |
151
|
0
|
|
|
|
|
|
local $Data::Dumper::Terse = 1; |
152
|
0
|
|
|
|
|
|
$self->client->print("Object($obj_name) " . Data::Dumper::Dumper($clone)); |
153
|
0
|
|
|
|
|
|
return $self; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
1; |