commit 96a49d1bd60b1463de5667d03f684605a801445f Author: knowpia <9812993@qq.com> Date: Thu Sep 8 15:23:13 2022 +0800 夺 diff --git a/app/.htaccess b/app/.htaccess new file mode 100644 index 0000000..3418e55 --- /dev/null +++ b/app/.htaccess @@ -0,0 +1 @@ +deny from all \ No newline at end of file diff --git a/app/AppService.php b/app/AppService.php new file mode 100644 index 0000000..96556e8 --- /dev/null +++ b/app/AppService.php @@ -0,0 +1,22 @@ +app = $app; + $this->request = $this->app->request; + + // 控制器初始化 + $this->initialize(); + } + + // 初始化 + protected function initialize() + {} + + /** + * 验证数据 + * @access protected + * @param array $data 数据 + * @param string|array $validate 验证器名或者验证规则数组 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 + * @return array|string|true + * @throws ValidateException + */ + protected function validate(array $data, $validate, array $message = [], bool $batch = false) + { + if (is_array($validate)) { + $v = new Validate(); + $v->rule($validate); + } else { + if (strpos($validate, '.')) { + // 支持场景 + [$validate, $scene] = explode('.', $validate); + } + $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); + $v = new $class(); + if (!empty($scene)) { + $v->scene($scene); + } + } + + $v->message($message); + + // 是否批量验证 + if ($batch || $this->batchValidate) { + $v->batch(true); + } + + return $v->failException(true)->check($data); + } + +} diff --git a/app/CodeAndMessage.php b/app/CodeAndMessage.php new file mode 100644 index 0000000..f8a8426 --- /dev/null +++ b/app/CodeAndMessage.php @@ -0,0 +1,30 @@ +$e->getFile(), + 'line'=>$e->getLine(), + 'message'=>$e->getMessage() + ]; + return show(SYSTEM_ERROR_MESSAGE,SYSTEM_ERROR_CODE,$data,$GLOBALS['appKey']); + // 其他错误交给系统处理 +// return parent::render($request, $e); + } +} diff --git a/app/Request.php b/app/Request.php new file mode 100644 index 0000000..fc9aba0 --- /dev/null +++ b/app/Request.php @@ -0,0 +1,8 @@ + $code,"message"=>$message,"data"=>$data]; + if(env("APP_DEBUG")){ + return json($result,$httpStatus); + } + return json(["RD"=>app\tools\Aes::encrypt(json_encode($result),$appKey)],$httpStatus); + } +} + +/** + * 验证手机号是否正确 + * @author honfei + * @param number $mobile + */ +if(!function_exists('is_mobile_number')) { + function is_mobile_number($mobile) + { + if (!is_numeric($mobile)) return false; + return (bool)preg_match('#^1[3,4,5,7,8,9]{1}[\d]{9}$#', $mobile); + } +} + + +/** + * 生成随机字符串 + * @param int $length 生成随机字符串的长度 + * @param string $char 组成随机字符串的字符串 + * @return string $string 生成的随机字符串 + */ +if(!function_exists('strRand')) { + function strRand(int $length = 32, string $char = '0123456789&abcdefghijklmnopqrstuvwxyz@ABCDEFGHIJKLMNOPQRSTUVWXYZ$') + { + if (!is_int($length) || $length < 0) { + return false; + } + $string = ''; + for ($i = $length; $i > 0; $i--) { + $string .= $char[mt_rand(0, strlen($char) - 1)]; + } + return $string; + } +} + + + +/** + * Discuz 经典双向加密/解密 + * @param string $string 明文 或 密文 + * @param string $operation DECODE表示解密,其它表示加密 + * @param string $key 密匙 + * @param string $expiry 密文有效期 + */ +if(!function_exists('authcode')) { + function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) + { + if ($operation == 'DECODE') { + $string = str_replace(' ', '+', $string); + } + $ckey_length = 4; + $key = md5($key ? $key : env('data_auth_key')); + $keya = md5(substr($key, 0, 16)); + $keyb = md5(substr($key, 16, 16)); + $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : ''; + $cryptkey = $keya . md5($keya . $keyc); + $key_length = strlen($cryptkey); + $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string; + $string_length = strlen($string); + $result = ''; + $box = range(0, 255); + $rndkey = []; + for ($i = 0; $i <= 255; $i++) { + $rndkey[$i] = ord($cryptkey[$i % $key_length]); + } + for ($j = $i = 0; $i < 256; $i++) { + $j = ($j + $box[$i] + $rndkey[$i]) % 256; + $tmp = $box[$i]; + $box[$i] = $box[$j]; + $box[$j] = $tmp; + } + for ($a = $j = $i = 0; $i < $string_length; $i++) { + $a = ($a + 1) % 256; + $j = ($j + $box[$a]) % 256; + $tmp = $box[$a]; + $box[$a] = $box[$j]; + $box[$j] = $tmp; + $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); + } + if ($operation == 'DECODE') { + if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) { + return substr($result, 26); + } else { + return ''; + } + } else { + return $keyc . str_replace('=', '', base64_encode($result)); + } + } +} + +use OSS\Core\OssException; +use OSS\OssClient; + +//阿里云OSS +/* +if (!function_exists('aliyun')) { + function aliyun($savePath, $category = '', $isunlink = false, $bucket = "hphb-storage") + { + $accessKeyId = env('aliyunsms.accessKeyId');//去阿里云后台获取秘钥 + $accessKeySecret = env('aliyunsms.accesskey');//去阿里云后台获取秘钥 + $endpoint = env('aliyunsms.oss_endpoint');//你的阿里云OSS地址 + $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); + // 判断bucketname是否存在,不存在就去创建 + if (!$ossClient->doesBucketExist($bucket)) { + $ossClient->createBucket($bucket); + } + $category = empty($category) ? $bucket : $category; + $savePath = str_replace("\\", "/", $savePath); + $object = '/' . $savePath;//想要保存文件的名称 + $file = env("upload_directory").'\\' . $savePath;//文件路径,必须是本地的。 + + try { + echo 'bc'; + $obj = $ossClient->uploadFile($bucket, $object, $file); + echo 'abc'; + if ($isunlink == true) { + unlink($file); + } + print_r($obj); + } catch (OssException $e) { + echo $e->getErrorMessage(); + } + $web = "https://hphb-storage.".env('aliyunsms.oss_endpoint').'/'.$object;//这里是你阿里云oss外网访问的Bucket域名 + return $web; + } +} +*/ +if (!function_exists('aliyun')) { + function aliyun($localfile = '', $path = '') + { + $config = [ + 'access' => env('aliyunsms.accessKeyId'), + 'access_key' => env('aliyunsms.accesskey'), + 'bucket' => 'hphb-storage', + 'url' => 'https://oss-cn-beijing.aliyuncs.com' + ]; + $path = "r/".$localfile; + $localfile = env("upload_directory").'/' . $localfile;//文件路径,必须是本地的。 + if (!file_exists($localfile)) { + return ('Not found file'); + } + if ($path == "") { + return ['code' => 1, 'message' => "远程文件名不能为空"]; + } + + $accessKeyId = $config['access']; + $accessKeySecret = $config['access_key']; + $endpoint = $config['url']; + try { + $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); + $info = $ossClient->uploadFile($config['bucket'], $path, $localfile); + if(empty($info['info']['url'])){ + return ['code' => 1, 'message' => "上传失败"]; + } + return ['code' => 0, 'message' => "", 'url' => $info['info']['url']]; + } catch (OssException $e) { + return ['code' => 1, 'message' => $e->getMessage()]; + } + } +} + + + +function getExt($filename) +{ + $arr = explode('.',$filename); + return array_pop($arr); +} + + +function StudentToArray($list = []) : array { + $result = []; + $result['lastIndex'] = 0; + $result['list']=[]; + foreach($list as $key => $vo){ + if($vo['id']>$result['lastIndex']){ + $result['lastIndex'] = $vo['id']; + } + $result["list"][] = [ + "id"=>$vo['id'], + "hot"=>$vo['hot'], + "avatar"=>$vo['avatar'], + "nickname"=>$vo['nickname'], + "is_disabled"=>$vo['disabled'], + "type"=>$vo["type"], + "identifier"=>$vo['identifier'], + "article_count"=>$vo['article_count'], + "city"=>$vo['city'], + "school"=>$vo['school'], + "age"=>$vo['age'], + ]; + } + if(count($list)where("id", "IN", $UserIds)->field($getFieldString)->select()->toArray(); + foreach ($UserLists as $vo) { + $getAllUsersMessage[$vo['id']] = $vo; + } + return $getAllUsersMessage; + } +} diff --git a/app/controller/Address.php b/app/controller/Address.php new file mode 100644 index 0000000..56591b9 --- /dev/null +++ b/app/controller/Address.php @@ -0,0 +1,75 @@ +where("userid",$userid)->select()->toArray(); + return show("获取成功!",SUCCESS_CODE,$list); + } + + //地址详细信息 + public function getaddress(){ + $userid = $GLOBALS['data']['userid']; + if (empty($userid)) { + return show("请登录后再发布!"); + } + + $address_id = $GLOBALS['data']['data']['address_id']; + if (empty($address_id)) { + return show("请输入地址编号!"); + } + + $info = Db::name("app_address")->where("id",$address_id)->find(); + if(empty($info) || $info['userid']!=$userid){ + return show("找不到该地址信息!"); + } + return show("获取成功!",SUCCESS_CODE,$info); + } + + //添加地址 + public function plus() + { + $post = $GLOBALS['data']['data']; + $userid = $GLOBALS['data']['userid']; + if (empty($userid)) { + return show("请登录后再发布!"); + } + + if(empty($post['name'])) return show("请输入收货人收件人姓名!"); + if(empty($post['mobile'])) return show("请输入收货人电话!"); + if(empty($post['province'])) return show("请输入省份!"); + if(empty($post['city'])) return show("请输入城市!"); + if(empty($post['area'])) return show("请输入区!"); + if(empty($post['detail'])) return show("请输入详细地址!"); + + $default = $post['is_default']; + if(!in_array($default, [0,1])){ + return show("默认地址值超出范围!"); + }else{ + if($default == 1){ + Db::name("app_address")->where("userid",$userid)->update(["is_default"=>0]); + } + } + + Db::name("app_address")->insert([ + "userid"=>$userid, + "name"=>$post['name'], + "mobile"=>$post['mobile'], + "province"=>$post['province'], + "city"=>$post['city'], + "area"=>$post['area'], + "detail"=>$post['detail'], + "is_default"=>$post['is_default'], + ]); + + return show("添加成功!", SUCCESS_CODE, []); + } +} \ No newline at end of file diff --git a/app/controller/Article.php b/app/controller/Article.php new file mode 100644 index 0000000..69e3b41 --- /dev/null +++ b/app/controller/Article.php @@ -0,0 +1,116 @@ +insert([ + "text"=>$post['content'], + "imgs"=>$post['imgs'], + "userid"=>$userid, + "createtime"=>time(), + "click"=>0 + ]); + Db::name("student")->inc("article_count",1)->where("id",$userid)->update(); + return show("发布成功!",SUCCESS_CODE,[]); + } + + public function delete(){ + $userid = $GLOBALS['data']['userid']; + if(empty($userid)){ + return show("请登录后操作!"); + } + $article_id = $GLOBALS['data']['data']["article_id"]; + if(empty($article_id)){ + return show("请上输入动态ID"); + } + + $info = Db::name("app_article")->where("id",$article_id)->find(); + if(empty($info) || $info['userid']!=$userid){ + return show("找不到该动态信息!"); + } + Db::name("app_article")->where("id",$article_id)->delete(); + return show("删除成功!",SUCCESS_CODE,[]); + } + + public function lists(){ + $userid = $GLOBALS['data']['userid']; + if(empty($userid)){ + return show("请登录后操作!"); + } + $lastIndex = empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"]; + if($lastIndex == 0){ + $where = "userid={$userid} and id>0"; + }else{ + $where = "userid={$userid} and id<".$lastIndex; + } + $result["lastIndex"] = 0; + $list = Db::name("app_article")->where($where)->order("id desc")->order('id desc')->limit(env("page_count"))->select()->toArray(); + foreach($list as $vo){ + $result['lastIndex'] = $vo['id']; + $result["list"][] = $vo; + } + if(count($list)where("id",$article_id)->find(); + if(empty($info)) return show("找不到该动态信息!"); + return show(SUCCESS_MESSAGE,SUCCESS_CODE,$info); + } + + public function getlists(){ + $userid = $GLOBALS['data']['userid']; + if(empty($userid)){ + return show("请登录后操作!"); + } + if(empty($GLOBALS['data']['data']['student_userid'])){ + return show("请输入用户ID!"); + } + $student_userid = $GLOBALS['data']['data']['student_userid']; + + $student = Db::name("student")->field("id")->where("id",$student_userid)->find(); + + if(empty($student)) return show("找不到用户信息!"); + + $lastIndex = empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"]; + if($lastIndex == 0){ + $where = "userid={$student_userid} and id>0"; + }else{ + $where = "userid={$student_userid} and id<".$lastIndex; + } + $result["lastIndex"] = 0; + $list = Db::name("app_article")->where($where)->order("id desc")->order('id desc')->limit(env("page_count"))->select()->toArray(); + foreach($list as $vo){ + $result['lastIndex'] = $vo['id']; + $result["list"][] = $vo; + } + if(count($list)where("id",$student_id)->field("id")->find(); + if(empty($info)){ + return show("找不到该学生信息!"); + } + + $data = [ + "userid"=>$userid, + "student_id"=>$student_id, + "createtime"=>date("Y-m-d",time()) + ]; + $data['sha'] = sha1(json_encode($data)); + + Db::startTrans(); + try { + $info = Db::name("app_help_log")->where("sha", $data['sha'])->find(); + if (!empty($info)) { + return show("你今天已经为他助力过,谢谢!"); + } else { + Db::name("app_help_log")->insert($data); + } + + $appHelp = Db::name("app_help")->where(["userid" => $userid, "student_id" => $student_id])->find(); + if (empty($appHelp)) { + Db::name("app_help")->insert([ + "userid" => $userid, + "student_id" => $student_id, + "count" => 1 + ]); + } else { + Db::name("app_help")->where(["id" => $appHelp['id']])->inc("count", 1)->update(); + } + Db::commit(); + return show("助力成功!", SUCCESS_CODE, []); + }catch (\Exception $e) { + Db::rollback(); + return show("助力失败!"); + } + } + + public function lists(){ + if(empty($GLOBALS['data']['data']['student_id'])){ + return show("请输入要助力的用户id!"); + } + $student_id = $GLOBALS['data']['data']['student_id']; + + $info = Db::name("student")->where("id",$student_id)->field("id")->find(); + if(empty($info)){ + return show("找不到该学生信息!"); + } + + $lastIndex = lastindex(); + if($lastIndex == 0) { + $lastIndex = 1; + } + $result = []; + $list = Db::name("appHelp")->where("student_id",$student_id)->limit(env("page_count"))->order('count desc')->paginate([ + "list_rows"=>env("page_count"), + "page"=>$lastIndex + ]); + + if(empty($list)) return show("获取成功", SUCCESS_CODE,$result); + if($list->currentPage() < $list->lastPage()){ + $result['lastIndex'] = $lastIndex +1; + }else{ + $result['lastIndex'] = 0; + } + + $users = getAllUsersMessage($list,'userid','id,nickname,avatar'); + + foreach($list as $vo){ + $result['list'][] = [ + "id"=>$vo['id'], + "userid"=>$vo['userid'], + "username"=>empty($users[$vo['userid']]['nickname'])?'':$users[$vo['userid']]['nickname'], + "count"=>$vo['count'] + ]; + } + + return show("获取成功!", SUCCESS_CODE, $result); + + } + + +} \ No newline at end of file diff --git a/app/controller/Main.php b/app/controller/Main.php new file mode 100644 index 0000000..86a88df --- /dev/null +++ b/app/controller/Main.php @@ -0,0 +1,145 @@ +1]; +// echo authcode(json_encode($j),'f'); + $GLOBALS['data'] = []; // 全局变量 + $api_version = ''; //当前版本号 + $timeout = env('APP_DEBUG')?1000000:20; //处理超时时间 + $userid = 0; //默认用户ID是0 + $appKey = env('app.DEFAULT_KEY'); + $GLOBALS['appKey'] = env('app.DEFAULT_KEY');//定义全局变量,报错时使用 + $startTime = microtime(true); //开始时间时间 + $LogArray = []; //记录日志数组 + $message = [ + 'token_error' => 'Token验证失败', + 'token_Illegal' => 'Token非法', + 'data_Illegal' => '非法数据', + 'logout_success' => '退出成功', + 'sign_error' => '数据签名错误', + 'data_timeout' => '请求数据超时', + 'cmd_error' => '没有CMD信息', + ]; +// $independent = ["user.logout"]; + try { + //获取访问者IP + $LogArray['ip'] = get_client_ip(); + + //获取用户上传的token + $clientToken = request()->post('tk'); + + //如果TOKEN不存在,则设置为空 + $clientToken = !empty($clientToken)?$clientToken:''; + + //记录日志开始,记录token和开始时间 + $LogArray['token'] = $clientToken; + $LogArray['start_time'] = $startTime; + + //如果存在TOKEN则需要解析token + $appToken = ""; + if ($clientToken) { + $tk = json_decode(authcode($clientToken),true); + $userid = $tk['userid']; + } + + //解密数据 + $data = request()->post(); + + + //定义常量 + define('PLATFORM', $data['RequestBody']['Platform'] ?? ''); //手机系统平台 IOS、ANDROID + define('DEVICE', $data['RequestBody']['Device'] ?? ''); //手机型号 + define('IM_NUMBER', $data['RequestBody']['IM'] ?? ''); //设备码 + define('APP_VERSION', $data['RequestBody']['APPVersion'] ?? ''); //版本号 + + + + $LogArray['userid'] = $userid; + $LogArray['platform'] = PLATFORM; + $LogArray['device'] = DEVICE; + $LogArray['im_number'] = IM_NUMBER; + $LogArray['app_version'] = APP_VERSION; + $LogArray['api_version'] = $api_version; + $LogArray['cmd'] = !empty($data['RequestBody']['CMD'])?$data['RequestBody']['CMD']:''; + $LogArray['data'] = json_encode($data); + + + if(empty($data['cmd'])) { + return show($message['cmd_error'],MISSING_PARAMETER); + } + + /********** + * start 调用退出 ************* + * 把apptoken表数据清空,只退出当前设置 + * 其它设置信息保留 + */ + if (strtolower($data['cmd']) == "sign.logout") { + if(!empty($appToken['id'])) { + $this->logout($appToken['id']); + $LogArray['return_data'] = $message['logout_success']; + $this->log($LogArray); + } + return show("退出成功!",SUCCESS_CODE); + } + + + if (($data['cmd'])) { + $action = explode('.', $data['cmd']); + if (is_array($action)) { + $ClassName = '\\app\\controller\\' . ucfirst($action[0]); + $FunctionName = $action[1]; + $class = new $ClassName(); + $GLOBALS['data'] = [ + 'data' => $data, + 'userid' => $userid + ]; + if(!empty($_FILES['file'])){ + $GLOBALS['data']['file'] = $_FILES['file']; + } + $backdata = $class->$FunctionName(); + $LogArray['return_data'] = !empty($GLOBALS['data']['returnData'])?$GLOBALS['data']['returnData']:''; + $this->log($LogArray); + unset($data); + return $backdata; + } + } + + } catch (\Exception $e) { + if(env("APP_DEBUG")){$msg = $e->getMessage();}else{$msg = "服务器故障!";} + return show($msg,SYSTEM_ERROR_CODE); + } + } + + private function logout($userid) + { + (new \app\model\AppToken)->where('id', $userid)->delete(); + } + + private function log($data) + { + $addData = [ + 'ip' => !empty($data['ip'])?$data['ip']:'', + 'token' => !empty($data['token'])?$data['token']:'', + 'start_time' => !empty($data['start_time'])?$data['start_time']:'', + 'userid' => !empty($data['userid'])?$data['userid']:'', + 'platform' => !empty($data['platform'])?$data['platform']:'', + 'device' => !empty($data['device'])?$data['device']:'', + 'im_number' => !empty($data['im_number'])?$data['im_number']:'', + 'app_version' => !empty($data['app_version'])?$data['app_version']:'', + 'api_version' => !empty($data['api_version'])?$data['api_version']:'', + 'cmd' => !empty($data['cmd'])?$data['cmd']:'', + 'data' => !empty($data['data'])?$data['data']:'', + 'return_data' => !empty($data['return_data'])?$data['return_data']:'', + 'end_time' => microtime(true), + 'usetime' => microtime(true) - $data['start_time'] + ]; + $applog = (new \app\model\AppLog)->insertGetId($addData); + return $applog; + } +} diff --git a/app/controller/Ranking.php b/app/controller/Ranking.php new file mode 100644 index 0000000..946d905 --- /dev/null +++ b/app/controller/Ranking.php @@ -0,0 +1,49 @@ +where($where)->limit(env("page_count"))->order('hot desc')->paginate([ + "list_rows"=>env("page_count"), + "page"=>$lastIndex + ]); + + if(empty($list)) return show("获取成功", SUCCESS_CODE,$result); + if($list->currentPage() < $list->lastPage()){ + $result['lastIndex'] = $lastIndex +1; + }else{ + $result['lastIndex'] = 0; + } + + + $result = StudentToArray($list); + return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result); + } + +} diff --git a/app/controller/Search.php b/app/controller/Search.php new file mode 100644 index 0000000..971bdbc --- /dev/null +++ b/app/controller/Search.php @@ -0,0 +1,28 @@ + 0"; + }else{ + $where = "id < ".$lastIndex; + } + + $KEY = $post['keywords']; + + $list = Db::name("student")->where("nickname like '{$KEY}%' or city like '{$KEY}%' or school like '{$KEY}%'")->order('hot desc')->limit(env("page_count"))->where($where)->select()->toArray(); + $result = StudentToArray($list); + return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result); + } + +} diff --git a/app/controller/Sign.php b/app/controller/Sign.php new file mode 100644 index 0000000..d28c1e5 --- /dev/null +++ b/app/controller/Sign.php @@ -0,0 +1,111 @@ +where("mobile",$GLOBALS['data']['data']['mobile'])->find(); + if(empty($info)){ + return show("找不到家长信息!"); + } + if($info['password']!=$password){ + return show("密码不正确,请重试!"); + } + + $tokenData = ['userid' => $info['id'],'loginTime' => time(),'rankStr' => strRand(5)]; + $tk = authcode(json_encode($tokenData), 'ENCODE'); + unset($info['password']); + $res = [ + 'TK' => $tk, + 'user' => [ + "userid"=>$info['id'], + "identifier"=>$info['identifier'], + "nickname"=>$info['nickname'], + "mobile"=>$info['mobile'], + "avatar"=> env("admin_pannel_address") . $info['avatar'], + "gender"=>$info['gender'], + "birthday"=>$info['birthday'], + "age"=>$info['age'], + "createtime"=>$info['createtime'], + "is_disabled"=>$info['disabled'], + "type"=>$info["type"], + "hot"=>$info['hot'] + ] + ]; + return show("验证成功!",SUCCESS_CODE,$res); + } + public function getuser(){ + if(empty($GLOBALS['data']['userid'])){ + return show("请上传TOKEN!"); + } + + $info = Db::name("student")->where("id",$GLOBALS['data']['userid'])->find(); + if(empty($info)){ + return show("找不到家长信息!"); + } + $res = [ + 'user' => [ + "userid"=>$info['id'], + "identifier"=>$info['identifier'], + "nickname"=>$info['nickname'], + "mobile"=>$info['mobile'], + "avatar"=> env("admin_pannel_address") . $info['avatar'], + "gender"=>$info['gender'], + "birthday"=>$info['birthday'], + "age"=>$info['age'], + "createtime"=>$info['createtime'], + "is_disabled"=>$info['disabled'], + "type"=>$info["type"], + "hot"=>$info['hot'] + ] + ]; + return show("操作成功!",SUCCESS_CODE,$res); + } + + public function repass(){ + if(empty($GLOBALS['data']['data']['mobile'])){ + return show("手机号不能为空!"); + } + $mobile = $GLOBALS['data']['data']['mobile']; + $info = Db::name("student")->where("mobile",$mobile)->find(); + if(empty($info)){ + return show("找不到用户信息!"); + } + + + if(empty($GLOBALS['data']['data']['code'])){ + return show("验证码不能为空!"); + } + $code = $GLOBALS['data']['data']['code']; + + if(empty($GLOBALS['data']['data']['password'])){ + return show("请输入密码!"); + } + $password = $GLOBALS['data']['data']['password']; + $code = Db::name("app_sms")->order("id desc")->where("mobile", $mobile)->find(); + if(empty($code)){ + return show("请发送短信后再试!"); + } + Db::name("app_sms")->where("id",$code['id'])->inc("count",1)->update(); + if((time() - $code['create_time'])>15*60){ + return show("短信已经失效,请重新发送!"); + } + + + + Db::name("student")->where("id",$info['id'])->update([ + "password" => md5($password) + ]); + return show(SUCCESS_MESSAGE,SUCCESS_CODE,[]); + } +} \ No newline at end of file diff --git a/app/controller/Sms.php b/app/controller/Sms.php new file mode 100644 index 0000000..bd1303a --- /dev/null +++ b/app/controller/Sms.php @@ -0,0 +1,44 @@ +order("id desc")->where("mobile",$mobileNumber)->find(); + if(!empty($info) && (time() - $info['create_time'])<$timeOut){ + return show("请在". ($timeOut-(time()-$info['create_time'])) ."后重新发送!"); + } + $code = rand(111111,999999); + try { + if(!env("APP_DEBUG")){ + $result = \app\tools\Sms::sendmsg($mobileNumber,$code); + if($result['code'] != 1){ + return show("运营商接口无法返回!"); + } + }else{ + $code = "000000"; + } + Db::name("app_sms")->insert([ + "ipaddress"=>get_client_ip(), + "mobile"=>$mobileNumber, + "code"=>$code, + "create_time"=>time(), + "count"=>0 + ]); + return show("发送成功!",SUCCESS_CODE); + }catch(\Exception $e){ + return show("发送失败,请联系客服人员!"); + } + } +} \ No newline at end of file diff --git a/app/controller/Student.php b/app/controller/Student.php new file mode 100644 index 0000000..fba8939 --- /dev/null +++ b/app/controller/Student.php @@ -0,0 +1,47 @@ +where($where)->limit(env("page_count"))->order('hot desc')->paginate([ + "list_rows"=>env("page_count"), + "page"=>$lastIndex + ]); + + if(empty($list)) return show("获取成功", SUCCESS_CODE,$result); + if($list->currentPage() < $list->lastPage()){ + $result['lastIndex'] = $lastIndex +1; + }else{ + $result['lastIndex'] = 0; + } + + + $result = StudentToArray($list); + return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result); + } + +} diff --git a/app/controller/Upload.php b/app/controller/Upload.php new file mode 100644 index 0000000..494d00d --- /dev/null +++ b/app/controller/Upload.php @@ -0,0 +1,34 @@ +$but['url']]); + }else{ + return show('服务器繁忙,请联系管理员'); + } + + } +} \ No newline at end of file diff --git a/app/controller/User.php b/app/controller/User.php new file mode 100644 index 0000000..168c61d --- /dev/null +++ b/app/controller/User.php @@ -0,0 +1,128 @@ +where("id",$userid)->find(); + if(empty($info)) return show("无此用户信息"); + unset($info['openid']); + return show(SUCCESS_MESSAGE,SUCCESS_CODE,$info); + } + + //修改头像 + public function modify_avatar(){ + if(empty($GLOBALS['data']['userid'])){ + return show("请上传TOKEN!"); + } + $userid = $GLOBALS['data']['userid']; + + $avatarUrl = $GLOBALS['data']['data']['avatar_url']; + if(empty($avatarUrl)){ + return show("请上传头像!"); + } + + Db::name("app_users")->where("id",$userid)->update(['avatar'=>$avatarUrl]); + return show("头像修改成功!",SUCCESS_CODE,[]); + } + + //修改昵称 + public function modify_nickname(){ + if(empty($GLOBALS['data']['userid'])){ + return show("请上传TOKEN!"); + } + $userid = $GLOBALS['data']['userid']; + + $nickname = $GLOBALS['data']['data']['nickname']; + if(empty(nickname)){ + return show("请输入昵称!"); + } + + Db::name("app_users")->where("id",$userid)->update(['nickname'=>$nickname]); + return show("昵称修改成功!",SUCCESS_CODE,[]); + } + + //狮友认证 + public function verify(){ + if(empty($GLOBALS['data']['userid'])){ + return show("请上传TOKEN!"); + } + $userid = $GLOBALS['data']['userid']; + + $mobileNumber = $GLOBALS['data']['data']['mobile']; + if(!is_mobile_number($mobileNumber)){ + return show("手机号不正确!"); + } + + $res = Db::name("shiyou")->where("mobile",$mobileNumber)->find(); + if(empty($res)) { + return show("未找到狮友信息!"); + } + + $code = Db::name("app_sms")->order("id desc")->where("mobile", $mobileNumber)->find(); + if(empty($code)){ + return show("请发送短信后再试!"); + } + Db::name("app_sms")->where("id",$code['id'])->inc("count",1)->update(); + if((time() - $code['create_time'])>15*60){ + return show("短信已经失效,请重新发送!"); + } + + if($GLOBALS['data']['data']['code'] != $code["code"]){ + return show("验证码不正确!"); + } + + Db::name("app_users")->where("id",$userid)->update(['identity'=>1]); + return show("狮友认证成功!",SUCCESS_CODE,[]); + } + + //发送验证码 + public function getcode(){ + if(empty($GLOBALS['data']['data']['mobile'])){ + return show("手机号不能为空!"); + } + $mobileNumber = $GLOBALS['data']['data']['mobile']; + if(!is_mobile_number($mobileNumber)){ + return show("手机号不正确!"); + } + + $user = Db::name("shiyou")->where("mobile",$mobileNumber)->find(); + if(empty($user)) return show("手机号狮友库中未找到,请核对!"); + $timeOut = 60; + $info = Db::name("app_sms")->order("id desc")->where("mobile",$mobileNumber)->find(); + if(!empty($info) && (time() - $info['create_time'])<$timeOut){ + return show("请在". ($timeOut-(time()-$info['create_time'])) ."后重新发送!"); + } + $code = rand(111111,999999); + try { + if(!env("APP_DEBUG")){ + $result = \app\tools\Sms::sendmsg($mobileNumber,$code); + if($result['code'] != 1){ + return show("运营商接口无法返回!"); + } + }else{ + $code = "000000"; + } + Db::name("app_sms")->insert([ + "ipaddress"=>get_client_ip(), + "mobile"=>$mobileNumber, + "code"=>$code, + "create_time"=>time(), + "count"=>0 + ]); + return show("发送成功!",SUCCESS_CODE); + }catch(\Exception $e){ + return show("发送失败,请联系客服人员!"); + } + } + + +} \ No newline at end of file diff --git a/app/event.php b/app/event.php new file mode 100644 index 0000000..e9851bb --- /dev/null +++ b/app/event.php @@ -0,0 +1,17 @@ + [ + ], + + 'listen' => [ + 'AppInit' => [], + 'HttpRun' => [], + 'HttpEnd' => [], + 'LogLevel' => [], + 'LogWrite' => [], + ], + + 'subscribe' => [ + ], +]; diff --git a/app/middleware.php b/app/middleware.php new file mode 100644 index 0000000..d2c3fda --- /dev/null +++ b/app/middleware.php @@ -0,0 +1,10 @@ + Request::class, + 'think\exception\Handle' => ExceptionHandle::class, +]; diff --git a/app/service.php b/app/service.php new file mode 100644 index 0000000..db1ee6a --- /dev/null +++ b/app/service.php @@ -0,0 +1,9 @@ + | +// +------------------------------------------------+ + +namespace app\tools; + +class Aes +{ + /** + * + * @param string $string 需要加密的字符串 + * @param string $key 密钥 + * @return string + */ + /* + public static function encrypt($string, $key) + { + $data = openssl_encrypt($string, 'AES-256-ECB', $key, OPENSSL_RAW_DATA, null); + return base64_encode($data); + } + */ + /** + * @param string $string 需要解密的字符串 + * @param string $key 密钥 + * @return string + */ + /* + public static function decrypt($string, $key) + { + $string = base64_decode($string); + $data = openssl_decrypt($string, 'AES-256-ECB', $key, OPENSSL_RAW_DATA, null); + return $data; + } + */ + /** + * aes加密 + * AES加密(PHP+FLUTTER) + */ + public static function encrypt($string ,$key) + { + return openssl_encrypt($string,"AES-256-CBC",$key,0 ,"0000000000000000"); + } + + /** + * aes解密 + */ + public static function decrypt($string ,$key) + { + return openssl_decrypt($string,"AES-256-CBC",$key,0,"0000000000000000"); + } + +} diff --git a/app/tools/Sms.php b/app/tools/Sms.php new file mode 100644 index 0000000..ee7471c --- /dev/null +++ b/app/tools/Sms.php @@ -0,0 +1,127 @@ + 0, 'message' => '参数不全']; + } + AlibabaCloud::accessKeyClient(env('aliyunsms.accessKeyId'), env('aliyunsms.accesskey')) + ->regionId(env('aliyunsms.regionid')) + ->asDefaultClient(); + try { + $result = AlibabaCloud::rpc() + ->product('Dysmsapi') + ->version('2017-05-25') + ->action('SendSms') + ->method('POST') + ->host('dysmsapi.aliyuncs.com') + ->options([ + 'query' => [ + 'RegionId' => env('aliyunsms.regionid'), + 'PhoneNumbers' => $number, + 'SignName' => $signName, + 'TemplateCode' => $template, + 'TemplateParam' => "{\"code\":\"" . $code . "\"}", + ], + ]) + ->request(); + $result = $result->toArray(); + return ['code' => 1, 'info' => $result]; + } catch (ClientException $e) { + return ['code' => 0, 'message' => $e->getErrorMessage()]; + } catch (ServerException $e) { + return ['code' => 0, 'message' => $e->getErrorMessage()]; + } + } + /** + * 获得用户的短信验证码 + * + * @param string $mobile [手机号] + * @return array + */ + public static function getMobileCode($mobile) + { + $smsExpiration = env('system.smsExpiration'); + $codeInfo = \app\tools\model\MobileCode::where('state=0 and mobile="'.$mobile.'"')->order('id desc')->find(); + $notMessage = '请先发送短信再验证'; + if ($codeInfo) { + if ((time() - $codeInfo['create_at']) <= $smsExpiration) { + return ['code' => 1, 'MobileCode' => $codeInfo['code'],'check_id'=>$codeInfo['id']]; + } + if ((time() - $codeInfo['create_at']) > $smsExpiration && (time() - $codeInfo['create_at']) <= 60 * 30) { + return ['code' => 0, 'message' => '验证码已过期']; + } + return ['code' => 0, 'message' => $notMessage]; + } + return ['code' => 0, 'message' => $notMessage]; + } + + /** + * 号码认证服务,利用一键登录TOKEN获取手机号 + * + * @param string $token + * @return array + */ + public static function getMobileNumber($token = ''): array + { + /** back array + * { + * "GetMobileResultDTO": { + * "Mobile": "18620725473" + * }, + * "Message": "OK", + * "RequestId": "098CC43B-8006-4127-9DC5-2B30CA741745", + * "Code": "OK" + * } + */ + if ($token == '') { + return ['code' => 0, 'message' => '参数不全']; + } + AlibabaCloud::accessKeyClient(env('aliyunsms.accessKeyId'), env('aliyunsms.accesskey')) + ->regionId('cn-hangzhou') + ->asDefaultClient(); + try { + $result = AlibabaCloud::rpc() + ->product('Dypnsapi') + ->scheme('https') + ->version('2017-05-25') + ->action('GetMobile') + ->method('POST') + ->host('dypnsapi.aliyuncs.com') + ->options([ + 'query' => [ + 'RegionId' => "cn-hangzhou", + 'AccessToken' => $token, + ], + ])->request(); + return ['code' => 1, 'info' => $result->toArray()]; + } catch (ClientException $e) { + return ['code' => 0, 'message' => $e->getErrorMessage()]; + } catch (ServerException $e) { + return ['code' => 0, 'message' => $e->getErrorMessage()]; + } + + } +}