Thinkphp运政违章查询接口

创建数据库

SQL 查询结果 Host: localhost Database: jtzf Generation Time: 2018-11-01 12:23:29 Generated by: phpMyAdmin 4.4.15.10 / MySQL 5.5.57-log SQL 查询: show CREATE TABLE ashe_case; 记录: 1

Table	Create Table
ashe_case	CREATE TABLE `ashe_case` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `content` longtext NOT NULL,
 `create_time` int(11) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=73 DEFAULT CHARSET=utf8

创建case数据表用于储存查询之后返回来的数据;

SQL 查询结果 Host: localhost Database: jtzf Generation Time: 2018-11-01 12:24:58 Generated by: phpMyAdmin 4.4.15.10 / MySQL 5.5.57-log SQL 查询: show CREATE TABLE ashe_num; 记录: 1

Table	Create Table
ashe_num	CREATE TABLE `ashe_num` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `card` longtext NOT NULL,
 `create_time` int(11) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8

创建num数据表用于储存每次需要查询的车牌号码;

SQL 查询结果 Host: localhost Database: jtzf Generation Time: 2018-11-01 12:25:50 Generated by: phpMyAdmin 4.4.15.10 / MySQL 5.5.57-log SQL 查询: show CREATE TABLE ashe_rem; 记录: 1

Table	Create Table
ashe_rem	CREATE TABLE `ashe_rem` (
 `type` varchar(255) NOT NULL,
 `content` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

创建rem数据表用于储存当前查询的车牌的序号;

以下代码;

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        $data = input('get.');
        if ($data['tokent'] == 'asheblog'){
//            Db::name('rem')
//                ->where('type','num')
//                ->update([
//                    'content' => 0
//                ]);exit;
            $resultValue = $result = Db::name('num')
                ->order('id','desc')
                ->limit('1')
                ->value('card');
            $cardArray = json_decode($resultValue,true);
            $cardNum = count($cardArray);
            $num = Db::name('rem')
                ->where('type','num')
                ->value('content');
            $postNum = $num+1;
            if ($num >= $cardNum){
                return '最新查询的车牌号码是粤X'.$cardArray[$postNum-1].'本次已经查询完成';
            }
            $post_data = array('CarId' => '粤X' . $cardArray[$postNum], 'Party' => '广东******有限公司');
            $result = $this->sendPost('http://121.33.200.117:9090/Cases/CaseSummarySjgx/GetWaitTransactsForForm', $post_data);
            if ($result != '[]'){
                $json = str_replace(array('[', ']'), '', $result);
                $dbInsert = Db::name('case')
                    ->insert([
                        'content' => $json,
                        'create_time' => time()
                    ]);
                if ($dbInsert){
                    Db::name('rem')
                        ->where('type','num')
                        ->update([
                            'content' => $postNum
                        ]);
                    return '粤X'.$cardArray[$postNum].'查询成功!';
                }
            }else{
                Db::name('rem')
                    ->where('type','num')
                    ->update([
                        'content' => $postNum
                    ]);
                return '粤X'.$cardArray[$postNum].'数据为空';
            }
        }else{
            return 'token不正确';
        }
    }

    function sendPost($url, $post_data)
    {
        $postdata = http_build_query($post_data);
        $options = array('http' => array('method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60));
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }

    public function add(){
        return view();
    }

    public function addInsert(){
        $data = input('post.');
        $array = explode("\r\n",$data['content']);
        $array[0] = NULL;
        unset($array[0]);
        $result = Db::name('num')
            ->insert([
                'card' => json_encode($array),
                'create_time' => time()
            ]);
        if ($result){
            Db::name('rem')
                ->where('type','num')
                ->update([
                    'content' => 0
                ]);
            return '插入成功!';
        }else{
            return '插入失败!';
        }
    }

    public function getList(){
        $result = Db::name('case')
            //->whereTime('create_time', 'today')
            ->select();
        $resultArray = [];
        foreach($result as $item){
            $resultArray[$item['id']] = $item['content'];
        }
        $this->assign([
            'result' => $resultArray
        ]);
        return view();
    }
}

代码随手写的,懒得优化和美化了,将就看吧,估计以后会有用呢。

Comments: 3

「人生在世,留句话给我吧」

提交评论