line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
9
|
use File::Temp qw/:seekable/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
247
|
|
2
|
1
|
|
|
1
|
|
9
|
use Mojo::Util qw/url_escape/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
556
|
|
3
|
|
|
|
|
|
|
sub Mojo::Webqq::Client::_get_offpic { |
4
|
0
|
|
|
0
|
|
|
my $self = shift; |
5
|
0
|
|
|
|
|
|
my $file_path = shift; |
6
|
0
|
|
|
|
|
|
my $sender = shift; |
7
|
0
|
|
|
|
|
|
my $cb = pop; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#my $api = 'http://w.qq.com/d/channel/get_offpic2'; |
10
|
0
|
|
|
|
|
|
my $api = 'http://d.web2.qq.com/channel/get_offpic2'; |
11
|
0
|
|
|
|
|
|
my @query_string = ( |
12
|
|
|
|
|
|
|
file_path => url_escape($file_path), |
13
|
|
|
|
|
|
|
f_uin => $sender->id, |
14
|
|
|
|
|
|
|
clientid => $self->clientid, |
15
|
|
|
|
|
|
|
psessionid => $self->psessionid, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
my $callback = sub{ |
18
|
0
|
|
|
0
|
|
|
my ($data,$ua,$tx) = @_; |
19
|
0
|
0
|
|
|
|
|
unless(defined $data){ |
20
|
0
|
|
|
|
|
|
$self->warn("图片下载失败: " . $tx->error->{message}); |
21
|
0
|
|
|
|
|
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
0
|
|
|
|
|
return unless $tx->res->headers->content_type =~/^image\/(.*)/; |
24
|
0
|
0
|
|
|
|
|
my $type = $1=~/jpe?g/i ? ".jpg" |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25
|
|
|
|
|
|
|
: $1=~/png/i ? ".png" |
26
|
|
|
|
|
|
|
: $1=~/bmp/i ? ".bmp" |
27
|
|
|
|
|
|
|
: $1=~/gif/i ? ".gif" |
28
|
|
|
|
|
|
|
: undef |
29
|
|
|
|
|
|
|
; |
30
|
0
|
0
|
|
|
|
|
return unless defined $type; |
31
|
0
|
0
|
0
|
|
|
|
if(defined $self->pic_dir and not -d $self->pic_dir){ |
32
|
0
|
|
|
|
|
|
$self->error("无效的 pic_dir: " . $self->pic_dir); |
33
|
0
|
|
|
|
|
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
my @opt = ( |
36
|
|
|
|
|
|
|
TEMPLATE => "mojo_webqq_offpic_XXXX", |
37
|
|
|
|
|
|
|
SUFFIX => $type, |
38
|
|
|
|
|
|
|
UNLINK => 0, |
39
|
|
|
|
|
|
|
); |
40
|
0
|
0
|
|
|
|
|
defined $self->pic_dir?(push @opt,(DIR=>$self->pic_dir)):(push @opt,(TMPDIR=>1)); |
41
|
0
|
|
|
|
|
|
eval{ |
42
|
0
|
|
|
|
|
|
my $tmp = File::Temp->new(@opt); |
43
|
0
|
|
|
|
|
|
binmode $tmp; |
44
|
0
|
|
|
|
|
|
print $tmp $tx->res->body(); |
45
|
0
|
|
|
|
|
|
close $tmp; |
46
|
0
|
|
|
|
|
|
$self->emit(receive_pic => $tmp->filename,$sender); |
47
|
0
|
0
|
|
|
|
|
$self->emit(receive_friend_pic => $tmp->filename,$sender) if $sender->type eq "friend"; |
48
|
0
|
0
|
|
|
|
|
$self->emit(receive_sess_pic => $tmp->filename,$sender) if $sender->type ne "friend"; |
49
|
0
|
0
|
|
|
|
|
$cb->($self,$tmp->filename,$sender) if ref $cb eq "CODE"; |
50
|
|
|
|
|
|
|
}; |
51
|
0
|
0
|
|
|
|
|
$self->error("[Mojo::Webqq::Client::_get_offpic] $@") if $@; |
52
|
0
|
|
|
|
|
|
}; |
53
|
0
|
|
|
|
|
|
$self->http_get($self->gen_url($api,@query_string),{Referer=>'http://'. $self->domain . '/'},$callback); |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
1; |