|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlibabaCloud\ImageSearch\V20180120\Traits; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Trait SearchItemTrait |
|
7
|
|
|
* |
|
8
|
|
|
* @package AlibabaCloud\ImageSearch\V20180120\Traits |
|
9
|
|
|
*/ |
|
10
|
|
|
trait SearchItemTrait |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var int |
|
14
|
|
|
*/ |
|
15
|
|
|
private $start = 0; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int |
|
19
|
|
|
*/ |
|
20
|
|
|
private $num = 10; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $cateId = ''; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var |
|
29
|
|
|
*/ |
|
30
|
|
|
private $searchPicture; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return bool |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function buildPostContent() |
|
36
|
|
|
{ |
|
37
|
1 |
|
if (!$this->searchPicture) { |
|
38
|
1 |
|
return false; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
$map = []; |
|
42
|
|
|
|
|
43
|
1 |
|
$map['s'] = $this->start; |
|
44
|
1 |
|
$map['n'] = $this->num; |
|
45
|
1 |
|
if ($this->cateId !== null && $this->cateId !== '') { |
|
46
|
1 |
|
$map['cat_id'] = $this->cateId; |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
$encodePicName = base64_encode('searchPic'); |
|
50
|
1 |
|
$encodePicContent = base64_encode($this->searchPicture); |
|
51
|
|
|
|
|
52
|
1 |
|
$map['pic_list'] = $encodePicName; |
|
53
|
1 |
|
$map[$encodePicName] = $encodePicContent; |
|
54
|
|
|
|
|
55
|
1 |
|
$content = $this->buildContent($map); |
|
56
|
1 |
|
$this->body($content); |
|
|
|
|
|
|
57
|
1 |
|
$this->format('JSON'); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
1 |
|
return true; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param mixed $start |
|
64
|
|
|
* |
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function withStart($start) |
|
68
|
|
|
{ |
|
69
|
1 |
|
$this->start = $start; |
|
70
|
1 |
|
$this->buildPostContent(); |
|
71
|
|
|
|
|
72
|
1 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param mixed $num |
|
77
|
|
|
* |
|
78
|
|
|
* @return $this |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function withNum($num) |
|
81
|
|
|
{ |
|
82
|
1 |
|
$this->num = $num; |
|
83
|
1 |
|
$this->buildPostContent(); |
|
84
|
|
|
|
|
85
|
1 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param mixed $cateId |
|
90
|
|
|
* |
|
91
|
|
|
* @return $this |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public function withCateId($cateId) |
|
94
|
|
|
{ |
|
95
|
1 |
|
$this->cateId = $cateId; |
|
96
|
1 |
|
$this->buildPostContent(); |
|
97
|
|
|
|
|
98
|
1 |
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param mixed $searchPicture |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function withSearchPicture($searchPicture) |
|
107
|
|
|
{ |
|
108
|
1 |
|
$this->searchPicture = $searchPicture; |
|
109
|
1 |
|
$this->buildPostContent(); |
|
110
|
|
|
|
|
111
|
1 |
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param $map |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
1 |
|
private function buildContent($map) |
|
120
|
|
|
{ |
|
121
|
1 |
|
$meta = ''; |
|
122
|
1 |
|
$body = ''; |
|
123
|
1 |
|
$start = 0; |
|
124
|
|
|
|
|
125
|
1 |
|
foreach ($map as $key => $value) { |
|
126
|
1 |
|
if ($meta !== '') { |
|
127
|
1 |
|
$meta .= '#'; |
|
128
|
1 |
|
} |
|
129
|
1 |
|
$meta .= $key . ',' . $start . ',' . ($start + strlen($value)); |
|
130
|
1 |
|
$body .= $value; |
|
131
|
1 |
|
$start += strlen($value); |
|
132
|
1 |
|
} |
|
133
|
|
|
|
|
134
|
1 |
|
return $meta . '^' . $body; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|