Thinkphp 手机App接口demo分享

<?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();
        }

    }

}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值