<?php
namespace AppServ\Controller;
use Think\Controller;
class LoginController extends Controller
{
public function index()
{
header("Content-type: application/json");
if ($_POST) {
$datas = json_decode($_POST['data'], true);
$user = $datas['content']['user'];
$pwd = $datas['content']['pwd'];
//存储手机端发过来的值
$t = var_export($datas, true);
file_put_contents(APP_PATH . 'AppServ/Controller/post.txt', '<br><span style="color: #ff0000;font-weight: bold">'.date('H:i:s') . "</span><br>\n", FILE_APPEND);
file_put_contents(APP_PATH . 'AppServ/Controller/post.txt', '$t :' . $t . "<br>\n", FILE_APPEND);
$content = array();
$message = jsonData('5', '数据格式错误', $content);
if (isset($user) && !empty($user) && isset($pwd) && !empty($pwd) && $datas['token'] == "public") {
//查询是否有此用户
$m = D('Manager');
$map['mg_name'] = $user;
$map['mg_mobile'] = $user;
$map['_logic'] = 'OR';
$info=$m->where($map)->find();
//file_put_contents(APP_PATH.'AppServ/Controller/post.txt','$sql:'.$m->getLastSql()."<br>\n",FILE_APPEND);
if ($info) {
//查出随机字符
$pwd_str = $info['mg_rand_str'];
$pwd_true = $info['mg_pwd'];
//用户输入的密码
$pwd_false = md5(md5($pwd) . $pwd_str);
if ($pwd_true === $pwd_false) {
$data['token'] = md5($info['mg_id'] . time());
//设定token有效期一天
$data['timer'] = time() + 86400;
//用户id
$data['user_id'] = $info['mg_id'];
//token 存储
$t = D("token");
$msg = $t->add($data);
//存储成功返回
if ($msg) {
$content = array(
"token" => $data['token']
);
$message = jsonData('1', '登陆成功', $content);
} else {
$message = jsonData('3', '未知错误!', $content);
}
} else {
$message = jsonData('2', '密码错误!', $content);
}
} else {
$message = jsonData('4', '用户名不存在!', $content);
}
}
echo $message;
} else {
$this->display();
}
}
}
Thinkphp 手机App接口demo分享
最新推荐文章于 2023-03-17 10:49:38 发布