|
@@ -14,36 +14,6 @@ namespace Api; |
|
@@ -14,36 +14,6 @@ namespace Api; |
14
|
use Plugin\Cache;
|
14
|
use Plugin\Cache;
|
15
|
class Yohobuy
|
15
|
class Yohobuy
|
16
|
{
|
16
|
{
|
17
|
- /* 正式环境 */
|
|
|
18
|
- // php API
|
|
|
19
|
-// const API_URL = 'http://api2.open.yohobuy.com/';
|
|
|
20
|
-// const API_URL2 = 'http://api.open.yohobuy.com/';
|
|
|
21
|
-// const SERVICE_URL = 'http://service.api.yohobuy.com/';
|
|
|
22
|
-// const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
23
|
-
|
|
|
24
|
- //java API
|
|
|
25
|
- // const API_URL = 'http://api.yoho.yohoops.org/';//
|
|
|
26
|
- // const API_URL2 = 'http://api.yoho.yohoops.org/';//
|
|
|
27
|
- // const SERVICE_URL = 'http://service.yoho.yohoops.org/';
|
|
|
28
|
- // const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
29
|
- // const API_OLD = 'http://api2.open.yohobuy.com/';
|
|
|
30
|
- // 支付回调地址
|
|
|
31
|
- // const SERVICE_NOTIFY = 'http://service.yoho.cn/';
|
|
|
32
|
-
|
|
|
33
|
- // 测试环境 */
|
|
|
34
|
- const API_URL = 'http://testapi.yoho.cn:28078/'; // http://testapi.yoho.cn:28078/ http://devapi.yoho.cn:58078/
|
|
|
35
|
- const SERVICE_URL = 'http://testservice.yoho.cn:28077/'; // http://testservice.yoho.cn:28077/ http://devservice.yoho.cn:58077/
|
|
|
36
|
- const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
37
|
- const API_OLD = 'http://test2.open.yohobuy.com/';
|
|
|
38
|
-// 支付回调地址
|
|
|
39
|
- const SERVICE_NOTIFY = 'http://testservice.yoho.cn:28077/';
|
|
|
40
|
-
|
|
|
41
|
- /* 预览环境 */
|
|
|
42
|
-// const API_URL = 'http://preapi.yoho.cn/';
|
|
|
43
|
-// const API_URL2 = 'http://preapi.yoho.cn/';
|
|
|
44
|
-// const SERVICE_URL = 'http://preservice.yoho.cn/';
|
|
|
45
|
-// const YOHOBUY_URL = 'http://www.yohobuy.com/';
|
|
|
46
|
-// const API_OLD = 'http://api2.open.yohobuy.com/';
|
|
|
47
|
|
17
|
|
48
|
/**
|
18
|
/**
|
49
|
* 登录老接口Api配置
|
19
|
* 登录老接口Api配置
|
|
@@ -64,6 +34,17 @@ class Yohobuy |
|
@@ -64,6 +34,17 @@ class Yohobuy |
64
|
'h5' => 'fd4ad5fcfa0de589ef238c0e7331b585',
|
34
|
'h5' => 'fd4ad5fcfa0de589ef238c0e7331b585',
|
65
|
);
|
35
|
);
|
66
|
|
36
|
|
|
|
37
|
+ //分流服务器接口
|
|
|
38
|
+ public static $interfaceShunt = array(
|
|
|
39
|
+ 'tencentServers' => array(
|
|
|
40
|
+ 'api' => array('123.206.1.98', '123.206.2.80'),
|
|
|
41
|
+ 'service' => array('123.206.1.98', '123.206.2.80')
|
|
|
42
|
+ ),
|
|
|
43
|
+ 'awsServers' => array(
|
|
|
44
|
+ 'api' => 'app-java-168863769.cn-north-1.elb.amazonaws.com.cn',
|
|
|
45
|
+ 'service' => 'service-yoho-579825100.cn-north-1.elb.amazonaws.com.cn'
|
|
|
46
|
+ )
|
|
|
47
|
+ );
|
67
|
|
48
|
|
68
|
/**
|
49
|
/**
|
69
|
* 取得当前的客户端类型
|
50
|
* 取得当前的客户端类型
|
|
@@ -167,13 +148,27 @@ class Yohobuy |
|
@@ -167,13 +148,27 @@ class Yohobuy |
167
|
*/
|
148
|
*/
|
168
|
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
|
149
|
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
|
169
|
{
|
150
|
{
|
|
|
151
|
+ $isApi = false;
|
|
|
152
|
+ $isService = false;
|
|
|
153
|
+
|
|
|
154
|
+ if (USE_INTER_FACE_SHUNT) {
|
|
|
155
|
+ if (strpos($url, 'api.')) {
|
|
|
156
|
+ $isApi = true;
|
|
|
157
|
+ } else if (strpos($url, 'service.')) {
|
|
|
158
|
+ $isService = true;
|
|
|
159
|
+ }
|
|
|
160
|
+ $url = self::_getUrl($url, $data);
|
|
|
161
|
+ }
|
|
|
162
|
+
|
170
|
// 销毁私钥参数
|
163
|
// 销毁私钥参数
|
171
|
if (isset($data['private_key'])) {
|
164
|
if (isset($data['private_key'])) {
|
172
|
unset($data['private_key']);
|
165
|
unset($data['private_key']);
|
173
|
}
|
166
|
}
|
|
|
167
|
+
|
174
|
if (!empty($data)) {
|
168
|
if (!empty($data)) {
|
175
|
$url = self::httpBuildQuery($url, $data);
|
169
|
$url = self::httpBuildQuery($url, $data);
|
176
|
} //echo $url;
|
170
|
} //echo $url;
|
|
|
171
|
+
|
177
|
/* 开启缓存的情况 */
|
172
|
/* 开启缓存的情况 */
|
178
|
if ($cache && USE_CACHE) {
|
173
|
if ($cache && USE_CACHE) {
|
179
|
// 先尝试获取一级缓存(master), 有数据则直接返回.
|
174
|
// 先尝试获取一级缓存(master), 有数据则直接返回.
|
|
@@ -182,17 +177,27 @@ class Yohobuy |
|
@@ -182,17 +177,27 @@ class Yohobuy |
182
|
return $result;
|
177
|
return $result;
|
183
|
}
|
178
|
}
|
184
|
}
|
179
|
}
|
|
|
180
|
+
|
|
|
181
|
+
|
185
|
$ch = curl_init($url);
|
182
|
$ch = curl_init($url);
|
186
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
183
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
187
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
184
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
188
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
185
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
189
|
|
186
|
|
|
|
187
|
+ if ($isApi) {
|
|
|
188
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: api.yoho.cn'));
|
|
|
189
|
+ } else if ($isService) {
|
|
|
190
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: service.yoho.cn'));
|
|
|
191
|
+ }
|
|
|
192
|
+
|
190
|
if ($useGzip) {
|
193
|
if ($useGzip) {
|
191
|
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
|
194
|
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
|
192
|
}
|
195
|
}
|
|
|
196
|
+
|
193
|
if (!empty($userAgent)) {
|
197
|
if (!empty($userAgent)) {
|
194
|
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
|
198
|
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
|
195
|
}
|
199
|
}
|
|
|
200
|
+
|
196
|
$result = curl_exec($ch);
|
201
|
$result = curl_exec($ch);
|
197
|
if (!$returnJson && !empty($result)) {
|
202
|
if (!$returnJson && !empty($result)) {
|
198
|
$result = json_decode($result, true);
|
203
|
$result = json_decode($result, true);
|
|
@@ -229,9 +234,27 @@ class Yohobuy |
|
@@ -229,9 +234,27 @@ class Yohobuy |
229
|
*/
|
234
|
*/
|
230
|
public static function post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
|
235
|
public static function post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
|
231
|
{
|
236
|
{
|
232
|
- $ch = curl_init($url);
|
237
|
+ $isApi = false;
|
|
|
238
|
+ $isService = false;
|
|
|
239
|
+
|
|
|
240
|
+ if (USE_INTER_FACE_SHUNT) {
|
|
|
241
|
+ if (strpos($url, 'api.')) {
|
|
|
242
|
+ $isApi = true;
|
|
|
243
|
+ } else if (strpos($url, 'service.')) {
|
|
|
244
|
+ $isService = true;
|
|
|
245
|
+ }
|
|
|
246
|
+ $url = self::_getUrl($url, $data);
|
|
|
247
|
+ }
|
233
|
|
248
|
|
|
|
249
|
+ $ch = curl_init($url);
|
234
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
250
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
251
|
+
|
|
|
252
|
+ if ($isApi) {
|
|
|
253
|
+ array_push($header, 'Host: api.yoho.cn');
|
|
|
254
|
+ } else if ($isService) {
|
|
|
255
|
+ array_push($header, 'Host: service.yoho.cn');
|
|
|
256
|
+ }
|
|
|
257
|
+
|
235
|
if (!empty($header)) {
|
258
|
if (!empty($header)) {
|
236
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
259
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
237
|
} else {
|
260
|
} else {
|
|
@@ -247,6 +270,7 @@ class Yohobuy |
|
@@ -247,6 +270,7 @@ class Yohobuy |
247
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
|
270
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
|
248
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
271
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
249
|
curl_setopt($ch, CURLOPT_POST, true);
|
272
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
273
|
+
|
250
|
// 销毁私钥参数
|
274
|
// 销毁私钥参数
|
251
|
if (isset($data['private_key'])) {
|
275
|
if (isset($data['private_key'])) {
|
252
|
unset($data['private_key']);
|
276
|
unset($data['private_key']);
|
|
@@ -530,4 +554,40 @@ class Yohobuy |
|
@@ -530,4 +554,40 @@ class Yohobuy |
530
|
}
|
554
|
}
|
531
|
return $isMobile;
|
555
|
return $isMobile;
|
532
|
}
|
556
|
}
|
|
|
557
|
+
|
|
|
558
|
+ /**
|
|
|
559
|
+ *根据配置决定请求Java接口的地址
|
|
|
560
|
+ */
|
|
|
561
|
+ private static function _getUrl($url, $param)
|
|
|
562
|
+ {
|
|
|
563
|
+ if (USE_INTER_FACE_SHUNT === false) {
|
|
|
564
|
+ return $url;
|
|
|
565
|
+ }
|
|
|
566
|
+
|
|
|
567
|
+ $uid = 0;
|
|
|
568
|
+ $mod = 0;
|
|
|
569
|
+
|
|
|
570
|
+ if (isset($param['uid'])) {
|
|
|
571
|
+ $uid = $param['uid'];
|
|
|
572
|
+ $mod = $param['uid'] % 1024;
|
|
|
573
|
+ }
|
|
|
574
|
+
|
|
|
575
|
+ if ($mod > 128 || $uid === 0) {
|
|
|
576
|
+ $paseUrl = parse_url($url);
|
|
|
577
|
+ if (strpos($url, 'api.')) {
|
|
|
578
|
+ $url = 'http://' . self::$interfaceShunt['awsServers']['api'] . $paseUrl['path']. '/';
|
|
|
579
|
+ } else if (strpos($url, 'service.')) {
|
|
|
580
|
+ $url = 'http://' . self::$interfaceShunt['awsServers']['service'] . $paseUrl['path']. '/';
|
|
|
581
|
+ }
|
|
|
582
|
+ } else {
|
|
|
583
|
+ $paseUrl = parse_url($url);
|
|
|
584
|
+ if (strpos($url, 'api.')) {
|
|
|
585
|
+ $url = 'http://' . array_rand(self::$interfaceShunt['tencentServers']['api']) . $paseUrl['path'] . '/';
|
|
|
586
|
+ } else if (strpos($url, 'service.')) {
|
|
|
587
|
+ $url = 'http://' . array_rand(self::$interfaceShunt['tencentServers']['service']) . $paseUrl['path']. '/';
|
|
|
588
|
+ }
|
|
|
589
|
+ }
|
|
|
590
|
+
|
|
|
591
|
+ return $url;
|
|
|
592
|
+ }
|
533
|
} |
593
|
} |