Authored by hf

code review by fei.hong: do test yuanxiao huodong redirect

@@ -17,9 +17,7 @@ @@ -17,9 +17,7 @@
17 </div> 17 </div>
18 <script type="text/javascript"> 18 <script type="text/javascript">
19 setTimeout(function (){ 19 setTimeout(function (){
20 - location.href = '{{activityUrl}}';  
21 -  
22 - // location.href = '{{activityUrl}}?openby:yohobuy={"action":"go.h5","params":{"title":"元宵抽签","url":"{{activityUrl}}","share":"\/operations\/api\/v5\/webshare\/getShare","shareparam":{"share_id":"1"},"param":{"share_id":"1"}}}'; 20 + location.href = '{{{activityUrl}}}';
23 }, 2000); 21 }, 2000);
24 </script> 22 </script>
25 {{> cuxiao/yuanxiao/footer}} 23 {{> cuxiao/yuanxiao/footer}}
@@ -9,23 +9,11 @@ use Plugin\Helpers; @@ -9,23 +9,11 @@ use Plugin\Helpers;
9 */ 9 */
10 class YuanxiaoController extends HuodongAction 10 class YuanxiaoController extends HuodongAction
11 { 11 {
12 - // const STATIC_FILE = 'http://localhost:2222/assets/1.1.4';  
13 - const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.1.4'; 12 + // const STATIC_FILE = 'http://localhost:2222/assets/1.1.3';
  13 + const STATIC_FILE = 'http://cdn.yoho.cn/huodong/2016yuanxiao/1.1.5';
14 const ENCRYPT_KEY = 'iamgtskkwhoareyou'; 14 const ENCRYPT_KEY = 'iamgtskkwhoareyou';
15 15
16 /** 16 /**
17 - * 通过当前用户审判是否跳到登录页  
18 - *  
19 - */  
20 - private function auditJumpLogin()  
21 - {  
22 - $uid = $this->getLoggedUid();  
23 - if (!$uid || !is_numeric($uid)) {  
24 - $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));  
25 - }  
26 - }  
27 -  
28 - /**  
29 * 元宵抽签 17 * 元宵抽签
30 */ 18 */
31 public function indexAction() 19 public function indexAction()
@@ -34,12 +22,12 @@ class YuanxiaoController extends HuodongAction @@ -34,12 +22,12 @@ class YuanxiaoController extends HuodongAction
34 $playUrlEncode = strtr($playUrl, array('/' => '\\/')); 22 $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
35 23
36 $this->_view->display('index', array( 24 $this->_view->display('index', array(
37 - 'staticTitle' => '2016潮流运势测试', 25 + 'staticTitle' => '2016潮流运势测试',
38 'staticFile' => self::STATIC_FILE, 26 'staticFile' => self::STATIC_FILE,
39 'staticJS' => array( 27 'staticJS' => array(
40 'home.js' 28 'home.js'
41 ), 29 ),
42 - 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!', 30 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
43 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png', 31 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
44 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'), 32 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
45 'playUrl' => $this->isApp() ? $playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}': $playUrl, 33 'playUrl' => $this->isApp() ? $playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}': $playUrl,
@@ -56,7 +44,8 @@ class YuanxiaoController extends HuodongAction @@ -56,7 +44,8 @@ class YuanxiaoController extends HuodongAction
56 if (!$this->_isApp) { 44 if (!$this->_isApp) {
57 $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default')); 45 $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/yuanxiao/info')), 'default'));
58 } else { 46 } else {
59 - exit(); 47 + $playUrl = Helpers::url('/cuxiao/yuanxiao/index');
  48 + $this->go($playUrl . '?yohobuy={"action":"go.h5","params":{"islogin":"N","type":0,"url":"' . $playUrl . '","param":{}}}');
60 } 49 }
61 } 50 }
62 51
@@ -72,6 +61,7 @@ class YuanxiaoController extends HuodongAction @@ -72,6 +61,7 @@ class YuanxiaoController extends HuodongAction
72 61
73 // 调用接口 62 // 调用接口
74 $result = YuanxiaoModel::getChouqianInfo($uid, $nickName, $FormatBirthday, $gender); 63 $result = YuanxiaoModel::getChouqianInfo($uid, $nickName, $FormatBirthday, $gender);
  64 +
75 if ($result['code'] === 200) { // 处理成功就跳转到等待页 65 if ($result['code'] === 200) { // 处理成功就跳转到等待页
76 // 将返回的结果存入cookeie中15分钟 66 // 将返回的结果存入cookeie中15分钟
77 $cookieData = array( 67 $cookieData = array(
@@ -79,15 +69,19 @@ class YuanxiaoController extends HuodongAction @@ -79,15 +69,19 @@ class YuanxiaoController extends HuodongAction
79 'type' => $result['data']['randomCode'] 69 'type' => $result['data']['randomCode']
80 ); 70 );
81 $this->setCookie('yuanxiaochouqian', json_encode($cookieData), time() + 15 * 60); 71 $this->setCookie('yuanxiaochouqian', json_encode($cookieData), time() + 15 * 60);
82 - $this->go(Helpers::url('/cuxiao/yuanxiao/wait')); 72 +
  73 + $waitUrl = Helpers::url('/cuxiao/yuanxiao/wait');
  74 + $this->go(!$this->isWeixin() ? $waitUrl . '?openby:yohobuy={"action":"go.h5","params":{"url":"' . $waitUrl . '","islogin":"N","param":{"from":"app"}}}' : $waitUrl);
  75 +
83 } else { // 不成功就显示返回的错误信息 76 } else { // 不成功就显示返回的错误信息
  77 +
84 $this->_view->display('info', array( 78 $this->_view->display('info', array(
85 - 'staticTitle' => '2016潮流运势测试', 79 + 'staticTitle' => '2016潮流运势测试',
86 'staticFile' => self::STATIC_FILE, 80 'staticFile' => self::STATIC_FILE,
87 'staticJS' => array( 81 'staticJS' => array(
88 'info.js' 82 'info.js'
89 ), 83 ),
90 - 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!', 84 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
91 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png', 85 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
92 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'), 86 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
93 'birthday' => $birthday, 87 'birthday' => $birthday,
@@ -99,21 +93,14 @@ class YuanxiaoController extends HuodongAction @@ -99,21 +93,14 @@ class YuanxiaoController extends HuodongAction
99 } 93 }
100 } else { 94 } else {
101 $userData = YuanxiaoModel::getUserProfileData($uid); 95 $userData = YuanxiaoModel::getUserProfileData($uid);
102 - // 接口返回空数据时,设置默认值  
103 - if (empty($userData['birthday']) || $userData['birthday'] === '0000-00-00') {  
104 - $userData = array(  
105 - 'birthday' => '1990-01-01',  
106 - 'gender' => '3',  
107 - );  
108 - }  
109 96
110 $this->_view->display('info', array( 97 $this->_view->display('info', array(
111 - 'staticTitle' => '2016潮流运势测试', 98 + 'staticTitle' => '2016潮流运势测试',
112 'staticFile' => self::STATIC_FILE, 99 'staticFile' => self::STATIC_FILE,
113 'staticJS' => array( 100 'staticJS' => array(
114 'info.js' 101 'info.js'
115 ), 102 ),
116 - 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!', 103 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
117 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png', 104 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
118 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'), 105 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
119 'birthday' => date_format(date_create($userData['birthday']), 'Y年m月d日'), 106 'birthday' => date_format(date_create($userData['birthday']), 'Y年m月d日'),
@@ -129,17 +116,17 @@ class YuanxiaoController extends HuodongAction @@ -129,17 +116,17 @@ class YuanxiaoController extends HuodongAction
129 */ 116 */
130 public function waitAction() 117 public function waitAction()
131 { 118 {
132 - // 审判跳转登录页  
133 - // $this->auditJumpLogin(); 119 + $activityUrl = Helpers::url('/cuxiao/yuanxiao/result');
  120 + $activityUrlEncode = strtr($activityUrl, array('/' => '\\/'));
134 121
135 $this->_view->display('wait', array( 122 $this->_view->display('wait', array(
136 - 'staticTitle' => '2016潮流运势测试', 123 + 'staticTitle' => '2016潮流运势测试',
137 'staticFile' => self::STATIC_FILE, 124 'staticFile' => self::STATIC_FILE,
138 - 'activityUrl' => Helpers::url('/cuxiao/yuanxiao/result'), 125 + 'activityUrl' => !$this->isWeixin() ? $activityUrl . '?openby:yohobuy={"action":"go.h5","params":{"url":"' . $activityUrlEncode . '","islogin":"N","param":{"share_id":"19"},"share":"'.$activityUrlEncode.'","shareparam":{"share_id":"19"}}}' : $activityUrl,
139 'staticJS' => array( 126 'staticJS' => array(
140 'wait.js' 127 'wait.js'
141 ), 128 ),
142 - 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!', 129 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
143 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png', 130 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
144 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'), 131 'shareUrl' => Helpers::url('/cuxiao/yuanxiao/index'),
145 )); 132 ));
@@ -150,9 +137,6 @@ class YuanxiaoController extends HuodongAction @@ -150,9 +137,6 @@ class YuanxiaoController extends HuodongAction
150 */ 137 */
151 public function resultAction() 138 public function resultAction()
152 { 139 {
153 - // 审判跳转登录页  
154 - //$this->auditJumpLogin();  
155 -  
156 $result = $this->getCookie('yuanxiaochouqian', null); 140 $result = $this->getCookie('yuanxiaochouqian', null);
157 if (empty($result)) { // 未取到信息就重新测试 141 if (empty($result)) { // 未取到信息就重新测试
158 $this->go(Helpers::url('/cuxiao/yuanxiao/info')); 142 $this->go(Helpers::url('/cuxiao/yuanxiao/info'));
@@ -162,16 +146,17 @@ class YuanxiaoController extends HuodongAction @@ -162,16 +146,17 @@ class YuanxiaoController extends HuodongAction
162 $result = json_decode($result, true); 146 $result = json_decode($result, true);
163 $shareUrl = Helpers::url('/cuxiao/yuanxiao/share', array( 147 $shareUrl = Helpers::url('/cuxiao/yuanxiao/share', array(
164 'hash' => $this->encrypt($this->getUid()), 148 'hash' => $this->encrypt($this->getUid()),
165 - 'type' => $this->encrypt($result['type']) 149 + 'type' => $this->encrypt($result['type']),
  150 + 'name' => $this->encrypt($result['name'])
166 )); 151 ));
167 152
168 $this->_view->display('result', array( 153 $this->_view->display('result', array(
169 - 'staticTitle' => '2016潮流运势测试!',  
170 - 'needShare' => $this->checkNeedShare(), // 是否需要微信分享 154 + 'staticTitle' => '2016潮流运势测试',
  155 + 'needShare' => true, // 是否需要微信分享
171 'staticFile' => self::STATIC_FILE, 156 'staticFile' => self::STATIC_FILE,
172 'result' => $result, 157 'result' => $result,
173 'shareTitle' => $result['name'] . '的2016年潮流运势是' . $this->getChouqianTitle($result['type']), 158 'shareTitle' => $result['name'] . '的2016年潮流运势是' . $this->getChouqianTitle($result['type']),
174 - 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!', 159 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
175 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png', 160 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png',
176 'shareUrl' => $shareUrl, 161 'shareUrl' => $shareUrl,
177 'staticJS' => array( 162 'staticJS' => array(
@@ -192,22 +177,23 @@ class YuanxiaoController extends HuodongAction @@ -192,22 +177,23 @@ class YuanxiaoController extends HuodongAction
192 } 177 }
193 // 抽签结果 178 // 抽签结果
194 $type = $this->decrypt($this->get('type', '')); 179 $type = $this->decrypt($this->get('type', ''));
  180 + $name = $this->decrypt($this->get('name', ''));
195 181
196 // 调用接口获取type和count 182 // 调用接口获取type和count
197 $result = YuanxiaoModel::getChoujiangShareInfo($uid); 183 $result = YuanxiaoModel::getChoujiangShareInfo($uid);
198 184
199 $this->_view->display('share', array( 185 $this->_view->display('share', array(
200 - 'staticTitle' => '2016潮流运势测试', 186 + 'staticTitle' => '2016潮流运势测试',
201 'staticFile' => self::STATIC_FILE, 187 'staticFile' => self::STATIC_FILE,
202 'result' => array( 188 'result' => array(
203 - 'name' => $result['name'], 189 + 'name' => $name ?: $result['name'],
204 'type' => $type ?: $result['type'] 190 'type' => $type ?: $result['type']
205 ), 191 ),
206 'count' => $result['total'], 192 'count' => $result['total'],
207 'staticJS' => array( 193 'staticJS' => array(
208 'share.js' 194 'share.js'
209 ), 195 ),
210 - 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!', 196 + 'shareDesc' => '元宵快乐!一起来YOHO!BUY有货玩2016年潮流开运测试!',
211 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png' 197 'shareImg' => 'http://img02.yohoboys.com/staticimg/2016/02/19/16/02dbd38c84eccf1097b7e240452f0de856.png'
212 )); 198 ));
213 } 199 }
@@ -268,7 +254,16 @@ class YuanxiaoController extends HuodongAction @@ -268,7 +254,16 @@ class YuanxiaoController extends HuodongAction
268 */ 254 */
269 private function checkNeedShare() 255 private function checkNeedShare()
270 { 256 {
271 - if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false || $this->_isApp) { 257 + // Android
  258 + if ($this->_isApp) {
  259 + return true;
  260 + }
  261 + // IPhone
  262 + elseif (null !== $this->get('openby:yohobuy', null)) {
  263 + return true;
  264 + }
  265 + // 微信
  266 + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
272 return true; 267 return true;
273 } 268 }
274 269
@@ -276,6 +271,14 @@ class YuanxiaoController extends HuodongAction @@ -276,6 +271,14 @@ class YuanxiaoController extends HuodongAction
276 } 271 }
277 272
278 /** 273 /**
  274 + * 判断是否是微信访问
  275 + */
  276 + private function isWeixin()
  277 + {
  278 + return (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false);
  279 + }
  280 +
  281 + /**
279 * 加密字符串 282 * 加密字符串
280 * 283 *
281 * @param string $data 需要加密的字符串 284 * @param string $data 需要加密的字符串