From 24d2c72bd4f7640e04e3e06ae7dd325010ff96aa Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Tue, 30 Nov 2021 18:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E9=99=86=E6=B3=A8?= =?UTF-8?q?=E5=86=8CH5=E5=85=BC=E5=AE=B9=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/User.php | 38 +++++++++---------- app/service/ConstService.php | 6 +-- app/service/UserService.php | 71 +++++++++++++++++++++++++++++++++--- 3 files changed, 86 insertions(+), 29 deletions(-) diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 8bd035d3f..2b8f89d6a 100755 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -123,25 +123,6 @@ class User extends Common return ApiService::ApiDataReturn(UserService::ForgetPwdVerifySend($this->data_post)); } - /** - * 用户-验证码显示 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2021-03-04 - * @desc description - */ - public function UserVerifyEntry() - { - $params = [ - 'width' => 100, - 'height' => 28, - 'key_prefix' => input('type', 'user_reg'), - ]; - $verify = new \base\Verify($params); - $verify->Entry(); - } - /** * app用户手机绑定 * @author Devil @@ -168,7 +149,24 @@ class User extends Common return ApiService::ApiDataReturn(UserService::AppMobileBindVerifySend($this->data_post)); } - + /** + * 用户-验证码显示 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-04 + * @desc description + */ + public function UserVerifyEntry() + { + $params = [ + 'width' => 100, + 'height' => 28, + 'key_prefix' => input('type', 'user_reg'), + ]; + $verify = new \base\Verify($params); + $verify->Entry(); + } /** * 支付宝用户授权 diff --git a/app/service/ConstService.php b/app/service/ConstService.php index 67db9d50a..5883070a5 100644 --- a/app/service/ConstService.php +++ b/app/service/ConstService.php @@ -92,9 +92,9 @@ class ConstService // 用户注册类型列表 'common_user_reg_type_list' => [ - 0 => ['value' => 'sms', 'name' => '短信'], - 1 => ['value' => 'email', 'name' => '邮箱'], - 2 => ['value' => 'username', 'name' => '用户名'], + 0 => ['value' => 'username', 'name' => '账号'], + 1 => ['value' => 'sms', 'name' => '短信'], + 2 => ['value' => 'email', 'name' => '邮箱'], ], // 登录方式 diff --git a/app/service/UserService.php b/app/service/UserService.php index 6308cfbab..cc2cbc0a6 100755 --- a/app/service/UserService.php +++ b/app/service/UserService.php @@ -766,7 +766,7 @@ class UserService // 获取用户账户信息 $where = [$ac['data'] => $params['accounts'], 'is_delete_time'=>0]; - $user = Db::name('User')->field('id,pwd,salt,status')->where($where)->find(); + $user = Db::name('User')->where($where)->find(); if(empty($user)) { return DataReturn('帐号不存在', -3); @@ -804,14 +804,38 @@ class UserService // 返回数据,更新数据库 $data = [ - 'upd_time' => time(), - ]; + 'upd_time' => time(), + ]; if($params['type'] == 'username') { $salt = GetNumberCode(6); $data['salt'] = $salt; $data['pwd'] = LoginPwdEncryption($params['pwd'], $salt); } + + // 用户openid + if(empty($user[APPLICATION_CLIENT_TYPE.'_openid'])) + { + $openid = self::UserOpenidHandle($params); + if(!empty($openid['field']) && !empty($openid['value'])) + { + // openid放入用户data中 + $data[$openid['field']] = $openid['value']; + } + } + + // 用户unionid + if(empty($user[APPLICATION_CLIENT_TYPE.'_unionid'])) + { + $unionid = self::UserUnionidHandle($params); + if(!empty($unionid['field']) && !empty($unionid['value'])) + { + // unionid放入用户data中 + $data[$unionid['field']] = $unionid['value']; + } + } + + // 更新用户信息 if(Db::name('User')->where(['id'=>$user['id']])->update($data) !== false) { // 清除图片验证码 @@ -1230,7 +1254,7 @@ class UserService return DataReturn($ret, -1); } - // 是否开启用户注册 + // 是否开启用户登录 if(!in_array($params['type'], MyC('home_user_login_type', [], true))) { return DataReturn('暂时关闭登录', -1); @@ -1857,6 +1881,33 @@ class UserService return Db::name('User')->where(['id'=>$user_id])->update($data); } + /** + * 用户openid处理 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-02-11 + * @desc description + * @param [array] $params [输入参数] + */ + public static function UserOpenidHandle($params = []) + { + $field = null; + $value = null; + $fields_arr = array_column(MyConst('common_appmini_type'), 'value'); + foreach($fields_arr as $type) + { + $openid = $type.'_openid'; + if(!empty($params[$openid])) + { + $field = $openid; + $value = $params[$openid]; + break; + } + } + return ['field'=>$field, 'value'=>$value]; + } + /** * 用户unionid处理 * @author Devil @@ -1873,8 +1924,8 @@ class UserService // QQ用户unionid $field = null; $value = null; - $unionid_all = ['weixin_unionid', 'qq_unionid']; - foreach($unionid_all as $unionid) + $fields_arr = ['weixin_unionid', 'qq_unionid']; + foreach($fields_arr as $unionid) { if(!empty($params[$unionid])) { @@ -2042,6 +2093,14 @@ class UserService // 用户基础信息处理 $data = self::UserBaseHandle($data, $params); + // 用户openid + $openid = self::UserOpenidHandle($params); + if(!empty($openid['field']) && !empty($openid['value'])) + { + // openid放入用户data中 + $data[$openid['field']] = $openid['value']; + } + // 用户unionid $unionid = self::UserUnionidHandle($params); if(!empty($unionid['field']) && !empty($unionid['value']))