first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
<?php
/**
* Created by PhpStorm.
* User:
* Date: 2020/4/13
* Time: 13:27
*/
namespace app\api\controller;
use app\api\service\UserToken;
use app\api\validate\LoginValidate;
use app\lib\exception\ParamException;
use app\api\service\SendMessage;
use app\api\model\User;
use think\Db;
use think\facade\Cache;
class Login extends BaseController
{
/**
* 非小程序登录
* @url api/appLogin
* @return string
*/
public function appLogin()
{
//参数验证
(new LoginValidate())->goCheck();
//解密手机号和验证码验证
$telnum = $this->rsaDecipher($telnum = input('telnum'));
/* $code = input('code');
$codeCache = Cache::store('redis')->get($telnum);
if($code != $codeCache){
throw new ParamException([
'code' => 400,
'msg' => '验证码错误',
'errorCode' => 10000
]);
}*/
//手机号正则验证
$check = '/^(1(([35789][0-9])|(47)))\d{8}$/';
if (!preg_match($check, $telnum)){
throw new ParamException([
'code' => 400,
'msg' => '手机号格式不正确',
'errorCode' => 10000
]);
}
//查询数据库是否有该用户,有获取token,无新增并获取token
$userInfo = User::getUserInfoByPhone($telnum);
if($userInfo){
$ut = new UserToken('');
$token['token'] = $ut->LoginToken($userInfo['uid']);
$userInfo['token'] = $token['token'];
$userInfo['phone'] = substr_replace($userInfo['phone'],'****',3,4);
//查看用户数据库是否有分数,没有返回false,前端判断给弹出填志愿信息框
if(empty($userInfo['score'])){
$res['phone'] = $userInfo['phone'];
$res['user_name'] = $userInfo['user_name'];
$res['token'] = $token['token'];
return api_return('分数必填',$res);
}
return api_return('获取成功',$userInfo);
}else{
//定义数组
$array = input('');
$array['phone'] = $telnum;
//参数再次验证
$this->checkUserParam($array);
//数据库插入数据
$userInfo = User::addUserInfo($array);
$ut = new UserToken('');
$userInfo['token'] = $ut->LoginToken($userInfo['uid']);
return api_return('登录成功',$userInfo);
}
}
/*
* 修改用户信息
* */
public function modifyUserInfo(){
$user_id = $this->verifyToken();
$array = input('');
//参数验证
$this->checkUserParam($array);
$array['user_id'] = $user_id;
$array['token'] = $this->request->header('token','');
$result = User::editUserInfo($array);
if($result){
return api_return("修改成功",$result);
}else{
return api_return("修改失败",$result);
}
}
/**
* @url api/sendCode
* 发送手机号验证码
* @return \think\response\Json
*/
public function sendMobileCode()
{
$telnum = input('telnum');
if(empty($telnum)){
throw new ParamException([
'code' => 400,
'msg' => '手机号参数必须',
'errorCode' => 10000
]);
}
//解密手机号
$telnum = $this->rsaDecipher($telnum);
//手机号正则验证
$check = '/^(1(([35789][0-9])|(47)))\d{8}$/';
if (!preg_match($check, $telnum)){
return api_error('手机号格式错误');
}
$code = rand(1000,9999);
Cache::store("redis")->set($telnum,$code,300);
$res = SendMessage::sendAliMessage($telnum,config('alidayu.signName'),config('alidayu.msgSms'),['code'=>$code]);
if($res['status'] == 1)
return api_return('发送成功');
else
return api_error('发送失败');
}
}