diff --git a/application/api/controller/User.php b/application/api/controller/User.php index 1ef772f804b643bd3511d95ea94cadb49e67d141..65e2097dd7926f3d76a6af16d74ca55312c5c638 100755 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -97,28 +97,6 @@ class User extends Common return DataReturn('授权登录成功', 0, $result['data']['user_id']); } return DataReturn($result['msg'], -100); - - - - - // // 参数 - // if(empty($this->data_post['authcode'])) - // { - // return DataReturn('授权码不能为空', -1); - // } - - // // 授权 - // $ret = (new \base\AlipayAuth())->GetAuthCode($this->data_post['authcode'], MyC('common_app_mini_alipay_appid')); - // if($ret['status'] != 0) - // { - // return DataReturn($ret['msg'], -10); - // } else { - // $data = $ret['data']; - // $data['gender'] = empty($data['gender']) ? 0 : ($data['gender'] == 'm') ? 2 : 1; - // $data['openid'] = $data['user_id']; - // $data['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0; - // return UserService::AuthUserProgram($data, 'alipay_openid'); - // } } /** @@ -138,11 +116,6 @@ class User extends Common 'key_name' => 'openid', 'error_msg' => 'openid为空', ], - // [ - // 'checked_type' => 'empty', - // 'key_name' => 'userinfo', - // 'error_msg' => '用户数据为空', - // ], ]; $ret = ParamsChecked($this->data_post, $p); if($ret !== true) @@ -154,15 +127,14 @@ class User extends Common $user = UserService::UserInfo('alipay_openid', $this->data_post['openid']); if(empty($user)) { - $result = $this->data_post; - $result['nick_name'] = isset($result['nickName']) ? $result['nickName'] : ''; - $result['gender'] = empty($result['gender']) ? 0 : ($result['gender'] == 'f') ? 1 : 2; - return UserService::AuthUserProgram($result, 'alipay_openid'); + $result['nick_name'] = isset($this->data_post['nickName']) ? $this->data_post['nickName'] : ''; + $this->data_post['gender'] = empty($this->data_post['gender']) ? 0 : ($this->data_post['gender'] == 'f') ? 1 : 2; + return UserService::AuthUserProgram($this->data_post, 'alipay_openid'); } else { $user['is_mandatory_bind_mobile'] = intval(MyC('common_user_is_mandatory_bind_mobile')); return DataReturn('授权成功', 0, $user); } - return DataReturn(empty($result) ? '获取用户信息失败' : $result, -100); + return DataReturn(empty($this->data_post) ? '获取用户信息失败' : $result, -100); } /** diff --git a/application/common.php b/application/common.php index 585e0990df3190be828edd10c0961b51ac50d4d3..9ee2fc97bd1c9473df9e21688035435a576ee7d3 100755 --- a/application/common.php +++ b/application/common.php @@ -1293,74 +1293,6 @@ function Authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { } } -/** - * [SS 设置缓存] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-24T19:01:00+0800 - * @param [string] $key [缓存key] - * @param [mixed] $data [需要存储的数据] - * @return [boolean] [成功true, 失败false] - */ -function SS($key, $data) -{ - if(empty($key) || empty($data)) - { - return false; - } - - $data['cache_time'] = time(); - return cache($key, $data); -} - -/** - * [GS 获取缓存] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-24T18:54:54+0800 - * @param [string] $key [缓存key] - * @param [integer] $expires_time [默认过期时间0长期有效(单位秒)] - * @param [boolean] $is_filem_time [是否返回文件上一次更新时间] - * @return [boolean|mixed] [没数据false, 则数据] - */ -function GS($key, $expires_time = 0, $is_filem_time = false) -{ - if(empty($key)) - { - return false; - } - $data = cache($key); - if($data !== null) - { - $expires_time = intval($expires_time); - if($expires_time > 0) - { - if($data['cache_time']+$expires_time < time()) - { - return false; - } - } - return $data; - } - return false; -} - -/** - * [DS 删除缓存] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-24T19:01:00+0800 - * @param [string] $key [缓存key] - * @return [boolean] [成功true, 失败false] - */ -function DS($key) -{ - return cache($key, null); -} - /** * [ParamsChecked 参数校验方法] * @author Devil diff --git a/application/service/UserService.php b/application/service/UserService.php index 676293138042cdaddec5206b980a7475567a7e5e..7737c656d9d2ab202c18f990c2aa12f8abbf8d3a 100755 --- a/application/service/UserService.php +++ b/application/service/UserService.php @@ -1093,7 +1093,6 @@ class UserService // 用户数据 $salt = GetNumberCode(6); $data = [ - 'add_time' => time(), 'upd_time' => time(), 'salt' => $salt, 'pwd' => LoginPwdEncryption($params['pwd'], $salt), @@ -1676,6 +1675,7 @@ class UserService $data['referrer'] = self::UserReferrerDecrypt($params); // 添加用户 + $data['add_time'] = time(); $user_id = Db::name('User')->insertGetId($data); if($user_id > 0) { @@ -1819,7 +1819,6 @@ class UserService // 不存在添加/则更新 if(empty($temp_user)) { - $data['add_time'] = time(); $user_ret = self::UserInsert($data, $params); if($user_ret['code'] == 0) { diff --git a/extend/base/AlipayAuth.php b/extend/base/AlipayAuth.php index a45a4a7d323f39dd61e6b60d7f257e316dece9f5..5f93f13215c63ad18cf91ea1245161d31956d080 100755 --- a/extend/base/AlipayAuth.php +++ b/extend/base/AlipayAuth.php @@ -17,137 +17,6 @@ namespace base; */ class AlipayAuth { - /** - * [__construct 构造方法] - */ - public function __construct(){} - - /** - * [GetParamSign 生成参数和签名] - * @param [array] $data [待生成的参数] - * @param [array] $config [配置信息] - * @return [array] [生成好的参数和签名] - */ - private function GetParamSign($data, $config = []) - { - $param = ''; - $sign = ''; - ksort($data); - - foreach($data AS $key => $val) - { - $param .= "$key=" .urlencode($val). "&"; - $sign .= "$key=$val&"; - } - - $result = array( - 'param' => substr($param, 0, -1), - 'value' => substr($sign, 0, -1), - ); - if(!empty($config['key'])) - { - $result['sign'] = $result['value'].$config['key']; - } - return $result; - } - - /** - * [GetAlipayUserInfo 支付宝小程序获取用户信息] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-23T22:30:43+0800 - * @param [string] $authcode [用户授权码] - * @param [string] $app_id [应用appid] - * @return [array|boolean] [成功返回用户数据, 则false] - */ - public function GetAlipayUserInfo($authcode, $app_id) - { - // 从缓存获取用户信息 - $key = 'alipay_userinfo_'.$authcode; - $result = GS($key); - if($result !== false) - { - return ['status'=>0, 'msg'=>'success', 'data'=>$result]; - } - - // 获取授权信息并且获取用户信息 - $auth = $this->GetAuthAccessToken($authcode, $app_id); - if($auth['status'] == 0) - { - // 请求参数 - $param = [ - 'app_id' => $app_id, - 'method' => 'alipay.user.info.share', - 'charset' => 'utf-8', - 'format' => 'JSON', - 'sign_type' => 'RSA2', - 'timestamp' => date('Y-m-d H:i:s'), - 'version' => '1.0', - 'auth_token' => $auth['data']['access_token'], - ]; - - // 生成签名参数+签名 - $p = $this->GetParamSign($param); - $param['sign'] = $this->MyRsaSign($p['value']); - - // 执行请求 - $result = $this->HttpRequest('https://openapi.alipay.com/gateway.do', $param); - if(!empty($result['alipay_user_info_share_response']['code']) && $result['alipay_user_info_share_response']['code'] == 10000) - { - // 验证签名正确则存储缓存返回数据 - if(!$this->SyncRsaVerify($result, 'alipay_user_info_share_response')) - { - return ['status'=>-1, 'msg'=>'签名验证失败']; - } - - // 存储缓存 - SS($key, $result['alipay_user_info_share_response']); - - // 返回用户数据 - return ['status'=>0, 'msg'=>'success', 'data'=>$result['alipay_user_info_share_response']]; - } - - $msg = empty($result['error_response']['sub_msg']) ? '授权失败' : $result['error_response']['sub_msg']; - if(!empty($result['alipay_user_info_share_response']['sub_msg'])) - { - $msg = $result['alipay_user_info_share_response']['sub_msg']; - } - return ['status'=>-1, 'msg'=>$msg]; - } else { - return $auth; - } - } - - /** - * [GetAuthAccessToken 根据用户授权换取授权访问令牌] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-23T22:36:26+0800 - * @param [string] $authcode [用户授权码] - * @param [string] $app_id [应用appid] - * @return [array|boolean] [失败false, 用户授权信息] - */ - public function GetAuthAccessToken($authcode, $app_id) - { - // 获取用户授权信息 - $key = 'alipay_authcode_'.$authcode; - $result = GS($key, 0, true); - - // 过期判断 - if($result == false || $result['filemtime']+$result['re_expires_in'] < time()) - { - $result = $this->GetAuthCode($app_id, $key, $authcode); - } else { - if($result['filemtime']+$result['expires_in'] < time()) - { - $result = $this->GetAuthCode($app_id, $key, '', $result['refresh_token']); - } - } - return $result; - } - /** * [GetAuthCode 获取用户授权信息] * @author Devil @@ -201,6 +70,40 @@ class AlipayAuth return ['status'=>-1, 'msg'=>$msg]; } + /** + * [__construct 构造方法] + */ + public function __construct(){} + + /** + * [GetParamSign 生成参数和签名] + * @param [array] $data [待生成的参数] + * @param [array] $config [配置信息] + * @return [array] [生成好的参数和签名] + */ + private function GetParamSign($data, $config = []) + { + $param = ''; + $sign = ''; + ksort($data); + + foreach($data AS $key => $val) + { + $param .= "$key=" .urlencode($val). "&"; + $sign .= "$key=$val&"; + } + + $result = array( + 'param' => substr($param, 0, -1), + 'value' => substr($sign, 0, -1), + ); + if(!empty($config['key'])) + { + $result['sign'] = $result['value'].$config['key']; + } + return $result; + } + /** * [MyRsaSign 签名字符串] * @author Devil diff --git a/public/appmini/old/alipay/app.js b/public/appmini/old/alipay/app.js index 3ae5f2e2142e9325a5364a97e68d0502434492b0..1b1ffe9d1f403b7d2f2bf16e6bc802f805fda4ff 100644 --- a/public/appmini/old/alipay/app.js +++ b/public/appmini/old/alipay/app.js @@ -293,11 +293,11 @@ App({ */ user_auth_login(object, method, auth_data) { var openid = my.getStorageSync({key: this.data.cache_user_login_key}); - if ((openid || null) == null) + if ((openid.data || null) == null) { this.user_login(object, method, auth_data); } else { - this.get_user_login_info(object, method, openid, auth_data); + this.get_user_login_info(object, method, openid.data, auth_data); } }, diff --git a/public/appmini/old/alipay/pages/login/login.js b/public/appmini/old/alipay/pages/login/login.js index 03e8b06db9431ce1fb627aa86bb701300547e7f2..2bbc835bb40ff303a474cea14893b5ce49e6e185 100644 --- a/public/appmini/old/alipay/pages/login/login.js +++ b/public/appmini/old/alipay/pages/login/login.js @@ -17,7 +17,7 @@ Page({ */ onLoad(option) { // 标题设置 - my.setNavigationBar({title: '手机绑定'}); + my.setNavigationBar({title: (this.data.user == null) ? '授权用户信息' : '手机绑定'}); // 设置用户信息 this.setData({params: option, user: app.get_user_cache_info() || null}); @@ -39,17 +39,11 @@ Page({ user_auth_code(object, method, auth_data) { my.getOpenUserInfo({ success: (userinfo) => { - // my.alert({ - // title: '亲', - // content: userinfo, - // buttonText: '我知道了', - // }); - // 字符串则转为json对象(兼容支付宝框架bug) - // if(typeof(userinfo) == 'string') - // { + if(typeof(userinfo.response) == 'string') + { userinfo = JSON.parse(userinfo.response); - //} + } console.log(userinfo.response) app.user_auth_login(this, 'user_auth_back_event', userinfo.response); }