Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞鱼0526
ShopXO
提交
a42d1d2e
ShopXO
项目概览
飞鱼0526
/
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,发现更多精彩内容 >>
提交
a42d1d2e
编写于
5月 27, 2019
作者:
D
devil_gong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微信网页授权支付优化
上级
78a5b165
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
238 addition
and
180 deletion
+238
-180
application/plugins/weixinwebauthorization/index/Auth.php
application/plugins/weixinwebauthorization/index/Auth.php
+7
-175
application/plugins/weixinwebauthorization/index/Pay.php
application/plugins/weixinwebauthorization/index/Pay.php
+78
-0
application/plugins/weixinwebauthorization/service/AuthService.php
...on/plugins/weixinwebauthorization/service/AuthService.php
+150
-2
extend/payment/Weixin.php
extend/payment/Weixin.php
+3
-3
未找到文件。
application/plugins/weixinwebauthorization/index/Auth.php
浏览文件 @
a42d1d2e
...
...
@@ -11,11 +11,10 @@
namespace
app\plugins\weixinwebauthorization\index
;
use
think\Controller
;
use
app\service\PluginsService
;
use
app\plugins\weixinwebauthorization\service\Service
;
use
app\plugins\weixinwebauthorization\service\AuthService
;
/**
* 微信
登录 - 登录授权
* 微信
网页授权 - 授权处理
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
...
...
@@ -33,52 +32,7 @@ class Auth extends Controller
*/
public
function
Unbind
(
$params
=
[])
{
return
Service
::
WeixinUnbind
(
$params
);
}
/**
* 支付提示
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-25T20:15:23+0800
* @param [array] $params [输入参数]
*/
public
function
PayTips
(
$params
=
[])
{
// 自定义链接
$this
->
assign
(
'to_url'
,
MyUrl
(
'index/order/index'
));
$this
->
assign
(
'to_title'
,
'我的订单'
);
// 状态
if
(
isset
(
$params
[
'status'
])
&&
$params
[
'status'
]
==
0
)
{
$this
->
assign
(
'msg'
,
'支付成功'
);
return
$this
->
fetch
(
'public/tips_success'
);
}
else
{
$this
->
assign
(
'msg'
,
'支付失败'
);
return
$this
->
fetch
(
'public/tips_error'
);
}
}
/**
* 支付授权
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-25T14:44:32+0800
* @param [array] $params [输入参数]
*/
public
function
Pay
(
$params
=
[])
{
// 订单url处理
if
(
!
empty
(
$params
[
'id'
]))
{
$url
=
MyUrl
(
'index/order/detail'
,
[
'id'
=>
intval
(
$params
[
'id'
]),
'is_pay_auto'
=>
1
,
'is_pay_submit'
=>
1
]);
session
(
'plugins_pay_order_detail_url'
,
$url
);
}
// 调用授权
return
$this
->
Index
(
$params
);
return
AuthService
::
WeixinUnbind
(
$params
);
}
/**
...
...
@@ -91,25 +45,10 @@ class Auth extends Controller
*/
public
function
Index
(
$params
=
[])
{
$ret
=
PluginsService
::
PluginsData
(
'weixinwebauthorization'
);
$ret
=
AuthService
::
Auth
(
$params
]
);
if
(
$ret
[
'code'
]
==
0
)
{
// 参数校验
if
(
empty
(
$ret
[
'data'
][
'appid'
]))
{
$this
->
assign
(
'msg'
,
'appid未配置'
);
return
$this
->
fetch
(
'public/tips_error'
);
}
// 回调地址
$redirect_uri
=
urlencode
(
PluginsHomeUrl
(
'weixinwebauthorization'
,
'auth'
,
'callback'
));
// 授权方式
$auth_type
=
(
isset
(
$ret
[
'data'
][
'auth_type'
])
&&
$ret
[
'data'
][
'auth_type'
]
==
1
)
?
'snsapi_userinfo'
:
'snsapi_base'
;
// 授权code
$url
=
'https://open.weixin.qq.com/connect/oauth2/authorize?appid='
.
$ret
[
'data'
][
'appid'
]
.
'&redirect_uri='
.
$redirect_uri
.
'&response_type=code&scope='
.
$auth_type
.
'&state=login#wechat_redirect'
;
return
redirect
(
$url
);
return
redirect
(
$ret
[
'data'
]);
}
else
{
$this
->
assign
(
'msg'
,
$ret
[
'msg'
]);
return
$this
->
fetch
(
'public/tips_error'
);
...
...
@@ -117,7 +56,7 @@ class Auth extends Controller
}
/**
* 回调
*
授权
回调
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
...
...
@@ -126,31 +65,7 @@ class Auth extends Controller
*/
public
function
Callback
(
$params
=
[])
{
// 参数校验
if
(
empty
(
$params
[
'code'
]))
{
$this
->
assign
(
'msg'
,
'授权code为空'
);
return
$this
->
fetch
(
'public/tips_error'
);
}
// 远程获取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'
);
}
// 处理用户数据
$ret
=
Service
::
WeixinAuthBind
(
$ret
[
'data'
]);
$ret
=
AuthService
::
Callback
(
$params
);
if
(
$ret
[
'code'
]
==
0
)
{
// 是否订单支付授权,进入订单详情
...
...
@@ -170,88 +85,5 @@ class Auth extends Controller
return
$this
->
fetch
(
'public/tips_error'
);
}
}
/**
* 获取用户信息
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-24
* @desc description
* @param [array] $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
);
}
/**
* 远程获取access_token
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-24
* @desc description
* @param [array] $params [输入参数]
*/
private
function
RemoteAccessToken
(
$params
=
[])
{
$ret
=
PluginsService
::
PluginsData
(
'weixinwebauthorization'
);
if
(
$ret
[
'code'
]
==
0
)
{
// 参数校验
if
(
empty
(
$ret
[
'data'
][
'appid'
]))
{
return
DataReturn
(
'appid未配置'
,
-
1
);
}
if
(
empty
(
$ret
[
'data'
][
'secret'
]))
{
return
DataReturn
(
'secret未配置'
,
-
1
);
}
if
(
empty
(
$params
[
'code'
]))
{
return
DataReturn
(
'code授权码为空'
,
-
1
);
}
// 获取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
);
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
);
}
}
}
?>
\ No newline at end of file
application/plugins/weixinwebauthorization/index/Pay.php
0 → 100644
浏览文件 @
a42d1d2e
<?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\index
;
use
think\Controller
;
use
app\plugins\weixinwebauthorization\service\AuthService
;
/**
* 微信登录 - 微信里面支付
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class
Pay
extends
Controller
{
/**
* 支付授权
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-25T14:44:32+0800
* @param [array] $params [输入参数]
*/
public
function
Index
(
$params
=
[])
{
// 订单url处理
if
(
!
empty
(
$params
[
'id'
]))
{
$url
=
MyUrl
(
'index/order/detail'
,
[
'id'
=>
intval
(
$params
[
'id'
]),
'is_pay_auto'
=>
1
,
'is_pay_submit'
=>
1
]);
session
(
'plugins_pay_order_detail_url'
,
$url
);
}
// 调用授权
$ret
=
AuthService
::
Auth
(
$params
]);
if
(
$ret
[
'code'
]
==
0
)
{
return
redirect
(
$ret
[
'data'
]);
}
else
{
$this
->
assign
(
'msg'
,
$ret
[
'msg'
]);
return
$this
->
fetch
(
'public/tips_error'
);
}
}
/**
* 支付提示
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-25T20:15:23+0800
* @param [array] $params [输入参数]
*/
public
function
Tips
(
$params
=
[])
{
// 自定义链接
$this
->
assign
(
'to_url'
,
MyUrl
(
'index/order/index'
));
$this
->
assign
(
'to_title'
,
'我的订单'
);
// 状态
if
(
isset
(
$params
[
'status'
])
&&
$params
[
'status'
]
==
0
)
{
$this
->
assign
(
'msg'
,
'支付成功'
);
return
$this
->
fetch
(
'public/tips_success'
);
}
else
{
$this
->
assign
(
'msg'
,
'支付失败'
);
return
$this
->
fetch
(
'public/tips_error'
);
}
}
}
?>
\ No newline at end of file
application/plugins/weixinwebauthorization/service/Service.php
→
application/plugins/weixinwebauthorization/service/
Auth
Service.php
浏览文件 @
a42d1d2e
...
...
@@ -15,14 +15,162 @@ 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
class
Auth
Service
{
/**
* 授权
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-02-07T08:21:54+0800
* @param [array] $params [输入参数]
*/
public
static
function
Auth
(
$params
=
[])
{
$ret
=
PluginsService
::
PluginsData
(
'weixinwebauthorization'
);
if
(
$ret
[
'code'
]
==
0
)
{
// 参数校验
if
(
empty
(
$ret
[
'data'
][
'appid'
]))
{
return
DataReturn
(
'appid未配置'
,
-
1
);
}
// 回调地址
$redirect_uri
=
urlencode
(
PluginsHomeUrl
(
'weixinwebauthorization'
,
'auth'
,
'callback'
));
// 授权方式
$auth_type
=
(
isset
(
$ret
[
'data'
][
'auth_type'
])
&&
$ret
[
'data'
][
'auth_type'
]
==
1
)
?
'snsapi_userinfo'
:
'snsapi_base'
;
// 授权code
$url
=
'https://open.weixin.qq.com/connect/oauth2/authorize?appid='
.
$ret
[
'data'
][
'appid'
]
.
'&redirect_uri='
.
$redirect_uri
.
'&response_type=code&scope='
.
$auth_type
.
'&state=login#wechat_redirect'
;
return
DataReturn
(
'操作成功'
,
0
,
$url
);
}
return
$ret
;
}
/**
* 回调
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-02-07T08:21:54+0800
* @param [array] $params [输入参数]
*/
public
static
function
Callback
(
$params
=
[])
{
// 参数校验
if
(
empty
(
$params
[
'code'
]))
{
return
DataReturn
(
'授权code为空'
,
-
1
);
}
// 远程获取access_token
$ret
=
self
::
RemoteAccessToken
(
$params
);
if
(
$ret
[
'code'
]
!=
0
)
{
return
DataReturn
(
$ret
[
'msg'
],
-
1
);
}
// 获取用户信息
$ret
=
self
::
RemoteUserInfo
(
$ret
[
'data'
]);
if
(
$ret
[
'code'
]
!=
0
)
{
return
DataReturn
(
$ret
[
'msg'
],
-
1
);
}
// 处理用户数据
return
self
::
WeixinAuthBind
(
$ret
[
'data'
]);
}
/**
* 获取用户信息
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-24
* @desc description
* @param [array] $params [输入参数]
*/
public
static
function
RemoteUserInfo
(
$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
);
}
/**
* 远程获取access_token
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-24
* @desc description
* @param [array] $params [输入参数]
*/
public
static
function
RemoteAccessToken
(
$params
=
[])
{
$ret
=
PluginsService
::
PluginsData
(
'weixinwebauthorization'
);
if
(
$ret
[
'code'
]
==
0
)
{
// 参数校验
if
(
empty
(
$ret
[
'data'
][
'appid'
]))
{
return
DataReturn
(
'appid未配置'
,
-
1
);
}
if
(
empty
(
$ret
[
'data'
][
'secret'
]))
{
return
DataReturn
(
'secret未配置'
,
-
1
);
}
if
(
empty
(
$params
[
'code'
]))
{
return
DataReturn
(
'code授权码为空'
,
-
1
);
}
// 获取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
);
if
(
empty
(
$data
[
'access_token'
]))
{
if
(
empty
(
$data
[
'errmsg'
]))
{
return
DataReturn
(
'获取access_token失败'
,
-
100
);
}
else
{
return
DataReturn
(
$data
[
'errmsg'
],
-
100
);
}
}
return
DataReturn
(
'获取成功'
,
0
,
$data
);
}
return
$ret
;
}
/**
* 微信解绑
* @author Devil
...
...
extend/payment/Weixin.php
浏览文件 @
a42d1d2e
...
...
@@ -145,7 +145,7 @@ class Weixin
// 微信中打开
if
(
!
empty
(
$_SERVER
[
'HTTP_USER_AGENT'
])
&&
stripos
(
$_SERVER
[
'HTTP_USER_AGENT'
],
'MicroMessenger'
)
!==
false
&&
empty
(
$params
[
'user'
][
'weixin_web_openid'
]))
{
exit
(
header
(
'location:'
.
PluginsHomeUrl
(
'weixinwebauthorization'
,
'
auth'
,
'pay
'
,
input
())));
exit
(
header
(
'location:'
.
PluginsHomeUrl
(
'weixinwebauthorization'
,
'
pay'
,
'index
'
,
input
())));
}
// 获取支付参数
...
...
@@ -253,8 +253,8 @@ class Weixin
private
function
PayHtml
(
$pay_data
,
$redirect_url
)
{
// 支付跳转地址
$success_url
=
PluginsHomeUrl
(
'weixinwebauthorization'
,
'
auth'
,
'pay
tips'
,
[
'status'
=>
0
]);
$error_url
=
PluginsHomeUrl
(
'weixinwebauthorization'
,
'
auth'
,
'pay
tips'
,
[
'status'
=>-
1
]);
$success_url
=
PluginsHomeUrl
(
'weixinwebauthorization'
,
'
pay'
,
'
tips'
,
[
'status'
=>
0
]);
$error_url
=
PluginsHomeUrl
(
'weixinwebauthorization'
,
'
pay'
,
'
tips'
,
[
'status'
=>-
1
]);
// 支付代码
exit
(
'<html>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录