切换导航条
此项目
正在载入...
登录
景龙
/
xingqiu
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
景龙
6 years ago
提交
bc0a8e3589085c1183fe8dca071bd72891839024
1 个父辈
7da5122b
1 个管道 的构建
通过
耗费 1 秒
测试微信移动登录
变更
5
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
112 行增加
和
34 行删除
app/portal/controller/LoginController.php
public/themes/simpleboot3/portal/login/third_login.html
public/themes/simpleboot3_mobile/public/assets/js/public.js
public/themes/simpleboot3_mobile/public/slide.html
simplewind/cmf/controller/HomeBaseController.php
app/portal/controller/LoginController.php
查看文件 @
bc0a8e3
...
...
@@ -520,35 +520,4 @@ class LoginController extends HomeBaseController
->
find
();
return
$info
;
}
//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/themes/simpleboot3/portal/login/third_login.html
查看文件 @
bc0a8e3
...
...
@@ -34,7 +34,9 @@
<!--登陆-->
<div
class=
"login_right_main clearfix"
>
<div
class=
"WeChat"
>
<a
href=
"https://open.weixin.qq.com/connect/qrconnect?appid=wx9cfa880272f186bf&redirect_uri=http://www.starplanet.cn/portal/login/wx_login&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect"
><img
src=
"__TMPL__/public/assets/starImg/aicon_89.png"
alt=
""
></a>
<a
href=
"https://open.weixin.qq.com/connect/qrconnect?appid=wx9cfa880272f186bf&redirect_uri=http://www.starplanet.cn/portal/login/wx_login&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect"
>
<img
src=
"__TMPL__/public/assets/starImg/aicon_89.png"
alt=
""
>
</a>
</div>
<form
action=
"https://api.weibo.com/oauth2/authorize"
method=
"POST"
id=
"wb_form"
>
<div
class=
"Sina"
id=
"wb_login"
>
...
...
public/themes/simpleboot3_mobile/public/assets/js/public.js
查看文件 @
bc0a8e3
...
...
@@ -267,10 +267,13 @@ $(function() {
$
(
'#wb_form'
).
submit
();
});
//微信登录
//微信登录
(暂时无用)
$
(
'#wx_login'
).
click
(
function
(){
window
.
location
.
href
=
'/portal/login/wx_login_mobile'
;
});
//微信分享
});
//第三方分享
function
thirdShare
(
url
){
...
...
public/themes/simpleboot3_mobile/public/slide.html
查看文件 @
bc0a8e3
...
...
@@ -33,4 +33,23 @@
</div>
</li>
</ul>
</div>
\ No newline at end of file
</div>
<script
src=
"http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"
></script>
<script>
wx
.
config
({
debug
:
false
,
appId
:
"{$data.appid}"
,
timestamp
:
"{$data.timestamp}"
,
nonceStr
:
"{$data.nonceStr}"
,
signature
:
"{$data.signature}"
,
jsApiList
:
[
'checkJsApi'
,
'onMenuShareTimeline'
,
'onMenuShareAppMessage'
]
});
wx
.
ready
(
function
(){
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
});
</script>
...
...
simplewind/cmf/controller/HomeBaseController.php
查看文件 @
bc0a8e3
...
...
@@ -10,6 +10,7 @@
// +----------------------------------------------------------------------
namespace
cmf\controller
;
use
app\portal\controller\LoginController
;
use
think\Db
;
use
app\admin\model\ThemeModel
;
use
think\View
;
...
...
@@ -20,6 +21,8 @@ use think\Session;
class
HomeBaseController
extends
BaseController
{
private
$appkey2
=
'wx0bd7bc2aa0f332d6'
;
//微信公众号appkey
private
$appsecret2
=
'b62e49f48f48de7b7fff2ea0af3939de'
;
//微信公众号appsecret
protected
function
initialize
()
{
...
...
@@ -37,6 +40,7 @@ class HomeBaseController extends BaseController
$this
->
is_like
();
$this
->
getShareCount
();
$keyword
=
$this
->
request
->
param
(
'keyword'
);
$this
->
configShareWx
();
$this
->
assign
(
'keyword'
,
$keyword
);
}
...
...
@@ -395,4 +399,85 @@ hello;
$this
->
assign
(
'share'
,
$share
);
}
//获取微信分享配置信息
public
function
configShareWx
(
$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
;
}
//获取微信分享签名
public
function
getSignature
(){
$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
);
if
(
!
isset
(
$json_arr
[
'access_token'
])
&&
empty
(
$json_arr
[
'access_token'
])){
//用户取消登录
$this
->
redirect
(
'/portal/login/thirdLogin'
);
}
$token
=
$json_arr
[
'access_token'
];
$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'
];
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
...
...
请
注册
或
登录
后发表评论