diff --git a/application/plugins/weixinwebauthorization/index/Auth.php b/application/plugins/weixinwebauthorization/index/Auth.php index a163a35b3..34cf8062e 100644 --- a/application/plugins/weixinwebauthorization/index/Auth.php +++ b/application/plugins/weixinwebauthorization/index/Auth.php @@ -23,6 +23,19 @@ use app\plugins\weixinwebauthorization\service\Service; */ class Auth extends Controller { + /** + * 支付授权 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-05-25T14:44:32+0800 + * @param [array] $params [输入参数] + */ + public function Pay($params = []) + { + return $this->Index($params); + } + /** * 授权 * @author Devil @@ -92,7 +105,7 @@ class Auth extends Controller } // 处理用户数据 - $ret = Service::WeixinAuthReg($ret['data']); + $ret = Service::WeixinAuthBind($ret['data']); if($ret['code'] == 0) { $this->assign('msg', $ret['msg']); @@ -186,6 +199,5 @@ class Auth extends Controller return DataReturn($ret['msg'], -1); } } - } ?> \ No newline at end of file diff --git a/application/plugins/weixinwebauthorization/service/Service.php b/application/plugins/weixinwebauthorization/service/Service.php index e4fc888b1..0a25c11dd 100755 --- a/application/plugins/weixinwebauthorization/service/Service.php +++ b/application/plugins/weixinwebauthorization/service/Service.php @@ -24,7 +24,7 @@ use app\service\PluginsService; class Service { /** - * 微信登录注册 + * 微信绑定 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 @@ -32,26 +32,38 @@ class Service * @desc description * @param [array] $params [输入参数] */ - public static function WeixinAuthReg($params = []) + public static function WeixinAuthBind($params = []) { + // openid + if(empty($params['openid'])) + { + return DataReturn('用户openid为空', -1); + } + // 获取登录用户 $user = UserService::LoginUserInfo(); if(!empty($user)) { - return DataReturn('已登录,请先退出', -1); + // 是否已绑定 + if(!empty($user['weixin_web_openid'])) + { + return DataReturn('该帐号已绑定微信,请先解绑', -1); + } + + // 绑定 + if(Db::name('User')->where(['id'=>$user['id']])->update(['weixin_web_openid'=>$params['openid'], 'upd_time'=>time()])) + { + return DataReturn('绑定成功', 0); + } + return DataReturn('绑定失败', -100); } - // 是否有登录纪录 - if(!empty($params['openid'])) + // openid登录 + $user = UserService::UserInfo('weixin_web_openid', $params['openid']); + if(!empty($user)) { - $user = UserService::UserInfo('weixin_web_openid', $params['openid']); - if(!empty($user)) - { - // 用户登录 - return UserService::UserLoginHandle($user['id'], $params); - } - } else { - return DataReturn('用户openid为空', -1); + // 用户登录 + return UserService::UserLoginHandle($user['id'], $params); } // 用户名 diff --git a/extend/payment/Weixin.php b/extend/payment/Weixin.php index 1208492b8..eb1e00258 100755 --- a/extend/payment/Weixin.php +++ b/extend/payment/Weixin.php @@ -143,21 +143,10 @@ class Weixin } // 微信中打开 - // if(!empty($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) - // { - // $input = input(); - // if(empty($input['code'])) - // { - // $this->GetUserOpenId($params); - // } else { - // $ret = $this->Callback($input); - // if($ret['code'] != 0) - // { - // return $ret; - // } - // $params['user']['weixin_web_openid'] = $ret['data']; - // } - // } + 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()))); + } // 获取支付参数 $ret = $this->GetPayParams($params);