//fileUrl是传过来的图片网络url
string host1 = "https://api.weixin.qq.com/cv/ocr/idcard?type=photo&img_url="+ HttpUtility.UrlEncode(fileUrl, Encoding.UTF8) + "&access_token=" + newtoken;
//测试调用微信OCR
HttpWebRequest b1 = (HttpWebRequest)WebRequest.Create(host1);
b1.Method = "post";
b1.KeepAlive = true;
HttpWebResponse newresponse1 = (HttpWebResponse)b1.GetResponse();
StreamReader newreader1 = new StreamReader(newresponse1.GetResponseStream(), Encoding.UTF8);
JObject objJson = (JObject)JsonConvert.DeserializeObject(newreader1.ReadToEnd());
dynamic objResult = new ExpandoObject();
objResult.errcode = ((Newtonsoft.Json.Linq.JValue)objJson["errcode"]).Value.ToString();
objResult.errmsg = ((Newtonsoft.Json.Linq.JValue)objJson["errmsg"]).Value.ToString();
var sql = new StringBuilder();
if (objResult.errcode == "0")
{
objResult.type = ((Newtonsoft.Json.Linq.JValue)objJson["type"]).Value.ToString();
objResult.name = ((Newtonsoft.Json.Linq.JValue)objJson["name"]).Value.ToString();
objResult.race = ((Newtonsoft.Json.Linq.JValue)objJson["nationality"]).Value.ToString();
sql.Append(@"SELECT Top 1 raceNo FROM CMIS.EMP.Race where RaceName like '" + objResult.race + "%' ");
dynamic raceNo = await SqlMapperUtil.SqlWithParamsSingle<dynamic>(sql.ToString(), new { });
objResult.raceNo = raceNo.raceNo;
objResult.nricAdress = ((Newtonsoft.Json.Linq.JValue)objJson["addr"]).Value.ToString();
objResult.nric = ((Newtonsoft.Json.Linq.JValue)objJson["id"]).Value.ToString();
objResult.dateOfBirth = ((Newtonsoft.Json.Linq.JValue)objJson["birth"]).Value.ToString();
objResult.gender = ((Newtonsoft.Json.Linq.JValue)objJson["gender"]).Value.ToString();
objResult.genderNo = objResult.gender == "男" ? "1" : "2";
operateStatus.Data = objResult;
operateStatus.ResultSign = ResultSign.Successful;
operateStatus.code = ResultCode.Successful;
operateStatus.message = "获取成功";
}
else
{
operateStatus.Data = objResult;
operateStatus.ResultSign = ResultSign.Error;
operateStatus.code = ResultCode.Error;
operateStatus.message = "识别失败," + objResult.errmsg;
}
识别结果有时候没问题,如下:
有时候又报101000,
传入图片为同一张图片,上一次执行成功,下一次再执行也许就101000,说invalid image url hint,但是图片url根本没有问题,浏览器可以正常访问,到底什么原因啊?要是一直识别不出还好,但这时好时坏的。。。。报101000的几率更大,大概5次里面只有一次识别成功,求解
你好,你这个问题解决了吗?是如何解决的呀
传img_url,一直decode image failed
麻烦重新调用下