證系列API.png)
穩(wěn)定好用的認(rèn)證系列API合輯
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
public class Example {
public static void main(String[] args) throws Exception{
String host = "https://open.expauth.com";
String path = "/v1/tools/ocr/verInvoice";
String method = "POST";
// "{{AppCode}}" 替換成您的 AppCode
String appcode = "{{AppCode}}";
Map headers = new HashMap<>();
headers.put("X-Mce-Signature", "AppCode/" + appcode);
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map querys = new HashMap<>();
Map bodys = new HashMap<>();
// 填充參數(shù)
bodys.put("invoiceCode", "invoiceCode");
bodys.put("invoiceNumber", "invoiceNumber");
bodys.put("billingDate", "billingDate");
bodys.put("totalAmount", "totalAmount");
bodys.put("checkCode", "checkCode");
bodys.put("invoiceType", "invoiceType");
try {
/**
* 重要提示如下:
* HttpUtils請(qǐng)從
* https://static.miitang.com/saas/simple/HttpUtils.java 下載
*
* 相應(yīng)的依賴請(qǐng)參照
* https://static.miitang.com/saas/simple/pom.xml
*/
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
// 獲取 response 的 body
String resStr = EntityUtils.toString(response.getEntity());
System.out.println(resStr);
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode == 200){
// 請(qǐng)求成功,可根據(jù)業(yè)務(wù)碼(請(qǐng)求體中的code)進(jìn)行邏輯處理
} else if(statusCode == 610){
// 用戶輸入的參數(shù)問題,可直接提示用戶
} else if(statusCode == 611){
// 系統(tǒng)準(zhǔn)備的數(shù)據(jù)問題,如 文件數(shù)據(jù)下載失敗、數(shù)據(jù)不存在、數(shù)據(jù)重復(fù)請(qǐng)求等。 LOG it and 提示用戶
} else if(statusCode == 612){
// 用戶操作頻度問題,可提示用戶。 LOG it and 按業(yè)務(wù)特點(diǎn)做處理
} else if(statusCode >= 500 && statusCode < 600){
// 在運(yùn)行階段發(fā)生的系統(tǒng)穩(wěn)定性問題,客戶端可以重試,或者聯(lián)系我司客服
} else {
// 如賬戶密碼錯(cuò)誤、IP白名單問題、余額不足等,您應(yīng)該在對(duì)接過程中解決相關(guān)問題。
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
在Python中,使用?requests?庫(kù)發(fā)送?POST?請(qǐng)求到增值稅發(fā)票核驗(yàn)服務(wù)接口,根據(jù)響應(yīng)狀態(tài)碼進(jìn)行業(yè)務(wù)邏輯處理,包括成功、參數(shù)問題、數(shù)據(jù)問題、操作頻度問題和系統(tǒng)穩(wěn)定性問題等的處理。
import json
import requests
if __name__ == '__main__':
url = "https://open.expauth.com/v1/tools/ocr/verInvoice"
payload = json.dumps({
"invoiceCode": "invoiceCode",
"invoiceNumber": "invoiceNumber",
"billingDate": "billingDate",
"totalAmount": "totalAmount",
"checkCode": "checkCode",
"invoiceType": "invoiceType"
})
headers = {
"Content-Type": "application/json",
# "{{AppCode}}" 替換為您的 AppCode
"X-Mce-Signature": "AppCode/{{AppCode}}"
}
response = requests.request("POST", url, headers=headers, data=payload)
status_code = response.status_code
print("headers:", response.headers)
print("http 狀態(tài)碼:", str(status_code))
print(response.text)
if status_code == 200:
"請(qǐng)求成功,可根據(jù)業(yè)務(wù)碼(請(qǐng)求體中的code)進(jìn)行邏輯處理"
elif status_code == 610 :
"用戶輸入的參數(shù)問題,可直接提示用戶"
elif status_code == 611 :
"系統(tǒng)準(zhǔn)備的數(shù)據(jù)問題,如 文件數(shù)據(jù)下載失敗、數(shù)據(jù)不存在、數(shù)據(jù)重復(fù)請(qǐng)求等。 LOG it and 提示用戶"
elif status_code == 612 :
"用戶操作頻度問題,可提示用戶。 LOG it and 按業(yè)務(wù)特點(diǎn)做處理"
elif status_code >= 500 & status_code < 600 :
"在運(yùn)行階段發(fā)生的系統(tǒng)穩(wěn)定性問題,客戶端可以重試,或者聯(lián)系我司客服"
else:
"如賬戶密碼錯(cuò)誤、IP白名單問題、余額不足等,您應(yīng)該在對(duì)接過程中解決相關(guān)問題。"
在PHP中,使用?cURL?發(fā)送?POST?請(qǐng)求到增值稅發(fā)票核驗(yàn)服務(wù)接口,處理并輸出相應(yīng)的業(yè)務(wù)邏輯。它包括設(shè)置請(qǐng)求頭、發(fā)送請(qǐng)求、處理響應(yīng),根據(jù)響應(yīng)狀態(tài)碼進(jìn)行不同的業(yè)務(wù)邏輯處理,如成功、參數(shù)問題、數(shù)據(jù)問題、操作頻度問題、系統(tǒng)穩(wěn)定性問題等。
<?php
$host = "https://open.expauth.com";
$path = "/v1/tools/ocr/verInvoice";
$method = "POST";
$appcode = "{{您的AppCode}}";
$headers = array();
array_push($headers, "x-mce-signature:AppCode/" . $appcode);
//根據(jù)API的要求,定義相對(duì)應(yīng)的Content-Type
array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
$querys = "";
$bodys = "invoiceCode=invoiceCode&invoiceNumber=invoiceNumber&billingDate=billingDate&totalAmount=totalAmount&checkCode=checkCode&invoiceType=invoiceType";
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
$result = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); // 獲得響應(yīng)頭大小
$httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
$body = substr($result,$header_size);
curl_close($curl);
$retMap = json_decode($body, true);
$code = $retMap["code"];
echo $httpCode.PHP_EOL; // DEBUG
if($httpCode == 200){
// 請(qǐng)求成功,可根據(jù)業(yè)務(wù)碼(請(qǐng)求體中的code)進(jìn)行邏輯處理
echo $retMap["code"].PHP_EOL;
echo $retMap["message"].PHP_EOL;
echo $retMap["hasFees"].PHP_EOL;
echo $retMap["fees"].PHP_EOL;
if($code == "FP00000"){
// SUCCESS
echo "SUCCESS";
}
else{
// FAILURE
echo "FAILURE";
}
} else {
echo $code.PHP_EOL; // DEBUG
if($httpCode == 610){
// 用戶輸入的參數(shù)問題,可直接提示用戶
$errors = $retMap["errors"];
$errorMap = null;
foreach($errors as $key=>$value){
foreach($value as $key2=>$value2){
$errorMap[$key] = $value2;
break;
}
}
// 轉(zhuǎn)化為 key:tip
echo($errorMap["idCardNo"].PHP_EOL);
echo($errorMap["name"].PHP_EOL);
} else if($httpCode == 611){
// 系統(tǒng)準(zhǔn)備的數(shù)據(jù)問題,如 文件數(shù)據(jù)下載失敗、數(shù)據(jù)不存在、數(shù)據(jù)重復(fù)請(qǐng)求等。 LOG it and 提示用戶
echo "修訂數(shù)據(jù)狀態(tài),不要重復(fù)操作。".PHP_EOL;
} else if($httpCode == 612){
// 用戶操作頻度問題,可提示用戶。 LOG it and 按業(yè)務(wù)特點(diǎn)做處理
echo $retMap["message"].PHP_EOL;
} else if($httpCode >= 500 && $httpCode < 600){
// 在運(yùn)行階段發(fā)生的系統(tǒng)穩(wěn)定性問題,客戶端可以重試,或者聯(lián)系我司客服
// TODO: retry
echo "RETRY".PHP_EOL;
} else {
// 如賬戶密碼錯(cuò)誤、IP白名單問題、余額不足等,您應(yīng)該在對(duì)接過程中解決相關(guān)問題。
var_dump($retMap);
}
}
?>
增值稅發(fā)票(卷票)識(shí)別【API Space】
對(duì)比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力
一鍵對(duì)比試用API 限時(shí)免費(fèi)