整不好,我还是加个按钮来处理了,不过图片上传后,收到的数据怎么写入当前页面,要重新生成页面吗?如果重新生成页面,哪刚刚的图片怎么办是不是就没有了?
我现在的填报代码如下:
Dim e As RequestEventArgs = args(0)
Dim oid As Integer = args(1)
Dim wb As New weui
If e.PostValues.Count = 0 Then '生成增加订单网页
wb.AddForm("","form1","cardbookaddnew.htm")
With wb.AddInputGroup("form1","ipg1","名片正面") '文件上传
With .AddUploader("名片正面","",True)
.AllowDelete = True '允许删除
.Incremental = False '允许重复选择文件或连续拍照
End With
End With
With wb.AddButtonGroup("form1","btg2",True)
.Add("btn2", "解析名片", "button").Attribute= " on cl ick ='up ca rdz()'"
End With
With wb.AddInputGroup("form1","ipg2","名片信息")
.AddHiddenValue("OperID",oid)
.AddInput("公司名称","公司名称","text")
.AddInput("姓名","姓名","text")
.AddInput("职务","职务","text")
.AddInput("手机","手机","text")
.AddInput("传真","传真","text")
.AddInput("固话","固话","text")
.AddInput("Email","Email","text")
.AddInput("网址","网址","text")
.AddInput("地址","地址","text")
End With
With wb.AddInputGroup("form1","ipg3","备注")
.AddTextArea("备注").Placeholder = "请输入200字以内的备注"
With .AddUploader("名片反面","名片反面",False)
.TextPosition = 0 '标题靠左
End With
End With
wb.AddToast("","tst1", "正在上传",1)
wb.AddToast("","tst2", "上传成功",0)
wb.AddToast("","tst3", "上传失败",0).Icon= "warn"
wb.AppendHTML("<script src='./lib/ajaxform.js'></script>") '引入脚本文件
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "确定", "submit")
End With
e.WriteString(wb.Build) '生成网页
Else '保存新增的订单
Dim mpzm As String
For Each key As String In e.Files.Keys
If key = "名片正面" Then
For Each fl As String In e.Files(key)
Dim NewName As String = fl
Dim idx As Integer = fl.LastIndexOf(".")
Dim cnt As Integer = 1
Do While FileSys.FileExists("d:\web\temp\" & NewName) '判断文件夹是否存在同名文件
NewName = fl.Insert(idx,"(" & cnt & ")") '如果存在同名文件,在原文件名加上序号
cnt = cnt + 1 '递增序号
Loop
e.SaveFile(key,fl,"d:\web\temp\" & NewName) '保存接收到的文件
mpzm = "d:\web\temp\" & NewName
Next
End If
Next
mpzm = Functions.Execute("bdcardsb",mpzm)
e.WriteString(mpzm)
End If
ajaxform.js代码如下
function upcardz(){
var result = submitAjaxForm('form1','afterSubmit',true,'tst1');
}
function afterSubmit(result){
hide("tst1");
if (result) {
var vals=result.split("|");
if(vals.length==6){
document.getElementById("姓名").value=vals[0];
document.getElementById("手机").value=vals[1];
document.getElementById("固话").value=vals[2];
document.getElementById("Email").value=vals[3];
document.getElementById("网址").value=vals[4];
document.getElementById("地址").value=vals[5];
}
}
else{
show("tst3",2000);
}
}
这个刷新不了当前页
Functions.Execute("bdcardsb",mpzm)代码如下:
Dim mpzm As String = args(0)
Dim bmp As new Bitmap(mpzm)
Dim ms As new System.Io.MemoryStream()
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arr(ms.Length) As Byte
ms.Position = 0
ms.Read(arr, 0, ms.Length)
ms.Close()
Dim strbase64 As String = Convert.ToBase64String(arr)
bmp.dispose
'****读取图片完毕
Dim body As String = "id_card_side=front&image=" & UrlEncode(strbase64) & ""
Dim token As String = Functions.Execute("百度名片识别AccessToken")
Dim req = System.Net.WebRequest.Create("https://aip.baidubce.com/rest/2.0/ocr/v1/business_card?access_token=" & token)
req.Method = "POST"
req.C
Dim aryBuf As Byte() = Encoding.UTF8.GetBytes(body)
req.ContentLength = aryBuf.Length
Dim writer = req.GetRequestStream()
writer.Write(aryBuf, 0, aryBuf.Length)
writer.Close()
writer.Dispose()
Dim pos = req.GetResponse
'****获取数据完毕
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
pos.Close
stm.Close
reader.close
Dim jo As JObject = Jobject.Parse(str)
Dim lms() As String = {"NAME","MOBILE","TEL","EMAIL","URL","ADDR"}
Dim fhstr As String
For Each lm As String In lms
Dim jt As String = ""
For Each ja As JToken In jo("words_result")(lm)
jt = iif(jt > "",jt & "," & ja.ToString,ja.ToString)
Next
If fhstr > "" Then
fhstr = fhstr & "|" & jt
Else
fhstr = jt
End If
Next
Return fhstr
[此贴子已经被作者于2018/9/14 16:03:41编辑过]