【调度系统】广东民航医疗快线调度系统源代码
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?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":    //ÒÇÆ÷ÒDZíÅ̶ÁÊýʶ±ð
        $image    = empty($_REQUEST['image'])!=false ? "" : $_REQUEST['image'];
 
        if ($image!="") {
            $access_token = access_post($url, $post_data);
            $token = $access_token;
            //ÒÇÆ÷ÒDZíÅ̶ÁÊýʶ±ð
            $url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/meter?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;
 
    case "accurate":    //ͨÓÃÎÄ×Öʶ±ð£¨¸ß¾«¶Èº¬Î»Öð棩
        $image    = empty($_REQUEST['image'])!=false ? "" : $_REQUEST['image'];
 
        if ($image!="") {
            $access_token = access_post($url, $post_data);
            $token = $access_token;
            //ÒÇÆ÷ÒDZíÅ̶ÁÊýʶ±ð
            $url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate?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;
}
?>