forked from reference-project/taobao_thumb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaobao.php
54 lines (52 loc) · 1.11 KB
/
taobao.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$url = $_GET['url'];
$type = $_GET['type'];
if( $type === 'thumb' )
{
$url = parse_url($url);
parse_str($url['query'] , $url);
$url = 'http://tbskip.taobao.com/auction/storegallery/item_xml.htm?item_id=' . $url['id'];
$xmlstr = file_get_contents($url);
$xmlstr = trim($xmlstr);
$xmlstr = simplexml_load_string($xmlstr);
$ret = array();
foreach($xmlstr->item->images->image as $row)
{
$ret[] = ((string)$row->url);
}
exit(json_encode($ret));
}
elseif( $type === 'detail' )
{
$html = file_get_contents($url);
$url = parse_url($url);
$url2 = null;
if( strpos($url['host'],'taobao.com') !== false )
{
//taobao
preg_match('/\"https:\"\s===\slocation\.protocol\s\?\s\"([^\"]+)\"/is' , $html, $preg);
if($preg)
{
$url2 = $preg[1];
}
}
elseif( strpos($url['host'],'tmall.com') !== false )
{
//taobao
preg_match('/\"descUrl\"\:\"([^\"]+)\"/is' , $html, $preg);
if($preg)
{
$url2 = $preg[1];
}
}
if($url2)
{
$html = file_get_contents('http:'.$url2);
preg_match_all('/<img[\s\S]+?src=\"([^\"]+)\"?/is',$html,$preg);
if( $preg )
{
$ret = $preg[1];
exit(json_encode($ret));
}
}
}