Commit b1045e62 authored by 蒋林's avatar 蒋林

首页

parent 5f5addda
document.write("<li><a href=\"/hangye/83.html\" title=\"格力起诉美的“制冷王”空调侵权 索赔5000万元\">格力起诉美的“制冷王”空调侵权 </a></li><li><a href=\"/changshang/2017-06-20/84.html\" title=\"让台湾观众坠入了美的旋涡\">让台湾观众坠入了美的旋涡</a></li><li><a href=\"/shifu/24.html\" title=\"年轻时遇到了一些艳遇 回想起来依然记忆犹新\">年轻时遇到了一些艳遇 回想起来依</a></li>");
\ No newline at end of file
document.write("<li><a href=\"/changshang/2017-06-27/89.html\" title=\"测试\">测试</a></li><li><a href=\"/hangye/83.html\" title=\"格力起诉美的“制冷王”空调侵权 索赔5000万元\">格力起诉美的“制冷王”空调侵权 </a></li><li><a href=\"/changshang/2017-06-20/84.html\" title=\"让台湾观众坠入了美的旋涡\">让台湾观众坠入了美的旋涡</a></li><li><a href=\"/shifu/24.html\" title=\"年轻时遇到了一些艳遇 回想起来依然记忆犹新\">年轻时遇到了一些艳遇 回想起来依</a></li>");
\ No newline at end of file
document.write("<li><a href=\"/hangye/76.html\" title=\"家电回收条例有望年内出台 厂商只卖拒收罚10万\">家电回收条例有望年内出台 厂商只</a></li><li><a href=\"/pinlei/bingxiang/guzhangdaima/1.html\" title=\"科龙BCD-191W电冰箱故障代码表\">科龙BCD-191W电冰箱故障代码表</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/2.html\" title=\"美的洗衣机MB55-3006G按启动键后就进入洗衣(干洗)状态维修全过程\">美的洗衣机MB55-3006G按启动键后就</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/3.html\" title=\"自制拆装波轮洗衣机离合器中心螺帽配套工具\">自制拆装波轮洗衣机离合器中心螺帽</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/4.html\" title=\"自制拆洗衣机排水阀(水堵)工具\">自制拆洗衣机排水阀(水堵)工具</a></li><li><a href=\"/shifu/5.html\" title=\"科龙BCD-242/HC电冰箱故障代码表\">科龙BCD-242/HC电冰箱故障代码表</a></li><li><a href=\"/shifu/6.html\" title=\"小天鹅全自动洗衣机故障可控硅之“元凶”\">小天鹅全自动洗衣机故障可控硅之“</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/7.html\" title=\"洗衣机故障速修心得\">洗衣机故障速修心得</a></li><li><a href=\"/pinlei/dianshiji/jingyanjiqiao/8.html\" title=\"液晶屏逻辑板和屏坏简易判断及检修\">液晶屏逻辑板和屏坏简易判断及检修</a></li><li><a href=\"/shifu/2017-04-10/9.html\" title=\"自学成才不是梦 家电维修趣味七大口诀\">自学成才不是梦 家电维修趣味七大</a></li>");
\ No newline at end of file
document.write("<li><a href=\"/changshang/2017-06-27/89.html\" title=\"测试\">测试</a></li><li><a href=\"/hangye/76.html\" title=\"家电回收条例有望年内出台 厂商只卖拒收罚10万\">家电回收条例有望年内出台 厂商只</a></li><li><a href=\"/pinlei/bingxiang/guzhangdaima/1.html\" title=\"科龙BCD-191W电冰箱故障代码表\">科龙BCD-191W电冰箱故障代码表</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/2.html\" title=\"美的洗衣机MB55-3006G按启动键后就进入洗衣(干洗)状态维修全过程\">美的洗衣机MB55-3006G按启动键后就</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/3.html\" title=\"自制拆装波轮洗衣机离合器中心螺帽配套工具\">自制拆装波轮洗衣机离合器中心螺帽</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/4.html\" title=\"自制拆洗衣机排水阀(水堵)工具\">自制拆洗衣机排水阀(水堵)工具</a></li><li><a href=\"/shifu/5.html\" title=\"科龙BCD-242/HC电冰箱故障代码表\">科龙BCD-242/HC电冰箱故障代码表</a></li><li><a href=\"/shifu/6.html\" title=\"小天鹅全自动洗衣机故障可控硅之“元凶”\">小天鹅全自动洗衣机故障可控硅之“</a></li><li><a href=\"/pinlei/xiyiji/jingyanjiqiao/7.html\" title=\"洗衣机故障速修心得\">洗衣机故障速修心得</a></li><li><a href=\"/pinlei/dianshiji/jingyanjiqiao/8.html\" title=\"液晶屏逻辑板和屏坏简易判断及检修\">液晶屏逻辑板和屏坏简易判断及检修</a></li>");
\ No newline at end of file
document.write("<li><a href=\"/changshang/88.html\" title=\"美的空调全智能工厂:200台机器人有条不紊地工作\">美的空调全智能工厂:200台机器人有</a></li><li><a href=\"http://code.ibanshou.cn\" title=\"首页幻灯[扳手快查]\">首页幻灯[扳手快查]</a></li><li><a href=\"/changshang/2017-06-20/84.html\" title=\"让台湾观众坠入了美的旋涡\">让台湾观众坠入了美的旋涡</a></li><li><a href=\"/hangye/83.html\" title=\"格力起诉美的“制冷王”空调侵权 索赔5000万元\">格力起诉美的“制冷王”空调侵权 </a></li><li><a href=\"/hangye/82.html\" title=\"公牛全线产品完成新国标升级:未来加大自动化投入\">公牛全线产品完成新国标升级:未来加</a></li><li><a href=\"/hangye/81.html\" title=\"姑娘别怕 我只是把钳子别在了腰上\">姑娘别怕 我只是把钳子别在了腰上</a></li><li><a href=\"/hangye/80.html\" title=\"插座国家标准又升级了 你还在用老的万能孔吗?\">插座国家标准又升级了 你还在用老</a></li><li><a href=\"/hangye/76.html\" title=\"家电回收条例有望年内出台 厂商只卖拒收罚10万\">家电回收条例有望年内出台 厂商只</a></li><li><a href=\"/hangye/75.html\" title=\"智能家电售后问题凸显 掘金未来需要新思路\">智能家电售后问题凸显 掘金未来需</a></li><li><a href=\"/hangye/74.html\" title=\"中国制造加速走向全球 GMCC向世界展示中国“芯”\">中国制造加速走向全球 GMCC向世界</a></li>");
\ No newline at end of file
document.write("<li><a href=\"/changshang/2017-06-27/89.html\" title=\"测试\">测试</a></li><li><a href=\"/changshang/88.html\" title=\"美的空调全智能工厂:200台机器人有条不紊地工作\">美的空调全智能工厂:200台机器人有</a></li><li><a href=\"http://code.ibanshou.cn\" title=\"首页幻灯[扳手快查]\">首页幻灯[扳手快查]</a></li><li><a href=\"/changshang/2017-06-20/84.html\" title=\"让台湾观众坠入了美的旋涡\">让台湾观众坠入了美的旋涡</a></li><li><a href=\"/hangye/83.html\" title=\"格力起诉美的“制冷王”空调侵权 索赔5000万元\">格力起诉美的“制冷王”空调侵权 </a></li><li><a href=\"/hangye/82.html\" title=\"公牛全线产品完成新国标升级:未来加大自动化投入\">公牛全线产品完成新国标升级:未来加</a></li><li><a href=\"/hangye/81.html\" title=\"姑娘别怕 我只是把钳子别在了腰上\">姑娘别怕 我只是把钳子别在了腰上</a></li><li><a href=\"/hangye/80.html\" title=\"插座国家标准又升级了 你还在用老的万能孔吗?\">插座国家标准又升级了 你还在用老</a></li><li><a href=\"/hangye/76.html\" title=\"家电回收条例有望年内出台 厂商只卖拒收罚10万\">家电回收条例有望年内出台 厂商只</a></li><li><a href=\"/hangye/75.html\" title=\"智能家电售后问题凸显 掘金未来需要新思路\">智能家电售后问题凸显 掘金未来需</a></li>");
\ No newline at end of file
......@@ -20,4 +20,33 @@ $config = [
'logs' => 'e/data/phpcas.log',
'uc_base_url' => 'http://u.yunya.com/',
],
//wxh_internal_api
'wxh.internal' => [
'server' => [
'secret' => 'U2FsdGVkX19ZiutUoO6F',
],
'client' => [
'ucenter' => [
'apiUrl' => 'http://u.yunya.com/api/server',
'clientId' => 'common',
'clientSecret' => 'Kuy2dVHKRWKAFRXX2l6k'
],
'xue' => [
'apiUrl' => 'http://ct.yunya.com/api',
'clientId' => 'common',
'clientSecret' => 'Z2oKgZYYc8mznesYMf1o'
],
'code' => [
'apiUrl' => 'http://dev.wxherr.com/site/api-server',
'clientId' => 'common',
'clientSecret' => '1BO1WQwnpjc2GfjzrOuq'
],
'bbs' => [
'apiUrl' => 'http://bbs.yunya.com/api/server.php',
'clientId' => 'common',
'clientSecret' => 'U2FsdGVkX19ZiutUoO6F'
],
],
],
];
\ No newline at end of file
......@@ -5,19 +5,48 @@ $config = [
'isUseUcenter' => true,
//sso api config
'sso.apiurl' => 'http://testsso.yunyamooc.com/api/',
'sso.apiurl' => 'http://pre.u.ibanshou.cn/api/',
'sso.appid' => '10001',
'sso.appkey' => 'oY4@1f0#Io1u!Cd4@NJ#9YJFj1s@EGfDI@VA#vvRbqO',
//cas configs
'cas.configs' => [
'host' => 'sso.test.weixiuhui.tech',
'host' => 'sso.weixiuhui.cn',
'context' => '/cas',
'port' => 443,
'server_ca_cert_path' => '',
'debug' => true,
'server_ip' => ['114.55.56.29'],
'logs' => 'e/data/phpcas.log',
'uc_base_url' => 'http://testsso.yunyamooc.com/',
'debug' => false,
'server_ip' => ['54.222.158.174'],
'logs' => './data/log/phpcas.log',
'uc_base_url' => 'http://pre.u.ibanshou.cn/',
],
//wxh_internal_api
'wxh.internal' => [
'server' => [
'secret' => 'AJmfi4ORZURS0JwSkdiq3r',
],
'client' => [
'ucenter' => [
'apiUrl' => 'http://testsso.yunyamooc.com/api/server',
'clientId' => 'common',
'clientSecret' => 'z1z7AZCWpbEkfWpak0dx'
],
'xue' => [
'apiUrl' => 'http://test.yunyamooc.com/api',
'clientId' => 'common',
'clientSecret' => 'AwT3YKykIwkREb48C1w3'
],
'code' => [
'apiUrl' => 'http://testserv.pp.cc/wxherr/site/api-server',
'clientId' => 'common',
'clientSecret' => 'VBz7nU9qIeKUCjY89poG'
],
'bbs' => [
'apiUrl' => 'http://bbs.test.yunyamooc.com/api/server.php',
'clientId' => 'common',
'clientSecret' => 'AJmfi4ORZURS0JwSkdiq3r'
],
],
],
];
\ No newline at end of file
......@@ -54,6 +54,7 @@ $ecms_config['sets']['pagemustdt']=0;
$emoreport_r[1]['ppath']='';
require_once ECMS_PATH.'e/config/config.php';
require_once ECMS_PATH.'e/extend/phpcas/CAS.php';
require_once ECMS_PATH.'e/extend/ibanshou/ClientCas.php';
if(!defined('EmpireCMSConfig'))
......
<?php
//---------------------------用户自定义标签函数文件
use internalApi\bbs\Thread;
use internalApi\xue\CourseList;
function user_ibanshou($num)
{
require __DIR__.'/../extend/internalApi/autoload.php';
require __DIR__.'/../config/config_ibanshou.php';
\internalApi\base\Client::config($config['wxh.internal']['client']);
$thread = Thread::getHotThreads($num);
$list = CourseList::getRecommendList($num);
$str = '<div class="learnning-course newest">
<div class="tit">最新课程<span></span><a href="http://xue.ibanshou.cn/home/all-course">全部课程</a></div>
<div class="newest-list clearfix">';
foreach ($list as $val) {
$str .= "<div class=\"learn-course-box\">
<div class=\"lc-img\"><a href=\"{$val['url']}\"><img
src=\"{$val['preview_pic']}-ym.preview\"></a></div>
<h3><a href=\"{$val['url']}\">{$val['name']}</a></h3>
<p><span>{$val['favorite_count']}人已学</span><span>{$val['comment_count']}人评论</span></p>
</div>";
}
$str .= '</div></div><div class="latest-news">
<div class="common-tit-index">热门互动</div>
<ul class="news-list">';
foreach ($thread as $val) {
$str .= "<li>
<a href=\"{$val['url']}\">
<h3>{$val['subject']}</h3>
<p>{$val['views']}人已参与</p>
<img src=\"{$val['image']}\">
</a>
</li>";
}
echo $str . '</ul></div>';
}
?>
\ No newline at end of file
......@@ -304,7 +304,7 @@ $public_r=array('sitename'=>'扳手 - 征集slogan',
'pldatatbs'=>',1,',
'defpltempid'=>1,
'pl_num'=>12,
'plgroupid'=>0,
'plgroupid'=>1,
'closelisttemp'=>'',
'chclasscolor'=>'#99C4E3',
'timeclose'=>'',
......
......@@ -20,4 +20,41 @@ $config = [
'logs' => 'e/data/phpcas.log',
'uc_base_url' => 'http://u.yunya.com/',
],
//api host
'api.host' => [
'ucenter' => 'http://u.yunya.com',
'xue' => 'http://ct.yunya.com',
's' => 'http://s.yunya.com',
'bbs' => 'http://bbs.yunya.com',
],
//wxh_internal_api
'wxh.internal' => [
'server' => [
'secret' => 'U2FsdGVkX19ZiutUoO6F',
],
'client' => [
'ucenter' => [
'apiUrl' => 'http://u.yunya.com/api/server',
'clientId' => 'common',
'clientSecret' => 'Kuy2dVHKRWKAFRXX2l6k'
],
'xue' => [
'apiUrl' => 'http://ct.yunya.com/api',
'clientId' => 'common',
'clientSecret' => 'Z2oKgZYYc8mznesYMf1o'
],
'code' => [
'apiUrl' => 'http://dev.wxherr.com/site/api-server',
'clientId' => 'common',
'clientSecret' => '1BO1WQwnpjc2GfjzrOuq'
],
'bbs' => [
'apiUrl' => 'http://bbs.yunya.com/api/server.php',
'clientId' => 'common',
'clientSecret' => 'U2FsdGVkX19ZiutUoO6F'
],
],
],
];
\ No newline at end of file
......@@ -30,7 +30,6 @@ class ClientCas
if (empty($config)) {
printerrortourl('/',"config_ibanshou not found", 3);
}
require_once ECMS_PATH . "e/extend/phpcas/CAS.php";
$this->config = $config['cas.configs'];
$this->debug = $config['cas.configs']['debug'];
......
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 17:59
*/
function internalApiAutoloader($className) {
if (substr($className, 0, 12) == 'internalApi\\') {
$file = __DIR__.DIRECTORY_SEPARATOR.substr(str_replace('\\', DIRECTORY_SEPARATOR, $className), 12).'.php';
if (is_file($file)) {
include $file;
}
}
}
spl_autoload_register('internalApiAutoloader');
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 10:06
*/
namespace internalApi\base;
/**
* 客户端基类
*
* 提供客户端调用实现
* 本类分静态方法与动态类的区别,动态类最终内部每个接口集会有一个实例用于请求,而静态则提供全局协调和接口调用方法
*
* @package internalApi\base
*/
class Client
{
public $debug = false;
public $name;
protected $clientId;
protected $clientSecret;
protected $apiUrl;
protected $remoteIp;
protected static $instance = [];
protected static $config = [];
/**
* 获取 API 集的客户端实例
* 每个 API 集有一个实例用于签名和请求处理
*
* @return static
*/
protected static function getInstance()
{
$name = self::name();
if (!isset(self::$instance[$name])) {
self::$instance[$name] = new self($name);
}
return self::$instance[$name];
}
/**
* 获取 API 集的名称
*
* 如 internalApi\ucenter\Member 则名称为 ucenter
*
* @return bool|string
*/
public static function name()
{
$className = static::class;
$subName = strstr($className, '\\');
return substr($subName, 1, strpos($subName, '\\', 1)-1);
}
public function __construct($name)
{
if (isset(static::$config[$name])) {
foreach (static::$config[$name] as $k => $v) {
if ($this->$k === null) {
$this->$k = $v;
}
}
}
foreach (['clientId', 'clientSecret', 'apiUrl'] as $prop) {
if ($this->$prop === null) {
throw new ClientException("InternalApi $name initialize failed, \${$prop} not set!");
}
}
$this->name = $name;
}
public static function setDebug($debug=true)
{
$instance = self::getInstance();
$instance->debug = $debug;
}
public static function config($config)
{
self::$config = $config;
}
/**
* 调用请求,获取数据
*
* @param string $api
* @param array $params
* @return mixed
* @throws ClientException API 请求失败时,会抛出此异常
*/
protected static function call($api, $params=[])
{
$instance = self::getInstance();
$url = $instance->apiUrl.(strpos($instance->apiUrl, '?') !== false ? '&' : '?').'api='.urlencode($api);
list($sign, $timestamp, $nonce) = $instance->signature($api, $params);
$url .= "&client_id={$instance->clientId}&sign={$sign}&timestamp={$timestamp}&nonce={$nonce}";
list($httpCode, $response) = $instance->request($url, $params);
if ($httpCode == 403 && substr($response, 0, 6) === 'error:') {
$message = substr($response, 6);
throw new ClientException("接口 $api 调用失败: " . $message);
} elseif ($httpCode === 0) {
throw new ClientException('接口请求异常: '.$response, $httpCode);
} elseif ($httpCode != 200 || $response === false) {
throw new ClientException('接口响应异常: '.$response, $httpCode);
}
$data = @json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new ClientException('接口返回数据异常: ' . $response);
}
return $data;
}
/**
* 对请求进程签名
*
* @param string $api
* @param array $params
* @return array
*/
protected function signature($api, $params)
{
$timestamp = time();
$nonce = uniqid();
ksort($params);
$str = $api.http_build_query($params).$this->clientId.$this->clientSecret.$timestamp.$nonce;
$sign = md5($str);
return [$sign, $timestamp, $nonce];
}
protected function request($url, $post='', $headers=[]) {
//如果设置了远程IP,则直接用IP连接,省去解析
if ($this->remoteIp) {
$host = parse_url($url, PHP_URL_HOST);
$url = substr_replace($url, $this->remoteIp, strpos($url, $host), strlen($host));
//$url = preg_replace('/^(https?:\/\/)[^\/]+/i', '${1}'.$this->remoteIp, $url, 1);
$headers[] = "Host: $host";
}
$ci = curl_init($url);
//添加客户端信息以辨服务端识别和调试
$userAgent = 'PHP/'.PHP_VERSION.' ('.PHP_OS.') Client/'.$this->clientId;
if (isset($_SERVER['HTTP_HOST'])) {
$userAgent .= ' ('.$_SERVER['HTTP_HOST'].')';
}
$curl = curl_version();
$userAgent .= " cURL/{$curl['version']} ({$curl['ssl_version']})";
//基础设置
curl_setopt_array($ci, [
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 8,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => false,
CURLOPT_USERAGENT => $userAgent
]);
//POST 请求
if ($post) {
$body = is_array($post) ? http_build_query($post) : $post;
curl_setopt_array($ci, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body
]);
}
//优化
$headers[] = 'Expect:';
curl_setopt_array($ci, [
CURLOPT_HTTPHEADER => $headers,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
//CURLOPT_DNS_USE_GLOBAL_CACHE => false
]);
//调试
if ($this->debug) {
curl_setopt($ci, CURLINFO_HEADER_OUT, true);
$responseHeaders = '';
curl_setopt($ci, CURLOPT_HEADERFUNCTION, function ($ci, $header) use (&$responseHeaders) {
$responseHeaders .= $header;
return strlen($header);
});
}
$response = curl_exec($ci);
$httpCode = curl_getinfo($ci, CURLINFO_HTTP_CODE);
if ($response === false) {
$errno = curl_errno($ci);
$errmsg = curl_error($ci);
$response = "[$errno] $errmsg";
}
//获取调试信息
if ($this->debug) {
$httpInfo = curl_getinfo($ci);
}
curl_close($ci);
if ($this->debug) {
echo "<pre>\r\n=====INFO=====\r\n";
echo "Request URL: $url\r\n",
"Remote Address: {$httpInfo['primary_ip']}:{$httpInfo['primary_port']}\r\n",
"Local Address: {$httpInfo['local_ip']}:{$httpInfo['local_port']}\r\n",
"Namelookup Time: {$httpInfo['namelookup_time']}\r\n",
"Connect Time: {$httpInfo['connect_time']}\r\n",
"Pre Transfer Time: {$httpInfo['pretransfer_time']}\r\n",
"Start Transfer Time: {$httpInfo['starttransfer_time']}\r\n",
"File Time: {$httpInfo['filetime']}\r\n",
"Total Time: {$httpInfo['total_time']}\r\n";
if (isset($errno)) {
echo "\r\n=====ERROR=====\r\nErrorNo: $errno\r\nErrorMsg: $errmsg\r\n";
}
echo "\r\n=====REQUEST=====\r\n",$httpInfo['request_header'];
if (isset($body)) {
echo $body."\r\n";
}
echo "\r\n=====RESPONSE=====\r\n",$responseHeaders,$response;
echo "\r\n</pre>";
}
return [$httpCode, $response];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 15:37
*/
namespace internalApi\base;
class ClientException extends \ErrorException
{
}
\ No newline at end of file
<?php
namespace internalApi\base;
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 10:06
*/
class Server
{
protected $apiMap = [];
protected $secret;
public function __construct($secret)
{
$this->secret = $secret;
}
public function setApiMap($map)
{
$this->apiMap = $map;
}
public function addApiMap($map)
{
foreach ($map as $key => $list) {
if (!isset($this->apiMap[$key])) {
$this->apiMap[$key] = [];
}
foreach ($list as $name => $callable) {
if (isset($this->apiMap[$key][$name])) {
continue;
}
$this->apiMap[$key][$name] = $callable;
}
}
}
/**
* Invoke API and get data
*
* @param bool $return
* @return array
* @throws
*/
public function invoke($return=false)
{
$api = $this->checkSign();
if (!$api) {
$this->responseError('鉴权失败');
}
$arr = explode('.', $api);
if (count($arr) != 2) {
$this->responseError('错误的 API 名称');
}
list($group, $name) = $arr;
if (!isset($this->apiMap[$group]) || !isset($this->apiMap[$group][$name])) {
$this->responseError('API 不存在');
}
$callable = $this->apiMap[$group][$name][0];
if (!is_callable($callable)) {
$this->responseError('API 无法调用');
}
$paramsList = array_slice($this->apiMap[$group][$name], 1);
$params = [];
foreach ($paramsList as $k => $v) {
if (is_int($k)) {
$k = $v;
$hasDefault = false;
} else {
$hasDefault = true;
}
if (isset($_POST[$k])) {
$params[] = $_POST[$k];
} elseif ($hasDefault) {
$params[] = $v;
} else {
$this->responseError('缺少参数 '.$k);
}
}
$data = call_user_func_array($callable, $params);
if ($return) {
return $data;
} else {
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE);
}
}
public function responseError($message)
{
header('HTTP/1.0 403 Forbidden');
echo 'error:'.$message;
exit;
}
protected function checkSign()
{
$api = isset($_GET['api']) ? $_GET['api'] : '';
$clientId = isset($_GET['client_id']) ? $_GET['client_id'] : null;
$sign = isset($_GET['sign']) ? $_GET['sign'] : '';
$timestamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;
$nonce = isset($_GET['nonce']) ? $_GET['nonce'] : '';
$servTime = time();
$params = $_POST;
ksort($params);
$str = $api.http_build_query($params).$clientId.$this->secret.$timestamp.$nonce;
$servSign = md5($str);
if ($servSign !== $sign) {
return false;
}
if ($servTime - $timestamp > 300) {
return false;
}
return $api;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 16:44
*/
namespace internalApi\base;
class ServerException extends \Exception
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 17/6/28
* Time: 下午5:43
*/
namespace internalApi\bbs;
use internalApi\base\Client;
class Thread extends Client
{
public static function getHotThreads($num=1)
{
return self::call('thread.getHotThreads', compact('num'));
}
public static function countThreads($uid)
{
return self::call('thread.countThreads', compact('uid'));
}
}
\ No newline at end of file
<?php
/**
* 内部 API 客户端调用演示
*/
use internalApi\ucenter\Member;
//首先需要初始化客户端,传入配置
//配置的保存位置根据项目决定,只需最终调用 Client::config() 传入即可
$internalApiClientConfig = [
'ucenter' => [
'apiUrl' => 'http://u.yunya.com/api/server',
'clientId' => 'common',
'clientSecret' => 'Kuy2dVHKRWKAFRXX2l6k'
],
'xue' => [
'apiUrl' => 'http://u.yunya.com/test/api-server',
'clientId' => 'common',
'clientSecret' => 'Kuy2dVHKRWKAFRXX2l6k'
]
];
\internalApi\base\Client::config($internalApiClientConfig);
//调用API
$user = Member::getMemberInfo(12);
var_dump($user);
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/28
* Time: 10:23
*/
return [
'ucenter' => [
'apiUrl' => 'http://u.yunya.com/api/server',
'clientId' => 'common',
'clientSecret' => 'Kuy2dVHKRWKAFRXX2l6k'
],
'xue' => [
'apiUrl' => 'http://ct.yunya.com/api',
'clientId' => 'common',
'clientSecret' => 'Z2oKgZYYc8mznesYMf1o'
],
'code' => [
'apiUrl' => 'http://dev.wxherr.com/site/api-server',
'clientId' => 'common',
'clientSecret' => '1BO1WQwnpjc2GfjzrOuq'
]
];
\ No newline at end of file
<?php
namespace internalApi\code;
use internalApi\base\Client;
/**
* 扳手快查勋章 API
*/
class Medal extends Client
{
/**
* 获取扳手快查用户拥有的勋章数量
*
* @param $uid
* @return int
*/
public static function countUserMedals($uid)
{
return self::call('medal.countUserMedals', compact('uid'));
}
}
\ No newline at end of file
<?php
/**
* 内部 API 服务端使用演示
*/
//初始化API
$internalApiServerSecret = 'Kuy2dVHKRWKAFRXX2l6k';
$server = new \internalApi\base\Server($internalApiServerSecret);
/**
* 设置 API 列表,setApiMap 会覆盖所有已有的 API 设置
*
* API 以此形式定义
* [
* '组' => [
* '名称' => [Callable, 第一个参数名, 第二个参数名, 第三个参数名=>参数默认值],
* '名称' => [Callable, 第一个参数名, 第二个参数名, 第三个参数名=>参数默认值]
* ]
* ]
*
* 其中 Callable 为一个可调用名称,参见 php 的 Callable 和闭包
* 参数必须严格按照 Callable 的参数顺序写好,如果定义键名,则键名为参数名称,键值为默认值,有默认值的参数在客户端调用时可不传
*/
$server->setApiMap([
'courseList' => [
'recommendList' => ['\common\course::fetchCommendList', 'page', 'num'=>20],
'newCourseList' => ['\common\course::fetchNewList', 'page'=>1, 'num'=>20]
],
'otherApi' => [
'getLink' => ['\other\Api\Common::getLink']
]
]);
//添加 API 列表,addApiMap 只会对已有 API 列表新增,但性能较差,建议 setApiMap 一次性设置好
$server->addApiMap([
'member' => [
'getInfo' => ['\common\models\Member::findByUid', 'uid']
]
]);
//启动调用
$server->invoke();
//如果想获得返回数据自己做些处理,使用 $data = $server->invoke(true) 即可
\ No newline at end of file
<?php
namespace internalApi\ucenter;
use internalApi\base\Client;
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 15:57
*/
class Member extends Client
{
public static function getMemberInfo($uid)
{
return self::call('member.getInfo', compact('uid'));
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/28
* Time: 15:47
*/
namespace internalApi\xue;
use internalApi\base\Client;
/**
* 学院评论API
*
* @package internalApi\xue
*/
class Comment extends Client
{
/**
* 获取学院赞我的评论数量
*
* @param int $uid
* @return int
*/
public static function getLikeMsgCount($uid)
{
return self::call('comment.getLikeMsgCount', compact('uid'));
}
/**
* 获取学院回复我的评论数量
*
* @param int $uid
* @return int
*/
public static function getReplyMsgCount($uid)
{
return self::call('comment.getReplyMsgCount', compact('uid'));
}
}
\ No newline at end of file
<?php
namespace internalApi\xue;
use internalApi\base\Client;
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 14:49
*/
class CourseList extends Client
{
/**
* 获取推荐课程列表
*
* @param int $num
* @return array
*/
public static function getRecommendList($num=10)
{
return self::call('course.getRecommendList', compact('num'));
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/28
* Time: 15:24
*/
namespace internalApi\xue;
use internalApi\base\Client;
class Favorite extends Client
{
/**
* 获取用户学院收藏数量
*
* @param $uid
* @return int
*/
public static function countUserFavorites($uid)
{
return self::call('favorite.countUserFavorite', compact('uid'));
}
}
\ No newline at end of file
<?php
use internalApi\bbs\Thread;
use internalApi\xue\CourseList;
require __DIR__.'/../internalApi/autoload.php';
require __DIR__.'/../../config/config_ibanshou.php';
\internalApi\base\Client::config($config['wxh.internal']['client']);
//$thread = Thread::getHotThreads($num);
//echo json_encode($thread);
$list = CourseList::getRecommendList(4);
print_r($list);
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment