【调度系统】广东民航医疗快线调度系统源代码
hzj
2025-07-09 4418374d26a16ec759e06059c2b1fedabe1827e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
function access_post($url = '', $param = '') {
    if (empty($url) || empty($param)) {
        return false;
    }
    
    $postUrl = $url;
    $curlPost = $param;
    $api_info=file_get_contents($postUrl."?".$curlPost);
    $api_info=json_decode($api_info,true);
    $access_token = $api_info["access_token"];
    //if ($result!=1) {header("Location: /"); exit;}
    return $access_token;
}
 
$url = 'https://aip.baidubce.com/oauth/2.0/token';
$post_data['grant_type']       = 'client_credentials';
$post_data['client_id']      = 'qLaZeiLR3pnb03qto3OPoFtG';
$post_data['client_secret'] = 'TmpfWyGGy3xtDdESUz9yjtQ4PyOk8YEP';
$o = "";
foreach ( $post_data as $k => $v ) 
{
    $o.= "$k=" . urlencode( $v ). "&" ;
}
$post_data = substr($o,0,-1);
 
 
function request_post($url = '', $param = '')
{
    if (empty($url) || empty($param)) {
        return false;
    }
 
    $postUrl = $url;
    $curlPost = $param;
    // 初始化curl
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $postUrl);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    // 要求结果为字符串且输出到屏幕上
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    // post提交方式
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
    // 运行curl
    $data = curl_exec($curl);
    curl_close($curl);
 
    return $data;
}
$method = !empty($_REQUEST["method"])?$_REQUEST["method"]:"";
$a    = empty($_REQUEST['a'])!=false ? 0 : $_REQUEST['a'];
$res="";
 
switch ($method)
{
    case "meter":    //仪器仪表盘读数识别
        $image    = empty($_REQUEST['image'])!=false ? "" : $_REQUEST['image'];
 
        if ($image!="") {
            $access_token = access_post($url, $post_data);
            $token = $access_token;
            //仪器仪表盘读数识别
            //$url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/meter?access_token=' . $token;
            $url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/webimage?access_token=' . $token;
            $img = file_get_contents($image);
            $img = base64_encode($img);
            $bodys = array(
                'image' => $img
            );
            $api_json = request_post($url, $bodys);
            //echo $api_json."<br>";//exit;
            $api_info=json_decode($api_json,true);
            
 
            $error_code = $method = !empty($api_info["error_code"]) ? $api_info["error_code"] : 0;
            if ($error_code==0) {
                $res=0;
                foreach($api_info["words_result"] as $x=>$x_value) {
                  $words= !empty(intval($x_value["words"])) ? intval($x_value["words"]) : 0;
                  if ($words>$res) {
                    $res=$words;
                  }
                }
            }else{
                $res = -1;        //识别失败
            }
            //if ($res<=100) {
            //    //数字识别
            //    $url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/numbers?access_token=' . $token;
            //    $api_json = request_post($url, $bodys);
            //    $api_info=json_decode($api_json,true);
            //    $error_code = $method = !empty($api_info["error_code"]) ? $api_info["error_code"] : 0;
            //    if ($error_code==0) {
            //        $res=0;
            //        foreach($api_info["words_result"] as $x=>$x_value) {
            //          $words= !empty(intval($x_value["words"])) ? intval($x_value["words"]) : 0;
            //          if ($words>$res) {
            //            $res=$words;
            //          }
            //        }
            //    }
            //}
        }else{
            $res = -2;            //没图片
        }
    break;
}
//var_dump($res);
if ($a!=0) {
    echo $api_json;
}else{
    echo $res;
}
?>