切换导航条
此项目
正在载入...
登录
景龙
/
xingqiu
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
jinglong
6 years ago
提交
bd29c761f536f63addd9231ae3b07a39de97a839
1 个父辈
85fd3f02
1 个管道 的构建
通过
耗费 1 秒
调式分享
变更
5
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
132 行增加
和
98 行删除
app/portal/controller/LoginController.php
public/themes/simpleboot3_mobile/portal/region/get_more_video.html
public/themes/simpleboot3_mobile/public/share.html
public/themes/simpleboot3_mobile/public/slide.html
simplewind/cmf/controller/HomeBaseController.php
app/portal/controller/LoginController.php
查看文件 @
bd29c76
...
...
@@ -20,15 +20,6 @@ use app\portal\model\PortalPostModel;
class
LoginController
extends
HomeBaseController
{
private
$limit
=
8
;
//收藏,搜索分页
private
$appkey
=
737607150
;
//微博appkey
private
$appsecret
=
'd80b43a1e74e8ba095590b36a3459480'
;
//微博appsecret
private
$redirect_uri
=
'http://www.starplanet.cn/portal/login/wb_login'
;
//回调地址
private
$appkey1
=
'wx9cfa880272f186bf'
;
//微信开放平台appkey
private
$appsecret1
=
'11b643393b1e54d6ef5eaa984ba4e545'
;
//微信开放平台appsecret
private
$appkey2
=
'wx0bd7bc2aa0f332d6'
;
//微信公众号appkey
private
$appsecret2
=
'b62e49f48f48de7b7fff2ea0af3939de'
;
//微信公众号appsecret
//登录页面
public
function
login
(){
...
...
@@ -522,92 +513,11 @@ class LoginController extends HomeBaseController
return
$info
;
}
//获取微信分享配置信息
public
function
wxShare
(
$url
=
''
){
$jsapiTicket
=
$this
->
getSignature
();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol
=
(
!
empty
(
$_SERVER
[
'HTTPS'
])
&&
$_SERVER
[
'HTTPS'
]
!==
'off'
||
$_SERVER
[
'SERVER_PORT'
]
==
443
)
?
"https://"
:
"http://"
;
if
(
$url
===
''
)
{
$url
=
"
$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]
"
;
}
$timestamp
=
time
();
$nonceStr
=
$this
->
createNonceStr
();
$string
=
'jsapi_ticket='
.
$jsapiTicket
.
'&noncestr='
.
$nonceStr
.
'×tamp='
.
$timestamp
.
'&url='
.
$url
;
$signature
=
sha1
(
$string
);
$data
=
[
"appId"
=>
$this
->
appkey2
,
"nonceStr"
=>
$nonceStr
,
"timestamp"
=>
$timestamp
,
"url"
=>
$url
,
"signature"
=>
$signature
,
"rawString"
=>
$string
];
$this
->
assign
(
'data'
,
$data
);
}
//获取微信分享签名随机字符串
public
function
createNonceStr
(
$length
=
16
)
{
$chars
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
$str
=
""
;
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
{
$str
.=
substr
(
$chars
,
mt_rand
(
0
,
strlen
(
$chars
)
-
1
),
1
);
}
return
$str
;
}
//获取access_token
public
function
getWxAccessToken
(){
$url
=
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='
.
$this
->
appkey2
.
'&secret='
.
$this
->
appsecret2
;
$res
=
$this
->
http_get
(
$url
);
$json_arr
=
json_decode
(
$res
,
true
);
$token
=
$json_arr
[
'access_token'
];
return
$token
;
}
//获取微信分享签名
public
function
getSignature
(){
if
(
isset
(
$_SESSION
[
'ticket_expire_time'
])
&&
$_SESSION
[
'ticket_expire_time'
]
>
time
()
&&
$_SESSION
[
'ticket'
]){
$ticket
=
$_SESSION
[
'ticket'
];
}
else
{
$token
=
$this
->
getWxAccessToken
();
$url
=
'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='
.
$token
.
'&type=jsapi'
;
$res
=
$this
->
http_get
(
$url
);
$json_arr
=
json_decode
(
$res
,
true
);
$ticket
=
$json_arr
[
'ticket'
];
$_SESSION
[
'ticket'
]
=
$ticket
;
$_SESSION
[
'ticket_expire_time'
]
=
time
()
+
7000
;
}
return
$ticket
;
}
//curl get请求
public
function
http_get
(
$url
){
$curl
=
curl_init
();
//启动一个CURL会话
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
false
);
// 对认证证书来源的检查
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
false
);
// 从证书中检查SSL加密算法是否存在
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
30
);
// 设置超时限制防止死循环
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
false
);
//不开启header
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
// 获取的信息以文件流的形式返回
$result
=
curl_exec
(
$curl
);
//执行操作
curl_close
(
$curl
);
return
$result
;
}
//curl post请求
public
function
http_post
(
$url
,
$data
){
$curl
=
curl_init
();
//启动一个CURL会话
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
// 要访问的地址
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
false
);
// 对认证证书来源的检查
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
false
);
// 从证书中检查SSL加密算法是否存在
curl_setopt
(
$curl
,
CURLOPT_POST
,
true
);
// 发送一个常规的Post请求
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$data
));
// Post提交的数据包
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
30
);
// 设置超时限制防止死循环
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
false
);
// 开启header
//curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//请求头部
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
// 获取的信息以文件流的形式返回
$result
=
curl_exec
(
$curl
);
//执行操作
curl_close
(
$curl
);
return
$result
;
//微信分享
public
function
wx_share
(){
$article_id
=
$this
->
request
->
param
(
'id'
);
$postModel
=
new
PortalPostModel
();
$postModel
->
where
(
'id'
,
$article_id
)
->
setInc
(
'post_share_wx'
,
1
);
$this
->
apiResponse
(
1
,
'分享成功!'
);
}
}
...
...
public/themes/simpleboot3_mobile/portal/region/get_more_video.html
查看文件 @
bd29c76
...
...
@@ -152,6 +152,7 @@
</div>
</div>
<!--微信分享-->
<include
file=
"public@share"
/>
<include
file=
"public@footer"
/>
</body>
<script
src=
"__TMPL__/public/assets/js/base.js"
></script>
...
...
public/themes/simpleboot3_mobile/public/share.html
查看文件 @
bd29c76
...
...
@@ -18,11 +18,11 @@
wx
.
ready
(
function
()
{
//需在用户可能点击分享按钮前就先调用
wx
.
updateAppMessageShareData
({
title
:
title_title
,
// 分享标题
desc
:
''
,
// 分享描述
desc
:
url
,
// 分享描述
link
:
url
,
// 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl
:
''
,
// 分享图标
success
:
function
(
e
)
{
// 设置成功
wx_Share
();
}
});
wx
.
updateTimelineShareData
({
...
...
@@ -31,6 +31,7 @@
imgUrl
:
''
,
// 分享图标
success
:
function
()
{
// 设置成功
wx_Share
();
}
});
});
...
...
@@ -39,4 +40,20 @@
});
});
function
wx_Share
(){
var
article_id
=
getUrlParam
(
'id'
);
$
.
ajax
({
type
:
'POST'
,
url
:
'/portal/login/wx_share'
,
data
:
{
'id'
:
article_id
,
},
dataType
:
'json'
,
async
:
false
,
success
:
function
(
data
)
{
}
});
}
</script>
\ No newline at end of file
...
...
public/themes/simpleboot3_mobile/public/slide.html
查看文件 @
bd29c76
...
...
@@ -35,3 +35,4 @@
</ul>
</div>
<!--微信分享-->
<include
file=
"public@share"
/>
...
...
simplewind/cmf/controller/HomeBaseController.php
查看文件 @
bd29c76
...
...
@@ -21,6 +21,15 @@ use think\Session;
class
HomeBaseController
extends
BaseController
{
public
$appkey
=
737607150
;
//微博appkey
public
$appsecret
=
'd80b43a1e74e8ba095590b36a3459480'
;
//微博appsecret
public
$redirect_uri
=
'http://www.starplanet.cn/portal/login/wb_login'
;
//回调地址
public
$appkey1
=
'wx9cfa880272f186bf'
;
//微信开放平台appkey
public
$appsecret1
=
'11b643393b1e54d6ef5eaa984ba4e545'
;
//微信开放平台appsecret
public
$appkey2
=
'wx0bd7bc2aa0f332d6'
;
//微信公众号appkey
public
$appsecret2
=
'b62e49f48f48de7b7fff2ea0af3939de'
;
//微信公众号appsecret
protected
function
initialize
()
{
...
...
@@ -39,6 +48,13 @@ class HomeBaseController extends BaseController
$this
->
getShareCount
();
$keyword
=
$this
->
request
->
param
(
'keyword'
);
$this
->
assign
(
'keyword'
,
$keyword
);
$cmfDefaultTheme
=
cmf_get_current_theme
();
//域名后面相对路径
$url
=
$_SERVER
[
'REQUEST_URI'
];
if
(
$cmfDefaultTheme
==
'simpleboot3_mobile'
&&
strpos
(
$url
,
'Detail'
)
!==
false
){
$this
->
wxShare
();
}
}
protected
function
_initializeView
()
...
...
@@ -396,4 +412,93 @@ hello;
$this
->
assign
(
'share'
,
$share
);
}
//获取微信分享配置信息
public
function
wxShare
(
$url
=
''
){
$jsapiTicket
=
$this
->
getSignature
();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol
=
(
!
empty
(
$_SERVER
[
'HTTPS'
])
&&
$_SERVER
[
'HTTPS'
]
!==
'off'
||
$_SERVER
[
'SERVER_PORT'
]
==
443
)
?
"https://"
:
"http://"
;
if
(
$url
===
''
)
{
$url
=
"
$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]
"
;
}
$timestamp
=
time
();
$nonceStr
=
$this
->
createNonceStr
();
$string
=
'jsapi_ticket='
.
$jsapiTicket
.
'&noncestr='
.
$nonceStr
.
'×tamp='
.
$timestamp
.
'&url='
.
$url
;
$signature
=
sha1
(
$string
);
$data
=
[
"appId"
=>
$this
->
appkey2
,
"nonceStr"
=>
$nonceStr
,
"timestamp"
=>
$timestamp
,
"url"
=>
$url
,
"signature"
=>
$signature
,
"rawString"
=>
$string
];
$this
->
assign
(
'data'
,
$data
);
}
//获取微信分享签名随机字符串
public
function
createNonceStr
(
$length
=
16
)
{
$chars
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
$str
=
""
;
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
{
$str
.=
substr
(
$chars
,
mt_rand
(
0
,
strlen
(
$chars
)
-
1
),
1
);
}
return
$str
;
}
//获取access_token
public
function
getWxAccessToken
(){
$url
=
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='
.
$this
->
appkey2
.
'&secret='
.
$this
->
appsecret2
;
$res
=
$this
->
http_get
(
$url
);
$json_arr
=
json_decode
(
$res
,
true
);
$token
=
$json_arr
[
'access_token'
];
return
$token
;
}
//获取微信分享签名
public
function
getSignature
(){
if
(
isset
(
$_SESSION
[
'ticket_expire_time'
])
&&
$_SESSION
[
'ticket_expire_time'
]
>
time
()
&&
$_SESSION
[
'ticket'
]){
$ticket
=
$_SESSION
[
'ticket'
];
}
else
{
$token
=
$this
->
getWxAccessToken
();
$url
=
'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='
.
$token
.
'&type=jsapi'
;
$res
=
$this
->
http_get
(
$url
);
$json_arr
=
json_decode
(
$res
,
true
);
$ticket
=
$json_arr
[
'ticket'
];
$_SESSION
[
'ticket'
]
=
$ticket
;
$_SESSION
[
'ticket_expire_time'
]
=
time
()
+
7000
;
}
return
$ticket
;
}
//curl get请求
public
function
http_get
(
$url
){
$curl
=
curl_init
();
//启动一个CURL会话
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
false
);
// 对认证证书来源的检查
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
false
);
// 从证书中检查SSL加密算法是否存在
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
30
);
// 设置超时限制防止死循环
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
false
);
//不开启header
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
// 获取的信息以文件流的形式返回
$result
=
curl_exec
(
$curl
);
//执行操作
curl_close
(
$curl
);
return
$result
;
}
//curl post请求
public
function
http_post
(
$url
,
$data
){
$curl
=
curl_init
();
//启动一个CURL会话
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
// 要访问的地址
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
false
);
// 对认证证书来源的检查
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
false
);
// 从证书中检查SSL加密算法是否存在
curl_setopt
(
$curl
,
CURLOPT_POST
,
true
);
// 发送一个常规的Post请求
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$data
));
// Post提交的数据包
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
30
);
// 设置超时限制防止死循环
curl_setopt
(
$curl
,
CURLOPT_HEADER
,
false
);
// 开启header
//curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//请求头部
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
// 获取的信息以文件流的形式返回
$result
=
curl_exec
(
$curl
);
//执行操作
curl_close
(
$curl
);
return
$result
;
}
}
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论