Authored by yangyang

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

... ... @@ -25,7 +25,7 @@ class LoginData extends \LibModels\Wap\Passport\LoginData
* @param string $shoppingKey 未登录用户唯一识别码, 默认为空
* @return array 登录返回结果
*/
public static function signinByOpenID($nickname, $openId, $sourceType, $shoppingKey = null)
public static function signinByOpenID($nickname, $openId, $sourceType, $shoppingKey = null, $replaceId = '')
{
// 构建必传参数
$param = Yohobuy::param();
... ... @@ -35,13 +35,18 @@ class LoginData extends \LibModels\Wap\Passport\LoginData
$param['openId'] = $openId;
$param['source_type'] = $sourceType;
$param['nickname'] = $nickname;
//wechat传入replace_id
if (!empty($replaceId)) {
$param['replace_id'] = $replaceId;
}
//购物车
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
return Yohobuy::get(Yohobuy::API_URL2, $param);
}
}
... ...
<?php
namespace Plugin\Partner\wechat;
use Plugin\Partner\Factory;
define('WECHAT_CLASS_PATH', dirname(__FILE__) . '/class/');
require WECHAT_CLASS_PATH . 'Wechat.class.php';
/**
* 微信的调用接口
*
* @name Call
* @package lib/partner/wechat
* @copyright yoho.inc
* @version 5.0 (2016-01-12 10:54:54)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class Call extends Factory
{
//微信对象
protected $wechat;
/**
* 初始化
*/
protected function init()
{
$this->wechat = new \WechatAuth($this->apiConfig['appId'], $this->apiConfig['appKey']);
}
/**
* 获取授权URL
*
* @return string
*/
public function getAuthorizeUrl()
{
return $this->wechat->getAuthorizeURL($this->apiConfig['callback'], $this->apiConfig['scope']);
}
/**
* 获取授权的TOKEN
*
* @return array
*/
public function getAccessToken()
{
$token = array();
if (isset($_REQUEST['code']) && !empty($_REQUEST['code'])) {
try {
$token = $this->wechat->getAccessToken($_REQUEST['code']);
}
catch (Exception $e) {
// do nothing
}
}
return $token;
}
/**
* 获取当前用户的基本资料
*
* @param object $token 授权成功的TOKEN, 默认为NULL
* @return array
*/
public function getUserInfo($token)
{
$userInfo = array();
if (!empty($token)) {
$userInfo = $this->wechat->getUserInfo($token['access_token'], $token['openid']);
}
return $userInfo;
}
public function getFriends($token, $params)
{
}
public function syncShare($token, $content, $image, $link)
{
}
}
... ...
<?php
defined('SITE_MAIN') || define('SITE_MAIN', $_SERVER['HTTP_HOST']);
return array(
'appId' => 'wx3ae21dcbb82ad672',
'appKey' => 'e78afb2321e6a19085767e1a0f0d52c1',
'callback' => SITE_MAIN . '/passport/autosign/wechatback',
'scope' => 'snsapi_login'
);
... ...
<?php
/**
* @ignore
*/
class OAuthException extends Exception
{
// pass
}
class WechatAuth
{
/**
* @ignore
*/
public $appId;
/**
* @ignore
*/
public $appKey;
/**
* @ignore
*/
public $accessToken;
/**
* @ignore
*/
public $refreshToken;
/**
* Set API URLS
*/
/**
* @ignore
*/
function userInfoURL()
{
return 'https://api.weixin.qq.com/sns/userinfo';
}
/**
* @ignore
*/
function authorizeURL()
{
return 'https://open.weixin.qq.com/connect/qrconnect';
}
/**
* @ignore
*/
function accessTokenURL()
{
return 'https://api.weixin.qq.com/sns/oauth2/access_token';
}
/**
* construct WeichatOAuth object
*/
function __construct($appId, $appKey, $accessToken = NULL)
{
$this->appId = $appId;
$this->appKey = $appKey;
$this->accessToken = $accessToken;
}
/**
* authorize接口
* $callBackurl 回调地址
*/
function getAuthorizeURL($callBackurl, $scope, $responseType = 'code', $state = 'STATE#wechat_redirect')
{
$params = array();
$params['appid'] = $this->appId;
$params['redirect_uri'] = $callBackurl;
$params['response_type'] = $responseType;
$params['scope'] = $scope;
$params['state'] = $state;
return $this->authorizeURL() . "?" . http_build_query($params);
}
/*
* 获取accesstoken
* code:授权链接返回的code
*/
function getAccessToken($code, $grant_type = 'authorization_code')
{
if (empty($code)) {
return '';
}
$params = array();
$params['appid'] = $this->appId;
$params['secret'] = $this->appKey;
$params['code'] = $code;
$params['grant_type'] = $grant_type;
$url = $this->accessTokenURL() . "?" . http_build_query($params);
$result = self::getCurl($url);
return json_decode($result, true);
}
// 获取用户信息
function getUserInfo($access_token, $openid)
{
if (empty($access_token) || empty($openid)) {
return array();
}
$params = array();
$params['access_token'] = $access_token;
$params['openid'] = $openid;
$url = $this->userInfoURL() . "?" . http_build_query($params);
$result = self::getCurl($url);
return json_decode($result, true);
}
/**
* Send a GET requst using cURL
* @param string $url to request
* @param array $get values to send
* @param array $options for cURL
* @return string
*/
public static function getCurl($url,$method="GET")
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
... ...
{{> layout/header}}
<div class="brand-page brand-search-page yoho-page">
<div class="newbrand-search">
<form class="search-box clearfix">
<input type="text" class="search-input" id="keyword" placeholder="查找品牌">
<form class="search-box clearfix">
<input type="text" class="search-input" id="keyword" placeholder="查找品牌" autofocus>
<i class="search-icon iconfont">&#xe60f;</i>
<div class="search-action">
<span class="iconfont clear-text">&#xe623;</span>
... ...
... ... @@ -136,7 +136,7 @@ function picCaptchaAjaxFn(page, callback) {
type: 'POST',
url: url,
data: {
code: $ca.val()
verifyCode: $ca.val()
//mobile: $pn.val(),
//area: $region.text().split('+')[1]
... ... @@ -169,7 +169,7 @@ function msgCaptchaAjaxFn(page, callback) {
type: 'POST',
url: url,
data: {
code: $ca.val(),
verifyCode: $ca.val(),
mobile: $pn.val(),
area: $region.text().split('+')[1]
}
... ... @@ -465,7 +465,7 @@ exports.init = function(page) {
$regionSelect.change(function() {
$region.text('+' + $('#region').val());
$region.text($('#region').val());
validateRule(page, $pn, showErrTip); //验证
});
... ... @@ -493,7 +493,7 @@ exports.init = function(page) {
data: {
area: $region.text().split('+')[1],
mobile: $pn.val(),
code: $ca.val()
verifyCode: $ca.val()
}
}).then(function(data) {
if (data.code === 200) {
... ...
... ... @@ -259,9 +259,12 @@ if ($udPrice.length > 0) {
//【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
var index = $(this).addClass('hover').index();
var $this = $(this);
var index = $this.index();
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
var $this = $(this),
index = $this.index();
... ... @@ -296,4 +299,4 @@ $('.senior-sub').on('click', '.multi-select', function() {
clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
hideSeniorPanel();
});
\ No newline at end of file
});
... ...
... ... @@ -265,6 +265,7 @@
top: 39px;
background: #fff;
border: 1px solid #eaeceb;
z-index: 1;
ul {
max-width: 950px;
... ...
... ... @@ -5,16 +5,17 @@
*/
.product-search-page {
@import "shop-entry";
.goods-container {
height: auto;
padding: 25px 0 0 0;
position: relative;
width: 1150px + 10px;//每列增加右边距
}
@import "shop-entry";
.good-info {
width: 222px;
}
}
}
... ...
... ... @@ -230,12 +230,14 @@ class HomeModel
$sortList = ChannelConfig::$newArrivalSortList[$channel];
// 获取分类列表获取商品信息
$goodsList = SearchData::getSearchDataBySort($params, $sortList);
$pos = 1;
foreach ($goodsList as $goods) {
// 格式化数据
$val = Helpers::formatProduct($goods, true, true, true, 280, 373);
if ($val['price'] == false) {
$val['price'] = $val['salePrice'];
}
$val['url'] = sprintf('%s?channel=%s&from=%s-n_%s', $val['url'], $channel , $channel, $pos++);
//TODO 字段要调整
$val['isFew'] = $val['is_soon_sold_out'];
$val['tags']['isLimit'] = $val['tags']['is_limited'];
... ...
... ... @@ -2,7 +2,6 @@
use Action\AbstractAction;
use LibModels\Web\Passport\LoginData;
use Passport\PassportModel as PassportModel;
use Plugin\Helpers;
use Plugin\Partner\Factory;
... ... @@ -62,13 +61,14 @@ class AutosignController extends AbstractAction
$this->go(Factory::create('douban')->getAuthorizeUrl());
}
/**
/**
* 微信网站授权入口
*/
public function wechatAction(){
$url = QINWechat_Sdk_Open::getCode('http://www.yohobuy.com/passport/autosign/wechatback');
$this->helpGo($url);
public function wechatAction()
{
$this->setSession('_TOKEN', '');
$this->go(Factory::create('wechat')->getAuthorizeUrl());
}
/**
... ... @@ -88,7 +88,12 @@ class AutosignController extends AbstractAction
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
$this->go(Helpers::url('/passport/bind/index', array('openId' => $userId, 'sourceType' => 'alipay', 'nickname' => $realName)));
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $userId, 'sourceType' => 'alipay', 'nickname' => $realName)));
$this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
}
$refer = $this->getCookie('refer');
... ... @@ -126,11 +131,6 @@ class AutosignController extends AbstractAction
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq', $shoppingKey);
}
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
$this->go(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['openid'], 'sourceType' => 'qq', 'nickname' => $partnerInfo['nickname'])));
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
... ... @@ -139,6 +139,16 @@ class AutosignController extends AbstractAction
$refer = rawurldecode($refer);
}
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['openid'], 'sourceType' => 'qq', 'nickname' => $partnerInfo['nickname'])));
$this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
... ... @@ -169,7 +179,12 @@ class AutosignController extends AbstractAction
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
// $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name'])));
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name'])));
$this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
}
$refer = $this->getCookie('refer');
... ... @@ -199,18 +214,21 @@ class AutosignController extends AbstractAction
{
$renren = Factory::create('renren');
$access = $renren->getAccessToken();
/* 获取用户的详细信息 */
$partnerInfo = $renren->getUserInfo($access);
$result = array();
if ($partnerInfo && is_array($partnerInfo)) {
if ($access && is_array($access)) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['uid'], 'renren', $shoppingKey);
$result = LoginData::signinByOpenID($access['user']['name'], $access['user']['id'], 'renren', $shoppingKey);
}
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
// $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['nick_name'])));
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$fillHerf = rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['user']['id'], 'sourceType' => 'renren', 'nickname' => $access['user']['name'])));
$this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
}
$refer = $this->getCookie('refer');
... ... @@ -238,20 +256,25 @@ class AutosignController extends AbstractAction
*/
public function doubanbackAction()
{
$sina = Factory::create('douban');
$access = $sina->getAccessToken();
$douban = Factory::create('douban');
$access = $douban->getAccessToken();
/* 获取用户的详细信息 */
$partnerInfo = $sina->getUserInfo($access);
$partnerInfo = $douban->getUserInfo($access);
$result = array();
if ($partnerInfo && is_array($partnerInfo)) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['uid'], 'douban', $shoppingKey);
$result = LoginData::signinByOpenID($partnerInfo['name'], $partnerInfo['uid'], 'douban', $shoppingKey);
}
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
// $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name'])));
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$fillHerf =rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['douban_user_id'], 'sourceType' => 'douban', 'nickname' => $partnerInfo['name'])));
$this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
}
$refer = $this->getCookie('refer');
... ... @@ -273,52 +296,51 @@ class AutosignController extends AbstractAction
$this->go($refer);
}
}
/**
* 微信网站授权获取用户信息并登录
* @param string code
*/
public function wechatbackAction(){
$code = $this->helpGquery('code');
$accessToken = QINWechat_Sdk_Open::getAccessToken($code);
$userInfo = array();
if(empty($accessToken)){
$this->helpGo('/signin.html');
}
if(!isset($accessToken['access_token']) || !isset($accessToken['unionid']) || empty($accessToken['access_token']) || empty($accessToken['unionid'])){
$this->helpGo('/signin.html');
}
$userInfo = QINWechat_Sdk_Open::getUserInfo($accessToken['access_token'], $accessToken['unionid']);
if(empty($userInfo)){
$this->helpGo('/signin.html');
}
$this->wechatlogin($userInfo);
}
/**
* 微信登录
* @param array $userInfo
*/
public function wechatlogin($userInfo){
if(empty($userInfo)){
$this->helpGo('/signin.html');
}
try {
$oauthUserInfo = QINAuth_User_Utils::check('wechat', $userInfo['unionid'], $userInfo['nickname'], null, $userInfo);
$auth = QINAuth_Factory::profile('wechat');
$res=$auth->associate($oauthUserInfo['email'], array(
'password' => QINAuth_User_Utils::$defaultPassword,
'open_id' => $userInfo['unionid'],
'nick_name' => $userInfo['nickname']
));
} catch (Exception $e) {
$this->helpSession('passport_space')->__set('error_message', 'wechat' . $e->getMessage());
$this->helpGo('/signin.html');
}
//跳转到
$url = $this->authInfo($res, 'wechat' , $oauthUserInfo['email']);
$this->helpGo($url);
}
public function wechatbackAction()
{
$wechat = Factory::create('wechat');
$access = $wechat->getAccessToken();
/* 获取用户的详细信息 */
$partnerInfo = $wechat->getUserInfo($access);
$result = array();
if ($partnerInfo && is_array($partnerInfo)) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = LoginData::signinByOpenID($partnerInfo['nickname'],$partnerInfo['openid'], 'wechat', $shoppingKey,$partnerInfo['openid']);
}
//判定是否需要绑定手机号
if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$fillHerf =rawurlencode(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $partnerInfo['openid'], 'sourceType' => 'wechat', 'nickname' => $partnerInfo['nickname'])));
$this->go(Helpers::syncUserSession($result['data']['uid'], $fillHerf));
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
}
else {
$refer = rawurldecode($refer);
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
}
else {
$this->go($refer);
}
}
}
... ...