开发环境
编程语言:PHP
数据库 :Mysql
系统架构:B/S
前端技术:Vue
运行工具:PHPStudy
支持定做:java/php/python/android/小程序vue/爬虫/c#/asp.net
系统截图
核心代码
session_start();
class ShangjiaController extends CommonController {
public function __construct()
{
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header('Access-Control-Allow-Headers:Origin,Content-Type,Accept,token,X-Requested-With,device');
}
public $columData = [
'id','addtime'
,'shangjiazhanghao'
,'shangjiamingcheng'
,'mima'
,'shoujihao'
,'touxiang'
,'money'
];
/**
* 登录接口
* POST
* */
public function login(){
$username = isset($_REQUEST['username'])?$_REQUEST['username']:"";
$password = isset($_REQUEST['password'])?$_REQUEST['password']:"";
$sql = "select * from `shangjia` where `shangjiazhanghao` = '".$username."' and `mima` = '".$password."'";
$result = table_sql($sql);
if ($result->num_rows > 0) {
// 输出数据
while($row = $result->fetch_assoc()) {
$token_array = [
"iat" => time(), //签发时间
"exp" => time()+7200, //token 过期时间
'tablename'=> 'shangjia',//表名
'columData' => $this->columData,
'id' => $row['id'],
'isAdmin' => 0,
"success" => $row,//记录的uid的信息,如果有其它信息,可以再添加数组的键值对
'username' => $row['shangjiazhanghao'],
];
$tokens = base64_encode(json_encode($token_array));
$_SESSION[$tokens] = $row["id"];
$colum = "shangjiazhanghao";
$md5 = md5($row["id"]."+10086");
$_SESSION[$md5] = $row[$colum];
$data = ['code' => 0, 'token' => $tokens];
exit(json_encode($data));
}
} else {
exit(json_encode(['code'=>500,'msg'=>"账号或密码错误"]));
}
}
/**
* 退出
* post
*/
public function logout(){
$token = $this->token();
unset($token);
exit(json_encode(['code'=>0,'msg'=>'退出成功']));
}
/**
* 注册
* post
*/
public function register(){
$tmpData = strval(file_get_contents("php://input"));
$postData = json_decode($tmpData,true);
$colum = "shangjiazhanghao";
$trues = "select * from `shangjia` where `shangjiazhanghao` = '".$postData[$colum]."'";
$result = table_sql($trues);
if($result->num_rows<1){
$keyArr = $valArr = array();
foreach ($postData as $key => $value){
if (in_array($key, $this->columData) && ($value===0 || $value!="")){
array_push($keyArr,"`".$key."`");
array_push($valArr,"'".$value."'");
}
}
$key = implode(',',$keyArr);
$v = implode(',',$valArr);
$sql = "INSERT INTO `shangjia` (`id`,".$key.") VALUES (".time().",".$v.")";
$result = table_sql($sql);
if (!$result) exit(json_encode(['code'=>500,'msg'=>'注册失败。']));
exit(json_encode(['code'=>0]));
}
exit(json_encode(['code'=>500,'msg'=>"用户名已存在。"]));
}
/**
* 获取session
*/
public function session(){
$token = $this->token();
$data = json_decode(base64_decode($token),true);
$dbname = $data['tablename'];
$uid = $data['id'];
$sql = "select * from ".$dbname." where id=".$uid;
$result = table_sql($sql);
if ($result->num_rows > 0) {
// 输出数据
while($row = $result->fetch_assoc()) {
$arrayData = $row;
}
}
exit(json_encode(['code'=>0,'data'=>$arrayData]));
}
/**
* 找回密码 重置为123456
**/
public function resetPass(){
$username = $_REQUEST['username'];
$counts = "select * from `shangjia` where shangjiazhanghao = '".$username."'";
$cotte = table_sql($counts);
if($cotte->num_rows<1){
exit(json_encode(['code'=>500,'msg'=>"用户名错误。"]));
}
$sql = "update shangjia set mima = '123456' where shangjiazhanghao = '".$username."'";
$result = table_sql($sql);
exit(json_encode(['code'=>0,'msg'=>"密码已重置为:123456"]));
}
/**
* 分页,列表
* get
*/
public function page(){
$token = $this->token();
$tokens = json_decode(base64_decode($token),true);
if (!isset($tokens['id']) || empty($tokens['id'])) exit