排名
3
文章
317
粉丝
22
评论
14
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

code:
- public class BankCard
- {
- // 银行卡识别
- public static BankCardModel bankCard(string token)
- {
- string host = "https://aip.baidubce.com/rest/2.0/ocr/v1/bankcard?access_token=" + token;
- Encoding encoding = Encoding.Default;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host);
- request.Method = "post";
- request.KeepAlive = true;
- // 图片的base64编码
- string base64 = getFileBase64("c://card//bb.jpg");
- String str = "image=" + HttpUtility.UrlEncode(base64);
- byte[] buffer = encoding.GetBytes(str);
- request.ContentLength = buffer.Length;
- request.GetRequestStream().Write(buffer, 0, buffer.Length);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- string result = reader.ReadToEnd();
- //Console.WriteLine("银行卡识别:");
- //Console.WriteLine(result);
-
- BankCardModel bankCardModel = JsonConvert.DeserializeObject<BankCardModel>(result);
-
- return bankCardModel;
- }
-
- public static String getFileBase64(String fileName)
- {
- FileStream filestream = new FileStream(fileName, FileMode.Open);
- byte[] arr = new byte[filestream.Length];
- filestream.Read(arr, 0, (int)filestream.Length);
- string baser64 = Convert.ToBase64String(arr);
- filestream.Close();
- return baser64;
- }
- }
实体:
- public class BankCardModel
- {
- public BankCardModelItem result { get; set; }
- }
-
- public class BankCardModelItem
- {
- public string bank_card_number { get; set; }
- public string valid_date { get; set; }
- }
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)
评价