line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
2
|
1
|
|
|
1
|
|
5
|
use File::Temp qw/:seekable/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
718
|
|
3
|
|
|
|
|
|
|
sub Mojo::Weixin::_webwxgetheadimg { |
4
|
0
|
|
|
0
|
|
|
my $self = shift; |
5
|
0
|
|
|
|
|
|
my $object = shift; |
6
|
0
|
|
|
|
|
|
my $callback = shift; |
7
|
0
|
0
|
|
|
|
|
if(not $object->_avatar){ |
8
|
0
|
|
|
|
|
|
$self->warn("对象[ " . $object->displayname . " ]头像地址无效"); |
9
|
0
|
|
|
|
|
|
return; |
10
|
|
|
|
|
|
|
} |
11
|
0
|
|
|
|
|
|
my $url = 'https://' . $self->domain . $object->_avatar; |
12
|
|
|
|
|
|
|
$self->http_get($url,{Referer=>'https://' . $self->domain .'/'},sub{ |
13
|
0
|
|
|
0
|
|
|
my ($data,$ua,$tx) = @_; |
14
|
0
|
0
|
|
|
|
|
if(not defined $data){ |
15
|
0
|
|
|
|
|
|
$self->warn("获取对象[ " . $object->displayname . " ]头像失败: 数据无效"); |
16
|
0
|
|
|
|
|
|
return; |
17
|
|
|
|
|
|
|
} |
18
|
0
|
0
|
|
|
|
|
my $mime = $data=~/^GIF8/ ? 'image/gif' |
|
|
0
|
|
|
|
|
|
19
|
|
|
|
|
|
|
: $data=~/^PNG|\x89PNG/ ? 'image/png' |
20
|
|
|
|
|
|
|
: $tx->res->headers->content_type |
21
|
|
|
|
|
|
|
; |
22
|
0
|
|
|
|
|
|
$mime=~s/;.*$//; |
23
|
0
|
0
|
|
|
|
|
my $type = $mime=~/^image\/jpe?g/i ? ".jpg" |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24
|
|
|
|
|
|
|
: $mime=~/^image\/png/i ? ".png" |
25
|
|
|
|
|
|
|
: $mime=~/^image\/bmp/i ? ".bmp" |
26
|
|
|
|
|
|
|
: $mime=~/^image\/gif/i ? ".gif" |
27
|
|
|
|
|
|
|
: undef |
28
|
|
|
|
|
|
|
; |
29
|
0
|
0
|
|
|
|
|
if(not defined $type){ |
30
|
0
|
|
|
|
|
|
$self->warn("获取对象[ " . $object->displayname . " ]头像失败: 非图像类型数据"); |
31
|
0
|
|
|
|
|
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
0
|
0
|
|
|
|
if(defined $self->media_dir and not -d $self->media_dir){ |
34
|
0
|
|
|
|
|
|
$self->error("无效的 media_dir: " . $self->media_dir); |
35
|
0
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
my @opt = ( |
38
|
|
|
|
|
|
|
TEMPLATE => "mojo_weixin_avatar_XXXX", |
39
|
|
|
|
|
|
|
SUFFIX => $type, |
40
|
|
|
|
|
|
|
UNLINK => 0, |
41
|
|
|
|
|
|
|
); |
42
|
0
|
0
|
|
|
|
|
defined $self->media_dir?(push @opt,(DIR=>$self->media_dir)):(push @opt,(TMPDIR=>1)); |
43
|
0
|
|
|
|
|
|
eval{ |
44
|
0
|
|
|
|
|
|
my $tmp = File::Temp->new(@opt); |
45
|
0
|
|
|
|
|
|
binmode $tmp; |
46
|
0
|
|
|
|
|
|
print $tmp $data; |
47
|
0
|
|
|
|
|
|
close $tmp; |
48
|
0
|
|
|
|
|
|
$self->debug("获取对象[ " . $object->displayname . " ]头像成功: " . $tmp->filename); |
49
|
0
|
0
|
|
|
|
|
$callback->($tmp->filename,$data,$mime) if ref $callback eq "CODE"; |
50
|
|
|
|
|
|
|
}; |
51
|
0
|
0
|
|
|
|
|
$self->error("[ ". __PACKAGE__ . " ] $@") if $@; |
52
|
0
|
|
|
|
|
|
}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
1; |