我试图使用API,我写了这个代码,我的输出是
{
"error": {
"code":"MISSING_PARAMETER",
"message":"Missing X-FC-NonceHeader"
},
"request_id":"a7c6305b96eb4c999a95c4a5ef87b5d9",
"status":"ERROR"
}
什么是F-FC-Nonce如何修复
$headers = array("Content-Type" => "application/x-www-form-urlencoded");
$path = $_FILES["img"]["tmp_name"];
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'https://iai.flashsoftapi.com/v1/thai-id-card-ocr');
curl_setopt($curl_handle,CURLOPT_USERPWD,'key:key');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $base64);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
$text = curl_exec($curl_handle);
curl_close($curl_handle);
echo $文本;
根据它们的文档,它们使用以下Python代码生成nonce:
def generate_nonce(length=16):
"""Generate pseudorandom number."""
return ''.join([str(random.randint(0, 9)) for i in range(length)])
从表面上看,nonce可以在PHP中使用
function generate_nonce($length)
{
$out = [];
for ($i = 0; $i < $length; ++$i)
$out[] = rand(0,9);
return implode('', $out);
}