下面是一个端到端的提交一个的例子ExtractBusinessCard请求使用PHP编程语言:

< ?php / /简单的脚本制作和处理结果的ExtractBusinessCard LEADTOOLS云服务请求。/ /为了运行此脚本,以下更改需要补充道:/ / 1)把你的应用程序ID在$ appId变量GeneratePostOptions方法/ / 2)把你的应用程序密码在$密码变量GeneratePostOptions方法/ / / /脚本将执行以下操作顺序:/ / 1)执行ExtractBusinessCard LEADTOOLS云服务请求。一个成功的请求将返回一个惟一的标识符。/ / 2)我们将使用GUID查询服务,如果文件完成处理,身体将包含所有的/ /请求数据。/ / 3)我们将返回的json数据,解析它,显示返回的所有信息。美元servicesBaseUrl = " https://azure.leadtools.com/api/ ";/ /第一页文件中标记处理珍宝= 1美元;/ /发送值将显示页面的其余部分的服务文件中应处理。lastPage = 1美元; //We will be uploading the file via a URl. Files can also be passed by adding a PostFile to the request. Only 1 file will be accepted per request. //The services will use the following priority when determining what a request is trying to do GUID > URL > Request Body Content $fileURL = 'http://demo.leadtools.com/images/cloud_samples/business_card_sample.jpg'; $baseRecognitionURL = '%sRecognition/ExtractBusinessCard?firstPage=%s&lastPage=%s&fileurl=%s'; $formattedRecognitionURL = sprintf($baseRecognitionURL, $servicesBaseUrl, $firstPage, $lastPage, $fileURL); /* If uploading a file alongside the HTTP request: $baseRecognitionURL = '%sRecognition/ExtractBusinessCard?firstPage=%s&lastPage=%s'; $formattedRecognitionURL = sprintf($baseRecognitionURL, $servicesBaseUrl, $firstPage, $lastPage); */ //Generate the CURL options to be used $recognitionRequestOptions = GeneratePostOptions($formattedRecognitionURL); $request = curl_init(); curl_setopt_array($request, $recognitionRequestOptions); //Set the request URL if (!$guid = curl_exec($request)) { echo "There was an error processing the request. \n\r"; echo $guid; exit; } curl_close($request); //Close the request echo "Unique ID returned by the services: $guid \n\r"; echo "Querying Results...\n\r"; $baseQueryURL = '%sQuery?id=%s'; $formattedQueryURL = sprintf($baseQueryURL, $servicesBaseUrl, $guid); $queryRequestOptions = GeneratePostOptions($formattedQueryURL); while (true) { //Poll the services to determine if the request has finished processing. $request = curl_init(); curl_setopt_array($request, $queryRequestOptions); //Set the request URL if (!$results = curl_exec($request)) { echo "There was an error querying the services \n\r"; echo $results; curl_close($request); exit; } curl_close($request); $decodedResponse = json_decode($results); $fileStatus = $decodedResponse->{'FileStatus'}; if ($fileStatus != 100 && $fileStatus != 123) { //The file has finished processing break; } sleep(5); //If the file hasn't finished processing, we will wait 5 seconds before checking again. } echo "File finished processing with file status: " . $fileStatus . "\n\r"; //The file did not process successfully. Refer to our documentation for the full list of File Statuses and their associated meanings. if ($fileStatus != 200) { exit; } echo "Results: \n\r"; //Decode and parse the JSON results. $jsonArray = $decodedResponse->{'RequestData'}; foreach ($jsonArray as $serviceResults) { echo "Service Type: " . $serviceResults->{'ServiceType'} . "\n\r"; echo "Recognition Type: " . $serviceResults->{'RecognitionType'} . "\n\r"; $data = $serviceResults->{'data'}; var_dump($data); } function GeneratePostOptions($url) { //Function to generate the array of CURL options to be used. //If we are uploading via a URL, we will need to add a Content-Length:0 header value. //If we are uploading a file as post data, we do not need to include the Content-Length header. $appId = "Replace with Application ID"; $password = "Replace with Application Password"; //Remove if uploading the file as post data. $headers = array( "Content-Length : 0" ); /* //To upload a file as form data: $file = new CURLFile("path/to/file"); $imageData = array('image' => $file); //**NOTE** - Only 1 file will be accepted per request. */ $postOptions = array( CURLOPT_POST => 1, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERPWD => "$appId:$password", CURLOPT_FORBID_REUSE => 1, //Uncomment if uploading as post data. //CURLOPT_POSTFIELDS => $imageData, //Comment out the CURLOPT_HTTPHEADER if uploading as post data. CURLOPT_HTTPHEADER => $headers ); return $postOptions; } ?>