|
@@ -1,157 +1,262 @@
|
|
|
-<?php
|
|
|
-namespace app\newhome\controller;
|
|
|
-
|
|
|
-use think\Controller;
|
|
|
-use app\user\model\UserSkill;
|
|
|
-
|
|
|
-class User extends Controller {
|
|
|
-
|
|
|
- private $userModel, $skillModel;
|
|
|
-
|
|
|
- public function _initialize(){
|
|
|
- $this->skillModel = new UserSkill();
|
|
|
- $this->userModel = new \app\user\model\User();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public function login()
|
|
|
- {
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $info = $this->userModel->loginByUid($data['u']);
|
|
|
- $info['s'] = $this->skillModel->getUserSkill($info['i']);
|
|
|
- $info['time'] = time();
|
|
|
-
|
|
|
- return json($info);
|
|
|
- }
|
|
|
-
|
|
|
- public function getskill(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $info = $this->skillModel->getSkillByInfo($data['i']);
|
|
|
- return json($info);
|
|
|
- }
|
|
|
-
|
|
|
- public function addskill(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $info = $this->skillModel->addUserSkill($data['u'], $data['s']);
|
|
|
- return json($info);
|
|
|
- }
|
|
|
-
|
|
|
- public function other(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $res = $this->userModel->getUserById($data['u']);
|
|
|
- $path = "load/".$res['id'].'.txt';
|
|
|
-
|
|
|
- $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
- $info = fread($file, filesize($path));
|
|
|
- fclose($file);
|
|
|
-
|
|
|
- return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
- }
|
|
|
-
|
|
|
- public function load(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $id = $data['u'];
|
|
|
-
|
|
|
- if(strlen($id) > 10){
|
|
|
- $res = $this->userModel->getUserById($id);
|
|
|
- }else{
|
|
|
- $res = $this->userModel->getUserByCode($id);
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($res)) return json(['error'=>1023]);
|
|
|
- $path = "load/".$res['id'].".txt";
|
|
|
-
|
|
|
- if(!is_file($path)) $path = "load/".$res['short'].".txt";
|
|
|
-
|
|
|
- $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
- $info = fread($file, filesize($path));
|
|
|
- fclose($file);
|
|
|
-
|
|
|
- return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
- }
|
|
|
-
|
|
|
- public function save(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $id = $data['u'];
|
|
|
- $version = $data['v'];
|
|
|
- $path = "load/$id.txt";
|
|
|
-
|
|
|
- $res = $this->userModel->getUserById($id);
|
|
|
- if(empty($res)) return json(['error'=>1023]);
|
|
|
-
|
|
|
- $oldversion = $res['version'];
|
|
|
-
|
|
|
- if($version > $oldversion && $oldversion > 0){
|
|
|
- // 读取旧文件
|
|
|
- $old_file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
- $info = fread($old_file, filesize($path));
|
|
|
- fclose($old_file);
|
|
|
- // 备份旧文件
|
|
|
- $backup_file = fopen("backup/$id-$oldversion.txt", 'w') or die(json(['error'=>1009]));
|
|
|
- fwrite($backup_file, $info);
|
|
|
- fclose($backup_file);
|
|
|
-
|
|
|
- $this->userModel->update(['version'=>$version], ['id'=>$id]);
|
|
|
- }
|
|
|
-
|
|
|
- $file = fopen($path, 'w') or die(json(['error'=>1009]));
|
|
|
- fwrite($file, $data['l']);
|
|
|
- fclose($file);
|
|
|
-
|
|
|
- return json(['error'=>0]);
|
|
|
- }
|
|
|
-
|
|
|
- public function rand(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $id = $this->userModel->randOtherInfoById($data['i']);
|
|
|
- if(strlen($id) > 10){
|
|
|
- $res = $this->userModel->getUserById($id);
|
|
|
- }else{
|
|
|
- $res = $this->userModel->getUserByCode($id);
|
|
|
- }
|
|
|
-
|
|
|
- $path = "load/$id.txt";
|
|
|
- $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
- $info = fread($file, filesize($path));
|
|
|
- fclose($file);
|
|
|
-
|
|
|
- return json(['l'=>$info, 'p'=>$res['praise'], 'i'=>$res['id']]);
|
|
|
- }
|
|
|
-
|
|
|
- public function delete(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $id = $data['s'];
|
|
|
-
|
|
|
- $path = "load/$id.txt";
|
|
|
- $res = unlink($path);
|
|
|
-
|
|
|
- return json(['r'=>(($res)?1:0)]);
|
|
|
- }
|
|
|
-
|
|
|
- public function look(){
|
|
|
- $res = $this->userModel->lookList();
|
|
|
-
|
|
|
- return $res;
|
|
|
- }
|
|
|
-
|
|
|
- public function nickname(){
|
|
|
- $data = decode($this->request->post());
|
|
|
-
|
|
|
- $nickname = trim($data['n']);
|
|
|
- $res = $this->userModel->findUserByName($nickname);
|
|
|
- if($res) return json(['error'=>2020]);
|
|
|
-
|
|
|
- $this->userModel->addAndSave(['id'=>$data['u'], 'nickname'=>$nickname]);
|
|
|
-
|
|
|
- return json(['error'=>0]);
|
|
|
- }
|
|
|
-
|
|
|
+<?php
|
|
|
+namespace app\newhome\controller;
|
|
|
+
|
|
|
+use think\Controller;
|
|
|
+use app\user\model\UserSkill;
|
|
|
+
|
|
|
+class User extends Controller {
|
|
|
+
|
|
|
+ private $userModel, $skillModel;
|
|
|
+
|
|
|
+ public function _initialize(){
|
|
|
+ $this->skillModel = new UserSkill();
|
|
|
+ $this->userModel = new \app\user\model\User();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function login()
|
|
|
+ {
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $info = $this->userModel->loginByUid($data['u'], isset($data['e']) ? $data['e'] : '');
|
|
|
+ $info['s'] = $this->skillModel->getUserSkill($info['i']);
|
|
|
+// $last_login = strtotime($info['t']);
|
|
|
+// $now = time();
|
|
|
+// $offline_time = $now - $last_login > 21600 ? 21600 : $now - $last_login;
|
|
|
+// $info['time'] = $offline_time; //暂时限制离线时间上限,修正一个客户端版本的错误问题
|
|
|
+ $info['time'] = time();
|
|
|
+
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function sdk_login()
|
|
|
+ {
|
|
|
+ $data = decode($this->request->post());
|
|
|
+ $arr = explode("|", $data['e']);
|
|
|
+ $sdk_id = $arr[0];
|
|
|
+ $ts = $arr[1];
|
|
|
+ $sign = $arr[2];
|
|
|
+
|
|
|
+ if($sign != md5($sdk_id.$ts."CzNLahsrSMBcSJF6"))
|
|
|
+ {
|
|
|
+ return json(['error'=>1009]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = $this->userModel->loginBySdk($sdk_id);
|
|
|
+ $info['time'] = time();
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getskill(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $info = $this->skillModel->getSkillByInfo($data['i']);
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addskill(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $info = $this->skillModel->addUserSkill($data['u'], $data['s']);
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function other(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $res = $this->userModel->getUserById($data['u']);
|
|
|
+ $path = "load/".$res['id'].'.txt';
|
|
|
+
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function load(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $id = $data['u'];
|
|
|
+
|
|
|
+ if(strlen($id) > 10){
|
|
|
+ $res = $this->userModel->getUserById($id);
|
|
|
+ }else{
|
|
|
+ $res = $this->userModel->getUserByCode($id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($res)) return json(['error'=>1023]);
|
|
|
+ $path = "load/".$res['id'].".txt";
|
|
|
+
|
|
|
+ if(!is_file($path)) $path = "load/".$res['short'].".txt";
|
|
|
+
|
|
|
+ if(!is_file($path))
|
|
|
+ return json(['error'=>1009]);
|
|
|
+
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function save(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $id = $data['u'];
|
|
|
+ $version = $data['v'];
|
|
|
+ $path = "load/$id.txt";
|
|
|
+
|
|
|
+ $res = $this->userModel->getUserById($id);
|
|
|
+ if(empty($res)) return json(['error'=>1023]);
|
|
|
+
|
|
|
+ if(!$res['nickname'] && isset($data['n']))
|
|
|
+ {
|
|
|
+ $this->userModel->where('id', $id)->update(['nickname'=>$data['n']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $oldversion = $res['version'];
|
|
|
+
|
|
|
+ if($version > $oldversion && $oldversion > 0){
|
|
|
+ // 读取旧文件
|
|
|
+ $old_file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($old_file, filesize($path));
|
|
|
+ fclose($old_file);
|
|
|
+ // 备份旧文件
|
|
|
+ $backup_file = fopen("backup/$id-$oldversion.txt", 'w') or die(json(['error'=>1009]));
|
|
|
+ fwrite($backup_file, $info);
|
|
|
+ fclose($backup_file);
|
|
|
+
|
|
|
+ $this->userModel->update(['version'=>$version], ['id'=>$id]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $file = fopen($path, 'w') or die(json(['error'=>1009]));
|
|
|
+ fwrite($file, $data['l']);
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['error'=>0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function rand(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+ $my_id = isset($data['i']) ? $data['i'] : 0;
|
|
|
+
|
|
|
+ $id = $this->userModel->randOtherInfoById($data['i']);
|
|
|
+ if(strlen($id) > 10){
|
|
|
+ $res = $this->userModel->getUserById($id);
|
|
|
+ }else{
|
|
|
+ $res = $this->userModel->getUserByCode($id);
|
|
|
+ }
|
|
|
+
|
|
|
+ $path = "load/$id.txt";
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise'], 'i'=>$res['id']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function delete(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $id = $data['s'];
|
|
|
+
|
|
|
+ $path = "load/$id.txt";
|
|
|
+ $res = unlink($path);
|
|
|
+
|
|
|
+ return json(['r'=>(($res)?1:0)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function look(){
|
|
|
+ $res = $this->userModel->lookList();
|
|
|
+
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function nickname(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $nickname = trim($data['n']);
|
|
|
+ $res = $this->userModel->findUserByName($nickname);
|
|
|
+ if($res) return json(['error'=>2020]);
|
|
|
+
|
|
|
+ $this->userModel->addAndSave(['id'=>$data['u'], 'nickname'=>$nickname]);
|
|
|
+
|
|
|
+ return json(['error'=>0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function phone()
|
|
|
+ {
|
|
|
+ $data = decode($this->request->post());
|
|
|
+ $phone = trim($data['p']);
|
|
|
+ $zone = trim($data['z']);
|
|
|
+ $code = trim($data['c']);
|
|
|
+ $user_id = $data['u'];
|
|
|
+
|
|
|
+ $api = 'https://webapi.sms.mob.com';
|
|
|
+ // 发送验证码
|
|
|
+ $response = $this->post_request( $api . '/sms/verify', array(
|
|
|
+ 'appkey' => '20348b3a105da',
|
|
|
+ 'phone' => $phone,
|
|
|
+ 'zone' => $zone,
|
|
|
+ 'code' => $code,
|
|
|
+ ) );
|
|
|
+
|
|
|
+ $response = json_decode($response, true);
|
|
|
+ if($response['status'] != 200)
|
|
|
+ {
|
|
|
+ return json(['error'=>1010, 'msg'=>$response]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $res = $this->userModel->where('mobile', $phone)->find();
|
|
|
+ if($res)
|
|
|
+ {
|
|
|
+ $path = "load/".$res['id'].".txt";
|
|
|
+ if(!is_file($path)) $path = "load/".$res['short'].".txt";
|
|
|
+ if(!is_file($path))
|
|
|
+ return json(['error'=>1009]);
|
|
|
+
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise'], 'mobile'=>$phone]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->userModel->where('id', $user_id)->update(['mobile'=>$phone]);
|
|
|
+ return json(['mobile'=>$phone, 'res'=>$response]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起一个post请求到指定接口
|
|
|
+ *
|
|
|
+ * @param string $api 请求的接口
|
|
|
+ * @param array $params post参数
|
|
|
+ * @param int $timeout 超时时间
|
|
|
+ * @return string 请求结果
|
|
|
+ */
|
|
|
+ private function post_request( $api, array $params = array(), $timeout = 30 ) {
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt( $ch, CURLOPT_URL, $api );
|
|
|
+ // 以返回的形式接收信息
|
|
|
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
|
|
+ // 设置为POST方式
|
|
|
+ curl_setopt( $ch, CURLOPT_POST, 1 );
|
|
|
+ curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
|
|
|
+ // 不验证https证书
|
|
|
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
|
|
|
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
|
|
|
+ curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
|
|
|
+ curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
|
|
|
+ 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
|
|
|
+ 'Accept: application/json',
|
|
|
+ ) );
|
|
|
+ // 发送数据
|
|
|
+ $response = curl_exec( $ch );
|
|
|
+ // 不要忘记释放资源
|
|
|
+ curl_close( $ch );
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
}
|