Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
s_ibanshou
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋林
s_ibanshou
Commits
b1045e62
Commit
b1045e62
authored
Jun 29, 2017
by
蒋林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页
parent
5f5addda
Changes
26
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
928 additions
and
419 deletions
+928
-419
firstnews.js
d/js/js/firstnews.js
+1
-1
hotplnews.js
d/js/js/hotplnews.js
+1
-1
newnews.js
d/js/js/newnews.js
+1
-1
config_ibanshou.php
e/back_conf/dev/config_ibanshou.php
+29
-0
config_ibanshou.php
e/back_conf/test/config_ibanshou.php
+35
-6
connect.php
e/class/connect.php
+1
-0
userfun.php
e/class/userfun.php
+42
-0
config.php
e/config/config.php
+1
-1
config_ibanshou.php
e/config/config_ibanshou.php
+37
-0
ClientCas.php
e/extend/ibanshou/ClientCas.php
+0
-1
autoload.php
e/extend/internalApi/autoload.php
+18
-0
Client.php
e/extend/internalApi/base/Client.php
+253
-0
ClientException.php
e/extend/internalApi/base/ClientException.php
+14
-0
Server.php
e/extend/internalApi/base/Server.php
+139
-0
ServerException.php
e/extend/internalApi/base/ServerException.php
+15
-0
Thread.php
e/extend/internalApi/bbs/Thread.php
+25
-0
client_config.exmaple.php
e/extend/internalApi/client_config.exmaple.php
+27
-0
client_config_dev.php
e/extend/internalApi/client_config_dev.php
+25
-0
Medal.php
e/extend/internalApi/code/Medal.php
+24
-0
server.example.php
e/extend/internalApi/server.example.php
+44
-0
Member.php
e/extend/internalApi/ucenter/Member.php
+21
-0
Comment.php
e/extend/internalApi/xue/Comment.php
+43
-0
CourseList.php
e/extend/internalApi/xue/CourseList.php
+27
-0
Favorite.php
e/extend/internalApi/xue/Favorite.php
+27
-0
index.php
e/extend/test/index.php
+15
-0
index.html
index.html
+63
-408
No files found.
d/js/js/firstnews.js
View file @
b1045e62
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>"
);
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
\ No newline at end of file
d/js/js/hotplnews.js
View file @
b1045e62
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>"
);
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
\ No newline at end of file
d/js/js/newnews.js
View file @
b1045e62
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>"
);
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
\ No newline at end of file
e/back_conf/dev/config_ibanshou.php
View file @
b1045e62
...
@@ -20,4 +20,33 @@ $config = [
...
@@ -20,4 +20,33 @@ $config = [
'logs'
=>
'e/data/phpcas.log'
,
'logs'
=>
'e/data/phpcas.log'
,
'uc_base_url'
=>
'http://u.yunya.com/'
,
'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
e/back_conf/test/config_ibanshou.php
View file @
b1045e62
...
@@ -5,19 +5,48 @@ $config = [
...
@@ -5,19 +5,48 @@ $config = [
'isUseUcenter'
=>
true
,
'isUseUcenter'
=>
true
,
//sso api config
//sso api config
'sso.apiurl'
=>
'http://
testsso.yunyamooc.com
/api/'
,
'sso.apiurl'
=>
'http://
pre.u.ibanshou.cn
/api/'
,
'sso.appid'
=>
'10001'
,
'sso.appid'
=>
'10001'
,
'sso.appkey'
=>
'oY4@1f0#Io1u!Cd4@NJ#9YJFj1s@EGfDI@VA#vvRbqO'
,
'sso.appkey'
=>
'oY4@1f0#Io1u!Cd4@NJ#9YJFj1s@EGfDI@VA#vvRbqO'
,
//cas configs
//cas configs
'cas.configs'
=>
[
'cas.configs'
=>
[
'host'
=>
'sso.
test.weixiuhui.tech
'
,
'host'
=>
'sso.
weixiuhui.cn
'
,
'context'
=>
'/cas'
,
'context'
=>
'/cas'
,
'port'
=>
443
,
'port'
=>
443
,
'server_ca_cert_path'
=>
''
,
'server_ca_cert_path'
=>
''
,
'debug'
=>
true
,
'debug'
=>
false
,
'server_ip'
=>
[
'114.55.56.29'
],
'server_ip'
=>
[
'54.222.158.174'
],
'logs'
=>
'e/data/phpcas.log'
,
'logs'
=>
'./data/log/phpcas.log'
,
'uc_base_url'
=>
'http://testsso.yunyamooc.com/'
,
'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
e/class/connect.php
View file @
b1045e62
...
@@ -54,6 +54,7 @@ $ecms_config['sets']['pagemustdt']=0;
...
@@ -54,6 +54,7 @@ $ecms_config['sets']['pagemustdt']=0;
$emoreport_r
[
1
][
'ppath'
]
=
''
;
$emoreport_r
[
1
][
'ppath'
]
=
''
;
require_once
ECMS_PATH
.
'e/config/config.php'
;
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'
;
require_once
ECMS_PATH
.
'e/extend/ibanshou/ClientCas.php'
;
if
(
!
defined
(
'EmpireCMSConfig'
))
if
(
!
defined
(
'EmpireCMSConfig'
))
...
...
e/class/userfun.php
View file @
b1045e62
<?php
<?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
e/config/config.php
View file @
b1045e62
...
@@ -304,7 +304,7 @@ $public_r=array('sitename'=>'扳手 - 征集slogan',
...
@@ -304,7 +304,7 @@ $public_r=array('sitename'=>'扳手 - 征集slogan',
'pldatatbs'
=>
',1,'
,
'pldatatbs'
=>
',1,'
,
'defpltempid'
=>
1
,
'defpltempid'
=>
1
,
'pl_num'
=>
12
,
'pl_num'
=>
12
,
'plgroupid'
=>
0
,
'plgroupid'
=>
1
,
'closelisttemp'
=>
''
,
'closelisttemp'
=>
''
,
'chclasscolor'
=>
'#99C4E3'
,
'chclasscolor'
=>
'#99C4E3'
,
'timeclose'
=>
''
,
'timeclose'
=>
''
,
...
...
e/config/config_ibanshou.php
View file @
b1045e62
...
@@ -20,4 +20,41 @@ $config = [
...
@@ -20,4 +20,41 @@ $config = [
'logs'
=>
'e/data/phpcas.log'
,
'logs'
=>
'e/data/phpcas.log'
,
'uc_base_url'
=>
'http://u.yunya.com/'
,
'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
e/extend/ibanshou/ClientCas.php
View file @
b1045e62
...
@@ -30,7 +30,6 @@ class ClientCas
...
@@ -30,7 +30,6 @@ class ClientCas
if
(
empty
(
$config
))
{
if
(
empty
(
$config
))
{
printerrortourl
(
'/'
,
"config_ibanshou not found"
,
3
);
printerrortourl
(
'/'
,
"config_ibanshou not found"
,
3
);
}
}
require_once
ECMS_PATH
.
"e/extend/phpcas/CAS.php"
;
$this
->
config
=
$config
[
'cas.configs'
];
$this
->
config
=
$config
[
'cas.configs'
];
$this
->
debug
=
$config
[
'cas.configs'
][
'debug'
];
$this
->
debug
=
$config
[
'cas.configs'
][
'debug'
];
...
...
e/extend/internalApi/autoload.php
0 → 100644
View file @
b1045e62
<?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'
);
e/extend/internalApi/base/Client.php
0 → 100644
View file @
b1045e62
<?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
}
×tamp=
{
$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\n
ErrorNo:
$errno
\r\n
ErrorMsg:
$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
e/extend/internalApi/base/ClientException.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/base/Server.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/base/ServerException.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/bbs/Thread.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/client_config.exmaple.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/client_config_dev.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/code/Medal.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/server.example.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/ucenter/Member.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/xue/Comment.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/xue/CourseList.php
0 → 100644
View file @
b1045e62
<?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
e/extend/internalApi/xue/Favorite.php
0 → 100644
View file @
b1045e62
<?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
e/extend/test/index.php
0 → 100644
View file @
b1045e62
<?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
index.html
View file @
b1045e62
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment