Authored by 周少峰

Merge branch 'develop' of git.dev.yoho.cn:web/yohobuy into feature/web-list

@@ -25,7 +25,7 @@ class LoginData extends \LibModels\Wap\Passport\LoginData @@ -25,7 +25,7 @@ class LoginData extends \LibModels\Wap\Passport\LoginData
25 * @param string $shoppingKey 未登录用户唯一识别码, 默认为空 25 * @param string $shoppingKey 未登录用户唯一识别码, 默认为空
26 * @return array 登录返回结果 26 * @return array 登录返回结果
27 */ 27 */
28 - public static function signinByOpenID($nickname, $openId, $sourceType, $shoppingKey = null) 28 + public static function signinByOpenID($nickname, $openId, $sourceType, $shoppingKey = null, $replaceId = '')
29 { 29 {
30 // 构建必传参数 30 // 构建必传参数
31 $param = Yohobuy::param(); 31 $param = Yohobuy::param();
@@ -35,13 +35,18 @@ class LoginData extends \LibModels\Wap\Passport\LoginData @@ -35,13 +35,18 @@ class LoginData extends \LibModels\Wap\Passport\LoginData
35 $param['openId'] = $openId; 35 $param['openId'] = $openId;
36 $param['source_type'] = $sourceType; 36 $param['source_type'] = $sourceType;
37 $param['nickname'] = $nickname; 37 $param['nickname'] = $nickname;
  38 + //wechat传入replace_id
  39 + if (!empty($replaceId)) {
  40 + $param['replace_id'] = $replaceId;
  41 + }
  42 + //购物车
38 if (!empty($shoppingKey)) { 43 if (!empty($shoppingKey)) {
39 $param['shopping_key'] = $shoppingKey; 44 $param['shopping_key'] = $shoppingKey;
40 } 45 }
41 46
42 $param['client_secret'] = Sign::getSign($param); 47 $param['client_secret'] = Sign::getSign($param);
43 48
44 - return Yohobuy::get(Yohobuy::API_URL, $param); 49 + return Yohobuy::get(Yohobuy::API_URL2, $param);
45 } 50 }
46 51
47 } 52 }
  1 +<?php
  2 +
  3 +namespace Plugin\Partner\wechat;
  4 +
  5 +use Plugin\Partner\Factory;
  6 +
  7 +define('WECHAT_CLASS_PATH', dirname(__FILE__) . '/class/');
  8 +require WECHAT_CLASS_PATH . 'Wechat.class.php';
  9 +
  10 +/**
  11 + * 微信的调用接口
  12 + *
  13 + * @name Call
  14 + * @package lib/partner/wechat
  15 + * @copyright yoho.inc
  16 + * @version 5.0 (2016-01-12 10:54:54)
  17 + * @author xiaowei <xiaowei.gong@yoho.cn>
  18 + */
  19 +class Call extends Factory
  20 +{
  21 +
  22 + //微信对象
  23 + protected $wechat;
  24 +
  25 + /**
  26 + * 初始化
  27 + */
  28 + protected function init()
  29 + {
  30 + $this->wechat = new \WechatAuth($this->apiConfig['appId'], $this->apiConfig['appKey']);
  31 + }
  32 +
  33 + /**
  34 + * 获取授权URL
  35 + *
  36 + * @return string
  37 + */
  38 + public function getAuthorizeUrl()
  39 + {
  40 + return $this->wechat->getAuthorizeURL($this->apiConfig['callback'], $this->apiConfig['scope']);
  41 + }
  42 +
  43 + /**
  44 + * 获取授权的TOKEN
  45 + *
  46 + * @return array
  47 + */
  48 + public function getAccessToken()
  49 + {
  50 + $token = array();
  51 +
  52 + if (isset($_REQUEST['code']) && !empty($_REQUEST['code'])) {
  53 + try {
  54 + $token = $this->wechat->getAccessToken($_REQUEST['code']);
  55 + }
  56 + catch (Exception $e) {
  57 + // do nothing
  58 + }
  59 + }
  60 +
  61 + return $token;
  62 + }
  63 +
  64 + /**
  65 + * 获取当前用户的基本资料
  66 + *
  67 + * @param object $token 授权成功的TOKEN, 默认为NULL
  68 + * @return array
  69 + */
  70 + public function getUserInfo($token)
  71 + {
  72 + $userInfo = array();
  73 +
  74 + if (!empty($token)) {
  75 + $userInfo = $this->wechat->getUserInfo($token['access_token'], $token['openid']);
  76 + }
  77 +
  78 + return $userInfo;
  79 + }
  80 +
  81 + public function getFriends($token, $params)
  82 + {
  83 +
  84 + }
  85 +
  86 + public function syncShare($token, $content, $image, $link)
  87 + {
  88 +
  89 + }
  90 +
  91 +}
  1 +<?php
  2 +
  3 +defined('SITE_MAIN') || define('SITE_MAIN', $_SERVER['HTTP_HOST']);
  4 +
  5 +return array(
  6 + 'appId' => 'wx3ae21dcbb82ad672',
  7 + 'appKey' => 'e78afb2321e6a19085767e1a0f0d52c1',
  8 + 'callback' => SITE_MAIN . '/passport/autosign/wechatback',
  9 + 'scope' => 'snsapi_login'
  10 +);
  1 +<?php
  2 +
  3 +/**
  4 + * @ignore
  5 + */
  6 +class OAuthException extends Exception
  7 +{
  8 + // pass
  9 +}
  10 +
  11 +class WechatAuth
  12 +{
  13 +
  14 + /**
  15 + * @ignore
  16 + */
  17 + public $appId;
  18 +
  19 + /**
  20 + * @ignore
  21 + */
  22 + public $appKey;
  23 +
  24 + /**
  25 + * @ignore
  26 + */
  27 + public $accessToken;
  28 +
  29 + /**
  30 + * @ignore
  31 + */
  32 + public $refreshToken;
  33 +
  34 + /**
  35 + * Set API URLS
  36 + */
  37 +
  38 + /**
  39 + * @ignore
  40 + */
  41 + function userInfoURL()
  42 + {
  43 + return 'https://api.weixin.qq.com/sns/userinfo';
  44 + }
  45 +
  46 + /**
  47 + * @ignore
  48 + */
  49 + function authorizeURL()
  50 + {
  51 + return 'https://open.weixin.qq.com/connect/qrconnect';
  52 + }
  53 +
  54 + /**
  55 + * @ignore
  56 + */
  57 + function accessTokenURL()
  58 + {
  59 + return 'https://api.weixin.qq.com/sns/oauth2/access_token';
  60 + }
  61 +
  62 + /**
  63 + * construct WeichatOAuth object
  64 + */
  65 + function __construct($appId, $appKey, $accessToken = NULL)
  66 + {
  67 + $this->appId = $appId;
  68 + $this->appKey = $appKey;
  69 + $this->accessToken = $accessToken;
  70 + }
  71 +
  72 + /**
  73 + * authorize接口
  74 + * $callBackurl 回调地址
  75 + */
  76 + function getAuthorizeURL($callBackurl, $scope, $responseType = 'code', $state = 'STATE#wechat_redirect')
  77 + {
  78 + $params = array();
  79 + $params['appid'] = $this->appId;
  80 + $params['redirect_uri'] = $callBackurl;
  81 + $params['response_type'] = $responseType;
  82 + $params['scope'] = $scope;
  83 + $params['state'] = $state;
  84 + return $this->authorizeURL() . "?" . http_build_query($params);
  85 + }
  86 +
  87 + /*
  88 + * 获取accesstoken
  89 + * code:授权链接返回的code
  90 + */
  91 +
  92 + function getAccessToken($code, $grant_type = 'authorization_code')
  93 + {
  94 + if (empty($code)) {
  95 + return '';
  96 + }
  97 + $params = array();
  98 + $params['appid'] = $this->appId;
  99 + $params['secret'] = $this->appKey;
  100 + $params['code'] = $code;
  101 + $params['grant_type'] = $grant_type;
  102 + $url = $this->accessTokenURL() . "?" . http_build_query($params);
  103 + $result = self::getCurl($url);
  104 + return json_decode($result, true);
  105 + }
  106 +
  107 + // 获取用户信息
  108 + function getUserInfo($access_token, $openid)
  109 + {
  110 + if (empty($access_token) || empty($openid)) {
  111 + return array();
  112 + }
  113 + $params = array();
  114 + $params['access_token'] = $access_token;
  115 + $params['openid'] = $openid;
  116 + $url = $this->userInfoURL() . "?" . http_build_query($params);
  117 + $result = self::getCurl($url);
  118 + return json_decode($result, true);
  119 + }
  120 +
  121 + /**
  122 + * Send a GET requst using cURL
  123 + * @param string $url to request
  124 + * @param array $get values to send
  125 + * @param array $options for cURL
  126 + * @return string
  127 + */
  128 + public static function getCurl($url,$method="GET")
  129 + {
  130 + $curl = curl_init();
  131 + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  132 + curl_setopt($curl, CURLOPT_URL, $url);
  133 + curl_setopt($curl, CURLOPT_TIMEOUT, 20);
  134 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  135 + curl_setopt($curl, CURLOPT_HEADER, 0);
  136 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  137 +
  138 + $output = curl_exec($curl);
  139 + curl_close($curl);
  140 + return $output;
  141 + }
  142 +}
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div class="brand-page brand-search-page yoho-page"> 2 <div class="brand-page brand-search-page yoho-page">
3 <div class="newbrand-search"> 3 <div class="newbrand-search">
4 <form class="search-box clearfix"> 4 <form class="search-box clearfix">
5 - <input type="text" class="search-input" id="keyword" placeholder="查找品牌"> 5 + <input type="text" class="search-input" id="keyword" placeholder="查找品牌" autofocus>
6 <i class="search-icon iconfont">&#xe60f;</i> 6 <i class="search-icon iconfont">&#xe60f;</i>
7 <div class="search-action"> 7 <div class="search-action">
8 <span class="iconfont clear-text">&#xe623;</span> 8 <span class="iconfont clear-text">&#xe623;</span>
@@ -259,9 +259,12 @@ if ($udPrice.length > 0) { @@ -259,9 +259,12 @@ if ($udPrice.length > 0) {
259 259
260 //【高级选项】鼠标移入显示子项 260 //【高级选项】鼠标移入显示子项
261 $seniorAttrWrap.on('mouseenter', '.attr', function() { 261 $seniorAttrWrap.on('mouseenter', '.attr', function() {
262 - var index = $(this).addClass('hover').index(); 262 + var $this = $(this);
  263 + var index = $this.index();
  264 +
  265 + $this.addClass('hover').siblings().removeClass('hover');
263 266
264 - $seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide'); 267 + $seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
265 }).on('mouseleave', '.attr', function() { 268 }).on('mouseleave', '.attr', function() {
266 var $this = $(this), 269 var $this = $(this),
267 index = $this.index(); 270 index = $this.index();
@@ -265,6 +265,7 @@ @@ -265,6 +265,7 @@
265 top: 39px; 265 top: 39px;
266 background: #fff; 266 background: #fff;
267 border: 1px solid #eaeceb; 267 border: 1px solid #eaeceb;
  268 + z-index: 1;
268 269
269 ul { 270 ul {
270 max-width: 950px; 271 max-width: 950px;
@@ -230,12 +230,14 @@ class HomeModel @@ -230,12 +230,14 @@ class HomeModel
230 $sortList = ChannelConfig::$newArrivalSortList[$channel]; 230 $sortList = ChannelConfig::$newArrivalSortList[$channel];
231 // 获取分类列表获取商品信息 231 // 获取分类列表获取商品信息
232 $goodsList = SearchData::getSearchDataBySort($params, $sortList); 232 $goodsList = SearchData::getSearchDataBySort($params, $sortList);
  233 + $pos = 1;
233 foreach ($goodsList as $goods) { 234 foreach ($goodsList as $goods) {
234 // 格式化数据 235 // 格式化数据
235 $val = Helpers::formatProduct($goods, true, true, true, 280, 373); 236 $val = Helpers::formatProduct($goods, true, true, true, 280, 373);
236 if ($val['price'] == false) { 237 if ($val['price'] == false) {
237 $val['price'] = $val['salePrice']; 238 $val['price'] = $val['salePrice'];
238 } 239 }
  240 + $val['url'] = sprintf('%s?channel=%s&from=%s-n_%s', $val['url'], $channel , $channel, $pos++);
239 //TODO 字段要调整 241 //TODO 字段要调整
240 $val['isFew'] = $val['is_soon_sold_out']; 242 $val['isFew'] = $val['is_soon_sold_out'];
241 $val['tags']['isLimit'] = $val['tags']['is_limited']; 243 $val['tags']['isLimit'] = $val['tags']['is_limited'];
@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 use LibModels\Web\Passport\LoginData; 4 use LibModels\Web\Passport\LoginData;
5 -use Passport\PassportModel as PassportModel;  
6 use Plugin\Helpers; 5 use Plugin\Helpers;
7 use Plugin\Partner\Factory; 6 use Plugin\Partner\Factory;
8 7
@@ -66,9 +65,10 @@ class AutosignController extends AbstractAction @@ -66,9 +65,10 @@ class AutosignController extends AbstractAction
66 /** 65 /**
67 * 微信网站授权入口 66 * 微信网站授权入口
68 */ 67 */
69 - public function wechatAction(){  
70 - $url = QINWechat_Sdk_Open::getCode('http://www.yohobuy.com/passport/autosign/wechatback');  
71 - $this->helpGo($url); 68 + public function wechatAction()
  69 + {
  70 + $this->setSession('_TOKEN', '');
  71 + $this->go(Factory::create('wechat')->getAuthorizeUrl());
72 } 72 }
73 73
74 /** 74 /**
@@ -88,7 +88,12 @@ class AutosignController extends AbstractAction @@ -88,7 +88,12 @@ class AutosignController extends AbstractAction
88 88
89 //判定是否需要绑定手机号 89 //判定是否需要绑定手机号
90 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') { 90 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
91 - $this->go(Helpers::url('/passport/bind/index', array('openId' => $userId, 'sourceType' => 'alipay', 'nickname' => $realName))); 91 + $token = Helpers::makeToken($result['data']['uid']);
  92 + $this->setSession('_TOKEN', $token);
  93 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  94 + $this->setCookie('_TOKEN', $token);
  95 + $fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $userId, 'sourceType' => 'alipay', 'nickname' => $realName)));
  96 + $this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
92 } 97 }
93 98
94 $refer = $this->getCookie('refer'); 99 $refer = $this->getCookie('refer');
@@ -126,11 +131,6 @@ class AutosignController extends AbstractAction @@ -126,11 +131,6 @@ class AutosignController extends AbstractAction
126 $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq', $shoppingKey); 131 $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq', $shoppingKey);
127 } 132 }
128 133
129 - //判定是否需要绑定手机号  
130 - if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {  
131 - $this->go(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['openid'], 'sourceType' => 'qq', 'nickname' => $partnerInfo['nickname'])));  
132 - }  
133 -  
134 $refer = $this->getCookie('refer'); 134 $refer = $this->getCookie('refer');
135 if (empty($refer)) { 135 if (empty($refer)) {
136 $refer = SITE_MAIN . '/?go=1'; 136 $refer = SITE_MAIN . '/?go=1';
@@ -139,6 +139,16 @@ class AutosignController extends AbstractAction @@ -139,6 +139,16 @@ class AutosignController extends AbstractAction
139 $refer = rawurldecode($refer); 139 $refer = rawurldecode($refer);
140 } 140 }
141 141
  142 + //判定是否需要绑定手机号
  143 + if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
  144 + $token = Helpers::makeToken($result['data']['uid']);
  145 + $this->setSession('_TOKEN', $token);
  146 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  147 + $this->setCookie('_TOKEN', $token);
  148 + $fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['openid'], 'sourceType' => 'qq', 'nickname' => $partnerInfo['nickname'])));
  149 + $this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
  150 + }
  151 +
142 if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) { 152 if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
143 $token = Helpers::makeToken($result['data']['uid']); 153 $token = Helpers::makeToken($result['data']['uid']);
144 $this->setSession('_TOKEN', $token); 154 $this->setSession('_TOKEN', $token);
@@ -169,7 +179,12 @@ class AutosignController extends AbstractAction @@ -169,7 +179,12 @@ class AutosignController extends AbstractAction
169 179
170 //判定是否需要绑定手机号 180 //判定是否需要绑定手机号
171 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') { 181 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
172 -// $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name']))); 182 + $token = Helpers::makeToken($result['data']['uid']);
  183 + $this->setSession('_TOKEN', $token);
  184 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  185 + $this->setCookie('_TOKEN', $token);
  186 + $fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name'])));
  187 + $this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
173 } 188 }
174 189
175 $refer = $this->getCookie('refer'); 190 $refer = $this->getCookie('refer');
@@ -199,18 +214,21 @@ class AutosignController extends AbstractAction @@ -199,18 +214,21 @@ class AutosignController extends AbstractAction
199 { 214 {
200 $renren = Factory::create('renren'); 215 $renren = Factory::create('renren');
201 $access = $renren->getAccessToken(); 216 $access = $renren->getAccessToken();
202 - /* 获取用户的详细信息 */  
203 - $partnerInfo = $renren->getUserInfo($access);  
204 217
205 $result = array(); 218 $result = array();
206 - if ($partnerInfo && is_array($partnerInfo)) { 219 + if ($access && is_array($access)) {
207 $shoppingKey = Helpers::getShoppingKeyByCookie(); 220 $shoppingKey = Helpers::getShoppingKeyByCookie();
208 - $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['uid'], 'renren', $shoppingKey); 221 + $result = LoginData::signinByOpenID($access['user']['name'], $access['user']['id'], 'renren', $shoppingKey);
209 } 222 }
210 223
211 //判定是否需要绑定手机号 224 //判定是否需要绑定手机号
212 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') { 225 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
213 -// $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['nick_name']))); 226 + $token = Helpers::makeToken($result['data']['uid']);
  227 + $this->setSession('_TOKEN', $token);
  228 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  229 + $this->setCookie('_TOKEN', $token);
  230 + $fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['user']['id'], 'sourceType' => 'renren', 'nickname' => $access['user']['name'])));
  231 + $this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
214 } 232 }
215 233
216 $refer = $this->getCookie('refer'); 234 $refer = $this->getCookie('refer');
@@ -238,20 +256,25 @@ class AutosignController extends AbstractAction @@ -238,20 +256,25 @@ class AutosignController extends AbstractAction
238 */ 256 */
239 public function doubanbackAction() 257 public function doubanbackAction()
240 { 258 {
241 - $sina = Factory::create('douban');  
242 - $access = $sina->getAccessToken(); 259 + $douban = Factory::create('douban');
  260 + $access = $douban->getAccessToken();
243 /* 获取用户的详细信息 */ 261 /* 获取用户的详细信息 */
244 - $partnerInfo = $sina->getUserInfo($access); 262 + $partnerInfo = $douban->getUserInfo($access);
245 263
246 $result = array(); 264 $result = array();
247 if ($partnerInfo && is_array($partnerInfo)) { 265 if ($partnerInfo && is_array($partnerInfo)) {
248 $shoppingKey = Helpers::getShoppingKeyByCookie(); 266 $shoppingKey = Helpers::getShoppingKeyByCookie();
249 - $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['uid'], 'douban', $shoppingKey); 267 + $result = LoginData::signinByOpenID($partnerInfo['name'], $partnerInfo['uid'], 'douban', $shoppingKey);
250 } 268 }
251 269
252 //判定是否需要绑定手机号 270 //判定是否需要绑定手机号
253 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') { 271 if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
254 -// $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name']))); 272 + $token = Helpers::makeToken($result['data']['uid']);
  273 + $this->setSession('_TOKEN', $token);
  274 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  275 + $this->setCookie('_TOKEN', $token);
  276 + $fillHerf =rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['douban_user_id'], 'sourceType' => 'douban', 'nickname' => $partnerInfo['name'])));
  277 + $this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
255 } 278 }
256 279
257 $refer = $this->getCookie('refer'); 280 $refer = $this->getCookie('refer');
@@ -274,51 +297,50 @@ class AutosignController extends AbstractAction @@ -274,51 +297,50 @@ class AutosignController extends AbstractAction
274 } 297 }
275 } 298 }
276 299
277 -  
278 /** 300 /**
279 * 微信网站授权获取用户信息并登录 301 * 微信网站授权获取用户信息并登录
280 * @param string code 302 * @param string code
281 */ 303 */
282 - public function wechatbackAction(){  
283 - $code = $this->helpGquery('code');  
284 - $accessToken = QINWechat_Sdk_Open::getAccessToken($code);  
285 - $userInfo = array();  
286 - if(empty($accessToken)){  
287 - $this->helpGo('/signin.html'); 304 + public function wechatbackAction()
  305 + {
  306 + $wechat = Factory::create('wechat');
  307 + $access = $wechat->getAccessToken();
  308 + /* 获取用户的详细信息 */
  309 + $partnerInfo = $wechat->getUserInfo($access);
  310 +
  311 + $result = array();
  312 + if ($partnerInfo && is_array($partnerInfo)) {
  313 + $shoppingKey = Helpers::getShoppingKeyByCookie();
  314 + $result = LoginData::signinByOpenID($partnerInfo['nickname'],$partnerInfo['openid'], 'wechat', $shoppingKey,$partnerInfo['openid']);
288 } 315 }
289 - if(!isset($accessToken['access_token']) || !isset($accessToken['unionid']) || empty($accessToken['access_token']) || empty($accessToken['unionid'])){  
290 - $this->helpGo('/signin.html'); 316 +
  317 + //判定是否需要绑定手机号
  318 + if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
  319 + $token = Helpers::makeToken($result['data']['uid']);
  320 + $this->setSession('_TOKEN', $token);
  321 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  322 + $this->setCookie('_TOKEN', $token);
  323 + $fillHerf =rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $partnerInfo['openid'], 'sourceType' => 'wechat', 'nickname' => $partnerInfo['nickname'])));
  324 + $this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
291 } 325 }
292 - $userInfo = QINWechat_Sdk_Open::getUserInfo($accessToken['access_token'], $accessToken['unionid']);  
293 - if(empty($userInfo)){  
294 - $this->helpGo('/signin.html'); 326 +
  327 + $refer = $this->getCookie('refer');
  328 + if (empty($refer)) {
  329 + $refer = SITE_MAIN . '/?go=1';
295 } 330 }
296 - $this->wechatlogin($userInfo); 331 + else {
  332 + $refer = rawurldecode($refer);
297 } 333 }
298 334
299 - /**  
300 - * 微信登录  
301 - * @param array $userInfo  
302 - */  
303 - public function wechatlogin($userInfo){  
304 - if(empty($userInfo)){  
305 - $this->helpGo('/signin.html');  
306 - }  
307 - try {  
308 - $oauthUserInfo = QINAuth_User_Utils::check('wechat', $userInfo['unionid'], $userInfo['nickname'], null, $userInfo);  
309 - $auth = QINAuth_Factory::profile('wechat');  
310 - $res=$auth->associate($oauthUserInfo['email'], array(  
311 - 'password' => QINAuth_User_Utils::$defaultPassword,  
312 - 'open_id' => $userInfo['unionid'],  
313 - 'nick_name' => $userInfo['nickname']  
314 - ));  
315 - } catch (Exception $e) {  
316 - $this->helpSession('passport_space')->__set('error_message', 'wechat' . $e->getMessage());  
317 - $this->helpGo('/signin.html');  
318 - }  
319 - //跳转到  
320 - $url = $this->authInfo($res, 'wechat' , $oauthUserInfo['email']);  
321 - $this->helpGo($url); 335 + if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
  336 + $token = Helpers::makeToken($result['data']['uid']);
  337 + $this->setSession('_TOKEN', $token);
  338 + $this->setSession('_LOGIN_UID', $result['data']['uid']);
  339 + $this->setCookie('_TOKEN', $token);
  340 + $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
  341 + }
  342 + else {
  343 + $this->go($refer);
  344 + }
322 } 345 }
323 -  
324 } 346 }