line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Weixin::Model; |
2
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
6
|
use base qw(Mojo::Weixin::Model::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
373
|
|
4
|
1
|
|
|
1
|
|
5
|
use List::Util qw(first); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
353
|
use Mojo::Weixin::Model::Remote::_webwxinit; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
367
|
use Mojo::Weixin::Model::Remote::_webwxgetcontact; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
356
|
use Mojo::Weixin::Model::Remote::_webwxbatchgetcontact_friend; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
339
|
use Mojo::Weixin::Model::Remote::_webwxbatchgetcontact_group; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
9
|
1
|
|
|
1
|
|
6
|
use Mojo::Weixin::Model::Remote::_webwxbatchgetcontact_group_member; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
10
|
1
|
|
|
1
|
|
360
|
use Mojo::Weixin::Model::Remote::_webwxstatusnotify; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
11
|
1
|
|
|
1
|
|
328
|
use Mojo::Weixin::Model::Remote::_webwxcreatechatroom; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
12
|
1
|
|
|
1
|
|
836
|
use Mojo::Weixin::Model::Remote::_webwxupdatechatroom; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
13
|
1
|
|
|
1
|
|
490
|
use Mojo::Weixin::Model::Remote::_webwxoplog_markname; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
14
|
1
|
|
|
1
|
|
450
|
use Mojo::Weixin::Model::Remote::_webwxoplog_stick; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
15
|
1
|
|
|
1
|
|
497
|
use Mojo::Weixin::Model::Remote::_webwxverifyuser; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
16
|
1
|
|
|
1
|
|
340
|
use Mojo::Weixin::Model::Remote::_webwxgetheadimg; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
17
|
1
|
|
|
1
|
|
350
|
use Mojo::Weixin::User; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
18
|
1
|
|
|
1
|
|
5
|
use Mojo::Weixin::Group; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
19
|
1
|
|
|
1
|
|
4
|
use Mojo::Weixin::Const; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2677
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub model_init{ |
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
$self->state('updating'); |
24
|
0
|
|
|
|
|
|
$self->info("获取联系人信息..."); |
25
|
0
|
|
|
|
|
|
my $initinfo = $self->_webwxinit(); |
26
|
0
|
0
|
|
|
|
|
if(not defined $initinfo){ |
27
|
0
|
|
|
|
|
|
$self->error("获取联系人信息失败"); |
28
|
0
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
|
my($user,undef,$init_groups) = @$initinfo; |
31
|
0
|
0
|
|
|
|
|
if(defined $user){ |
32
|
0
|
|
|
|
|
|
$self->info("更新个人信息成功"); |
33
|
0
|
|
|
|
|
|
$self->user(Mojo::Weixin::User->new($user)); |
34
|
0
|
|
|
|
|
|
$self->_webwxstatusnotify($self->user->id,3); |
35
|
|
|
|
|
|
|
#$self->emit(update_user=>$self->user); |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
my $contactinfo = $self->_webwxgetcontact(); |
38
|
0
|
0
|
|
|
|
|
if(not defined $contactinfo){ |
39
|
0
|
|
|
|
|
|
$self->error("获取通讯录联系人信息失败"); |
40
|
0
|
|
|
|
|
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
my($friends,$contact_groups) = @$contactinfo; |
43
|
0
|
0
|
0
|
|
|
|
if(ref $friends eq "ARRAY" and @$friends>0){ |
44
|
|
|
|
|
|
|
#$self->friend([ map {Mojo::Weixin::Friend->new($_)} grep {$_->{id} ne $user->{id}} @$friends ]); |
45
|
0
|
|
|
|
|
|
my @tmp; |
46
|
0
|
|
|
|
|
|
for(@$friends){ |
47
|
0
|
0
|
|
|
|
|
if($_->{id} ne $user->{id}){ |
48
|
0
|
|
|
|
|
|
push @tmp,Mojo::Weixin::Friend->new($_); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else{ |
51
|
0
|
|
|
|
|
|
$self->user(Mojo::Weixin::User->new($_)); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
$self->friend(\@tmp); |
55
|
0
|
|
|
|
|
|
$self->info("更新好友信息成功"); |
56
|
0
|
|
|
|
|
|
$self->emit(update_user=>$self->user); |
57
|
0
|
|
|
|
|
|
$self->emit(update_friend=>$self->friend); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my %groups_id; |
61
|
0
|
0
|
0
|
|
|
|
if(ref $init_groups eq "ARRAY" and @$init_groups >0){ |
62
|
0
|
|
|
|
|
|
for(@$init_groups){ |
63
|
0
|
|
|
|
|
|
$groups_id{$_->{id}} = 1; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
0
|
0
|
|
|
|
if(ref $contact_groups eq "ARRAY" and @$contact_groups>0){ |
67
|
0
|
|
|
|
|
|
for(@$contact_groups){ |
68
|
0
|
|
|
|
|
|
$groups_id{$_->{id}} = 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if(keys %groups_id){ |
72
|
0
|
|
|
|
|
|
my @groups = $self->_webwxbatchgetcontact_group(0,keys %groups_id); |
73
|
0
|
0
|
|
|
|
|
if(@groups){ |
74
|
0
|
0
|
|
|
|
|
if($self->is_init_group_member){ |
75
|
0
|
|
|
|
|
|
$self->group([]); |
76
|
0
|
|
|
|
|
|
for my $g (@groups){ |
77
|
0
|
|
|
|
|
|
my @member = $self->_webwxbatchgetcontact_group_member($g->{_eid},map {$_->{id}} @{$g->{member}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
$g->{member} = \@member if @member; |
79
|
0
|
|
|
|
|
|
my $group = Mojo::Weixin::Group->new($g); |
80
|
0
|
|
|
|
|
|
push @{ $self->group },$group; |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->info("更新群组[ @{[$group->displayname]} ]信息成功"); |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
$self->emit(update_group=>$self->group); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else{ |
86
|
0
|
|
|
|
|
|
$self->group([ map { Mojo::Weixin::Group->new($_) } @groups ]); |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->info("更新群组[ @{[$_->displayname]} ]信息成功") for $self->groups; |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->emit(update_group=>$self->group); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else{ |
92
|
0
|
|
|
|
|
|
$self->error("更新群组信息失败"); |
93
|
0
|
|
|
|
|
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
return 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
0
|
0
|
|
sub update_user { |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
sub update_friend{ |
102
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
103
|
0
|
0
|
|
|
|
|
my @friend_ids = map {ref $_ eq "Mojo::Weixin::Friend"?$_->id:$_} @_; |
|
0
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if(@friend_ids){ |
105
|
0
|
|
|
|
|
|
my @return = $self->_webwxbatchgetcontact_friend(@friend_ids); |
106
|
0
|
0
|
|
|
|
|
return if not @return; |
107
|
0
|
|
|
|
|
|
$self->add_friend(Mojo::Weixin::Friend->new($_)) for @return; |
108
|
0
|
|
|
|
|
|
return 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
sub update_group{ |
112
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
113
|
0
|
0
|
|
|
|
|
my @group_ids = map {ref $_ eq "Mojo::Weixin::Group"?$_->id:$_} @_; |
|
0
|
|
|
|
|
|
|
114
|
0
|
|
0
|
|
|
|
my $is_update_group_member = $_[1] // $self->is_update_group_member; |
115
|
0
|
0
|
|
|
|
|
if(@group_ids){ |
116
|
0
|
|
|
|
|
|
my @return = $self->_webwxbatchgetcontact_group($is_update_group_member,@group_ids); |
117
|
0
|
0
|
|
|
|
|
return if not @return; |
118
|
0
|
|
|
|
|
|
$self->add_group(Mojo::Weixin::Group->new($_)) for @return; |
119
|
0
|
|
|
|
|
|
return 1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub search_friend{ |
124
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
my %p = @_; |
126
|
0
|
0
|
|
|
|
|
if($p{_check_remote}){ |
127
|
0
|
0
|
|
|
|
|
if(wantarray){ |
128
|
0
|
|
|
|
|
|
my @f = $self->_search($self->friend,@_); |
129
|
0
|
0
|
|
|
|
|
if(@f){return @f} |
|
0
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
else{ |
131
|
0
|
0
|
|
|
|
|
$self->update_friend($p{id}) if defined $p{id}; |
132
|
0
|
|
|
|
|
|
return $self->_search($self->friend,@_); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
else{ |
136
|
0
|
|
|
|
|
|
my $f = $self->_search($self->friend,@_); |
137
|
0
|
0
|
|
|
|
|
if(defined $f){return $f } |
|
0
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
else{ |
139
|
0
|
0
|
|
|
|
|
$self->update_friend($p{id}) if defined $p{id}; |
140
|
0
|
|
|
|
|
|
return $self->_search($self->friend,@_); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
0
|
|
|
|
|
|
return $self->_search($self->friend,@_); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
sub search_group{ |
147
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
148
|
0
|
|
|
|
|
|
my %p = @_; |
149
|
0
|
0
|
|
|
|
|
if($p{_check_remote}){ |
150
|
0
|
0
|
|
|
|
|
if(wantarray){ |
151
|
0
|
|
|
|
|
|
my @g = $self->_search($self->group,@_); |
152
|
0
|
0
|
|
|
|
|
if(@g){return @g} |
|
0
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
else{ |
154
|
0
|
0
|
|
|
|
|
$self->update_group($p{id}) if defined $p{id}; |
155
|
0
|
|
|
|
|
|
return $self->_search($self->group,@_); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else{ |
159
|
0
|
|
|
|
|
|
my $g = $self->_search($self->group,@_); |
160
|
0
|
0
|
|
|
|
|
if(defined $g){return $g } |
|
0
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
else{ |
162
|
0
|
0
|
|
|
|
|
$self->update_group($p{id}) if defined $p{id}; |
163
|
0
|
|
|
|
|
|
return $self->_search($self->group,@_); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
|
return $self->_search($self->group,@_); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
sub add_friend{ |
170
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
171
|
0
|
|
|
|
|
|
my $friend = shift; |
172
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型\n") if ref $friend ne "Mojo::Weixin::Friend"; |
173
|
0
|
0
|
|
|
|
|
$self->emit(new_friend=>$friend) if $self->_add($self->friend,$friend) == 1; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
sub remove_friend{ |
176
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
177
|
0
|
|
|
|
|
|
my $friend = shift; |
178
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型\n") if ref $friend ne "Mojo::Weixin::Friend"; |
179
|
0
|
0
|
|
|
|
|
$self->emit(lose_friend=>$friend) if $self->_remove($self->friend,$friend) == 1; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
sub add_group{ |
182
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
183
|
0
|
|
|
|
|
|
my $group = shift; |
184
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型\n") if ref $group ne "Mojo::Weixin::Group"; |
185
|
0
|
0
|
|
|
|
|
$self->emit(new_group=>$group) if $self->_add($self->group,$group) == 1; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
sub remove_group{ |
188
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
189
|
0
|
|
|
|
|
|
my $group = shift; |
190
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型\n") if ref $group ne "Mojo::Weixin::Group"; |
191
|
0
|
0
|
|
|
|
|
$self->emit(lose_group=>$group) if $self->_remove($self->group,$group) == 1; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub is_group_id{ |
195
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
196
|
0
|
|
|
|
|
|
my $gid = shift; |
197
|
0
|
0
|
|
|
|
|
return $gid=~/^\@\@|\@chatroom$/ ? 1 : 0; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
sub code2sex{ |
200
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
201
|
0
|
|
|
|
|
|
my $c = shift; |
202
|
0
|
|
|
|
|
|
my %h = ( |
203
|
|
|
|
|
|
|
0 => "", |
204
|
|
|
|
|
|
|
1 => "male", |
205
|
|
|
|
|
|
|
2 => "female", |
206
|
|
|
|
|
|
|
); |
207
|
0
|
|
0
|
|
|
|
return $h{$c} || ""; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub each_friend{ |
211
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
212
|
0
|
|
|
|
|
|
my $callback = shift; |
213
|
0
|
0
|
|
|
|
|
$self->die("参数必须是函数引用") if ref $callback ne "CODE"; |
214
|
0
|
|
|
|
|
|
for (@{$self->friend}){ |
|
0
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
$callback->($self,$_); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
sub each_group{ |
219
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
220
|
0
|
|
|
|
|
|
my $callback = shift; |
221
|
0
|
0
|
|
|
|
|
$self->die("参数必须是函数引用") if ref $callback ne "CODE"; |
222
|
0
|
|
|
|
|
|
for (@{$self->group}){ |
|
0
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
$callback->($self,$_); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub friends{ |
228
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
229
|
0
|
|
|
|
|
|
return @{$self->friend}; |
|
0
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
sub groups{ |
232
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
233
|
0
|
|
|
|
|
|
return @{$self->group}; |
|
0
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub set_markname { |
237
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
238
|
0
|
|
|
|
|
|
my $object = shift; |
239
|
0
|
|
|
|
|
|
my $markname = shift; |
240
|
0
|
0
|
0
|
|
|
|
if(ref $object ne "Mojo::Weixin::Friend" and ref $object ne "Mojo::Weixin::Group::Member"){ |
241
|
0
|
|
|
|
|
|
$self->die("无效的对象数据类型"); |
242
|
0
|
|
|
|
|
|
return; |
243
|
|
|
|
|
|
|
} |
244
|
0
|
0
|
|
|
|
|
$self->warn("设置群成员备注的功能当前可能已被官方屏蔽") if ref $object ne "Mojo::Weixin::Group::Member"; |
245
|
0
|
|
|
|
|
|
my $displayname = $object->displayname; |
246
|
0
|
|
|
|
|
|
my $ret = $self->_webwxoplog_markname($object->id,$markname); |
247
|
0
|
0
|
|
|
|
|
if($ret){ |
248
|
0
|
|
|
|
|
|
$self->info("设置对象 $displayname 备注[ $markname ]成功"); |
249
|
0
|
|
|
|
|
|
return 1; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
else{ |
252
|
0
|
|
|
|
|
|
$self->info("设置对象 $displayname 备注[ $markname ]失败"); |
253
|
0
|
|
|
|
|
|
return 0; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub stick{ |
259
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
260
|
0
|
|
|
|
|
|
my $object = shift; |
261
|
0
|
|
|
|
|
|
my $op = shift; |
262
|
0
|
0
|
0
|
|
|
|
if(ref $object ne "Mojo::Weixin::Group" and ref $object ne "Mojo::Weixin::Friend"){ |
263
|
0
|
|
|
|
|
|
$self->die("无效的对象数据类型"); |
264
|
0
|
|
|
|
|
|
return; |
265
|
|
|
|
|
|
|
} |
266
|
0
|
|
0
|
|
|
|
my $ret = $self->_webwxoplog_stick($object->id,$op // 1); |
267
|
0
|
|
|
|
|
|
my $displayname = $object->displayname; |
268
|
0
|
0
|
|
|
|
|
if($ret){ |
269
|
0
|
0
|
|
|
|
|
$op?$self->info("设置对象[ $displayname ]置顶成功"): $self->info("取消对象[ $displayname ]置顶成功"); |
270
|
0
|
|
|
|
|
|
return 1; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
else{ |
273
|
0
|
0
|
|
|
|
|
$op?$self->info("设置对象[ $displayname ]置顶失败"): $self->info("取消对象[ $displayname ]置顶失败"); |
274
|
0
|
|
|
|
|
|
return 0; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
sub create_group { |
279
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
280
|
0
|
|
|
|
|
|
my $friends; |
281
|
|
|
|
|
|
|
my $displayname; |
282
|
0
|
0
|
|
|
|
|
if(ref $_[0] eq "HASH"){ |
|
|
0
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
my %opt = @_; |
284
|
0
|
|
|
|
|
|
$friends = $opt{friends}; |
285
|
0
|
|
|
|
|
|
$displayname = $opt{displayname}; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
elsif(ref $_[0] eq "ARRAY"){ |
288
|
0
|
|
|
|
|
|
$friends = $_[0]; |
289
|
0
|
|
|
|
|
|
$displayname = $_[1]; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
else{ |
292
|
0
|
|
|
|
|
|
$friends = \@_; |
293
|
|
|
|
|
|
|
} |
294
|
0
|
|
|
|
|
|
my $group_info = $self->_webwxcreatechatroom($friends,$displayname); |
295
|
0
|
0
|
|
|
|
|
if(not defined $group_info){ |
296
|
0
|
0
|
|
|
|
|
$self->error("创建群聊". (defined $displayname?"[ $displayname ]":"") . "失败"); |
297
|
0
|
|
|
|
|
|
return; |
298
|
|
|
|
|
|
|
} |
299
|
0
|
|
0
|
|
|
|
my $group = Mojo::Weixin::Group->new($self->_webwxbatchgetcontact_group($group_info->{id}) // $group_info); |
300
|
0
|
|
|
|
|
|
$self->add_group($group); |
301
|
0
|
|
|
|
|
|
$self->info("创建群聊[ ". $group->displayname ." ]成功"); |
302
|
0
|
|
|
|
|
|
return $group; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub set_group_displayname { |
306
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
307
|
0
|
|
|
|
|
|
my $group = shift; |
308
|
0
|
|
|
|
|
|
my $displayname = shift; |
309
|
0
|
0
|
|
|
|
|
if(ref $group ne "Mojo::Weixin::Group"){ |
310
|
0
|
|
|
|
|
|
$self->die("无效的对象数据类型"); |
311
|
0
|
|
|
|
|
|
return; |
312
|
|
|
|
|
|
|
} |
313
|
0
|
0
|
|
|
|
|
if(not $displayname){ |
314
|
0
|
|
|
|
|
|
$self->die("无效的显示名称"); |
315
|
0
|
|
|
|
|
|
return; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
0
|
|
|
|
|
|
my $ret = $self->_webwxupdatechatroom("mod",$group,$displayname); |
319
|
0
|
0
|
|
|
|
|
if($ret){ |
320
|
0
|
|
|
|
|
|
$self->info("修改群显示名称[ $displayname ]成功"); |
321
|
0
|
|
|
|
|
|
return 1; |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
else{ |
324
|
0
|
|
|
|
|
|
$self->info("修改群显示名称[ $displayname ]失败"); |
325
|
0
|
|
|
|
|
|
return 0; |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub invite_friend{ |
330
|
0
|
|
|
0
|
0
|
|
my $self =shift; |
331
|
0
|
|
|
|
|
|
my $group = shift; |
332
|
0
|
|
|
|
|
|
my @friends = @_; |
333
|
0
|
|
|
|
|
|
for(@friends){ |
334
|
0
|
0
|
|
|
|
|
$self->die("非好友对象") if not $_->is_friend; |
335
|
|
|
|
|
|
|
} |
336
|
0
|
0
|
|
|
|
|
$self->die("非群组对象") if not $group->is_group; |
337
|
0
|
|
|
|
|
|
my $ret = $self->_webwxupdatechatroom("add",$group,@friends); |
338
|
0
|
0
|
|
|
|
|
if($ret){ |
339
|
0
|
|
|
|
|
|
$self->update_group($group); |
340
|
0
|
|
|
|
|
|
$self->info("邀请好友 " . join("、",map {$_->displayname} grep {defined $_} @friends[0..2]) . "... 加入群[ " . $group->displayname . " ]成功"); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
341
|
0
|
|
|
|
|
|
return 1; |
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
else{ |
344
|
0
|
|
|
|
|
|
$self->info("邀请好友 " . join("、",map {$_->displayname} grep {defined $_} @friends[0..2]) . "... 加入群[ " . $group->displayname . " ]失败"); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
|
return 0; |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
sub kick_group_member{ |
349
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
350
|
0
|
|
|
|
|
|
my $group = shift; |
351
|
0
|
|
|
|
|
|
my @members = @_; |
352
|
0
|
|
|
|
|
|
for(@members){ |
353
|
0
|
0
|
|
|
|
|
$self->die("非群成员对象") if not $_->is_group_member; |
354
|
|
|
|
|
|
|
} |
355
|
0
|
0
|
|
|
|
|
$self->die("非群组对象") if not $group->is_group; |
356
|
0
|
|
|
|
|
|
my $ret = $self->_webwxupdatechatroom("del",$group,@members); |
357
|
0
|
0
|
|
|
|
|
if($ret){ |
358
|
0
|
|
|
|
|
|
$group->remove_group_member($_) for @members; |
359
|
0
|
|
|
|
|
|
$self->info("从群组[ ". $group->displayname. " ]移除群成员 " . join("、",map {$_->displayname} grep {defined $_} @members[0..2]) . " 成功"); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
360
|
0
|
|
|
|
|
|
return 1; |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
else{ |
363
|
0
|
|
|
|
|
|
$self->info("从群组[ ". $group->displayname. " ]移除群成员 " . join("、",map {$_->displayname} grep {defined $_} @members[0..2]) . " 失败"); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
364
|
0
|
|
|
|
|
|
return 0; |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
sub make_friend{ |
369
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
370
|
0
|
|
|
|
|
|
my $member = shift; |
371
|
0
|
|
0
|
|
|
|
my $content = shift || ''; |
372
|
0
|
0
|
|
|
|
|
$self->die("非群组成员对象") if not $member->is_group_member; |
373
|
0
|
|
|
|
|
|
my $ret = $self->_webwxverifyuser($member->id,$content,2,""); |
374
|
0
|
0
|
|
|
|
|
if($ret){ |
375
|
0
|
0
|
|
|
|
|
$self->info("好友请求[ ". $member->displayname . " ]发送成功: " . ($content?$content:"(验证内容为空)")); |
376
|
0
|
|
|
|
|
|
return 1; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
else{ |
379
|
0
|
0
|
|
|
|
|
$self->info("好友请求[ ". $member->displayname . " ]发送失败: " . ($content?$content:"(验证内容为空)")); |
380
|
0
|
|
|
|
|
|
return 0; |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub accept_friend_request{ |
385
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
386
|
0
|
|
|
|
|
|
my $id = shift; |
387
|
0
|
|
|
|
|
|
my $displayname = shift; |
388
|
0
|
|
|
|
|
|
my $ticket = shift; |
389
|
0
|
|
|
|
|
|
my $ret = $self->_webwxverifyuser($id,"",3,$ticket); |
390
|
0
|
0
|
|
|
|
|
if($ret){ |
391
|
0
|
|
|
|
|
|
$self->info("[ " . $displayname . " ]的好友请求已被接受"); |
392
|
0
|
|
|
|
|
|
return 1; |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
else{ |
395
|
0
|
|
|
|
|
|
$self->info("[ " . $displayname . " ]的好友请求接受失败"); |
396
|
0
|
|
|
|
|
|
return 0; |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub get_avatar { |
401
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
402
|
0
|
|
|
|
|
|
my $object = shift; |
403
|
0
|
|
|
|
|
|
my $callback = shift; |
404
|
0
|
0
|
|
|
|
|
if(ref($object) !~ /Mojo::Weixin::User|Mojo::Weixin::Friend|Mojo::Weixin::Group|Mojo::Weixin::Group::Member/){ |
|
|
0
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
$self->die("不支持的数据类型"); |
406
|
0
|
|
|
|
|
|
return; |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
elsif(ref $callback ne "CODE"){ |
409
|
0
|
|
|
|
|
|
$self->warn("未设置回调函数"); |
410
|
0
|
|
|
|
|
|
return; |
411
|
|
|
|
|
|
|
} |
412
|
0
|
|
|
|
|
|
$self->_webwxgetheadimg($object,$callback); |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
1; |