Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
starsw001
ShopXO
提交
8f662b21
ShopXO
项目概览
starsw001
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8f662b21
编写于
5月 24, 2019
作者:
D
devil_gong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微信授权
上级
7d07a871
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
210 addition
and
13 deletion
+210
-13
application/plugins/view/weixinwebauthorization/index/public/success.html
...ins/view/weixinwebauthorization/index/public/success.html
+55
-0
application/plugins/weixinwebauthorization/index/Auth.php
application/plugins/weixinwebauthorization/index/Auth.php
+62
-13
application/plugins/weixinwebauthorization/install.sql
application/plugins/weixinwebauthorization/install.sql
+2
-0
application/plugins/weixinwebauthorization/service/Service.php
...cation/plugins/weixinwebauthorization/service/Service.php
+91
-0
未找到文件。
application/plugins/view/weixinwebauthorization/index/public/success.html
0 → 100644
浏览文件 @
8f662b21
{{include file="public/header" /}}
<!-- header nav start -->
{{if isset($is_header) and $is_header eq 1}}
<!-- header top nav -->
{{include file="public/header_top_nav" /}}
<!-- search -->
{{include file="public/nav_search" /}}
<!-- goods category -->
{{include file="public/goods_category" /}}
{{/if}}
<!-- header nav end -->
<!-- conntent start -->
<div
class=
"am-g my-content"
>
<div
class=
"am-u-md-6 am-u-sm-centered"
>
<div
class=
"am-panel am-radius tips-success"
>
<div
class=
"am-panel-bd"
>
<i
class=
"am-icon-check-circle am-icon-sm"
></i>
<span
class=
"msg"
>
{{$msg}}
</span>
<div
class=
"tips-nav"
>
<a
href=
"{{$Think.__MY_URL__}}"
class=
"am-btn am-btn-secondary am-radius"
>
回到首页
</a>
</div>
</div>
</div>
</div>
</div>
<!-- conntent end -->
{{include file="public/footer" /}}
{{if !empty($data['body_html'])}}
{{$data.body_html|raw}}
{{/if}}
<script
type=
"text/javascript"
>
{{
if
isset
(
$is_parent
)
and
$is_parent
eq
1
}}
setTimeout
(
function
()
{
if
(
self
.
frameElement
&&
self
.
frameElement
.
tagName
==
"
IFRAME
"
)
{
parent
.
location
.
reload
();
}
else
{
window
.
location
.
href
=
'
{{$Think.__MY_URL__}}
'
;
}
},
1500
);
{{
else
/}
}
setTimeout
(
function
()
{
window
.
location
.
href
=
'
{{$Think.__MY_URL__}}
'
;
},
1500
);
{{
/
if
}}
</script>
\ No newline at end of file
application/plugins/weixinwebauthorization/index/Auth.php
浏览文件 @
8f662b21
...
...
@@ -12,6 +12,7 @@ namespace app\plugins\weixinwebauthorization\index;
use
think\Controller
;
use
app\service\PluginsService
;
use
app\plugins\weixinwebauthorization\service\Service
;
/**
* 微信登录 - 登录授权
...
...
@@ -74,28 +75,69 @@ class Auth extends Controller
return
$this
->
fetch
(
'public/tips_error'
);
}
// 本地获取access_token
// 远程获取access_token
$ret
=
$this
->
RemoteAccessToken
(
$params
);
if
(
$ret
[
'code'
]
!=
0
)
{
$this
->
assign
(
'msg'
,
$ret
[
'msg'
]);
return
$this
->
fetch
(
'public/tips_error'
);
}
// 获取用户信息
$ret
=
$this
->
UserInfo
(
$ret
[
'data'
]);
if
(
$ret
[
'code'
]
!=
0
)
{
$this
->
assign
(
'msg'
,
$ret
[
'msg'
]);
return
$this
->
fetch
(
'public/tips_error'
);
}
echo
'<pre>'
;
print_r
(
$ret
);
// 处理用户数据
$ret
=
Service
::
WeixinAuthReg
(
$ret
[
'data'
]);
if
(
$ret
[
'code'
]
==
0
)
{
$this
->
assign
(
'msg'
,
$ret
[
'msg'
]);
$this
->
assign
(
'data'
,
$ret
[
'data'
]);
return
$this
->
fetch
(
'../../../plugins/view/weixinwebauthorization/index/public/success'
);
}
else
{
$this
->
assign
(
'msg'
,
$ret
[
'msg'
]);
return
$this
->
fetch
(
'public/error'
);
}
}
/**
* 获取
access_token
* 获取
用户信息
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-24
* @desc description
* @param
array $params [description
]
* @param
[array] $params [输入参数
]
*/
private
function
AccessToken
(
$params
=
[])
private
function
UserInfo
(
$params
=
[])
{
// 参数校验
if
(
empty
(
$params
[
'access_token'
]))
{
return
DataReturn
(
'access_token为空'
,
-
1
);
}
if
(
empty
(
$params
[
'openid'
]))
{
return
DataReturn
(
'openid为空'
,
-
1
);
}
// 获取用户详细信息
$url
=
'https://api.weixin.qq.com/sns/userinfo?access_token='
.
$params
[
'access_token'
]
.
'&openid='
.
$params
[
'openid'
]
.
'&lang=zh_CN'
;
$data
=
json_decode
(
file_get_contents
(
$url
),
true
);
if
(
empty
(
$data
[
'openid'
]))
{
if
(
empty
(
$data
[
'errmsg'
]))
{
return
DataReturn
(
'获取用户信息失败'
,
-
100
);
}
else
{
return
DataReturn
(
$data
[
'errmsg'
],
-
100
);
}
}
return
DataReturn
(
'获取成功'
,
0
,
$data
);
}
/**
...
...
@@ -105,7 +147,7 @@ class Auth extends Controller
* @version 1.0.0
* @date 2019-05-24
* @desc description
* @param
array $params [description
]
* @param
[array] $params [输入参数
]
*/
private
function
RemoteAccessToken
(
$params
=
[])
{
...
...
@@ -129,9 +171,16 @@ class Auth extends Controller
// 获取access_token
$url
=
'https://api.weixin.qq.com/sns/oauth2/access_token?appid='
.
$ret
[
'data'
][
'appid'
]
.
'&secret='
.
$ret
[
'data'
][
'secret'
]
.
'&code='
.
$params
[
'code'
]
.
'&grant_type=authorization_code'
;
$data
=
json_decode
(
file_get_contents
(
$url
),
true
);
echo
'<pre>'
;
print_r
(
$data
);
die
;
if
(
empty
(
$data
[
'access_token'
]))
{
if
(
empty
(
$data
[
'errmsg'
]))
{
return
DataReturn
(
'获取access_token失败'
,
-
100
);
}
else
{
return
DataReturn
(
$data
[
'errmsg'
],
-
100
);
}
}
return
DataReturn
(
'获取成功'
,
0
,
$data
);
}
else
{
return
DataReturn
(
$ret
[
'msg'
],
-
1
);
...
...
application/plugins/weixinwebauthorization/install.sql
0 → 100644
浏览文件 @
8f662b21
#
用户
ALTER
TABLE
`s_user`
add
`weixin_web_openid`
char
(
60
)
NOT
NULL
DEFAULT
''
COMMENT
'微信web用户openid'
after
`weixin_openid`
;
\ No newline at end of file
application/plugins/weixinwebauthorization/service/Service.php
0 → 100755
浏览文件 @
8f662b21
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace
app\plugins\weixinwebauthorization\service
;
use
think\Db
;
use
app\service\UserService
;
use
app\service\PluginsService
;
/**
* 微信登录服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class
Service
{
/**
* 微信登录注册
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-03
* @desc description
* @param [array] $params [输入参数]
*/
public
static
function
WeixinAuthReg
(
$params
=
[])
{
// 获取登录用户
$user
=
UserService
::
LoginUserInfo
();
if
(
!
empty
(
$user
))
{
return
DataReturn
(
'已登录,请先退出'
,
-
1
);
}
// 是否有登录纪录
if
(
!
empty
(
$params
[
'openid'
]))
{
$user
=
UserService
::
UserInfo
(
'weixin_web_openid'
,
$params
[
'openid'
]);
if
(
!
empty
(
$user
))
{
// 用户登录
$ret
=
UserService
::
Login
([
'accounts'
=>
$user
[
'username'
],
'pwd'
=>
$user
[
'username'
]]);
if
(
$ret
[
'code'
]
==
0
)
{
return
DataReturn
(
'登录成功'
,
0
,
$ret
[
'data'
]);
}
}
}
else
{
return
DataReturn
(
'用户openid为空'
,
-
1
);
}
// 游客数据
$salt
=
GetNumberCode
(
6
);
$data
=
[
'weixin_web_openid'
=>
$params
[
'openid'
],
'username'
=>
$params
[
'openid'
],
'nickname'
=>
empty
(
$params
[
'nickname'
])
?
''
:
$params
[
'nickname'
],
'gender'
=>
empty
(
$params
[
'sex'
])
?
0
:
(
isset
(
$params
[
'sex'
])
&&
$params
[
'sex'
]
==
1
)
?
2
:
1
,
'province'
=>
empty
(
$params
[
'province'
])
?
''
:
$params
[
'province'
],
'city'
=>
empty
(
$params
[
'city'
])
?
''
:
$params
[
'city'
],
'avatar'
=>
empty
(
$params
[
'headimgurl'
])
?
''
:
$params
[
'headimgurl'
],
'status'
=>
0
,
'salt'
=>
$salt
,
'pwd'
=>
LoginPwdEncryption
(
$params
[
'openid'
],
$salt
),
'add_time'
=>
time
(),
'upd_time'
=>
time
(),
];
// 数据添加
$ret
=
UserService
::
UserInsert
(
$data
,
$params
);
if
(
$ret
[
'code'
]
==
0
)
{
// 用户登录session纪录
if
(
UserService
::
UserLoginRecord
(
$ret
[
'data'
][
'user_id'
]))
{
return
DataReturn
(
'登录成功'
,
0
,
$ret
[
'data'
]);
}
}
return
DataReturn
(
'登录失败'
,
-
100
);
}
}
?>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录