Authored by hf

modify api to yohobuy test env

framework @ 75bbc3b0
1 -Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05 1 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 * 所有Controller控制器的基类 4 * 所有Controller控制器的基类
5 * 5 *
6 * @name AbstractAction 6 * @name AbstractAction
7 - * @package 7 + * @package library
8 * @copyright yoho.inc 8 * @copyright yoho.inc
9 * @version 1.0 (2015-9-15 11:55:25) 9 * @version 1.0 (2015-9-15 11:55:25)
10 * @author fei.hong <fei.hong@yoho.cn> 10 * @author fei.hong <fei.hong@yoho.cn>
@@ -41,13 +41,13 @@ class AbstractAction extends Controller_Abstract @@ -41,13 +41,13 @@ class AbstractAction extends Controller_Abstract
41 41
42 // 设置环境变量 42 // 设置环境变量
43 switch (APPLICATION_ENV) { 43 switch (APPLICATION_ENV) {
44 - case 'production': 44 + case 'production': // 生产
45 $this->_view->assign('rlsEnv', true); 45 $this->_view->assign('rlsEnv', true);
46 break; 46 break;
47 - case 'testing': 47 + case 'testing': // 测试
48 $this->_view->assign('testEnv', true); 48 $this->_view->assign('testEnv', true);
49 break; 49 break;
50 - case 'develop': 50 + case 'develop': // 开发
51 default: 51 default:
52 $this->_view->assign('devEnv', true); 52 $this->_view->assign('devEnv', true);
53 break; 53 break;
@@ -350,25 +350,25 @@ class AbstractAction extends Controller_Abstract @@ -350,25 +350,25 @@ class AbstractAction extends Controller_Abstract
350 'textCn' => '男生', 350 'textCn' => '男生',
351 'textEn' => 'BOYS', 351 'textEn' => 'BOYS',
352 'styleClass' => 'boys', 352 'styleClass' => 'boys',
353 - 'url' => '/boys.html', 353 + 'url' => '/boys',
354 ), 354 ),
355 1 => array( 355 1 => array(
356 'textCn' => '女生', 356 'textCn' => '女生',
357 'textEn' => 'GIRLS', 357 'textEn' => 'GIRLS',
358 'styleClass' => 'girls', 358 'styleClass' => 'girls',
359 - 'url' => '/girls.html', 359 + 'url' => '/girls',
360 ), 360 ),
361 2 => array( 361 2 => array(
362 'textCn' => '潮童', 362 'textCn' => '潮童',
363 'textEn' => 'KIDS', 363 'textEn' => 'KIDS',
364 'styleClass' => 'kids', 364 'styleClass' => 'kids',
365 - 'url' => '/kids.html', 365 + 'url' => '/kids',
366 ), 366 ),
367 3 => array( 367 3 => array(
368 'textCn' => '创意生活', 368 'textCn' => '创意生活',
369 'textEn' => 'LIFE STYLE', 369 'textEn' => 'LIFE STYLE',
370 'styleClass' => 'life', 370 'styleClass' => 'life',
371 - 'url' => '/life.html', 371 + 'url' => '/life',
372 ), 372 ),
373 4 => array( 373 4 => array(
374 'textCn' => '逛', 374 'textCn' => '逛',
@@ -9,15 +9,20 @@ @@ -9,15 +9,20 @@
9 * @version 1.0 (2015-9-30 16:42:51) 9 * @version 1.0 (2015-9-30 16:42:51)
10 * @author fei.hong <fei.hong@yoho.cn> 10 * @author fei.hong <fei.hong@yoho.cn>
11 */ 11 */
12 -namespace Api;  
13 12
14 -use Plugin\Cache; 13 +namespace Api;
15 14
16 class Yohobuy 15 class Yohobuy
17 { 16 {
18 17
19 - const API_URL = 'http://api2.open.yohobuy.com/';  
20 - const SERVICE_URL = 'http://service.api.yohobuy.com/'; 18 +// /* 正式环境 */
  19 +// const API_URL = 'http://api2.open.yohobuy.com/';
  20 +// const SERVICE_URL = 'http://service.api.yohobuy.com/';
  21 +// const YOHOBUY_URL = 'http://www.yohobuy.com/';
  22 +
  23 + /* 测试环境 */
  24 + const API_URL = 'http://test2.open.yohobuy.com/';
  25 + const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
21 const YOHOBUY_URL = 'http://www.yohobuy.com/'; 26 const YOHOBUY_URL = 'http://www.yohobuy.com/';
22 27
23 /** 28 /**
@@ -101,18 +106,6 @@ class Yohobuy @@ -101,18 +106,6 @@ class Yohobuy
101 */ 106 */
102 public static function get($url, $data = array(), $returnJson = false, $timeout = 5) 107 public static function get($url, $data = array(), $returnJson = false, $timeout = 5)
103 { 108 {
104 -// // 代表是否开启缓存  
105 -// $useCache = $cache && isset($data['client_secret']);  
106 -//  
107 -// /* 先尝试获取一级缓存(master), 有数据则直接返回 */  
108 -// if ($useCache) {  
109 -// $key = md5($url . $data['client_secret']);  
110 -// $result = Cache::get($key, 'master');  
111 -// if (!empty($result)) {  
112 -// return $result;  
113 -// }  
114 -// }  
115 -  
116 // 销毁私钥参数 109 // 销毁私钥参数
117 if (isset($data['private_key'])) { 110 if (isset($data['private_key'])) {
118 unset($data['private_key']); 111 unset($data['private_key']);
@@ -131,18 +124,6 @@ class Yohobuy @@ -131,18 +124,6 @@ class Yohobuy
131 } 124 }
132 curl_close($ch); 125 curl_close($ch);
133 $data = array(); 126 $data = array();
134 -  
135 -// /* 设置一级二级缓存 或 获取二级缓存(slave) */  
136 -// if ($useCache) {  
137 -// // 如果接口异常没数据返回,则获取二级缓存  
138 -// if (empty($result)) {  
139 -// $result = Cache::get($key, 'slave');  
140 -// }  
141 -// // 如果接口正常有数据返回,则设置数据缓存  
142 -// else {  
143 -// Cache::set($key, $result);  
144 -// }  
145 -// }  
146 127
147 return $result; 128 return $result;
148 } 129 }
@@ -165,8 +146,7 @@ class Yohobuy @@ -165,8 +146,7 @@ class Yohobuy
165 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 146 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
166 if (!empty($header)) { 147 if (!empty($header)) {
167 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 148 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
168 - }  
169 - else { 149 + } else {
170 curl_setopt($ch, CURLOPT_HEADER, 0); 150 curl_setopt($ch, CURLOPT_HEADER, 0);
171 } 151 }
172 152
@@ -242,8 +222,7 @@ class Yohobuy @@ -242,8 +222,7 @@ class Yohobuy
242 do { 222 do {
243 do { 223 do {
244 $status = curl_multi_exec($mh, $running); 224 $status = curl_multi_exec($mh, $running);
245 - }  
246 - while ($status == CURLM_CALL_MULTI_PERFORM); 225 + } while ($status == CURLM_CALL_MULTI_PERFORM);
247 226
248 if ($status != CURLM_OK) { 227 if ($status != CURLM_OK) {
249 break; 228 break;
@@ -252,8 +231,7 @@ class Yohobuy @@ -252,8 +231,7 @@ class Yohobuy
252 if ($running > 0) { 231 if ($running > 0) {
253 curl_multi_select($mh, 0.5); 232 curl_multi_select($mh, 0.5);
254 } 233 }
255 - }  
256 - while ($running); 234 + } while ($running);
257 235
258 // 获取API接口响应的结果 236 // 获取API接口响应的结果
259 foreach ($urlList as $name => $api) { 237 foreach ($urlList as $name => $api) {
@@ -293,16 +271,16 @@ class Yohobuy @@ -293,16 +271,16 @@ class Yohobuy
293 $client->SetOpt(YAR_OPT_PACKAGER, 'php'); 271 $client->SetOpt(YAR_OPT_PACKAGER, 'php');
294 $client->SetOpt(YAR_OPT_TIMEOUT, $timeout); 272 $client->SetOpt(YAR_OPT_TIMEOUT, $timeout);
295 $client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout); 273 $client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout);
296 - 274 +
297 try { 275 try {
298 $result = call_user_func_array(array($client, $method), $parameters); 276 $result = call_user_func_array(array($client, $method), $parameters);
299 } catch (\Exception $e) { 277 } catch (\Exception $e) {
300 $result = array(); 278 $result = array();
301 } 279 }
302 - 280 +
303 return $result; 281 return $result;
304 } 282 }
305 - 283 +
306 /** 284 /**
307 * 并行(异步)调用远程服务 285 * 并行(异步)调用远程服务
308 * 286 *
@@ -322,6 +300,7 @@ class Yohobuy @@ -322,6 +300,7 @@ class Yohobuy
322 YAR_OPT_CONNECT_TIMEOUT => $timeout 300 YAR_OPT_CONNECT_TIMEOUT => $timeout
323 )); 301 ));
324 } 302 }
  303 +
325 public static function yarConcurrentLoop($callback = null) 304 public static function yarConcurrentLoop($callback = null)
326 { 305 {
327 \Yar_Concurrent_Client::loop($callback); 306 \Yar_Concurrent_Client::loop($callback);
  1 +<?php
  2 +
  3 +namespace Configs;
  4 +
  5 +/**
  6 + * 缓存配置文件
  7 + */
  8 +class CacheConfig
  9 +{
  10 +
  11 + const KEY_ACTION_INDEX_INDEX = 'key_action_index_index';
  12 +
  13 +}
1 <?php 1 <?php
  2 +
2 namespace LibModels\Wap\Category; 3 namespace LibModels\Wap\Category;
3 4
4 use Api\Yohobuy; 5 use Api\Yohobuy;
@@ -15,22 +16,22 @@ use Api\Sign; @@ -15,22 +16,22 @@ use Api\Sign;
15 */ 16 */
16 class BrandData 17 class BrandData
17 { 18 {
18 - /**  
19 - * 获取品牌数据 19 +
  20 + /**
  21 + * 获取品牌数据
20 * 22 *
21 - * @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据 23 + * @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据
22 * 24 *
23 - * @return array 品牌数据  
24 - */ 25 + * @return array 品牌数据
  26 + */
25 public static function getBrandsData($channel = 1) 27 public static function getBrandsData($channel = 1)
26 { 28 {
27 - // 构建必传参数  
28 - $param = Yohobuy::param();  
29 - 29 + // 构建必传参数
  30 + $param = Yohobuy::param();
30 $param['method'] = 'app.brand.brandlist'; 31 $param['method'] = 'app.brand.brandlist';
31 - $param['yh_channel'] = $channel; 32 + $param['yh_channel'] = $channel;
32 $param['client_secret'] = Sign::getSign($param); 33 $param['client_secret'] = Sign::getSign($param);
33 - 34 +
34 return Yohobuy::get(Yohobuy::API_URL, $param); 35 return Yohobuy::get(Yohobuy::API_URL, $param);
35 } 36 }
36 37
@@ -41,13 +42,12 @@ class BrandData @@ -41,13 +42,12 @@ class BrandData
41 */ 42 */
42 public static function getBrandTopData() 43 public static function getBrandTopData()
43 { 44 {
44 - // 构建必传参数  
45 - $param = Yohobuy::param();  
46 -  
47 - $param['content_code'] = 'ce6ac059493ec26241a8cbe0bfa1b17a'; 45 + // 构建必传参数
  46 + $param = Yohobuy::param();
  47 + $param['content_code'] = 'ce6ac059493ec26241a8cbe0bfa1b17a';
48 $param['client_secret'] = Sign::getSign($param); 48 $param['client_secret'] = Sign::getSign($param);
49 -  
50 - return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/get', $param); 49 +
  50 + return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/get', $param);
51 } 51 }
52 52
53 /** 53 /**
@@ -60,11 +60,10 @@ class BrandData @@ -60,11 +60,10 @@ class BrandData
60 { 60 {
61 // 构建必传参数 61 // 构建必传参数
62 $param = Yohobuy::param(); 62 $param = Yohobuy::param();
63 -  
64 - $param['brand_id'] = '$brandId'; 63 + $param['brand_id'] = $brandId;
65 $param['method'] = 'app.brand.getBrandIntro'; 64 $param['method'] = 'app.brand.getBrandIntro';
66 $param['client_secret'] = Sign::getSign($param); 65 $param['client_secret'] = Sign::getSign($param);
67 - 66 +
68 return Yohobuy::get(Yohobuy::API_URL, $param); 67 return Yohobuy::get(Yohobuy::API_URL, $param);
69 } 68 }
70 69
@@ -77,11 +76,10 @@ class BrandData @@ -77,11 +76,10 @@ class BrandData
77 { 76 {
78 // 构建必传参数 77 // 构建必传参数
79 $param = Yohobuy::param(); 78 $param = Yohobuy::param();
80 -  
81 - $param['brand_id'] = '$brandId'; 79 + $param['brand_id'] = $brandId;
82 $param['method'] = 'app.brand.banner'; 80 $param['method'] = 'app.brand.banner';
83 $param['client_secret'] = Sign::getSign($param); 81 $param['client_secret'] = Sign::getSign($param);
84 - 82 +
85 return Yohobuy::get(Yohobuy::API_URL, $param); 83 return Yohobuy::get(Yohobuy::API_URL, $param);
86 } 84 }
87 85
@@ -113,7 +111,9 @@ class BrandData @@ -113,7 +111,9 @@ class BrandData
113 'p_d' => $p_d 111 'p_d' => $p_d
114 ); 112 );
115 // 拉取筛选参数 113 // 拉取筛选参数
116 - $queriedParams = array_filter($selectItems, function($v) {return $v !== null;}); 114 + $queriedParams = array_filter($selectItems, function($v) {
  115 + return $v !== null;
  116 + });
117 117
118 // 构建必传参数 118 // 构建必传参数
119 $param = Yohobuy::param(); 119 $param = Yohobuy::param();
@@ -123,7 +123,8 @@ class BrandData @@ -123,7 +123,8 @@ class BrandData
123 $param['limit'] = $limit; 123 $param['limit'] = $limit;
124 $param['yh_channel'] = $channel; 124 $param['yh_channel'] = $channel;
125 $param['client_secret'] = Sign::getSign($param); 125 $param['client_secret'] = Sign::getSign($param);
126 - 126 +
127 return Yohobuy::get(Yohobuy::API_URL, $param); 127 return Yohobuy::get(Yohobuy::API_URL, $param);
128 } 128 }
  129 +
129 } 130 }
@@ -16,16 +16,14 @@ class BoysController extends AbstractAction @@ -16,16 +16,14 @@ class BoysController extends AbstractAction
16 $this->setTitle('男生首页'); 16 $this->setTitle('男生首页');
17 // 显示侧边栏 17 // 显示侧边栏
18 $this->setNavSide(); 18 $this->setNavSide();
19 -  
20 - // 显示顶部下载  
21 - $this->setHeaderDownload();  
22 // 设置顶部信息(搜索) 19 // 设置顶部信息(搜索)
23 $this->setHomeChannelHeader(); 20 $this->setHomeChannelHeader();
24 21
25 $data = array('boysHomePage' => true); 22 $data = array('boysHomePage' => true);
  23 + $uid = $this->getUid();
26 24
27 // 频道数据 25 // 频道数据
28 - $channelData = IndexData::getUserChannelData(0, '1,3', '201504091403001'); 26 + $channelData = IndexData::getUserChannelData($uid, '1,3', '201504091403001');
29 if (isset($channelData['code']) && $channelData['code'] == 200) { 27 if (isset($channelData['code']) && $channelData['code'] == 200) {
30 $data['content'] = FloorProcess::getContent($channelData['data']); 28 $data['content'] = FloorProcess::getContent($channelData['data']);
31 } 29 }
@@ -16,16 +16,14 @@ class GirlsController extends AbstractAction @@ -16,16 +16,14 @@ class GirlsController extends AbstractAction
16 $this->setTitle('女生首页'); 16 $this->setTitle('女生首页');
17 // 显示侧边栏 17 // 显示侧边栏
18 $this->setNavSide(); 18 $this->setNavSide();
19 -  
20 - // 显示顶部下载  
21 - $this->setHeaderDownload();  
22 // 设置顶部信息(搜索) 19 // 设置顶部信息(搜索)
23 $this->setHomeChannelHeader(); 20 $this->setHomeChannelHeader();
24 21
25 $data = array('grilsHomePage' => true); 22 $data = array('grilsHomePage' => true);
  23 + $uid = $this->getUid();
26 24
27 // 频道数据 25 // 频道数据
28 - $channelData = IndexData::getUserChannelData(0, '2,3', '201504091403002'); 26 + $channelData = IndexData::getUserChannelData($uid, '2,3', '201504091403002');
29 if (isset($channelData['code']) && $channelData['code'] == 200) { 27 if (isset($channelData['code']) && $channelData['code'] == 200) {
30 $data['content'] = FloorProcess::getContent($channelData['data'], 2); 28 $data['content'] = FloorProcess::getContent($channelData['data'], 2);
31 } 29 }
@@ -15,8 +15,6 @@ class IndexController extends AbstractAction @@ -15,8 +15,6 @@ class IndexController extends AbstractAction
15 */ 15 */
16 public function indexAction() 16 public function indexAction()
17 { 17 {
18 - $data = array();  
19 -  
20 // 背景图获取 18 // 背景图获取
21 $banner = IndexData::getBannerStart(); 19 $banner = IndexData::getBannerStart();
22 if ($banner) { 20 if ($banner) {
@@ -27,7 +25,7 @@ class IndexController extends AbstractAction @@ -27,7 +25,7 @@ class IndexController extends AbstractAction
27 $this->setNavFooter(); 25 $this->setNavFooter();
28 26
29 // 生成HTML (index.html) 27 // 生成HTML (index.html)
30 - $this->_view->html('index'); 28 + // $this->_view->html('index');
31 29
32 // 渲染模板 30 // 渲染模板
33 $this->_view->display('index', $data); 31 $this->_view->display('index', $data);
@@ -16,16 +16,14 @@ class KidsController extends AbstractAction @@ -16,16 +16,14 @@ class KidsController extends AbstractAction
16 $this->setTitle('潮童首页'); 16 $this->setTitle('潮童首页');
17 // 显示侧边栏 17 // 显示侧边栏
18 $this->setNavSide(); 18 $this->setNavSide();
19 -  
20 - // 显示顶部下载  
21 - $this->setHeaderDownload();  
22 // 设置顶部信息(搜索) 19 // 设置顶部信息(搜索)
23 $this->setHomeChannelHeader(); 20 $this->setHomeChannelHeader();
24 21
25 $data = array('kidsHomePage' => true); 22 $data = array('kidsHomePage' => true);
  23 + $uid = $this->getUid();
26 24
27 // 频道数据 25 // 频道数据
28 - $channelData = IndexData::getUserChannelData(0, '', 'e9875682c1599a886bfbdb965b740022'); 26 + $channelData = IndexData::getUserChannelData($uid, '', 'e9875682c1599a886bfbdb965b740022');
29 if (isset($channelData['code']) && $channelData['code'] == 200) { 27 if (isset($channelData['code']) && $channelData['code'] == 200) {
30 $data['content'] = FloorProcess::getContent($channelData['data'], 3); 28 $data['content'] = FloorProcess::getContent($channelData['data'], 3);
31 } 29 }
@@ -16,16 +16,14 @@ class LifestyleController extends AbstractAction @@ -16,16 +16,14 @@ class LifestyleController extends AbstractAction
16 $this->setTitle('创意生活首页'); 16 $this->setTitle('创意生活首页');
17 // 显示侧边栏 17 // 显示侧边栏
18 $this->setNavSide(); 18 $this->setNavSide();
19 -  
20 - // 显示顶部下载  
21 - $this->setHeaderDownload();  
22 // 设置顶部信息(搜索) 19 // 设置顶部信息(搜索)
23 $this->setHomeChannelHeader(); 20 $this->setHomeChannelHeader();
24 21
25 $data = array('lifestyleHomePage' => true); 22 $data = array('lifestyleHomePage' => true);
  23 + $uid = $this->getUid();
26 24
27 // 频道数据 25 // 频道数据
28 - $channelData = IndexData::getUserChannelData(0, '', '9aa25f5133f011ec96c2045eb15ae425'); 26 + $channelData = IndexData::getUserChannelData($uid, '', '9aa25f5133f011ec96c2045eb15ae425');
29 if (isset($channelData['code']) && $channelData['code'] == 200) { 27 if (isset($channelData['code']) && $channelData['code'] == 200) {
30 $data['content'] = FloorProcess::getContent($channelData['data'], 4); 28 $data['content'] = FloorProcess::getContent($channelData['data'], 4);
31 } 29 }
@@ -107,9 +107,23 @@ class LoginController extends AbstractAction @@ -107,9 +107,23 @@ class LoginController extends AbstractAction
107 107
108 /* 调用登录接口进行登录 */ 108 /* 调用登录接口进行登录 */
109 $data = LoginData::signin($area, $profile, $password); 109 $data = LoginData::signin($area, $profile, $password);
110 - if ($data['code'] == 200) {  
111 - $data['data'] = '/'; // @todo 110 + if ($data['code'] != 200 || !isset($data['data']['uid'])) {
  111 + break;
112 } 112 }
  113 +
  114 +// /* 获取用户的信息 */
  115 +// $profile = LoginData::profile($data['data']['uid']);
  116 +// $name = 'YOHO!';
  117 +// if (!empty($profile['data']['nickname'])) {
  118 +// $name = $profile['data']['nickname'];
  119 +// } elseif (!empty($profile['data']['username'])) {
  120 +// $name = $profile['data']['username'];
  121 +// } elseif (!empty($profile['data']['email'])) {
  122 +// $name = $profile['data']['email'];
  123 +// } elseif (!empty($profile['data']['mobile'])) {
  124 +// $name = $profile['data']['mobile'];
  125 +// }
  126 + $data['data'] = '/'; // @todo
113 } 127 }
114 while (false); 128 while (false);
115 129
@@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index" @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
19 application.dispatcher.defaultAction = "index" 19 application.dispatcher.defaultAction = "index"
20 20
21 ;;初始化命名空间 21 ;;初始化命名空间
22 -application.namespaces = "Action,Api,LibModels,Plugin" 22 +application.namespaces = "Action,Api,Configs,LibModels,Plugin"
23 23
24 ;;使用composer 24 ;;使用composer
25 composer.autoload = 0 25 composer.autoload = 0
@@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index" @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
19 application.dispatcher.defaultAction = "index" 19 application.dispatcher.defaultAction = "index"
20 20
21 ;;初始化命名空间 21 ;;初始化命名空间
22 -application.namespaces = "Action,Api,LibModels,Plugin" 22 +application.namespaces = "Action,Api,Configs,LibModels,Plugin"
23 23
24 ;;使用composer 24 ;;使用composer
25 composer.autoload = 0 25 composer.autoload = 0
@@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index" @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
19 application.dispatcher.defaultAction = "index" 19 application.dispatcher.defaultAction = "index"
20 20
21 ;;初始化命名空间 21 ;;初始化命名空间
22 -application.namespaces = "Action,Api,LibModels,Plugin" 22 +application.namespaces = "Action,Api,Configs,LibModels,Plugin"
23 23
24 ;;使用composer 24 ;;使用composer
25 composer.autoload = 0 25 composer.autoload = 0
  1 +User-agent: *
  2 +Disallow: /