Authored by hf

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

Showing 36 changed files with 3868 additions and 202 deletions

Too many changes to show.

To preserve performance only 36 of 36+ files are displayed.

... ... @@ -838,6 +838,14 @@
},
...
],
defaultSizes: [
{
numZero: true,
name: 'X',
numStr: '0/10'
},
...
]
totalNum: 20
}
... ...
... ... @@ -375,7 +375,7 @@ class AbstractAction extends Controller_Abstract
return $udid;
}
/*
* 设置网站SEO的标题
*
... ...
... ... @@ -227,7 +227,7 @@ class Yohobuy
}
curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookie_str));
}
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
// 销毁私钥参数
... ...
<?php
namespace LibModels\Web\Passport;
use Api\Sign;
use Api\Yohobuy;
/**
* 登录的数据模型
*
* @name LoginData
* @package LibModels/Web/Passport
* @copyright yoho.inc
* @version 1.0 (2015-12-30 14:05:04)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class LoginData extends \LibModels\Wap\Passport\LoginData
{
/**
* 第三方登录接口(包括alipay,qq,sina)
* @param string $nickname 姓名
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @param string $shoppingKey 未登录用户唯一识别码, 默认为空
* @return array 登录返回结果
*/
public static function signinByOpenID($nickname, $openId, $sourceType, $shoppingKey = null)
{
// 构建必传参数
$param = Yohobuy::param();
$param['v'] = '4';
$param['method'] = 'app.passport.signinByOpenID';
$param['openId'] = $openId;
$param['source_type'] = $sourceType;
$param['nickname'] = $nickname;
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
<?php
namespace LibModels\Web\Passport;
use Api\Yohobuy;
use Api\Sign;
use Plugin\Helpers;
class RegData extends \LibModels\Wap\Passport\RegData
{
/**
* 根据手机号获取用户信息[TODO +cache]
*
* @param string $area
* @param string $mobile
* @return string
*/
public static function getUserInfoByMobile($area, $mobile)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.userlist';
$param['mobile'] = Helpers::makeMobile($area, $mobile);
$param['debug'] = 'Y';
$param['screen_size'] = '320x568';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
\ No newline at end of file
... ...
... ... @@ -19,13 +19,15 @@ class BrandData
const URI_BRAND_TOPPOS = 'operations/api/v5/resource/get';
const URL_BRAND_LOGO = '/shops/service/v1/brand';
const URL_BRAND_FOLDER = '/cmsproduct/service/v1/brands';
const URL_BRAND_NODECONTENT = '/operations/service/v6/htmlcontent';
/**
* 获取品牌介绍
* 获取品牌简介
*
* @param integer $brandId 品牌ID
* @param int 用户ID
* @return array 品牌介绍信息
* @param int 用户ID
* @return array 品牌介绍信息
*/
public static function getBrandIntro($brandId, $uid)
{
... ... @@ -42,9 +44,9 @@ class BrandData
}
/**
* 获取品牌banner数据
* 获取品牌banner
* @param integer $brandId 品牌ID
* @return array banner数据
* @return array banner
*/
public static function getBrandBanner($brandId)
{
... ... @@ -58,17 +60,17 @@ class BrandData
}
/**
* 获取品牌介绍信息
* 获取品牌介绍详情
*
* @param int $id 品牌id
* @return array
*/
public static function getBrandLogo($id)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByids', array($id ));
public static function getBrandLogo($brandId)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByids', array($brandId ));
}
/**
/**
* 通过域名获取品牌LOGO信息
*
* @param int $domain 品牌domain
... ... @@ -78,5 +80,27 @@ class BrandData
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByDomain', array($domain ));
}
/**
* 通过品牌id获取品牌Folder
*
* @param int $brand_id 品牌id
* @param int $status 状态
* @return array
*/
public static function getFolderByBrand($brand_id,$status = 1)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_FOLDER, 'getFolderByBrand', array($brand_id,$status ));
}
/**
* 根据节点和运行模式选择静态内容
* @param $node 20141219-100447
* @param string $mode
* @return mixed
*/
public static function getByNodeContent($node, $mode='release')
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_NODECONTENT, 'getByNodeContent', array($node, $mode));
}
}
... ...
... ... @@ -18,12 +18,12 @@ class SearchData extends \LibModels\Wap\Product\SearchData
case 'release':
if($type == 'sort'){
return 'http://100.98.132.63/yohosearch/sortgroup.json';
}
if($type == 'discount'){
}elseif($type == 'discount'){
return 'http://100.98.132.63/yohosearch/discount.json';
}
if($type == 'recent'){
}elseif($type == 'recent'){
return 'http://100.98.132.63/yohosearch/recent.json';
}elseif($type == 'review'){
}
return 'http://100.98.132.63/yohosearch/search.json';
case 'test':
... ... @@ -33,11 +33,13 @@ class SearchData extends \LibModels\Wap\Product\SearchData
if($type == 'sort'){
return 'http://101.200.31.165/yohosearch/sortgroup.json';
}
if($type == 'discount'){
elseif($type == 'discount'){
return 'http://101.200.31.165/yohosearch/discount.json';
}
if($type == 'recent'){
elseif($type == 'recent'){
return 'http://101.200.31.165/yohosearch/recent.json';
}elseif($type == 'review'){
return 'http://itemapi.yohobuy.com/item/item/recentreview';
}
return 'http://101.200.31.165/yohosearch/search.json';
}
... ... @@ -68,14 +70,48 @@ class SearchData extends \LibModels\Wap\Product\SearchData
}
/**
* 获取品类数据
*
* @return array 品类数据
* 根据查询条件查询品类列表
*
* @param string $query 关键字
* @param bool $needAllSort 为1时返回全部分类
* @param bool needSmallSort 为1时返回小分类
* @param string $brand 品牌,查多个品牌以逗号分隔
* @param string $mosort 产品产品大分类ID,查多个大类以逗号分隔
* @param string $misort 产品产品中分类ID,查多个中类以逗号分隔
* @param string $sort 产品产品小分类ID,查多个小类以逗号分隔
* @param string $gender 性别,默认为null,"1"表示男, "2"表示女, "3"表示通用
* @param integer $color 颜色id
* @param integer $size 尺码id
* @param integer $price 价格
* @param integer $style 风格ID
* @param integer $parameter_xxx 属性类型ID与值ID 参数名称格式:parameter_{属性类型ID}={属性值ID},如查询厚度为中“parameter_875=4801”
* @param integer $stocknumber 库存量
* @param integer $shelve_time 时间区间
* @param integer $specialoffer 特价类型
* @param bool $sales 是否销售
* @param bool $promotion 是否为促销品
* @param integer $vdt 是否为促销品
* @param bool $vdt 折扣类型
* @param integer $p_d 促销浮点值
* @param integer $attribute 商品属性 1正常商品 2赠品
* @param integer $limited 是否限量 “N”或“Y”
* @param integer $new 是否新品 “N”或“Y”
* @param integer $status 是否上架
* @param integer $sell_channels 销售平台
* @param integer $p_d_int 促销折扣 int型如7
* @param integer $act_temp 活动模板
* @param integer $act_rec 活动模板是否推荐
* @param integer $act_status 活动模板商品状态
* @param integer $attribute_not 过滤商品属性,attribute_not=2过滤掉赠品
* @param integer $not_* not_字段名,过滤字段
* @return array 搜索到的数据
*/
public static function getClassesData($condition = array(), $cache = false)
public static function getClassesData($classes = array(), $cache = false)
{
$param['brand'] = $condition;
return Yohobuy::get(self::getUrl('sort'),$param, $cache);
$classes['sales'] = 'Y'; //在销售商品分类
$classes['status'] = 1; //上架商品分类
$classes['stocknumber'] = 1; //过滤掉已售罄
return Yohobuy::get(self::getUrl('sort'),$classes, $cache);
}
/**
... ... @@ -91,4 +127,14 @@ class SearchData extends \LibModels\Wap\Product\SearchData
public static function recentShelve(){
return Yohobuy::get(self::getUrl('recent'));
}
/**
* 获取最近浏览记录
* @param int $limit
* @return json
*/
public static function getRecentReview($limit = 0)
{
}
}
\ No newline at end of file
... ...
... ... @@ -109,5 +109,45 @@ class Cache
{
return md5($prefix . '_' . $key);
}
/**
* 累加
*
* @param string $key
* @param int $offset
* @param int $initialValue
* @param int $expiry
* @return boolean
*/
public static function increment($key, $offset = 1, $initialValue = 0, $expiry = 0) {
return self::getMemcache('master')->increment(self::makeKey($key, 'master'), $offset, $initialValue, $expiry);
}
/**
* 递减
*
* @param string $key
* @param int $offset
* @return boolean
*/
public static function decrement($key, $offset = 1) {
return self::getMemcache('master')->decrement(self::makeKey($key, 'master'), $offset);
}
/**
* 获取memcache
*
* @param string $host
* @return object
*/
private static function getMemcache($host) {
$cache = new \stdClass();
if (DIRECTORY_SEPARATOR === '\\') {
$cache = HoodCache::Memcache($host);
}
else {
$cache = HoodCache::Memcached($host);
}
return $cache;
}
}
... ...
<?php
namespace Plugin;
use Hood\Session;
class Captcha {
private static $V = array(
"a",
"e",
"i",
"o",
"u",
"y"
);
private static $VN = array(
"a",
"e",
"i",
"o",
"u",
"y",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
);
private static $C = array(
"b",
"c",
"d",
"f",
"g",
"h",
"j",
"k",
"m",
"n",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"z"
);
private static $CN = array(
"b",
"c",
"d",
"f",
"g",
"h",
"j",
"k",
"m",
"n",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"z",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
);
private $_width = 160;
private $_height = 60;
private $_fs = 28;
private $_dotNoiseLevel = 50;
private $_lineNoiseLevel = 5;
private $_wordLen = 6;
private $_useNumbers = true;
/**
* Generate new random word
*
* @return string
*/
protected function _generateWord() {
$word = '';
$wordLen = $this->getWordLen ();
$vowels = $this->_useNumbers ? self::$VN : self::$V;
$consonants = $this->_useNumbers ? self::$CN : self::$C;
for($i = 0; $i < $wordLen; $i = $i + 2) {
$consonant = $consonants [array_rand ( $consonants )];
$vowel = $vowels [array_rand ( $vowels )];
$word .= $consonant . $vowel;
}
if (strlen ( $word ) > $wordLen) {
$word = substr ( $word, 0, $wordLen );
}
return $word;
}
public function getWordLen() {
return $this->_wordLen;
}
/**
* 设置验证码长度
*
* @param string $wordLen
* @return \Plugin\Captcha
*/
public function setWordLen($wordLen) {
$this->_wordLen = $wordLen;
return $this;
}
/**
* 获取图像宽度
*
* @return int
*/
public function getWidth() {
return $this->_width;
}
/**
* 获取图像高度
*
* @return int
*/
public function getHeight() {
return $this->_height;
}
/**
* 设置图像宽度
*
* @param int $width
* @return \Plugin\Captcha
*/
public function setWidth($width) {
$this->_width = $width;
return $this;
}
/**
* 设置图像高度
*
* @param int $height
* @return \Plugin\Captcha
*/
public function setHeight($height) {
$this->_height = $height;
return $this;
}
/**
*
*/
public function getFontSize() {
return $this->_fs;
}
public function setFontSize($fs) {
$this->_fs = $fs;
return $this;
}
/**
* 设置干扰点
*
* @param string $noise
* @return \Plugin\Captcha
*/
public function setDotNoiseLevel($noise = 100) {
$this->_dotNoiseLevel = $noise;
return $this;
}
/**
* 设置干扰线
*
* @param string $noise
* @return \Plugin\Captcha
*/
public function setLineNoiseLevel($noise = 5) {
$this->_lineNoiseLevel = $noise;
return $this;
}
/**
* 获取干扰点
*
* @return string
*/
public function getDotNoiseLevel() {
return $this->_dotNoiseLevel;
}
/**
* 获取干扰线
*
* @return string
*/
public function getLineNoiseLevel() {
return $this->_lineNoiseLevel;
}
/**
* Generate random frequency
*
* @return float
*/
protected function _randomFreq() {
return mt_rand ( 700000, 1000000 ) / 15000000;
}
/**
* Generate random phase
*
* @return float
*/
protected function _randomPhase() {
// random phase from 0 to pi
return mt_rand ( 0, 3141592 ) / 1000000;
}
/**
* Generate random character size
*
* @return int
*/
protected function _randomSize() {
return 0;
return mt_rand ( 300, 700 ) / 100;
}
public function getFont() {
return dirname ( __FILE__ ) . '/ttf/2.ttf';
}
/**
* 将验证码存入Sessioin
*
* @param string $namespace
* @param string $code
* @return true
*/
public static function setToSession($namespace, $code) {
self::getSessionObject($namespace)->captcha = $code;
return true;
}
/**
* 从session中取出已经生成的验证码
*
* @param string $namespace
* @return string|false
*/
public static function getFromSession($namespace) {
$code = self::getSessionObject($namespace)->captcha;
if (!empty( $code )) {
return $code;
} else {
return false;
}
}
/**
* Constructor
*
* @param array $options
* @return void
*/
public function __construct($options = null) {
if (isset ( $options )) {
foreach ( $options as $k => $v ) {
call_user_func ( array ($this, 'set' . ucfirst ( $k ) ), $v );
}
}
}
public function generate($namespace) {
$word = $this->_generateWord ();
self::setToSession ( $namespace, $word );
header ( "Content-type: image/png" );
$this->_generateImage ( $word );
return $word;
}
/**
* 生成验证码
*
* @param string $word
*/
protected function _generateImage($word) {
if (! extension_loaded("gd")) {
exit("Image CAPTCHA requires GD extension");
}
if (! function_exists("imagepng")) {
exit("Image CAPTCHA requires PNG support");
}
if (! function_exists("imageftbbox")) {
exit("Image CAPTCHA requires FT fonts support");
}
$font = $this->getFont();
if (empty($font)) {
exit("Image CAPTCHA requires font");
}
$w = $this->getWidth ();
$h = $this->getHeight ();
$fsize = $this->getFontSize ();
$img = imagecreatetruecolor ( $w, $h );
$text_color = imagecolorallocate ( $img, 0, 0, 0 );
$bg_color = imagecolorallocate ( $img, 255, 255, 255 );
imagefilledrectangle ( $img, 0, 0, $w - 1, $h - 1, $bg_color );
$textbox = imageftbbox ( $fsize, 0, $font, $word );
$x = ($w - ($textbox [2] - $textbox [0])) / 2;
$y = ($h - ($textbox [7] - $textbox [1])) / 2;
imagefttext ( $img, $fsize, 0, $x, $y, $text_color, $font, $word );
// generate noise
for($i = 0; $i < $this->_dotNoiseLevel; $i ++) {
imagefilledellipse ( $img, mt_rand ( 0, $w ), mt_rand ( 0, $h ), 2, 2, $text_color );
}
for($i = 0; $i < $this->_lineNoiseLevel; $i ++) {
imageline ( $img, mt_rand ( 0, $w ), mt_rand ( 0, $h ), mt_rand ( 0, $w ), mt_rand ( 0, $h ), $text_color );
}
// transformed image
$img2 = imagecreatetruecolor ( $w, $h );
$bg_color = imagecolorallocate ( $img2, 255, 255, 255 );
imagefilledrectangle ( $img2, 0, 0, $w - 1, $h - 1, $bg_color );
// apply wave transforms
$freq1 = $this->_randomFreq ();
$freq2 = $this->_randomFreq ();
$freq3 = $this->_randomFreq ();
$freq4 = $this->_randomFreq ();
$ph1 = $this->_randomPhase ();
$ph2 = $this->_randomPhase ();
$ph3 = $this->_randomPhase ();
$ph4 = $this->_randomPhase ();
$szx = $this->_randomSize ();
$szy = $this->_randomSize ();
for($x = 0; $x < $w; $x ++) {
for($y = 0; $y < $h; $y ++) {
$sx = $x + (sin ( $x * $freq1 + $ph1 ) + sin ( $y * $freq3 + $ph3 )) * $szx;
$sy = $y + (sin ( $x * $freq2 + $ph2 ) + sin ( $y * $freq4 + $ph4 )) * $szy;
if ($sx < 0 || $sy < 0 || $sx >= $w - 1 || $sy >= $h - 1) {
continue;
} else {
$color = (imagecolorat ( $img, $sx, $sy ) >> 16) & 0xFF;
$color_x = (imagecolorat ( $img, $sx + 1, $sy ) >> 16) & 0xFF;
$color_y = (imagecolorat ( $img, $sx, $sy + 1 ) >> 16) & 0xFF;
$color_xy = (imagecolorat ( $img, $sx + 1, $sy + 1 ) >> 16) & 0xFF;
}
if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) {
// ignore background
continue;
} elseif ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0) {
// transfer inside of the image as-is
$newcolor = 0;
} else {
// do antialiasing for border items
$frac_x = $sx - floor ( $sx );
$frac_y = $sy - floor ( $sy );
$frac_x1 = 1 - $frac_x;
$frac_y1 = 1 - $frac_y;
$newcolor = $color * $frac_x1 * $frac_y1 + $color_x * $frac_x * $frac_y1 + $color_y * $frac_x1 * $frac_y + $color_xy * $frac_x * $frac_y;
}
imagesetpixel ( $img2, $x, $y, imagecolorallocate ( $img2, $newcolor, $newcolor, $newcolor ) );
}
}
// generate noise
for($i = 0; $i < $this->_dotNoiseLevel; $i ++) {
imagefilledellipse ( $img2, mt_rand ( 0, $w ), mt_rand ( 0, $h ), 2, 2, $text_color );
}
for($i = 0; $i < $this->_lineNoiseLevel; $i ++) {
imageline ( $img2, mt_rand ( 0, $w ), mt_rand ( 0, $h ), mt_rand ( 0, $w ), mt_rand ( 0, $h ), $text_color );
}
imagepng ( $img2 );
imagedestroy ( $img );
imagedestroy ( $img2 );
}
/**
* 获取session对象
*
* @param string $namespace
* @return object
*/
public static function getSessionObject($namespace)
{
if(strtoupper(substr(PHP_OS,0,3)) === 'WIN')
{
return Session::fileStart($namespace);
}
else
{
return Session::start($namespace, null, 'yohobuy.com');
}
}
}
\ No newline at end of file
... ...
... ... @@ -13,6 +13,9 @@ class Channel
public static function getFormat($channel, $data)
{
if(empty($data)) {
return array();
}
// 通用处理器
$result = Process::getContent($data, $channel);
$channelResult = array();
... ...
... ... @@ -322,11 +322,14 @@ class Process
'singlehot' => array(
'name' => '',
'imgHot' => array(),
'brands' => array()
'brands' => array(),
'navs'=> array(),
)
);
// text模版
$result['singlehot']['name'] = $title;
//textNav模版
$result['singlehot']['navs'] = self::mergeNavProcess($source, $type);
// goods模版
$result['singlehot']['imgHot'] = self::mergeGoodsProcess($goods, $type);
// floor模版
... ... @@ -503,6 +506,7 @@ class Process
);
// text
$result['girlkids']['name'] = $data[$key]['data']['text'];
// goods
$result['girlkids']['imgHot'] = self::mergeGoodsProcess($data[$key + 2], $type);
unset($data[$key], $data[$key + 1], $data[$key + 2]);
... ... @@ -638,8 +642,12 @@ class Process
$result['category']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// floor模版
foreach ($data[$key + 2]['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 185, 510, 2);
foreach ($data[$key + 2]['data'] as $pos => $val) {
$width = 185; $height = 510;
if($pos == 1) {
$width = 377; $height = 504;
}
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['category']['list'][] = array(
'href' => $val['url'],
... ... @@ -762,7 +770,7 @@ class Process
$skns = '';
foreach ($data['data'] as $val) {
$skns .= $val['id'] . ' ';
}
}
$params = array(
'query' => rtrim($skns),
'client_type' => 'web'
... ...
<?php
namespace Plugin;
use Plugin\Images;
use Plugin\Paging;
/**
* 搜索辅助类
*/
... ... @@ -10,11 +10,10 @@ class HelperSearch
/**
* 请求时用的所有参数
*/
private static $params = array();
public static $params = array();
//当前页面
private static $current_url = '';
private static $page = 1;
//当前页
public static $page = 1;
/**
* 选中的条件
... ... @@ -25,147 +24,141 @@ class HelperSearch
* list分类面包屑
* @var array
*/
public static $listnav = array(
array(
public static $listnav = array();
//设置导航
private static function setListNav($option = array())
{
$cookieChannel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
if (isset($option['brandName']) && !empty($option['brandName'])) {
$initNav = $option['brandName'];
}else{
$initNav = '列表';
}
self::$listnav[0] = array(
'href' => '',
'name' => '首页'
),
array(
'name' => $cookieChannel
);
self::$listnav[1] = array(
'href' => '',
'name' => '列表'
)
);
'name' => $initNav
);
}
/**
* 组织搜索模板数据
* @param array $data
* @param array $options
* @return array
*/
public static function getList($data = array() , $options = array()) {
if (empty($data)) {
return array();
}
public static function getList($data = array() , $options = array())
{
$result = array();
self::$params = $_GET;
unset(self::$params['/']);
unset(self::$params['page']);
unset(self::$params['/sale']);
unset(self::$params['sale']);
$result = array();
if (!isset($data['data']) || !isset($data['data']['product_list']) || !is_array($data['data']['product_list'])) {
return array();
}
$result['product_list'] = self::getProductList($data['data']['product_list'], $options['imgSize'], $options['minImgSize'], $options['gender']);
$filter = $data['data']['filter'];
//产品列表
$result['goods'] = self::getProductList($data['data']['product_list'], $options['imgSize']);
//总页数
$result['page_total'] = $data['data']['page_total'];
$result['total'] = $data['data']['total'];
//当前页
$result['page'] = $data['data']['page'];
//设置当前页
self::$page = $result['page'];
//搜索条件
if (isset($data['data']['filter']) && !empty($data['data']['filter'])) {
$filter = $data['data']['filter'];
$result['filter']['left_sort'] = isset($filter['minsort']) ? self::minsort($filter['minsort']) : array();
$result['filter']['group_sort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
$result['filter']['size'] = self::size($filter);
$result['filter']['color'] = self::color($filter);
$result['filter']['price'] = self::price($filter);
$result['filter']['brand'] = self::brand($filter);
$result['filter']['parameters'] = self::standard($filter);
$result['filter']['rowNum4'] = self::rowNum();
$result['filter']['rowNum6'] = self::rowNum(6);
$result['filter']['viewNum'] = self::viewNum();
$result['filter']['priceSubmit'] = self::priceSubmit();
$result['filter']['gender'] = self::gender($filter);
$result['filter']['selected'] = self::getSelected();
$result['filter']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
$result['filter']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
$result['filter']['clear'] =self::current();
$result['filter']['next'] = self::next($data['data']['page_total'],$data['data']['filter']);
$result['filter']['listnav'] = self::$listnav;
$result['filter']['discount'] = self::getDiscount($filter['discount']);
$result['filter']['recent'] = self::recentShelve($filter['recent']);
$result['filter']['seniorChose'] = self::seniorChose($filter);
}
//清除选中
$result['filters']['checkedConditions']['clearUrl'] = self::current();
//频道
$result['filters']['channel'] = self::gender($filter);
//分类
$result['filters']['sort'] = array();
//品牌
$result['filters']['brand'] = self::brand($filter, $options);
//价格
$result['filters']['price'] = self::price($filter);
//颜色
$result['filters']['color'] = self::color($filter);
//尺寸
$result['filters']['size'] = self::size($filter);
//高级选项
$result['filters']['seniorChose'] = self::seniorChose($filter);
//排序方式
$result['opts']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
//特殊:新品、特价、限量
$result['opts']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
//每行显示5个产品
$result['opts']['fivePerLine'] = true;
//每行显示6个产品
$result['opts']['sixPerLineHref'] = true;
//每页显示的数量
$result['opts']['countPerPage'] = $options['viewNum'];
//可选每页显示数量
$result['opts']['pageCounts'] = self::viewNum();
$result['opts']['curPage'] = self::$page;
$result['opts']['pageCount'] = $data['data']['page_total'];
$result['opts']['nextHref'] = self::next($data['data']['page_total'],$data['data']['filter']);
$result['hasNextPage'] = array(
'href' => self::next($data['data']['page_total'],$data['data']['filter']),
'src' => 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
);
//分类
$result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
//一周新品上架
$result['leftContent'][]['newSales'] = isset($filter['recent']) ? self::recentShelve($filter['recent']) : array();
//全部折扣
$result['leftContent'][]['allDiscount'] = isset($filter['discount']) ? self::getDiscount($filter['discount']) : array();
//总记录数
$result['totalCount'] = $data['data']['total'];
//分页
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
//选中条件
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
$result['pathNav'] = self::$listnav;
return $result;
}
/**
* 组织列表模板数据
*
*/
public static function getTemplateData($result, $options){
//模板数据
$data = array(
'brandBanner' => array(),
'pathNav' => $result['filter']['listnav'],
'shopEntry' => array(),
'filters' => array(
'checkedConditions' => array(
'conditions' => $result['filter']['selected'],
'clearUrl' => $result['filter']['clear']
),
'channel' => $result['filter']['gender'],
'sort' => array() ,
'brand' => $result['filter']['brand'],
'price' => $result['filter']['price'],
'color' => $result['filter']['color'],
'size' => $result['filter']['size'],
'seniorChose' => $result['filter']['seniorChose']
),
'opts' => array(
'sortType' => $result['filter']['sortType'],
'checks' => $result['filter']['checks'],
'fivePerLine' => true,
'sixPerLineHref' => '',
'countPerPage' => $options['viewNum'],
'pageCounts' => $result['filter']['viewNum'],
'curPage' => $result['page'],
'pageCount' => $result['page_total'],
'nextHref' => $result['filter']['next']
),
'goods' => $result['product_list'],
'allSort' => array(
'updateNum' => $result['filter']['group_sort']['all']['num'],
'list' => $result['filter']['group_sort']['list']
),
'advNav' => array(),
'advPic' => array(),
'newSales' => $result['filter']['recent'],
'allDiscount' => $result['filter']['discount']
);
return $data;
}
/**
* TODO 组织商品列表信息
* @param $product 接口返回商品列表
* @author sefon 2015-12-21 17:24:04
* @return array
*/
public static function getProductList($product,$imgSize){
$result = array();
$goods = array();
foreach($product as $key => $val){
//NEW
$isNew = $val['is_new'] == 'Y' ? true : false;
$isFew = $val['is_soon_sold_out'] == 'Y' ? true : false;
$is_promotion = $val['is_promotion'];
//限量商品
$isLimit = isset($val['is_limited']) && $val['is_limited'] === 'Y';
//即将售罄
$isFew = $val['is_soon_sold_out'] === 'Y' ? true : false;
//SALE
//新品节
//再到着
//年终大促
// 年中大促
foreach($val['goods_list'] as $k => $v){
$goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']);
}
if (!empty($val['default_images'])) {
$val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
}
$result[] = array(
$goods[] = array(
'tags' => array(
'isNew' => $isNew,
'isYearEndPromotion' => $is_promotion
'isLimit' => $isLimit
),
'url' => $goods_list[0]['url'],
'thumb' => $val['default_images'],
'name' => $val['product_name'],
'salePrice' => $val['sales_price'],
'isFew' => $isFew
'marketPrice' => $val['market_price'],
'isFew' => $isFew,
'skn' => $val['product_skn']
);
}
return $result;
return $goods;
}
/**
* 版型等其它筛选项
... ... @@ -253,16 +246,11 @@ class HelperSearch
/**
* 组织搜索列表页面的左侧分类
* @param array $sort
* @param array $params
* @return array
*/
/**
* 组织搜索列表页面的左侧分类
* @param array $sort
* @param array $params
* @param array $option
* @return array
*/
public static function groupSort($sort, $option = array()) {
self::setListNav($option);
$params = self::$params;
$gender = isset($params['gender']) ? $params['gender'] : '';
... ... @@ -295,14 +283,15 @@ class HelperSearch
'sort_id' => 0,
'name' => '全部品类',
'href' => self::buildurl($query) ,
'num' => 0,
'selected' => ''
// 'num' => 0,
'active' => ''
) ,
'list' => array()
);
foreach ($sort as $val) {
if (isset($params['msort']) && $params['msort'] == $val['sort_id']) {
self::$listnav[1] = array(
$nav_index = isset($option['brandName']) && $option['brandName'] ? 2 : 1;
self::$listnav[$nav_index] = array(
'sort_id' => $val['sort_id'],
'name' => $val['sort_name'],
'href' => self::buildurl(array(
... ... @@ -311,12 +300,12 @@ class HelperSearch
))
);
}
$result['all']['num']+= $val['count'];
//$result['all']['num']+= $val['count'];
$msort = array(
'sort_id' => $val['sort_id'],
'name' => $val['sort_name'],
'num' => $val['count'],
'selected' => isset($params['msort']) && $params['msort'] == $val['sort_id'] ? true : false,
// 'num' => $val['count'],
'active' => isset($params['msort']) && $params['msort'] == $val['sort_id'] ? true : false,
'href' => self::buildurl(array_merge($query, array(
'msort' => $val['sort_id']
))) ,
... ... @@ -328,15 +317,16 @@ class HelperSearch
$sub[] = array(
'sort_id' => $val['sort_id'],
'name' => '全部' . $val['sort_name'],
'num' => $val['count'],
'selected' => !isset($params['misort']) && isset($params['msort']) && $params['msort'] == $val['sort_id'] ? true : false,
// 'num' => $val['count'],
'childActive' => !isset($params['misort']) && isset($params['msort']) && $params['msort'] == $val['sort_id'] ? true : false,
'href' => self::buildurl(array_merge($query, array(
'msort' => $val['sort_id']
))) ,
);
foreach ($val['sub'] as $mval) {
if (isset($params['misort']) && $params['misort'] == $mval['sort_id']) {
self::$listnav[2] = array(
$nav_index = isset($option['brandName']) && $option['brandName'] ? 3 : 2;
self::$listnav[$nav_index] = array(
'sort_id' => $mval['sort_id'],
'name' => $mval['sort_name'],
'href' => ''
... ... @@ -346,8 +336,8 @@ class HelperSearch
$sub[] = array(
'sort_id' => $mval['sort_id'],
'name' => $mval['sort_name'],
'num' => $mval['count'],
'selected' => isset($params['misort']) && $params['misort'] == $mval['sort_id'] ? true : false,
// 'num' => $mval['count'],
'childActive' => isset($params['misort']) && $params['misort'] == $mval['sort_id'] ? true : false,
'href' => self::buildurl(array_merge($query, array(
'msort' => $val['sort_id'],
'misort' => $mval['sort_id']
... ... @@ -363,17 +353,19 @@ class HelperSearch
/**
* 品牌,可以多选
* @param array $brand
* @param array $filter
* @param array $options
* @return array
*/
public static function brand($filter) {
public static function brand($filter, $options = array()) {
if (isset($options['brandName'])) {
return array();
}
$params = self::$params;
$brand_ids = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
if (isset($params['brand'])) {
unset($params['brand']);
}
$result = array(
'default' => array() ,
'brandIndex' => array(
... ... @@ -391,14 +383,11 @@ class HelperSearch
'U~Z' => array() ,
)
);
$brand_keys = array_reverse(array_keys($result['list']));
if (isset($filter['brand']) && !empty($filter['brand'])) {
//有商品结果时
$brand = $filter['brand'];
foreach ($brand as $v) {
if (!isset($v['brand_alif']) && isset($v['brand_name_en'])) {
$v['brand_alif'] = substr($v['brand_name_en'], 0, 1);
}
... ... @@ -408,7 +397,6 @@ class HelperSearch
if (!isset($v['brand_domain'])) {
$v['brand_domain'] = '';
}
//选中的筛选条件
if (in_array($v['id'], $brand_ids)) {
$selected_brand = explode(',', self::$params['brand']);
... ... @@ -421,9 +409,7 @@ class HelperSearch
'href' => self::buildurl($selected_params)
);
}
$selected_brand = isset(self::$params['brand']) && !empty(self::$params['brand']) ? explode(',', self::$params['brand']) : array();
if (empty($selected_brand)) {
$url = self::buildurl(array_merge($params, array(
'brand' => $v['id']
... ... @@ -442,15 +428,13 @@ class HelperSearch
'brand' => implode(',', $selected_brand)
)));
}
$this_brand = array(
'brand_id' => $v['id'],
'name' => $v['brand_name'],
'alif' => $v['brand_alif'],
'href' => $url,
'selected' => in_array($v['id'], $brand_ids) ? true : false
'active' => in_array($v['id'], $brand_ids) ? true : false
);
if (count($result['default']) < 10) {
$result['default'][] = $this_brand;
}
... ... @@ -472,11 +456,9 @@ class HelperSearch
}
}
else if (isset($filter['paramNames']) && isset($filter['paramNames']['brand'])) {
//无商品结果时且选择了品牌
$brand = $filter['paramNames']['brand'];
foreach ($brand as $v) {
//选中的筛选条件
if (in_array($v['id'], $brand_ids)) {
$selected_brand = explode(',', self::$params['brand']);
... ... @@ -500,7 +482,7 @@ class HelperSearch
/**
* 尺码的链接,不能多选
* @param array $size
* @param array $filter
* @return array
*/
public static function size($filter) {
... ... @@ -544,7 +526,7 @@ class HelperSearch
/**
* 颜色,不能多选
* @param array $color
* @param array $filter
* @return array
*/
public static function color($filter) {
... ... @@ -599,7 +581,7 @@ class HelperSearch
/**
* 获取价格,不能多选
* @param array $price
* @param array $filter
* @return array
*/
public static function price($filter) {
... ... @@ -657,7 +639,7 @@ class HelperSearch
/**
* 风格,可以多选
* @param array $style
* @param array $filter
* @return array
*/
public static function style($filter) {
... ... @@ -743,7 +725,8 @@ class HelperSearch
/**
* 高级选项
*/
public static function seniorChose($filter){
public static function seniorChose($filter)
{
$style = self::style($filter);
$other = self::standard($filter);
$result = array_merge($style,$other);
... ... @@ -753,9 +736,9 @@ class HelperSearch
/**
* 每页显示数量
*/
public static function viewNum() {
public static function viewNum()
{
$params = self::$params;
$view_num = array(
60,
100,
... ... @@ -776,8 +759,9 @@ class HelperSearch
/**
* 显示行数
*/
public static function rowNum($num = 5) {
$params = self::$params;
public static function rowNum($num = 5)
{
$params = self::$params;
$params['rowNum'] = $num;
... ... @@ -787,7 +771,8 @@ class HelperSearch
/**
* 是否特价
*/
public static function specialoffer() {
public static function specialoffer()
{
$params = self::$params;
if (isset($params['specialoffer']) && !empty($params['specialoffer'])) {
unset($params['specialoffer']);
... ... @@ -808,7 +793,8 @@ class HelperSearch
/**
* 是否限量
*/
public static function limited() {
public static function limited()
{
$params = self::$params;
if (isset($params['limited']) && !empty($params['limited'])) {
unset($params['limited']);
... ... @@ -828,7 +814,8 @@ class HelperSearch
/**
* 是否新品
*/
public static function isnew() {
public static function isnew()
{
$params = self::$params;
if (isset($params['isNew']) && !empty($params['isNew'])) {
... ... @@ -849,7 +836,8 @@ class HelperSearch
/**
* 排序是否最新
*/
public static function orderTime() {
public static function orderTime()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -867,7 +855,8 @@ class HelperSearch
/**
* 排序是否默认
*/
public static function orderDefault() {
public static function orderDefault()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -883,7 +872,8 @@ class HelperSearch
/**
* 价格排序
*/
public static function orderPrice() {
public static function orderPrice()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -925,7 +915,8 @@ class HelperSearch
/**
* 折扣排序
*/
public static function orderDiscount() {
public static function orderDiscount()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -967,7 +958,8 @@ class HelperSearch
/**
* 获取自定义价格要提交的地址
*/
public static function priceSubmit() {
public static function priceSubmit()
{
$params = self::$params;
$price = array();
if (isset($params['price'])) {
... ... @@ -1009,7 +1001,8 @@ class HelperSearch
* @param array $params
* @return string
*/
private static function buildurl($params) {
private static function buildurl($params)
{
if (empty($params)) {
return self::current();
}
... ... @@ -1033,7 +1026,8 @@ class HelperSearch
/**
* 获取选中的条件
*/
public static function getSelected() {
public static function getSelected()
{
$result = array();
$is_array_key = array(
'brand',
... ... @@ -1057,7 +1051,10 @@ class HelperSearch
* @param array $list
* @return array
*/
public static function getDiscount(array $list = array()) {
public static function getDiscount(array $list = array())
{
$params = self::$params;
if (empty($list)) {
return array();
}
... ... @@ -1077,12 +1074,12 @@ class HelperSearch
$total+= $v['count'];
$query['p_d'] = $k;
$list[$k]['href'] = self::buildurl($query);
$list[$k]['num'] = $total;
$list[$k]['selected'] = isset($params['p_d']) && $params['p_d'] == $k ? true : false;
//$list[$k]['num'] = $total;
$list[$k]['active'] = isset($params['p_d']) && $params['p_d'] == $k ? true : false;
}
$result = array(
'updateNum' => $total,
'list' => $list
//'updateNum' => $total,
'list' => array_values($list)
);
return $result;
}
... ... @@ -1090,11 +1087,12 @@ class HelperSearch
/**
* 最新上架
*/
public static function recentShelve($list = array()){
public static function recentShelve($list = array())
{
if (empty($list)) {
return array();
}
$params = $_GET;
$params = self::$params;
$query = array();
if (isset($params['gender'])) {
$query['gender'] = $params['gender'];
... ... @@ -1106,21 +1104,21 @@ class HelperSearch
$query['misort'] = $params['misort'];
}
$data = array();
$total = 0;
$i = 0;
foreach ($list as $k => $v) {
$total+= $v;
$star_time = strtotime($k);
$end_time = $star_time+60*60*24;
$query['shelve_time'] = '';
$query['shelve_time'] = $star_time.','.$end_time;
if (isset($params['shelve_time']) && $query['shelve_time'] == $params['shelve_time']) {
$data[$i]['active'] = true;
}
@$data[$i]['href'] = self::buildurl($query);
$data[$i]['num'] = $v;
$data[$i]['name'] = $k;
$i++;
}
$result = array(
'updateNum' => $total,
//'updateNum' => $total,
'list' => $data
);
return $result;
... ... @@ -1130,11 +1128,7 @@ class HelperSearch
*/
public static function current(){
$url = explode('?', $_SERVER['REQUEST_URI']);
self::$current_url = $url[0];
self::$listnav[0] = array(
'href' => '$url[0]',
'name' => '首页'
);
self::$listnav[0]['href'] = $url[0];
return $url[0];
}
/**
... ... @@ -1150,4 +1144,28 @@ class HelperSearch
}
return self::buildurl($param);
}
/**
* 组织产品的图片
* @param $product
* @param $options
* @return array
*/
public static function getProductPic($product, $options)
{
$result = array();
if (isset($product[0]['goods_list']) && !empty($product[0]['goods_list'])){
foreach ($product[0]['goods_list'] as $key => $val){
$result[$key]['coverImg'] = Images::getImageUrl($val['images_url'], $options['imgSize'][0], $options['imgSize'][1]);
$result[$key]['url'] = Helpers::getUrlBySkc($product[0]['product_id'], $val['goods_id'], $product[0]['cn_alphabet']);
$result[$key]['src'] = Images::getImageUrl($val['images_url'], $options['imgSize'][0], $options['imgSize'][1]);
}
}
return $result;
}
//分页
public static function pager($total,$view_num){
$Paging = new Paging('Yoho');
return $Paging->setTotal($total)->setSize($view_num)->view(0);
}
}
... ...
... ... @@ -776,5 +776,34 @@ class Helpers
}
return 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $goods_id . '/' . $cn_alphabet. '.html';
}
/**
* 获取真实IP
*
* @return string
*/
public static function getClientIp()
{
$ip = '0.0.0.0';
if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != '')
$ip = $_SERVER['HTTP_CLIENT_IP'];
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '')
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '')
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}
/**
* 组合国际手机号
* @param $area
* @param $mobile
* @return string
*/
public static function makeMobile($area, $mobile){
if(empty($area) || $area == 86){
return $mobile;
}
return $area.'-'.$mobile;
}
}
... ...
<?php
namespace Plugin;
use \Hood\Paging as HPage;
class Paging extends HPage
{
/**
* 路径
*
* @var String
*/
private $path = '';
/**
* 查询参数
* String or Array
* @var mixed
*/
private $query;
/**
* 分页集尺寸
*
* @var Integer
*/
private $pageSetSize = 11;
/**
* 子串
*
* @var String
*/
private $substring = '?';
/**
* 连接符号
*
* @var String
*/
private $sign = '=';
/**
* 对符
*
* @var String
*/
private $pairs = '&';
/**
* 模板路径
*
* @var String
*/
private $templatePath = '';
/**
* jsName
* @var String
*/
private $jsFName = '';
/**
* 废弃参数
* @var String
*/
private $disuse = null;
/**
* 设置分页链接中的关键字
*
* @var String
*/
private $keyword = 'page';
/**
* 是否开启rewrite url
*
* @var bool
*/
private $rewrite = false;
/**
* 附加参数
* @var string
*/
private $appendParam = '';
/**
* 分页中代码当前页码的常量
*
*/
const PAGER_VARIABLE_STRING = "%{PAGE_NO}";
public function __construct($file)
{
$this->templatePath = __DIR__ . '/Paging/' . ucfirst($file) . '.php';
}
/**
* 新的获取当前偏移
* @return Integer
*/
public function getNewCurrent()
{
if ($this->currentPage > 1) {
return min($this->currentPage, $this->getPageNum());
}
$pageNo = !isset($_GET[$this->keyword]) ? 0 : (int)(intval($_GET[$this->keyword]) * $this->getSize()) - $this->getSize();
return (int)($pageNo < 0 ? 0 : $pageNo);
}
/**
* 重载当前页方法
* @return Integer
*/
public function getCurrent()
{
if ($this->currentPage > 1) {
return min($this->currentPage, $this->getPageNum());
}
$pageNo = isset($_GET[$this->keyword]) ? (int)intval($_GET[$this->keyword]) : 1;
if ($pageNo <= 0) {
$pageNo = 1;
}
$this->currentPage = min($pageNo, $this->getPageNum());
return $this->currentPage;
}
/**
* 获取关键词
* @return String
*/
public function getKeyword()
{
return $this->keyword;
}
/**
* 设置关键词
*
* @param String $keyword
* @return QLib_Paging
*/
public function setKeyword($keyword)
{
if (!empty($keyword)) {
$this->keyword = $keyword;
}
return $this;
}
/**
* 设置js名字
* @param String $name
* @return Q_Page_Abstract
*/
public function setFJs($name)
{
if (!empty($name)) {
$this->jsFName = $name;
}
return $this;
}
/**
* 设置附加参数
* @param string $param
* @return Q_Page_Abstract
*/
public function setAppendParam($param)
{
$this->appendParam = $param;
return $this;
}
/**
* 获取附加参数
* @return string
*/
public function getAppendParam()
{
return $this->appendParam;
}
/**
* 获取分页js名字
* @return String
*
*/
public function getFJs()
{
return $this->jsFName;
}
/**
*
* 设置链接的路径
*
* @param String $path
* @return QLib_Paging
*/
public function setPath($path)
{
if (!empty($path)) {
$this->path = trim($path);
}
return $this;
}
/**
* 设置连续Url
*
* @param bool $seo
* @return QLib_Paging
*/
public function rewrite($rw = true)
{
if ($rw == true) {
$this->substring = '';
$this->sign = '/';
$this->pairs = '/';
$this->rewrite = true;
}
return $this;
}
/**
* 取得程序路径
* @return String
*/
public function getPath()
{
return $this->path;
}
/**
* 设置分页集尺寸
*
* @param integer $num 大于1
* @return QLib_Paging
*/
public function setPageSetSize($num)
{
$this->pageSetSize = (int)intval($num);
return $this;
}
/**
* 取得分页集尺寸
*
* @return integer
*/
public function getPageSetSize()
{
return (int)$this->pageSetSize;
}
/**
* 获取查询参数
* @return String
*/
public function getQuery()
{
$query = $this->query;
if (empty($this->query)) {
$this->query = $this->autoUrl();
}
if (is_array($this->query) && count($this->query) > 0) {
$_query = array();
foreach ($this->query as $key => $value) {
if($key == '_pjax'){
break;
}
if ($key == $this->getKeyword()) {
continue;
}
if (is_array($value)) {
foreach ($value as $k => $val) {
$_query[] = "{$key}[]" . $this->sign . $val;
}
} else {
$_query[] = "{$key}" . $this->sign . $value;
}
}
$this->query = $this->pairs . implode($this->pairs, $_query);
}
return $this->query ? $this->query : '';
}
/**
* 获取URL
*
* @param Integer $pageNo
* @return String
*/
public function getUrl($pageNo)
{
$query = $this->getQuery();
if (strstr($query, self::PAGER_VARIABLE_STRING) && is_string($query)) {
$query = str_replace(self::PAGER_VARIABLE_STRING, $pageNo, $query);
} else {
if (empty($query)) {
$query = $this->getKeyword() . $this->sign . $pageNo;
} else {
$query = $this->getKeyword() . $this->sign . $pageNo . $query;
}
}
$url = $this->getPath() . $this->substring . $query;
if ($this->getFJs()) {
$url = $query;
}
return $url;
}
/**
* 设置查询参数
*
* @param mixed $query String or Array
* @return QLib_Paging
*/
public function setQuery($query)
{
$this->query = $query;
return $this;
}
/**
* 设置模板路径
*
* @param String $path
* @return QLib_Paging
*/
public function setTemplate($path)
{
$this->templatePath = $path;
return $this;
}
/**
* 输出模板
*/
public function view($print = true)
{
if ($this->getTotal() > 0) {
include($this->templatePath);
if($print){
print $html;
}else{
return $html;
}
}
return '';
}
/**
* 自动组织 URL
* @return Array
*/
private function autoUrl()
{
$queryOpt = $_SERVER['REQUEST_URI'];
$queryArg = parse_url($queryOpt);
$queryOpt = isset($queryArg['query']) ? explode('&', $queryArg['query']) : array();
$query = array();
foreach ($queryOpt as $key => $val) {
$strTmp = explode('=', $val);
if (count($strTmp) < 2 || empty($strTmp[0]) || $strTmp[1] == '' || $strTmp[0] == $this->getKeyword()) {
continue;
}
if (is_array($this->disuse)) {
if (in_array($strTmp[1], $this->disuse) || in_array($strTmp[0], $this->disuse)) {
continue;
}
} else {
if ($strTmp[1] == $this->disuse || $strTmp[0] == $this->disuse) {
continue;
}
}
$query[$strTmp[0]] = $strTmp[1];
}
return $query;
}
/**
* set废弃参数
* @param mixed $disuse
* @return QLib_Paging
*/
public function setDisuse($disuse = null)
{
$this->disuse = $disuse;
return $this;
}
}
\ No newline at end of file
... ...
<?php
$pages = array();
$pageNum = $this->getPageNum(); #总分页数
$current = $this->getCurrent(); #当前页
$size = $this->getSize(); #每页显示数
$total = $this->getTotal(); #获取总数
$pageSetNum = $this->getPageSetSize(); #分页集数
$start = $end = 0;
if($current <= 4){
$start = 1;
$end = $start + 4;
}elseif(($pageNum - $current - 2) > 1)
{
$start = $current - 2 < 1 ? 1 : $current - 2;
$end = $current + 2;
}else{
$start = $current - 2;
$end = $pageNum;
}
if($end > $pageNum)
{
$end = $pageNum;
}
$startNum = $size * ($current - 1) + 1;
$endNum = min($size * $current, $total);
$html = '';
if($current > 1)
{
$html .= '<a href="' . $this->getUrl($current - 1) . '" title="上一页"><span class="ifont10"><</span></a>';
}
if ($pageNum > 1) {
if($pageNum > 5 && $current > 4){
$html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>';
$html .= '<a><span>...</span></a>';
$start = $current - 2;
$end = $pageNum - $current <= 3 ? $pageNum : $current + 2;
}
for ($i = $start; $i <= $end; ++$i) {
$_start = $size * ($i - 1) + 1;
$_end = min($size * $i, $total);
if ($i != $current) {
$html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>';
}
else {
$html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>';
}
}
if($pageNum > 5 && $pageNum - $current > 3){
$html .= '<a><span>...</span></a>';
$html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>';
}
}
if ($current < $pageNum) {
$html .= '<a href="' . $this->getUrl($current + 1) . '" class="page_next" title="下一页"><span class="ifont10">></span></a>';
}
... ...
<?php
$pages = array();
$pageNum = $this->getPageNum(); #总分页数
$current = $this->getCurrent(); #当前页
$size = $this->getSize(); #每页显示数
$total = $this->getTotal(); #获取总数
$pageSetNum = $this->getPageSetSize(); #分页集数
$start = $end = 0;
if($current <= 4){
$start = 1;
$end = $start + 4;
}elseif(($pageNum - $current - 2) > 1)
{
$start = $current - 2 < 1 ? 1 : $current - 2;
$end = $current + 2;
}else{
$start = $current - 2;
$end = $pageNum;
}
if($end > $pageNum)
{
$end = $pageNum;
}
$startNum = $size * ($current - 1) + 1;
$endNum = min($size * $current, $total);
$html = '<div class="left"><span class="rgb9">'.$startNum.' - '.$endNum.' / 共'.$total.'件商品</span></div><div class="goods-page right">';
if ($current > 1) {
$html .= '<a href="' . $this->getUrl($current - 1) . '" class="page_pre" title="上一页"><span class="ifont10"><</span>上一页</a>';
}
if ($pageNum > 1) {
if($pageNum > 5 && $current > 4){
$html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>';
$html .= '<a><span>...</span></a>';
$start = $current - 2;
$end = $pageNum - $current <= 3 ? $pageNum : $current + 2;
}
for ($i = $start; $i <= $end; ++$i) {
$_start = $size * ($i - 1) + 1;
$_end = min($size * $i, $total);
if ($i != $current) {
$html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>';
}else {
$html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>';
}
}
if($pageNum > 5 && $pageNum - $current > 3){
$html .= '<a><span>...</span></a>';
$html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>';
}
}
if ($current < $pageNum) {
$html .= '<a href="' . $this->getUrl($current + 1) . '" title="下一页">下一页<span class="ifont10">></span></a>';
}
$html .= '</div>';
... ...
<?php
$pages = array();
$pageNum = $this->getPageNum(); #总分页数
$current = $this->getCurrent(); #当前页
$size = $this->getSize(); #每页显示数
$total = $this->getTotal(); #获取总数
$pageSetNum = $this->getPageSetSize(); #分页集数
$start = $end = 0;
if($current <= 4){
$start = 1;
$end = $start + 4;
}elseif(($pageNum - $current - 2) > 1)
{
$start = $current - 2 < 1 ? 1 : $current - 2;
$end = $current + 2;
}else{
$start = $current - 2;
$end = $pageNum;
}
if($end > $pageNum)
{
$end = $pageNum;
}
$startNum = $size * ($current - 1) + 1;
$endNum = min($size * $current, $total);
$html = '<div class="left"></div><div class="list-page right">';
if ($current > 1) {
$html .= '<a href="' . $this->getUrl($current - 1) . '" class="page_pre" title="上一页"><span class="ifont10"><</span>上一页</a>';
}
if ($pageNum > 1) {
if($pageNum >= 5 && $current > 4){
$html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>';
$html .= '<a><span>...</span></a>';
$start = $current - 2;
$end = $pageNum - $current <= 3 ? $pageNum : $current + 2;
}
for ($i = $start; $i <= $end; ++$i) {
$_start = $size * ($i - 1) + 1;
$_end = min($size * $i, $total);
if ($i != $current) {
$html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>';
}else {
$html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>';
}
}
if($pageNum > 5 && $pageNum - $current > 3){
$html .= '<a><span>...</span></a>';
$html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>';
}
}
if ($current < $pageNum) {
$html .= '<a href="' . $this->getUrl($current + 1) . '" title="下一页">下一页<span class="ifont10">></span></a>';
}
$html .= '</div>';
\ No newline at end of file
... ...
<?php
namespace Plugin\Partner\douban;
use Plugin\Partner\Factory;
define('DB_CLASS_PATH', dirname(__FILE__).'/class/');
require DB_CLASS_PATH . 'DoubanClient.class.php';
/**
* 豆瓣的调用接口
*
* @name Call
* @package lib/partner/douban
* @copyright yoho.inc
* @version 5.0 (2015-12-31 10:54:54)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class Call extends Factory
{
/*人人网对象*/
protected $douban;
/**
* 初始化
*/
protected function init()
{
$this->douban = new \DoubanClient($this->apiConfig['appId'], $this->apiConfig['appKey'], $this->apiConfig['callback'], $this->apiConfig['scope']);
}
/**
* 获取授权URL
*
* @return string
*/
public function getAuthorizeUrl()
{
return $this->douban->getAuthorizeURL();
}
/**
* 获取授权的TOKEN
*
* @return array
*/
public function getAccessToken()
{
$token = array();
if (isset($_GET['code']))
{
try
{
// 设置authorizeCode
$this->douban->setAuthorizeCode($_GET['code']);
// 通过authorizeCode获取accessToken,至此完成用户授权
$this->douban->requestAccessToken();
$token = (array) $this->douban->getToken();
}
catch (Exception $e)
{
// do nothing
}
}
return $token;
}
/**
* 获取当前用户的基本资料
*
* @param array $token 授权成功的TOKEN, 默认为NULL
* @return array
*/
public function getUserInfo($token)
{
$userInfo = array();
if (is_array($token) && isset($token['access_token']))
{
// 获得保存的token
$this->douban->setAccessToken($token);
// 获得当前登录用户信息
$userInfo = $this->douban->api('/v2/user/~me', 'GET', null, true);
}
return $userInfo;
}
/**
* 获取当前用户的偶像(关注)列表
*
* 此接口暂未开放
*
* @return array
*/
public function getFriends($token, $params)
{
return array();
}
/**
* 同步分享
*
* @param String $image 新鲜事图片地址
* @param String $content 新鲜事主体内容 注意:最多200个字符。
* @param String $link 新鲜事标题和图片指向的链接
* @return Long 发布新鲜事的ID
*/
public function syncShare($token, $content, $image, $link)
{
$result = false;
if (is_array($token) && isset($token['access_token']))
{
// 获得保存的token
$this->douban->setAccessToken($token);
// 发表一篇说说
$param = array('source' => $this->apiConfig['appKey'], 'text' => $content, 'rec_image' => $image, 'rec_url' => $link,);
$result = $this->douban->api('/shuo/v2/statuses', 'POST', $param, true);
}
return $result;
}
}
\ No newline at end of file
... ...
<?php
defined('DOMAIN') || define('DOMAIN', $_SERVER['HTTP_HOST']);
return array(
'appId' => '09f4fa0661be14ec1ddeee13253a3ec4',
'appKey' => 'b4204e2055d63102',
'callback' => DOMAIN . '/passport/login/doubanback',
'scope' => 'douban_basic_common',
);
\ No newline at end of file
... ...
<?php
class DoubanClient {
/**
* @brief 豆瓣Oauth类词头
*/
const PREFIX = 'Douban';
/**
* @brief authorizeCode请求链接
*/
protected $authorizeUri = 'https://www.douban.com/service/auth2/auth';
/**
* @brief accessToken请求链接
*/
protected $accessUri = 'https://www.douban.com/service/auth2/token';
/**
* @brief api请求链接
*/
protected $apiUri = 'https://api.douban.com';
/**
* @brief 豆瓣应用public key
*/
protected $clientId;
/**
* @brief 豆瓣应用secret key
*/
protected $secret;
/**
* @brief callback链接
*/
protected $redirectUri;
/**
* @brief Api权限
*/
protected $scope;
/**
* @brief 返回类型,默认使用code
*/
protected $responseType;
/**
* @brief 用户授权码
*/
protected $authorizeCode;
/**
* @brief 储存返回的令牌(accessToken,refreshToken)
*/
protected $tokens;
/**
* @brief 通过authorizeCode获得的访问令牌
*/
protected $accessToken;
/**
* @brief 用于刷新accessToken
*/
protected $refreshToken;
/**
* @var 默认请求头信息
*/
protected $defaultHeader = array(
'Content_type: application/x-www-form-urlencoded'
);
/**
* @var 需授权的请求头
*/
protected $authorizeHeader;
/**
* @var curl默认设置
*/
protected $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'simple-douban-oauth2-0.4',
);
/**
* @brief 初始化豆瓣OAUTH,设置相关参数
*
* @param string $client_id
* @param string $secret
* @param string $redirect_uri
* @param string $scope
* @param string $responseType
*
* @return void
*/
public function __construct($clientId, $secret, $redirectUri, $scope ='douban_basic_common', $responseType = 'code')
{
$this->clientId = $clientId;
$this->secret = $secret;
$this->redirectUri = $redirectUri;
$this->scope = $scope;
$this->responseType = $responseType;
// // API基类路径
// $basePath = dirname(__FILE__).'/api/DoubanBase.php';
// // 载入API基类
// try {
// $this->fileLoader($basePath);
// } catch(Exception $e) {
// echo 'Baseloader error:'.$e->getMessage();
// }
}
/**
* @brief 跳转到豆瓣用户授权页面,获取AuthorizeCode
*
* @return redirect
*/
public function requestAuthorizeCode()
{
// 获取AuthorizeCode请求链接
$authorizeUrl = $this->getAuthorizeUrl();
header('Location:'.$authorizeUrl);
}
/**
* @brief 设置AuthorizeCode
*
* @param string $authorizeCode
*
* @return void
*/
public function setAuthorizeCode($authorizeCode)
{
$this->authorizeCode = $authorizeCode;
}
/**
* @brief 通过AuthorizeCode获取accessToken
*
* @return string
*/
public function requestAccessToken()
{
// 获取accessToken请求链接
$accessUrl = $this->getAccessUrl();
$header = $this->defaultHeader;
$result = $this->curl($accessUrl, 'POST', $header);
$this->tokens = json_decode($result);
$this->refreshToken = $this->tokens->refresh_token;
$this->accessToken = $this->tokens->access_token;
}
/**
* @brief 获取token
*
* @return string
*/
public function getToken()
{
return $this->tokens;
}
/**
* @brief 获取accessToken
*
* @return string
*/
public function getAccessToken()
{
return $this->accessToken;
}
/**
* @brief 设置token
*
* @return string
*/
public function setAccessToken($token)
{
if (is_array($token) && isset($token['access_token'])) {
$this->accessToken = $token['access_token'];
}
}
/**
* @brief 生成豆瓣用户授权页面完整地址
*
* @return string
*/
public function getAuthorizeUrl()
{
$params = array(
'client_id' => $this->clientId,
'redirect_uri' => $this->redirectUri,
'response_type' => $this->responseType,
'scope' => $this->scope
);
return $this->authorizeUri.'?'.http_build_query($params);
}
/**
* @brief 生成豆瓣access_token完整获取链接
*
* @return string
*/
public function getAccessUrl()
{
$params = array(
'client_id' => $this->clientId,
'client_secret' => $this->secret,
'redirect_uri' => $this->redirectUri,
'grant_type' => 'authorization_code',
'code' => $this->authorizeCode,
);
return $this->accessUri.'?'.http_build_query($params);
}
/**
* @brief 请求豆瓣API,返回包含相关数据的对象
*
* @param object $API
* @param array $data
* @param boolean 为true时会在header中发送accessToken
*
* @return object
*/
public function api($api, $type = 'POST', $data = null, $authorization = false)
{
// API的完整URL
$url = $this->apiUri.$api;
$header = $authorization ? $this->getAuthorizeHeader() : $this->defaultHeader;
$response = $this->curl($url, $type, $header, $data);
$result = json_decode($response, true);
return $result;
}
/**
* @brief 请求豆瓣API,返回包含相关数据的对象
*
* @param object $API
* @param array $data
* @param boolean 为true时会在header中发送accessToken
*
* @return object
*/
public function makeRequest($api, $data = null, $authorization = false)
{
// API的完整URL
$url = $this->apiUri.$api->uri;
$header = $authorization ? $this->getAuthorizeHeader() : $this->defaultHeader;
$type = $api->type;
return $this->curl($url, $type, $header, $data);
}
/**
* @brief 豆瓣API实例注册函数
*
* @param string $api
*
* @return object
*/
public function apiRegister($api)
{
$doubanApi = self::PREFIX.ucfirst(strtolower($api));
// 需要注册的API路径
$apiPath = dirname(__FILE__).'/api/'.$doubanApi.'.php';
try {
$this->fileLoader($apiPath);
} catch(Exception $e) {
echo 'Apiloader error:'.$e->getMessage();
}
return new $doubanApi($this->clientId);
}
/**
* @brief 获取Authorization header
*
* @return array
*/
protected function getAuthorizeHeader()
{
return $this->authorizeHeader = array('Authorization: Bearer '.$this->accessToken);
}
/**
* @brief 使用CURL模拟请求,并返回取得的数据
*
* @param string $url
* @param string $type
* @param array $header
* @param array $data
*
* @return object
*/
protected function curl($url, $type, $header, $data = null)
{
$opts = $this->CURL_OPTS;
$opts[CURLOPT_URL] = $url;
$opts[CURLOPT_CUSTOMREQUEST] = $type;
$header[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $header;
if ($type == 'POST' || $type =='PUT') {
$opts[CURLOPT_POSTFIELDS] = $data;
}
$ch = curl_init();
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
// if (curl_errno($ch)) {
// die('CURL error: '.curl_error($ch));
// }
curl_close($ch);
return $result;
}
/**
* @brief 文件加载类
*
* @param string $path
*
* @return void
*/
protected function fileLoader($path)
{
// 文件路径错误时抛出异常
if ( ! file_exists($path)) {
throw new Exception('The file you wanted to load does not exists.');
}
require $path;
}
}
... ...
<?php
/**
* @file DoubanBase.php
* @brief 豆瓣api的Base类
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-11-27
*/
class DoubanBase {
/**
* @brief 豆瓣API uri
*/
protected $uri;
/**
* @brief API请求方式
*/
protected $type;
/**
* @brief 豆瓣应用public key
*/
protected $clientId;
/**
* @brief 使用魔术方法获取类属性
*
* @param mixed $name
*
* @return mixed
*/
public function __get($name)
{
if (property_exists($this, $name)) {
return $this->$name;
}
}
}
... ...
<?php
/**
* @file DoubanBook.php
* @brief 豆瓣图书API
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-11-27
*/
class DoubanBook extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 获取指定书籍
*
* @param int $id
*
* @return object
*/
public function getBook($id)
{
$this->uri = '/v2/book/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 获取Isbn对应书籍
*
* @param string $name
*
* @return object
*/
public function isbn($name)
{
$this->uri = '/v2/book/isbn/'.$name;
$this->type = 'GET';
return $this;
}
/**
* @brief 图书搜素接口(未测试),q和tag必选其一。
*
* @param string $q
* @param string $tag
* @param int $start
* @param int $count
*
* @return object
*/
public function search($q, $tag, $start = 0, $count = 20)
{
$params = array(
'q' => $q,
'tag' => $tag,
'start' => $start,
'count' => $count
);
$this->uri = '/v2/book/search?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
/**
* @brief 获取某个图书中标记最多的标签(未测试)
*
* @param string $id
*
* @return object
*/
public function bookTags($id)
{
$this->uri = '/v2/book/'.$id.'/tags';
$this->type = 'GET';
return $this;
}
/**
* @brief 获取用户对图书的所有标签(未测试)
*
* @param string $name
*
* @return object
*/
public function userTags($name)
{
$this->uri = '/v2/book/user/'.$name.'/tags';
$this->type = 'GET';
return $this;
}
/**
* @brief 获取某个用户的所有图书收藏信息(未测试)
*
* @param string $name
*
* @return object
*/
public function collections($name)
{
$this->uri = '/v2/book/user/'.$name.'/collections';
$this->type = 'GET';
return $this;
}
/**
* @brief 获取用户对某本图书的收藏信息(为测试)
*
* @param string $id
*
* @return object
*/
public function getCollection($id)
{
$this->uri = '/v2/book/'.$id.'/collection';
$this->type = 'GET';
return $this;
}
/**
* @brief 用户收藏某本图书(未测试)
*
* @param string $id
*
* @return object
*/
public function addCollection($id)
{
$this->uri = '/v2/book/'.$id.'/collection';
$this->type = 'POST';
return $this;
}
/**
* @brief 用户修改对某本图书的收藏(未测试)
*
* @param string $id
*
* @return object
*/
public function editCollection($id)
{
$this->uri = '/v2/book/'.$id.'/collection';
$this->type = 'PUT';
return $this;
}
/**
* @brief 用户删除对某本图书的收藏(未测试)
*
* @param string $id
*
* @return object
*/
public function deleteCollection($id)
{
$this->uri = '/v2/book/'.$id.'/collection';
$this->type = 'DELETE';
return $this;
}
/**
* @brief 获取某个用户的所有笔记(未测试)
*
* @param string $name
*
* @return object
*/
public function userAnnotations($name)
{
$this->uri = '/v2/book/user/'.$name.'/annotations';
$this->type = 'GET';
return $this;
}
/**
* @brief 获取某本图书的所有笔记(未测试)
*
* @param string $id
*
* @return object
*/
public function bookAnnotations($id)
{
$this->uri = '/v2/book/user/'.$id.'/annotations';
$this->type = 'GET';
return $this;
}
/**
* @brief 获取某篇笔记的信息(未测试)
*
* @param string $id
*
* @return object
*/
public function getAnnotation($id)
{
$this->uri = '/v2/book/annotation/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 用户给某本图书写笔记(未测试)
*
* @param string $id
*
* @return object
*/
public function addAnnotation($id)
{
$this->uri = '/v2/book/'.$id.'/annotations';
$this->type = 'POST';
return $this;
}
/**
* @brief 用户修改某篇笔记(未测试)
*
* @param string $id
*
* @return object
*/
public function editAnnotation($id)
{
$this->uri = '/v2/book/annotation/'.$id;
$this->type = 'PUT';
return $this;
}
/**
* @brief 用户删除某篇笔记(未测试)
*
* @param string $id
*
* @return object
*/
public function deleteAnnotation($id)
{
$this->uri = '/v2/book/annotation/'.$id;
$this->type = 'DELETE';
return $this;
}
/**
* @brief 添加书评
*
* @return object
*/
public function addReview()
{
$this->uri = '/v2/book/reviews';
$this->type = 'POST';
return $this;
}
/**
* @brief 修改书评
*
* @param string $id
*
* @return object
*/
public function editReview($id)
{
$this->uri = '/v2/book/review/'.$id;
$this->type = 'PUT';
return $this;
}
/**
* @brief 删除书评
*
* @param string $id
*
* @return object
*/
public function deleteReview($id)
{
$this->uri = '/v2/book/review/'.$id;
$this->type = 'DELETE';
return $this;
}
}
... ...
<?php
/**
* @file DuobanComment.php
* @brief 豆瓣回复API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanComment extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
public function getCommentsList($target, $id)
{
$this->uri = '/v2/'.$target.'/'.$id.'/comments';
$this->type = 'GET';
return $this;
}
public function addComment($target, $id)
{
$this->uri = '/v2/'.$target.'/'.$id.'/comments';
$this->type = 'POST';
return $this;
}
public function getComment($target, $targetId, $commentId)
{
$this->uri = '/v2/'.$target.'/'.$targetId.'/comment/'.$commentId;
$this->type = 'GET';
return $this;
}
public function deleteComment($target, $targetId, $commentId)
{
$this->uri = '/v2/'.$target.'/'.$targetId.'/comment/'.$commentId;
$this->type = 'DELETE';
return $this;
}
}
... ...
<?php
/**
* @file DoubanDiscussion.php
* @brief 豆瓣论坛API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanDiscussion extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
public function getDiscussion($id)
{
$this->uri = '/v2/discussion/'.$id;
$this->type = 'GET';
return $this;
}
public function editDiscussion($id)
{
$this->uri = '/v2/discussion/'.$id;
$this->type = 'PUT';
return $this;
}
public function deleteDiscussion($id)
{
$this->uri = '/v2/discussion/'.$id;
$this->type = 'DELETE';
return $this;
}
public function addDiscussion($target, $id)
{
$this->uri = '/v2/'.$target.'/'.$id.'/discussions';
$this->type = 'POST';
return $this;
}
public function getDiscussionsList($target, $id)
{
$this->uri = '/v2/'.$target.'/'.$id.'/discussions';
$this->type = 'GET';
return $this;
}
}
... ...
<?php
/**
* @file DoubanDoumail.php
* @brief 豆邮API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanDoumail extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 获取一封豆邮
*
* @param string $id 豆邮id
*
* @return object
*/
public function get($id)
{
$this->uri = '/v2/doumail/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 获取用户收件箱
*
* @return object
*/
public function inbox()
{
$this->uri = '/v2/doumail/inbox';
$this->type = 'GET';
return $this;
}
public function outbox()
{
$this->uri = '/v2/doumail/outbox';
$this->type = 'GET';
return $this;
}
public function unread()
{
$this->uri = '/v2/doumail/inbox/unread';
$this->type = 'GET';
return $this;
}
public function read($id)
{
$this->uri = '/v2/doumail/'.$id;
$this->type = 'PUT';
return $this;
}
public function mutilRead()
{
$this->uri = '/v2/doumail/read';
$this->type = 'PUT';
return $this;
}
public function delete($id)
{
$this->uri = '/v2/doumail/'.$id;
$this->type = "DELETE";
return $this;
}
public function mutilDelete()
{
$this->uri = '/v2/doumail/delete';
$this->type = 'POST';
return $this;
}
public function add()
{
$this->uri = '/v2/doumails';
$this->type = 'POST';
return $this;
}
}
... ...
<?php
/**
* @file DoubanEvent.php
* @brief 豆瓣同城API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanEvent extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
public function get($id)
{
$this->uri = '/v2/event/'.$id;
$this->type = 'GET';
return $this;
}
public function participants($id)
{
$this->uri = '/v2/event/'.$id.'/participants';
$this->type = 'GET';
return $this;
}
public function wishers($id)
{
$this->uri = '/v2/event/'.$id.'/wishers';
$this->type = 'GET';
return $this;
}
public function userCreated($id)
{
$this->uri = '/v2/event/user_created/'.$id;
$this->type = 'GET';
return $this;
}
public function userParticipated($id)
{
$this->uri = '/v2/event/user_participated/'.$id;
$this->type = 'GET';
return $this;
}
public function userWished($id)
{
$this->uri = '/v2/event/user_wished/'.$id;
$this->type = 'GET';
return $this;
}
public function eventList()
{
$this->uri = '/v2/event/list';
$this->type = 'GET';
return $this;
}
public function loc($id)
{
$this->uri = '/v2/loc/'.$id;
$this->type = 'GET';
return $this;
}
public function locList()
{
$this->uri = '/v2/loc/list';
$this->type = 'GET';
return $this;
}
public function join($id)
{
$this->uri = '/v2/event/'.$id.'/participants';
$this->type = 'POST';
return $this;
}
public function quit($id)
{
$this->uri = '/v2/event/'.$id.'/participants';
$this->type = 'DELETE';
return $this;
}
public function wish($id)
{
$this->uri = '/v2/event/'.$id.'/wishers';
$this->type = 'POST';
return $this;
}
public function unwish($id)
{
$this->uri = '/v2/event/'.$id.'/wishers';
$this->type = 'DELETE';
return $this;
}
}
... ...
<?php
/**
* @file DoubanMiniblog.php
* @brief 豆瓣广播API
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-03
*/
class DoubanMiniblog extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 发送一条豆瓣广播
*
* @return object
*/
public function addMiniblog()
{
$this->uri = '/shuo/v2/statuses/';
$this->type = 'POST';
return $this;
}
/**
* @brief 读取一条广播
*
* @param string $id
*
* @return object
*/
public function getMiniblog($id)
{
$this->uri = '/shuo/v2/statuses/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 删除一条广播
*
* @param string $id
*
* @return object
*/
public function deleteMiniblog($id)
{
$this->uri = '/shuo/v2/statuses/'.$id;
$this->type = 'DELETE';
return $this;
}
/**
* @brief 获取一条广播的回复列表(未测试)
*
* @param string $id
* @param int $start
* @param int $count
*
* @return object
*/
public function getCommentsList($id, $start = 0, $count = 20)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/comments?start='.$start.'&count='.$count;
$this->type = 'GET';
return $this;
}
/**
* @brief 回复某条广播(未测试)
*
* @param string $id
*
* @return object
*/
public function addComment($id)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/comments';
$this->type = 'POST';
return $this;
}
/**
* @brief 获取广播的单条回复(未测试)
*
* @param string $id
*
* @return object
*/
public function getComment($id)
{
$this->uri ='/shuo/v2/statuses/comment/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 删除广播的单条回复
*
* @param string $id
*
* @return object
*/
public function deleleComment($id)
{
$this->uri = '/shuo/v2/statuses/comment/'.$id;
$this->type = 'DELETE';
return $this;
}
/**
* @brief 获取一条广播的转发相关信息(未测试)
*
* @param string $id
*
* @return object
*/
public function getReshare($id)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/reshare';
$this->type = 'GET';
return $this;
}
/**
* @brief 转发一条广播
*
* @param string $id
*
* @return object
*/
public function reshare($id)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/reshare';
$this->type = 'POST';
return $this;
}
/**
* @brief 获取一条广播的赞相关信息(未测试)
*
* @param string $id
*
* @return object
*/
public function getLikers($id)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/like';
$this->type = 'GET';
return $this;
}
/**
* @brief 赞一条广播
*
* @param string $id
*
* @return object
*/
public function like($id)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/like';
$this->type = 'POST';
return $this;
}
/**
* @brief 取消赞(未测试)
*
* @param string $id
*
* @return object
*/
public function dislike($id)
{
$this->uri = '/shuo/v2/statuses/'.$id.'/like';
$this->type = 'DELETE';
return $this;
}
public function following($id)
{
$this->uri = '/shuo/v2/users/'.$id.'/following';
$this->type = 'GET';
return $this;
}
public function followers($id)
{
$this->uri = '/shuo/v2/users/'.$id.'/followers';
$this->type = 'GET';
return $this;
}
public function followInCommon($id)
{
$this->uri = '/shuo/v2/users/'.$id.'/follow_in_common';
$this->type = 'GET';
return $this;
}
public function suggestions($id)
{
$this->uri = '/shuo/v2/users/'.$id.'/following_followers_of';
$this->type = 'GET';
return $this;
}
public function block($id)
{
$this->uri = '/shuo/v2/users/'.$id.'/block';
$this->type = 'POST';
return $this;
}
public function unfollow()
{
$this->uri = '/shuo/v2/friendships/destroy';
$this->type = 'POST';
return $this;
}
public function show($source, $sourceId, $targetId)
{
$params = array(
'source' => $source,
'source_id' => $sourceId,
'target_id' => $targetId
);
$this->uri = '/shuo/v2/friendships/show?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
/**
* @brief 获取当前登录用户及其所关注用户的最新广播(友邻广播)
*
* @param string $sinceId
* @param string $untilId
* @param string $count
* @param string $start
*
* @return object
*/
public function homeTimeline($sinceId = null, $untilId = null, $count = null, $start = null )
{
$params = array(
'since_id' => $sinceId,
'until_id' => $untilId,
'count' => $count,
'start' => $start
);
$this->uri = '/shuo/v2/statuses/home_timeline?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
/**
* @brief 获取用户发布的广播列表
*
* @param string $user
* @param string $sinceId
* @param string $untilId
*
* @return object
*/
public function userTimeline($user, $sinceId = null, $untilId = null)
{
$params = array(
'since_id' => $sinceId,
'until_id' => $untilId
);
$this->uri = '/shuo/v2/statuses/user_timeline/'.$user.'?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
}
... ...
<?php
/**
* @file DoubanMovie.php
* @brief 豆瓣电影API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanMovie extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 获取电影信息
*
* @param string $id
*
* @return object
*/
public function get($id)
{
$this->uri = '/v2/movie/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 根据imdb号获取电影信息
*
* @param string $name
*
* @return object
*/
public function imdb($name)
{
$this->uri = '/v2/movie/imdb/'.$name;
$this->type = 'GET';
return $this;
}
public function search($q, $tag, $start = 0, $count = 20)
{
$params = array(
'q' => $q,
'tag' => $tag,
'start' => $start,
'count' => $count
);
$this->uri = '/v2/movie/search?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
public function movieTags($id)
{
$this->uri = '/v2/movie/'.$id.'/tags';
$this->type = 'GET';
return $this;
}
public function userTags($id)
{
$this->uri = '/v2/movie/user_tags/'.$id;
$this->type = 'GET';
return $this;
}
public function addReview()
{
$this->uri = '/v2/movie/reviews';
$this->type = 'POST';
return $this;
}
public function editReview($id)
{
$this->uri = '/v2/movie/review/'.$id;
$this->type = 'PUT';
return $this;
}
public function deleteReview($id)
{
$this->uri = '/v2/movie/review/'.$id;
$this->type = 'DELETE';
return $this;
}
}
... ...
<?php
/**
* @file DoubanMusic.php
* @brief 豆瓣音乐API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanMusic extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 获取音乐信息
*
* @param $id
*
* @return object
*/
public function get($id)
{
$this->uri = '/v2/music/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 搜索音乐
*
* @param $q
* @param $tag
* @param $start
* @param $count
*
* @return object
*/
public function search($q, $tag = null, $start = 0, $count = 20)
{
$params = array(
'q' => $q,
'tag' => $tag,
'start' => $start,
'count' => $count
);
$this->uri = '/v2/music/search?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
/**
* @brief 某个音乐中标记最多的标签
*
* @param $id
*
* @return object
*/
public function musicTags($id)
{
$this->uri = '/v2/music/'.$id.'/tags';
$this->type = 'GET';
return $this;
}
public function addReview()
{
$this->uri = '/v2/music/reviews';
$this->type = 'POST';
return $this;
}
public function editReview($id)
{
$this->uri = '/v2/music/review/'.$id;
$this->type = 'PUT';
return $this;
}
public function deleteReview($id)
{
$this->uri = '/v2/music/review/'.$id;
$this->type = 'DELETE';
return $this;
}
/**
* @brief 用户对音乐的所有标签
*
* @param $id
*
* @return object
*/
public function userTags($id)
{
$this->uri = '/v2/music/user_tags/'.$id;
$this->type = 'GET';
return $this;
}
}
... ...
<?php
/**
* @file DoubanNote.php
* @brief 豆瓣日记API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanNote extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 获取一条日记
*
* @param $id
* @param $format
*
* @return object
*/
public function getNote($id, $format = 'text')
{
$this->uri = '/v2/note/'.$id.'?format='.$format;
$this->type = 'GET';
return $this;
}
public function addNote()
{
$this->uri = '/v2/notes';
$this->type = 'POST';
return $this;
}
public function editNote($id)
{
$this->uri = '/v2/note/'.$id;
$this->type = 'PUT';
return $this;
}
public function deleteNote($id)
{
$this->uri = '/v2/note/'.$id;
$this->type = 'DELETE';
return $this;
}
public function like($id)
{
$this->uri = '/v2/note/'.$id.'/like';
$this->type = 'POST';
return $this;
}
public function dislike($id)
{
$this->uri = '/v2/note/'.$id.'/like';
$this->type = 'DELETE';
return $this;
}
public function image($id)
{
$this->uri = '/v2/note/'.$id;
$this->type = 'POST';
return $this;
}
public function getCommentsList($id)
{
$this->uri = '/v2/note/'.$id.'/comments';
$this->type = 'GET';
return $this;
}
public function reply($id)
{
$this->uri = '/v2/note/'.$id.'/comments';
$this->type = 'POST';
return $this;
}
public function getComment($noteId, $commentId)
{
$this->uri = '/v2/note/'.$noteId.'/comment/'.$commentId;
$this->type = 'GET';
return $this;
}
public function deleteComment($noteId, $commentId)
{
$this->uri = '/v2/note/'.$noteId.'/comment/'.$id;
$this->type = 'DELETE';
return $this;
}
}
... ...
<?php
/**
* @file DoubanOnline.php
* @brief 豆瓣线上活动API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanOnline extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->client = $clientId;
}
public function getOnline($id)
{
$this->uri = '/v2/online/'.$id;
$this->type = 'GET';
return $this;
}
public function participants($id)
{
$this->uri = '/v2/online/'.$id.'/participants';
$this->type = 'GET';
return $this;
}
public function getDiscussionsList($id)
{
$this->uri = '/v2/online/'.$id.'/discussions';
$this->type = 'GET';
return $this;
}
public function getOnlinesList($cate)
{
$this->uri = '/v2/onlines?cate='.$cate;
$this->type = 'GET';
return $this;
}
public function addOnline()
{
$this->uri = '/v2/onlines';
$this->type = 'POST';
return $this;
}
public function editOnline($id)
{
$this->uri = '/v2/onlines/'.$id;
$this->type = 'PUT';
return $this;
}
public function deleteOnline($id)
{
$this->uri = '/v2/onlines/'.$id;
$this->type = 'DELETE';
return $this;
}
public function join($id)
{
$this->uri = '/v2/online/'.$id.'/participants';
$this->type = 'POST';
return $this;
}
public function quit($id)
{
$this->uri = '/v2/online/'.$id.'/participants';
$this->type = 'DELETE';
return $this;
}
public function like($id)
{
$this->uri = '/v2/online/'.$id.'/like';
$this->type = 'POST';
return $this;
}
public function dislike($id)
{
$this->uri = '/v2/online/'.$id.'/like';
$this->type = 'DELETE';
return $this;
}
public function getPhoto($id)
{
$this->uri = '/v2/online/'.$id.'/photos';
$this->type = 'GET';
return $this;
}
public function addPhoto($id)
{
$this->uri = '/v2/online/'.$id.'/photos';
$this->type = 'POST';
return $this;
}
public function replyDiscussion($id)
{
$this->uri = '/v2/online/'.$id.'/discussions';
$this->type = 'POST';
return $this;
}
public function userParticipated($id, $excludeExpired = true)
{
$this->uri = '/v2/online/user_participated/'.$id.'?exclude_expired='.$excludeExpired;
$this->type = 'GET';
return $this;
}
public function userCreated($id)
{
$this->uri = '/v2/online/user_created/'.$id;
$this->type = 'GET';
return $this;
}
}
... ...
<?php
/**
* @file DoubanPhoto.php
* @brief 豆瓣相册API接口
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-05
*/
class DoubanPhoto extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId和accessToken
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
public function getAlbum($id)
{
$this->uri = '/v2/album/'.$id;
$this->type = 'GET';
return $this;
}
public function addAlbum()
{
$this->uri = '/v2/albums';
$this->type = 'POST';
return $this;
}
public function editAlbum($id)
{
$this->uri = '/v2/album/'.$id;
$this->type = 'PUT';
return $this;
}
public function deleteAlbum($id)
{
$this->uri = '/v2/album/'.$id;
$this->type = 'DELETE';
return $this;
}
public function getPhotosList($id)
{
$this->uri = '/v2/album/'.$id.'/photos';
$this->type = 'GET';
return $this;
}
public function getPhoto($id)
{
$this->uri = '/v2/photo/'.$id;
$this->type = 'GET';
return $this;
}
public function likeAlbum($id)
{
$this->uri = '/v2/album/'.$id.'/like';
$this->type = 'POST';
return $this;
}
public function dislikeAlbum($id)
{
$this->uri = '/v2/album/'.$id.'/like';
$this->type = 'DELETE';
return $this;
}
public function getUserAlbumList($id)
{
$this->uri = '/v2/album/user_created/'.$id;
$this->type = 'GET';
return $this;
}
public function userLiked($id)
{
$this->uri = '/v2/album/user_liked/'.$id;
$this->type = 'GET';
return $this;
}
public function addPhoto($id)
{
$this->uri = '/v2/album/'.$id;
$this->type = 'POST';
return $this;
}
public function editPhoto($id)
{
$this->uri = '/v2/album/'.$id;
$this->type = 'PUT';
return $this;
}
public function deletePhoto($id)
{
$this->uri = '/v2/album/'.$id;
$this->type = 'DELETE';
return $this;
}
public function likePhoto($id)
{
$this->uri = '/v2/photo/'.$id.'/like';
$this->type = 'POST';
return $this;
}
public function dislikePhoto($id)
{
$this->uri = '/v2/photo/'.$id.'/like';
$this->type = 'DELETE';
return $this;
}
}
... ...
<?php
/**
* @file DoubanUser.php
* @brief 豆瓣用户API
* @author JonChou <ilorn.mc@gmail.com>
* @date 2012-12-03
*/
class DoubanUser extends DoubanBase {
/**
* @brief 构造函数,初始设置clientId
*
* @param string $clientId
*
* @return void
*/
public function __construct($clientId)
{
$this->clientId = $clientId;
}
/**
* @brief 获取当前授权用户信息
*
* @return object
*/
public function me()
{
$this->uri = '/v2/user/~me';
$this->type = 'GET';
return $this;
}
/**
* @brief 获取指定ID用户信息
*
* @param string $id
*
* @return object
*/
public function get($id)
{
$this->uri = '/v2/user/'.$id;
$this->type = 'GET';
return $this;
}
/**
* @brief 搜索用户
*
* @param string $q
* @param int $start
* @param int $count
*
* @return object
*/
public function search($q, $start = null, $count = null)
{
$params = array(
'q' => $q,
'start' => $start,
'count' => $count
);
$this->uri = '/v2/user?'.http_build_query($params);
$this->type = 'GET';
return $this;
}
}
... ...
<?php
namespace Plugin\Partner\renren;
use Plugin\Partner\Factory;
define('RENREN_CLASS_PATH', dirname (__FILE__) . '/class/');
require RENREN_CLASS_PATH . 'RennClientBase.class.php';
/**
* 人人网的调用接口
*
* @name Call
* @package lib/partner/renren
* @copyright yoho.inc
* @version 5.0 (2015-12-31 10:54:54)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class Call extends Factory
{
/*人人网对象*/
protected $renn;
/**
* 初始化
*/
protected function init()
{
$this->renn = new \RennClientBase($this->apiConfig['appId'], $this->apiConfig['appKey']);
}
/**
* 获取授权URL
*
* @return string
*/
public function getAuthorizeUrl()
{
return $this->renn->getAuthorizeURL($this->apiConfig['callback'], 'code', null, null, true, $this->apiConfig['scope']);
}
/**
* 获取授权的TOKEN
*
* @return array
*/
public function getAccessToken()
{
$token = array();
if (isset($_REQUEST['code']))
{
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = $this->apiConfig['callback'];
try
{
$token = $this->renn->getTokenFromTokenEndpoint('code', $keys, TokenType::Bearer);
// 返回数组格式的信息
$token = $this->renn->getTokens();
}
catch (Exception $e)
{
// do nothing
}
}
return $token;
}
/**
* 获取当前用户的基本资料
*
* @see http://open.renren.com/wiki/API/v2/user/get
* @param object $token 授权成功的TOKEN, 默认为NULL
* @return array
*/
public function getUserInfo($token)
{
$userInfo = array();
if (!empty($token))
{
if (is_array($token))
{
$token = new AccessToken(isset($token['type']) ? $token['type'] : TokenType::Bearer, $token['accessToken'], isset($token['refreshToken']) ? $token['refreshToken'] : null, isset($token['macKey']) ? $token['macKey'] : null, isset($token['macAlgorithm']) ? $token['macAlgorithm'] : null);
}
// 获得保存的token
$this->renn->authWithToken($token);
// 获得当前登录用户
if (isset($token->accessToken))
{
$parts = explode('-', $token->accessToken);
if (isset($parts[1]))
{
$params = array('userId' => $parts[1]);
try
{
$userInfo = $this->renn->execute('/v2/user/login/get', 'GET', $params, array(), array());
}
catch (Exception $e)
{
// do nothing
}
}
}
}
return $userInfo;
}
/**
* 获取当前用户的偶像(关注)列表
*
* @see http://open.renren.com/wiki/V2/friend/list
* @param object $token 访问令牌
* @param array $params 参数列表
* Long $userId 用户ID。该字段默认为当前用户
* Integer $pageSize 页面大小。默认大小500。
* Integer $pageNumber 页码。取值大于零,默认值为1
* @return array
*/
public function getFriends($token, $params)
{
$friends = array();
if (!empty($token))
{
if (is_array($token))
{
$token = new AccessToken(isset($token['type']) ? $token['type'] : TokenType::Bearer, $token['accessToken'], isset($token['refreshToken']) ? $token['refreshToken'] : null, isset($token['macKey']) ? $token['macKey'] : null, isset($token['macAlgorithm']) ? $token['macAlgorithm'] : null);
}
// 获得保存的token
$this->renn->authWithToken($token);
// 获取当前登录用户的好友列表
if (!isset($params['userId']) && isset($token->accessToken))
{
$parts = explode('-', $token->accessToken);
if (isset($parts[1]))
{
$params['userId'] = $parts[1];
}
}
try
{
$friends = $this->renn->execute('/v2/user/friend/list', 'GET', $params, array(), array());
}
catch (Exception $e)
{
// do nothing
}
}
return $friends;
}
/**
* 同步分享
*
* 发送自定义新鲜事。新鲜事会发布用户的个人动态信息到用户人人网主页,同时会出现在好友的新鲜事中
*
* @see http://open.renren.com/wiki/API/v2/feed/put
* @param object $token 访问令牌
* @param String $image 新鲜事图片地址
* @param String $content 新鲜事主体内容 注意:最多200个字符。
* @param String $link 新鲜事标题和图片指向的链接
* @return Long 发布新鲜事的ID
*/
public function syncShare($token, $content, $image, $link)
{
$result = false;
if (!empty($token))
{
if (is_array($token))
{
$token = new AccessToken(isset($token['type']) ? $token['type'] : TokenType::Bearer, $token['accessToken'], isset($token['refreshToken']) ? $token['refreshToken'] : null, isset($token['macKey']) ? $token['macKey'] : null, isset($token['macAlgorithm']) ? $token['macAlgorithm'] : null);
}
// 获得保存的token
$this->renn->authWithToken($token);
$params = array('title' => '来自YOHO的分享', 'message' => $content, 'actionTargetUrl' => $link,
'imageUrl' => $image, 'description' => $content, 'targetUrl' => $link,);
try
{
$result = $this->renn->execute('/v2/feed/put', 'POST', $params, array(), array());
}
catch (Exception $e)
{
// do nothing
}
}
return $result;
}
/**
* 返回token的所有信息(包括user)
*
* 备注:所有此方法必须先调用 getAccessToken()
*
* @return array
*/
public function getTokens()
{
return $this->renn->getTokens();
}
}
\ No newline at end of file
... ...
<?php
defined('DOMAIN') || define('DOMAIN', $_SERVER['HTTP_HOST']);
return array(
'appId' => '783130c654c94a77ace97054ae266019',
'appKey' => '05e430de8c1e40d3a1f39ca8d3f8252c',
'callback' => DOMAIN . '/passport/login/renrenback',
'scope' => 'publish_feed,photo_upload',
);
\ No newline at end of file
... ...
<?php
include_once ('RennClientBase.class.php');
include_once ('service/RennServiceBase.php');
include_once ('service/AlbumService.php');
include_once ('service/BlogService.php');
include_once ('service/ShareService.php');
include_once ('service/UbbService.php');
include_once ('service/NotificationService.php');
include_once ('service/FeedService.php');
include_once ('service/InvitationService.php');
include_once ('service/ProfileService.php');
include_once ('service/AppService.php');
include_once ('service/StatusService.php');
include_once ('service/LikeService.php');
include_once ('service/PhotoService.php');
include_once ('service/CommentService.php');
include_once ('service/UserService.php');
include_once ('service/FriendService.php');
class RennClient extends RennClientBase {
private $albumService;
private $blogService;
private $shareService;
private $ubbService;
private $notificationService;
private $feedService;
private $invitationService;
private $profileService;
private $appService;
private $statusService;
private $likeService;
private $photoService;
private $commentService;
private $userService;
private $friendService;
function getAlbumService() {
if (empty ($this -> albumService )) {
$this->albumService = new AlbumService ( $this, $this->accessToken );
}
return $this->albumService;
}
function getBlogService() {
if (empty ($this -> blogService )) {
$this->blogService = new BlogService ( $this, $this->accessToken );
}
return $this->blogService;
}
function getShareService() {
if (empty ($this -> shareService )) {
$this->shareService = new ShareService ( $this, $this->accessToken );
}
return $this->shareService;
}
function getUbbService() {
if (empty ($this -> ubbService )) {
$this->ubbService = new UbbService ( $this, $this->accessToken );
}
return $this->ubbService;
}
function getNotificationService() {
if (empty ($this -> notificationService )) {
$this->notificationService = new NotificationService ( $this, $this->accessToken );
}
return $this->notificationService;
}
function getFeedService() {
if (empty ($this -> feedService )) {
$this->feedService = new FeedService ( $this, $this->accessToken );
}
return $this->feedService;
}
function getInvitationService() {
if (empty ($this -> invitationService )) {
$this->invitationService = new InvitationService ( $this, $this->accessToken );
}
return $this->invitationService;
}
function getProfileService() {
if (empty ($this -> profileService )) {
$this->profileService = new ProfileService ( $this, $this->accessToken );
}
return $this->profileService;
}
function getAppService() {
if (empty ($this -> appService )) {
$this->appService = new AppService ( $this, $this->accessToken );
}
return $this->appService;
}
function getStatusService() {
if (empty ($this -> statusService )) {
$this->statusService = new StatusService ( $this, $this->accessToken );
}
return $this->statusService;
}
function getLikeService() {
if (empty ($this -> likeService )) {
$this->likeService = new LikeService ( $this, $this->accessToken );
}
return $this->likeService;
}
function getPhotoService() {
if (empty ($this -> photoService )) {
$this->photoService = new PhotoService ( $this, $this->accessToken );
}
return $this->photoService;
}
function getCommentService() {
if (empty ($this -> commentService )) {
$this->commentService = new CommentService ( $this, $this->accessToken );
}
return $this->commentService;
}
function getUserService() {
if (empty ($this -> userService )) {
$this->userService = new UserService ( $this, $this->accessToken );
}
return $this->userService;
}
function getFriendService() {
if (empty ($this -> friendService )) {
$this->friendService = new FriendService ( $this, $this->accessToken );
}
return $this->friendService;
}
}
?>
... ...