老师:你好!我发布可以读取身份证信息,为什么发布读取不到信息了Dim pic1 As String = e.Form.Controls("PictureViewer1").SelectedItem Dim ppic1 As String = pic1.Remove(0, 6)
Dim isfront As Boolean = e.Form.Controls("rdbfront").checked
Try
Dim client As New Baidu.Aip.Ocr.Ocr(Vars("APIKey"), Vars("SecretKey")) '初始化接口类,传入创建的应用的API Key,Secret Key
client.Timeout = 60000 '设置超时时间
Dim data() As Byte = System.IO.File.ReadAllBytes(ppic1) '把图片文件字节流加载进来,
Dim options As New Dictionary(Of String, Object) '使用字典传递参数
'options.Add("detect_direction","true") '是否检测图像朝向,默认不检测
options.Add("detect_risk", "true")
Dim jo = client.Idcard(data, IIf(isfront, "front", "back"), options) '调用接口开始识别,返回值为JObject对象
If jo("error_code") IsNot Nothing AndAlso jo("error_code") <> 0 Then
' txt.text = "识别失败: " & vbcrlf & jo("error_msg").Tostring
Else
Dim sbu As New StringBuilder
' sbu.AppendLine( "--------************-----------")
' sbu.AppendLine( "状态:" & jo("image_status").Tostring)
If isfront Then
' If jo("risk_type") IsNot Nothing Then sbu.AppendLine("风险类型:" & jo("risk_type").Tostring)
' If jo("edit_tool") IsNot Nothing Then sbu.AppendLine("编辑状态:" & jo("edit_tool").Tostring)
' sbu.AppendLine( "--------************-----------")
' sbu.AppendLine( "识别出" & jo("words_result_num").Tostring & "条信息:")
' If jo("words_result")("公民身份号码") IsNot Nothing Then sbu.AppendLine( "--公民身份号码:" & jo("words_result")("公民身份号码")("words").ToString)
'如果号码识别失败,不会出现出生属性,所以需要判断一下
If jo("words_result")("公民身份号码") IsNot Nothing Then Tables("员工信息表").Current("身份证号") = jo("words_result")("公民身份号码")("words").ToString
' If jo("words_result")("出生") IsNot Nothing Then sbu.AppendLine( "--出生日期:" & jo("words_result")("出生")("words").ToString)
If jo("words_result")("姓名") IsNot Nothing Then Tables("员工信息表").Current("姓名") = jo("words_result")("姓名")("words").ToString
If jo("words_result")("住址") IsNot Nothing Then Tables("员工信息表").Current("家庭住址") = jo("words_result")("住址")("words").ToString
' If jo("words_result")("姓名") IsNot Nothing Then sbu.AppendLine( "--姓名:" & jo("words_result")("姓名")("words").ToString)
' If jo("words_result")("性别") IsNot Nothing Then sbu.AppendLine( "--性别:" & jo("words_result")("性别")("words").ToString)
' If jo("words_result")("民族") IsNot Nothing Then sbu.AppendLine( "--民族:" & jo("words_result")("民族")("words").ToString)
' If jo("words_result")("住址") IsNot Nothing Then sbu.AppendLine( "--住址:" & jo("words_result")("住址")("words").ToString)
Else
sbu.AppendLine( "识别出" & jo("words_result_num").Tostring & "条信息:")
If jo("words_result")("签发机关") IsNot Nothing Then sbu.AppendLine( "--签发机关:" & jo("words_result")("签发机关")("words").ToString)
If jo("words_result")("签发日期") IsNot Nothing Then sbu.AppendLine( "--签发日期:" & jo("words_result")("签发日期")("words").ToString)
If jo("words_result")("失效日期") IsNot Nothing Then sbu.AppendLine( "--失效日期:" & jo("words_result")("失效日期")("words").ToString)
End If
' txt.text = txt.text & vbcrlf & sbu.ToString
End If
'txt.text = txt.text & vbcrlf & "识别结果: " & vbcrlf & result.Tostring
Catch ex As exception
' txt.text = txt.text & vbcrlf & "识别接口调用失败,错误描述: " & vbcrlf & ex.message
End Try