diff --git a/HJGL_DS/SgManager.AI/APIBaseModel.cs b/HJGL_DS/SgManager.AI/APIBaseModel.cs new file mode 100644 index 0000000..9d04b07 --- /dev/null +++ b/HJGL_DS/SgManager.AI/APIBaseModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class APIBaseModel where T : class, new() + { + + public T contextModel//这里的context 调用要重新实例化一个 + { + get; set; + } + public bool state { get; set; } + + /// + /// 非接口信息错误 + /// + public string errorMsg { get; set; } + } +} diff --git a/HJGL_DS/SgManager.AI/AccessTokenModel.cs b/HJGL_DS/SgManager.AI/AccessTokenModel.cs new file mode 100644 index 0000000..5f4414c --- /dev/null +++ b/HJGL_DS/SgManager.AI/AccessTokenModel.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class AccessTokenModel + { + public bool IsSuccess { get; set; } + public SuccessAccessTokenModel SuccessModel { get; set; } + public ErrorAccessTokenModel ErrorModel { get; set; } + } + /// + /// 获取accesstoken,正常 的 百度接口返回的json 实体模型 + /// + public class SuccessAccessTokenModel + { + public string refresh_token { get; set; } + public int expires_in { get; set; } + public string scope { get; set; } + public string session_key { get; set; } + public string session_secret { get; set; } + + public string access_token { get; set; } + } + + /// + /// 获取accesstoken,失败的 百度接口返回的json 实体模型 + /// + public class ErrorAccessTokenModel + { + public string error { get; set; } + public string error_description { get; set; } + + } + +} diff --git a/HJGL_DS/SgManager.AI/BaiduError.cs b/HJGL_DS/SgManager.AI/BaiduError.cs new file mode 100644 index 0000000..0db3f63 --- /dev/null +++ b/HJGL_DS/SgManager.AI/BaiduError.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class BaiduError + { + public static string getBaiduError(String errCode) + { + string error = "未知错误"; + switch (errCode) + { + case "222202": + error = "未识别到人脸"; + break; + + case "223106": + error = "该人脸不存在"; + break; + + case "223110": + error = "uid_list包含数量过多"; + break; + + case "223111": + error = "目标用户组不存在"; + break; + + case "223112": + error = "quality_conf格式不正确"; + break; + + case "223113": + error = "人脸有被遮挡,请重新操作"; + break; + + case "223114": + error = "人脸模糊,请重新操作"; + break; + + case "223115": + error = "人脸光照不好,请重新操作"; + break; + + + case "223116": + error = "人脸不完整,请重新操作"; + break; + + + case "223117": + error = "app_list包含app数量过多"; + break; + + + case "223118": + error = "质量控制项错误"; + break; + + case "223119": + error = "活体控制项错误"; + break; + + case "223120": + error = "活体检测未通过,请重新操作"; + break; + case "223121": + error = "左眼遮挡程度过高,请重新操作"; + break; + case "223122": + error = "右眼遮挡程度过高,请重新操作"; + break; + case "223123": + error = "左脸遮挡程度过高,请重新操作"; + break; + case "223124": + error = "右脸遮挡程度过高,请重新操作"; + break; + case "223125": + error = "下巴遮挡程度过高,请重新操作"; + break; + + case "223126": + error = "鼻子遮挡程度过高,请重新操作"; + break; + case "223127": + error = "嘴巴遮挡程度过高,请重新操作"; + break; + + } + + return error; + } + } +} diff --git a/HJGL_DS/SgManager.AI/ConfigAppSetting.cs b/HJGL_DS/SgManager.AI/ConfigAppSetting.cs new file mode 100644 index 0000000..2753f4f --- /dev/null +++ b/HJGL_DS/SgManager.AI/ConfigAppSetting.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class ConfigAppSetting + { + public static double getConfigAppSetting(String name) + { + try + { + return Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings[name]); + } + catch (Exception ex) + { + return 0; + } + + } + } +} diff --git a/HJGL_DS/SgManager.AI/ErrorTypeModel.cs b/HJGL_DS/SgManager.AI/ErrorTypeModel.cs new file mode 100644 index 0000000..a559f36 --- /dev/null +++ b/HJGL_DS/SgManager.AI/ErrorTypeModel.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + /// + /// 错误信息 实体 + /// + public class ErrorTypeModel + { + /// + /// 日志Id + /// + public string log_id { get; set; } + /// + /// 错误码 + /// + public string error_code { get; set; } + + /// + /// 错误信息 + /// + public string error_msg { get; set; } + + /// + /// 错误信息中文描述 + /// + public string error_discription { get; set; } + } +} diff --git a/HJGL_DS/SgManager.AI/FaceClass.cs b/HJGL_DS/SgManager.AI/FaceClass.cs new file mode 100644 index 0000000..a84318e --- /dev/null +++ b/HJGL_DS/SgManager.AI/FaceClass.cs @@ -0,0 +1,312 @@ +using AOP.Common.DataConversion; +using Baidu.Aip.Face; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + + public static class FaceClass + { + + + public static Baidu.Aip.Face.Face getFaceClant() + { + // 设置APPID/AK/SK + var APP_ID = System.Configuration.ConfigurationManager.AppSettings["APP_ID"].ToString(); + var API_KEY = System.Configuration.ConfigurationManager.AppSettings["API_KEY"].ToString(); + var SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"].ToString(); + var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY); + client.Timeout = 60000; // 修改超时时间 + return client; + + } + + + public static object SearchFileFace(String imagePath) + { + String strbaser64 = ConvertDataFormatAndImage.ImageToByte64String(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg); // 图片的base64编码 + var imageType = "BASE64"; + var groupIdList = "WX_Face_TCC"; + // 如果有可选参数 + var options = new Dictionary{ + {"quality_control", "NORMAL"}, + {"liveness_control", "NORMAL"}, + {"max_user_num", 1} + }; + // 带参数调用人脸搜索 + object result = new object(); + List frs = new List(); + try + { + result = getFaceClant().Search(strbaser64, imageType, groupIdList, options); + + if (result != null) + { + var data = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result)); + String error_msg = data.error_msg; + String errorCode = data.error_code; + if (error_msg == "SUCCESS") + { + + for (int i = 0; i < data.result.user_list.Count; i++) + { + faceResult fr = new faceResult(); + fr.user_id = data.result.user_list[i].user_id; + fr.user_info = getUserName(fr.user_id); + fr.errMess = error_msg; + try + { + string score = data.result.user_list[i].score.ToString(); + fr.score = double.Parse(score); + } + catch + { + fr.score = 0; + } + if (fr.score > 85) + frs.Add(fr); + + } + } + else + { + faceResult fr = new faceResult(); + fr.errMess = error_msg; + fr.errCode = errorCode; + frs.Add(fr); + } + } + } + catch (Exception ex) + { + faceResult fr = new faceResult(); + fr.errMess = ex.ToString(); + frs.Add(fr); + } + return frs; + } + + public static object SearchFace(String url) + { + var image = url; + var imageType = "URL"; + var groupIdList = "WX_Face_TCC"; + // 如果有可选参数 + var options = new Dictionary{ + {"quality_control", "NORMAL"}, + {"liveness_control", "LOW"}, + {"max_user_num", 1} + }; + // 带参数调用人脸搜索 + object result = new object(); + try + { + result = getFaceClant().Search(image, imageType, groupIdList, options); + } + catch (Exception ex) + { + return null; + } + List frs = new List(); + if (result != null) + { + var data = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result)); + String error_msg = data.error_msg; + if (error_msg == "SUCCESS") + { + + for (int i = 0; i < data.result.user_list.Count; i++) + { + faceResult fr = new faceResult(); + fr.user_id = data.result.user_list[i].user_id; + fr.user_info = getUserName(fr.user_id); + + try + { + string score = data.result.user_list[i].score.ToString(); + fr.score = double.Parse(score); + } + catch + { + fr.score = 0; + } + if (fr.score > 85) + { + frs.Add(fr); + break; + } + + } + } + else return null; + } + return frs; + } + + + public static String getUserName(string id) + { + string userName = "未知用户"; + switch (id) + { + + case "A01844": + userName = "张腾云"; + break; + case "A04979": + userName = "张延强"; + break; + case "A05352": + userName = "王勇C"; + break; + case "A06539": + userName = "崔璐峰"; + break; + case "A04984": + userName = "杨新民"; + break; + case "A05303": + userName = "李文娟"; + break; + case "A04988": + userName = "马明"; + break; + case "A06926": + userName = "王建峰"; + break; + default: + userName = "未知用户"; + break; + + + } + return userName; + + } + + // 在线活体检测 + public static string FaceVerify(string imagePath) + { + string token = AccessToken.getAccessToken(); + string host = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token=" + token; + Encoding encoding = Encoding.Default; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host); + request.Method = "post"; + request.KeepAlive = true; + String strbaser64 = ConvertDataFormatAndImage.ImageToByte64String(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg); // 图片的base64编码 + String str = "[{\"image\":\"" + strbaser64 + "\",\"image_type\":\"BASE64\",\"face_field\":\"quality,human\"}]"; + 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.Default); + string result = reader.ReadToEnd(); + //Console.WriteLine("在线活体检测:"); + Console.WriteLine(result); + return result; + } + + // 人脸注册 + public static string add(string user_id, string user_card, string imgUrl, string token) + { + bool first = true; + if (string.IsNullOrEmpty(token)) + { + token = AccessToken.getAccessToken(); + first = false; + } + string host = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add?access_token=" + token; + Encoding encoding = Encoding.Default; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host); + request.Method = "post"; + request.KeepAlive = true; + String str = "{\"image\":\"" + imgUrl + "\",\"image_type\":\"URL\",\"group_id\":\"WX_Face_TCC\",\"user_id\":\"" + user_card + "\",\"user_info\":\"" + user_id + "\",\"quality_control\":\"LOW\",\"liveness_control\":\"NORMAL\"}"; + 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.Default); + string result = reader.ReadToEnd(); + //Console.WriteLine("人脸注册:"); + //Console.WriteLine(result); + var res = JsonConvert.DeserializeObject(result); + + if (result.Contains("Access token invalid or no longer valid") && first) + { + token = null; + add(user_id, user_card, imgUrl, token); + } + + if (result.Contains("face is already exist")) + result = update(user_id, user_card, imgUrl, token); + if (res.error_code == "0") + { + + } + + + return result; + } + // 人脸更新 + public static string update(string user_id, string user_card, string imgUrl, string token) + { + if (string.IsNullOrEmpty(token)) + token = AccessToken.getAccessToken(); + string host = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/update?access_token=" + token; + Encoding encoding = Encoding.Default; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host); + request.Method = "post"; + request.KeepAlive = true; + String str = "{\"image\":\"" + imgUrl + "\",\"image_type\":\"URL\",\"group_id\":\"WX_Face_TCC\",\"user_id\":\"" + user_card + "\",\"user_info\":\"" + user_id + "\",\"quality_control\":\"LOW\",\"liveness_control\":\"NORMAL\"}"; + 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.Default); + string result = reader.ReadToEnd(); + if (result.Contains("user is not exist")) + result = add(user_id, user_card, imgUrl, token); + return result; + } + + + } + + + public static class AccessToken + + { + // 调用getAccessToken()获取的 access_token建议根据expires_in 时间 设置缓存 + // 返回token示例 + public static String TOKEN = "24.adda70c11b9786206253ddb70affdc46.2592000.1493524354.282335-1234567"; + + // 百度云中开通对应服务应用的 API Key 建议开通应用的时候多选服务 + private static String clientId = "百度云应用的AK"; + // 百度云中开通对应服务应用的 Secret Key + private static String clientSecret = "百度云应用的SK"; + + public static String getAccessToken() + { + String authHost = "https://aip.baidubce.com/oauth/2.0/token"; + HttpClient client = new HttpClient(); + List> paraList = new List>(); + paraList.Add(new KeyValuePair("grant_type", "client_credentials")); + paraList.Add(new KeyValuePair("client_id", System.Configuration.ConfigurationManager.AppSettings["API_KEY"].ToString())); + paraList.Add(new KeyValuePair("client_secret", System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"].ToString())); + + HttpResponseMessage response = client.PostAsync(authHost, new FormUrlEncodedContent(paraList)).Result; + String result = response.Content.ReadAsStringAsync().Result; + var to = JsonConvert.DeserializeObject(result); + Console.WriteLine(result); + return to.access_token; + } + } +} diff --git a/HJGL_DS/SgManager.AI/GpsPolygonHelper.cs b/HJGL_DS/SgManager.AI/GpsPolygonHelper.cs new file mode 100644 index 0000000..54dfe49 --- /dev/null +++ b/HJGL_DS/SgManager.AI/GpsPolygonHelper.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + + public class Gpslocation + { + public double lat; + public double lng; + } + public class GpsPolygonHelper + {/// + /// 判断当前位置是否在不规则形状里面 + /// + /// 不规则形状的定点数 + /// 当前x坐标 + /// 当前y坐标 + /// 不规则形状x坐标集合 + /// 不规则形状y坐标集合 + /// + public static bool PositionPnpoly(int nvert, List vertx, List verty, double testx, double testy) + { + int i, j, c = 0; + for (i = 0, j = nvert - 1; i < nvert; j = i++) + { + if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i])) + { + c = 1 + c; ; + } + } + if (c % 2 == 0) + { + return false; + } + else + { + return true; + } + } + + /// + /// 坐标点是否在多边形内判断 + /// + /// + /// + /// + + public static bool isPointInPolygon(Gpslocation point, List pts) + { + + //检查类型 + if (point == null || pts == null) + return false; + + var N = pts.Count; + var boundOrVertex = true; //如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true + var intersectCount = 0; //cross points count of x + var precision = 2e-10; //浮点类型计算时候与0比较时候的容差 + Gpslocation p1, p2; //neighbour bound vertices + var p = point; //测试点 + p1 = pts[0]; //left vertex + for (var i = 1; i <= N; ++i) + { + //check all rays + if (p.lat.Equals(p1.lat) && p.lng.Equals(p1.lng)) + { + return boundOrVertex; //p is an vertex + } + + p2 = pts[i % N]; //right vertex + if (p.lat < Math.Min(p1.lat, p2.lat) || p.lat > Math.Max(p1.lat, p2.lat)) + { + //ray is outside of our interests + p1 = p2; + continue; //next ray left point + } + + if (p.lat > Math.Min(p1.lat, p2.lat) && p.lat < Math.Max(p1.lat, p2.lat)) + { + //ray is crossing over by the algorithm (common part of) + if (p.lng <= Math.Max(p1.lng, p2.lng)) + { + //x is before of ray + if (p1.lat == p2.lat && p.lng >= Math.Min(p1.lng, p2.lng)) + { + //overlies on a horizontal ray + return boundOrVertex; + } + + if (p1.lng == p2.lng) + { + //ray is vertical + if (p1.lng == p.lng) + { + //overlies on a vertical ray + return boundOrVertex; + } + else + { + //before ray + ++intersectCount; + } + } + else + { + //cross point on the left side + var xinters = + (p.lat - p1.lat) * (p2.lng - p1.lng) / (p2.lat - p1.lat) + + p1.lng; //cross point of lng + if (Math.Abs(p.lng - xinters) < precision) + { + //overlies on a ray + return boundOrVertex; + } + + if (p.lng < xinters) + { + //before ray + ++intersectCount; + } + } + } + } + else + { + //special case when ray is crossing through the vertex + if (p.lat == p2.lat && p.lng <= p2.lng) + { + //p crossing over p2 + var p3 = pts[(i + 1) % N]; //next vertex + if (p.lat >= Math.Min(p1.lat, p3.lat) && p.lat <= Math.Max(p1.lat, p3.lat)) + { + //p.lat lies between p1.lat & p3.lat + ++intersectCount; + } + else + { + intersectCount += 2; + } + } + } + p1 = p2; //next ray left point + } + + if (intersectCount % 2 == 0) + { + //偶数在多边形外 + return false; + } + else + { + //奇数在多边形内 + return true; + } + + } + } +} diff --git a/HJGL_DS/SgManager.AI/IDCardClass.cs b/HJGL_DS/SgManager.AI/IDCardClass.cs new file mode 100644 index 0000000..44d9c8a --- /dev/null +++ b/HJGL_DS/SgManager.AI/IDCardClass.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class IDCardClass + { + + + // Distinguish(pb_SidePic.ImageLocation, "back", false, "true"); + // Distinguish(pb_PositivePic.ImageLocation, "front", false, "true"); + /// + /// 识别操作 + /// + /// + /// 身份证 正面还是背面 + /// + /// + public static APIBaseModel idcard(string filePath, string id_card_side = "front", bool detect_direction = false, string detect_risk = "false") + { + var temp = IDCardToken.GetAccessToken(); + if (temp.IsSuccess) + { + string data = ""; + string error = ""; + string token = temp.SuccessModel.access_token; + var result = IDCardRecognition.GetIdcardRecognitionString(temp.SuccessModel.access_token, filePath, ref data, out error, id_card_side, detect_direction, detect_risk); + return result; + } + return null; + + } + } +} diff --git a/HJGL_DS/SgManager.AI/IDCardRecognition.cs b/HJGL_DS/SgManager.AI/IDCardRecognition.cs new file mode 100644 index 0000000..3d974dc --- /dev/null +++ b/HJGL_DS/SgManager.AI/IDCardRecognition.cs @@ -0,0 +1,84 @@ +using AOP.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web; + +namespace SgManager.AI +{ + /// + /// 文字识别--身份证识别 应用(只是获取身份证图片 信息,没有和公安部联网,无法确认真假,只是单纯从图片上识别文字) + /// + public class IDCardRecognition + { + // 身份证识别 + + /// + /// 身份证识别 + /// + /// Accesstoken + /// 图片路径 + /// 识别结果 + /// 错误信息 + /// front:身份证正面;back:身份证背面 + /// 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:- true:检测朝向;- false:不检测朝向。 + /// string 类型 是否开启身份证风险类型(身份证复印件、临时身份证、身份证翻拍、修改过的身份证)功能,默认不开启,即:false。可选值:true-开启;false-不开启 + /// 结果状态 + public static APIBaseModel GetIdcardRecognitionString(string token, string imagePath, ref string recognitionString, out string errorMsg, string id_card_side = "front", bool detect_direction = false, string detect_risk = "false") + { + bool resultState = true; + + APIBaseModel tempModel = new APIBaseModel(); + tempModel.contextModel = new IDCardRecognitionModel(); + + string strbaser64 = ""; + try + { + #region 基础校验 + string verificationMsg = ""; + errorMsg = ""; + var verifyResult = ImageVerification.VerificationImage(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg, tempModel, out verificationMsg, out strbaser64); + if (!verifyResult.state) + { + return verifyResult; + } + + recognitionString = ""; + + string host = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=" + token; + String str = "id_card_side=" + id_card_side + "&detect_direction=" + detect_direction + "&detect_risk=" + detect_risk + "&image=" + HttpUtility.UrlEncode(strbaser64); + var tempResult = HttpRequestHelper.Post(host, str); + recognitionString = tempResult; + if (recognitionString.Contains("\"error_code\""))//说明异常 + { + resultState = false; + tempModel.state = false; + tempModel.contextModel.errorTypeModel = Json.ToObject(tempResult); + tempModel.contextModel.errorTypeModel.error_discription = OCR_CharacterRecognitionErrorType.GetErrorCodeToDescription(tempModel.contextModel.errorTypeModel.error_code); + } + else + { + tempModel.state = true; + var temp = Json.ToObject(tempResult); + tempModel.contextModel.successModel = temp; + } + #endregion + + return tempModel; + } + catch (Exception ex)//接口外部异常,如网络异常 + { + resultState = false; + errorMsg = ex.ToString(); + tempModel.state = false; + tempModel.errorMsg = ex.ToString(); + return tempModel; + + } + } + + + } +} diff --git a/HJGL_DS/SgManager.AI/IDCardRecognitionModel.cs b/HJGL_DS/SgManager.AI/IDCardRecognitionModel.cs new file mode 100644 index 0000000..b1f56f0 --- /dev/null +++ b/HJGL_DS/SgManager.AI/IDCardRecognitionModel.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ /// + /// 身份证识别 实体 + /// + public class IDCardRecognitionModel + { + + + public IDCardRecognitionSuccessResultModel successModel { get; set; } + + public ErrorTypeModel errorTypeModel { get; set; } + + } + + public class IDCardRecognitionSuccessResultModel + { + + public long log_id { get; set; } + + public int direction { get; set; } + + public int words_result_num { get; set; } + + public string image_status { get; set; } + public string idcard_type { get; set; } + public string edit_tool { get; set; } + + public string risk_type { get; set; } + public Words_result words_result { get; set; } + } + + public class Words_result + { + + + public 住址 住址 { get; set; } + public 公民身份号码 公民身份号码 { get; set; } + public 出生 出生 { get; set; } + public 姓名 姓名 { get; set; } + public 性别 性别 { get; set; } + + public 民族 民族 { get; set; } + + public 签发日期 签发日期 { get; set; } + public 失效日期 失效日期 { get; set; } + public 签发机关 签发机关 { get; set; } + + } + + public class 住址 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 公民身份号码 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 出生 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 姓名 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 性别 + { + + public Location location { get; set; } + public string words { get; set; } + } + public class 民族 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 签发日期 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 失效日期 + { + + public Location location { get; set; } + public string words { get; set; } + } + + public class 签发机关 + { + + public Location location { get; set; } + public string words { get; set; } + } + + + + public class Location + { + + public int left { get; set; } + public int top { get; set; } + public int width { get; set; } + public int height { get; set; } + + } + + public class DicModel + { + + public string words { get; set; } + public Location location { get; set; } + + } + +} diff --git a/HJGL_DS/SgManager.AI/IDCardToken.cs b/HJGL_DS/SgManager.AI/IDCardToken.cs new file mode 100644 index 0000000..04ccfb2 --- /dev/null +++ b/HJGL_DS/SgManager.AI/IDCardToken.cs @@ -0,0 +1,60 @@ +using AOP.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public static class IDCardToken + { + + // 调用getAccessToken()获取的 access_token建议根据expires_in 时间 设置缓存 + // 返回token示例 + public static String TOKEN = "24.adda70c11b9786206253ddb70affdc46.2592000.1493524354.282335-1234567"; + + // 百度云中开通对应服务应用的 API Key 建议开通应用的时候多选服务 + private static String clientId = System.Configuration.ConfigurationManager.AppSettings["ID_API_KEY"].ToString();// "onreA4ms0OUi2eclj8CnMoaV"; + // 百度云中开通对应服务应用的 Secret Key + private static String clientSecret = System.Configuration.ConfigurationManager.AppSettings["ID_SECRET_KEY"].ToString();// "ge8kERfb5uxqUKyOhdLMD2ozumNUigjY"; + + private static String getBaiduAccessToken() + { + String authHost = "https://aip.baidubce.com/oauth/2.0/token"; + HttpClient client = new HttpClient(); + List> paraList = new List>(); + paraList.Add(new KeyValuePair("grant_type", "client_credentials")); + paraList.Add(new KeyValuePair("client_id", clientId)); + paraList.Add(new KeyValuePair("client_secret", clientSecret)); + + HttpResponseMessage response = client.PostAsync(authHost, new FormUrlEncodedContent(paraList)).Result; + String result = response.Content.ReadAsStringAsync().Result; + Console.WriteLine(result); + return result; + } + + public static AccessTokenModel GetAccessToken() + { + + AccessTokenModel tempAccessTokenModel = new AccessTokenModel(); + string tempData = getBaiduAccessToken(); + if (tempData.Contains("\"error\"")) + {//标识异常 + + tempAccessTokenModel.IsSuccess = false; + tempAccessTokenModel.ErrorModel = Json.ToObject(tempData); + } + else + {//标识正常 + tempAccessTokenModel.IsSuccess = true; + tempAccessTokenModel.SuccessModel = Json.ToObject(tempData); + } + + return tempAccessTokenModel; + + } + + } +} diff --git a/HJGL_DS/SgManager.AI/ImageVerification.cs b/HJGL_DS/SgManager.AI/ImageVerification.cs new file mode 100644 index 0000000..f1b14a9 --- /dev/null +++ b/HJGL_DS/SgManager.AI/ImageVerification.cs @@ -0,0 +1,142 @@ +using AOP.Common.DataConversion; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web; + +namespace SgManager.AI +{ + public class ImageVerification + { + /// + /// 验证图片规格 + /// + /// 图片路径 + /// + /// 默认图片最大是4MB + /// 默认最短15px + /// 默认最长4096px + /// 是否验证通过 + public static bool VerificationImage(string filePath, out string Msg, int defaultImageSize = 1024 * 1024 * 4, int defaultShortLength = 15, int defaultLongLength = 4096) + { + bool isPass = true; + Msg = "";//提示信息 + + string filename = System.IO.Path.GetFileName(filePath); + + + #region 初始化验证参数 + if (!File.Exists(filePath)) + { + return false; + } + + if (string.IsNullOrEmpty(filename)) + { + Msg = "文件不能为空!"; + return false; + } + + #endregion + + #region 验证是否是图片 + bool isImg = false;//是否是图片标识 + string[] imgTypeList = new string[] { ".jpg", ".png", "bmp" }; + + //得到文件后缀 + string fileType = System.IO.Path.GetExtension(filePath); + + for (int i = 0; i < imgTypeList.Count(); i++) + { + + if (fileType.ToLower() == imgTypeList[i]) + { + + isImg = true; + } + } + + if (!isImg) + { + + Msg = "上传文件不是图片格式!请重新上传!"; + return false; + } + #endregion + + #region 验证图片大小 + + int imgSize = defaultImageSize; + byte[] bs = File.ReadAllBytes(filePath); + + + if (bs.Length > imgSize) + { + Msg = "图片大小不能" + imgSize / 1024 / 1024 + "MB"; + return false; + + } + #endregion + + #region 验证图片尺寸大小 + + + System.Drawing.Image tempImage = System.Drawing.Image.FromFile(filePath); + + int picWidth = tempImage.Width; + int picHeigth = tempImage.Height; + + if (!(defaultShortLength <= picWidth && picWidth <= defaultLongLength) && (defaultShortLength <= picHeigth && picHeigth <= defaultLongLength)) + { + + Msg = "图片尺寸规格最短边至少" + defaultShortLength + "px,最长边最大" + defaultLongLength + "px,"; + return false; + } + + #endregion + + return isPass; + + } + + public static APIBaseModel VerificationImage(string imagePath, System.Drawing.Imaging.ImageFormat imageFormat, APIBaseModel tempModel, out string errorMsg, out string strbaser64) where T : class, new() + { + #region 基础校验 + string verificationMsg = ""; + strbaser64 = ""; + errorMsg = ""; + bool isVerification = ImageVerification.VerificationImage(imagePath, out verificationMsg); + if (!isVerification) + { + + errorMsg += verificationMsg; + tempModel.state = false; + tempModel.errorMsg = errorMsg; + return tempModel; + } + strbaser64 = ConvertDataFormatAndImage.ImageToByte64String(imagePath, imageFormat); // 图片的base64编码 + Encoding encoding = Encoding.Default; + string urlEncodeImage = HttpUtility.UrlEncode(strbaser64); + + byte[] tempBuffer = encoding.GetBytes(urlEncodeImage); + + if (tempBuffer.Length > 1024 * 1024 * 4) + { + + errorMsg += "图片加密 后的大小超过4MB!"; + + tempModel.state = false; + tempModel.errorMsg = errorMsg; + return tempModel; + + } + tempModel.state = true; + return tempModel; + #endregion + } + + } +} diff --git a/HJGL_DS/SgManager.AI/MapClass.cs b/HJGL_DS/SgManager.AI/MapClass.cs new file mode 100644 index 0000000..80bde57 --- /dev/null +++ b/HJGL_DS/SgManager.AI/MapClass.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + class MapClass + { + } +} diff --git a/HJGL_DS/SgManager.AI/OCR_CharacterRecognitionErrorType.cs b/HJGL_DS/SgManager.AI/OCR_CharacterRecognitionErrorType.cs new file mode 100644 index 0000000..2da69d6 --- /dev/null +++ b/HJGL_DS/SgManager.AI/OCR_CharacterRecognitionErrorType.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class OCR_CharacterRecognitionErrorType + { + public static string GetErrorCodeToDescription(string errorCode) + { + string errorDecrition = ""; + + switch (errorCode) + { + + case "1": errorDecrition = "服务器内部错误,请再次请求, 如果持续出现此类错误,请通过QQ群(224994340)或工单联系技术支持团队。"; break; + case "2": errorDecrition = "服务暂不可用,请再次请求, 如果持续出现此类错误,请通过QQ群(224994340)或工单联系技术支持团队。"; break; + + case "3": errorDecrition = "调用的API不存在,请检查后重新尝试。"; break; + case "4": errorDecrition = "集群超限额。"; break; + case "6": errorDecrition = "无权限访问该用户数据。"; break; + case "14": errorDecrition = "IAM鉴权失败,建议用户参照文档自查生成sign的方式是否正确,或换用控制台中ak sk的方式调用。"; break; + case "17": errorDecrition = "每天请求量超限额。"; break; + case "18": errorDecrition = "QPS超限额。"; break; + case "19": errorDecrition = "请求总量超限额。"; break; + + case "100": errorDecrition = "无效的access_token参数,请检查后重新尝试。"; break; + case "110": errorDecrition = "access token过期。"; break; + case "282000": errorDecrition = "服务器内部错误,如果您使用的是高精度接口,报这个错误码的原因可能是您上传的图片中文字过多,识别超时导致的,建议您对图片进行切割后再识别,其他情况请再次请求, 如果持续出现此类错误,请通过QQ群(631977213)或工单联系技术支持团队。"; break; + case "216100": errorDecrition = "请求中包含非法参数,请检查后重新尝试。"; break; + case "216101": errorDecrition = "缺少必须的参数,请检查参数是否有遗漏。"; break; + case "216102": errorDecrition = "请求了不支持的服务,请检查调用的url。"; break; + case "216103": errorDecrition = "请求中某些参数过长,请检查后重新尝试。"; break; + case "216110": errorDecrition = "appid不存在,请重新核对信息是否为后台应用列表中的appid。"; break; + case "216200": errorDecrition = "图片为空,请检查后重新尝试。"; break; + case "216201": errorDecrition = "上传的图片格式错误,现阶段我们支持的图片格式为:PNG、JPG、JPEG、BMP,请进行转码或更换图片。"; break; + case "216202": errorDecrition = "上传的图片大小错误,现阶段我们支持的图片大小为:base64编码后小于4M,分辨率不高于4096*4096,请重新上传图片。"; break; + case "216630": errorDecrition = "识别错误,请再次请求,如果持续出现此类错误,请通过QQ群(631977213)或工单联系技术支持团队。"; break; + case "216631": errorDecrition = "识别银行卡错误,出现此问题的原因一般为:您上传的图片非银行卡正面,上传了异形卡的图片或上传的银行卡正品图片不完整。"; break; + case "216633": errorDecrition = "识别身份证错误,出现此问题的原因一般为:您上传了非身份证图片或您上传的身份证图片不完整。"; break; + + case "216634": errorDecrition = "检测错误,请再次请求,如果持续出现此类错误,请通过QQ群(631977213)或工单联系技术支持团队。"; break; + case "282003": errorDecrition = "请求参数缺失。"; break; + case "282005": errorDecrition = "处理批量任务时发生部分或全部错误,请根据具体错误码排查。"; break; + case "282006": errorDecrition = "批量任务处理数量超出限制,请将任务数量减少到10或10以下。"; break; + case "282110": errorDecrition = "URL参数不存在,请核对URL后再次提交。"; break; + case "282111": errorDecrition = "URL格式非法,请检查url格式是否符合相应接口的入参要求。"; break; + case "282112": errorDecrition = "url下载超时,请检查url对应的图床/图片无法下载或链路状况不好,您可以重新尝试一下,如果多次尝试后仍不行,建议更换图片地址。"; break; + case "282113": errorDecrition = "URL返回无效参数。"; break; + case "282114": errorDecrition = "URL长度超过1024字节或为0。"; break; + case "282808": errorDecrition = "request id xxxxx 不存在。"; break; + case "282809": errorDecrition = "返回结果请求错误(不属于excel或json)。"; break; + case "282810": errorDecrition = "图像识别错误。"; break; + + default: errorDecrition = "未知的错误!"; break; + } + + return errorDecrition; + + } + } +} diff --git a/HJGL_DS/SgManager.AI/PostMail.cs b/HJGL_DS/SgManager.AI/PostMail.cs new file mode 100644 index 0000000..b42c254 --- /dev/null +++ b/HJGL_DS/SgManager.AI/PostMail.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Mail; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class PostMail + { + public class EmailParameterSet + { + /// + /// 收件人的邮件地址 + /// + public string ConsigneeAddress { get; set; } + + /// + /// 收件人的名称 + /// + public string ConsigneeName { get; set; } + + /// + /// 收件人标题 + /// + public string ConsigneeHand { get; set; } + + /// + /// 收件人的主题 + /// + public string ConsigneeTheme { get; set; } + + /// + /// 发件邮件服务器的Smtp设置 + /// + public string SendSetSmtp { get; set; } + + /// + /// 发件人的邮件 + /// + public string SendEmail { get; set; } + + /// + /// 发件人的邮件密码 + /// + public string SendPwd { get; set; } + /// + /// 发件内容 + /// + public string SendContent { get; set; } + } + + public bool MailSend(EmailParameterSet EPSModel) + { + try + { + //确定smtp服务器端的地址,实列化一个客户端smtp + System.Net.Mail.SmtpClient sendSmtpClient = new System.Net.Mail.SmtpClient(EPSModel.SendSetSmtp);//发件人的邮件服务器地址 + //构造一个发件的人的地址 + System.Net.Mail.MailAddress sendMailAddress = new MailAddress(EPSModel.SendEmail, EPSModel.ConsigneeHand, Encoding.UTF8);//发件人的邮件地址和收件人的标题、编码 + + //构造一个收件的人的地址 + System.Net.Mail.MailAddress consigneeMailAddress = new MailAddress(EPSModel.ConsigneeAddress, EPSModel.ConsigneeName, Encoding.UTF8);//收件人的邮件地址和收件人的名称 和编码 + + //构造一个Email对象 + System.Net.Mail.MailMessage mailMessage = new MailMessage(sendMailAddress, consigneeMailAddress);//发件地址和收件地址 + mailMessage.Subject = EPSModel.ConsigneeTheme;//邮件的主题 + mailMessage.BodyEncoding = Encoding.UTF8;//编码 + mailMessage.SubjectEncoding = Encoding.UTF8;//编码 + mailMessage.Body = EPSModel.SendContent;//发件内容 + mailMessage.IsBodyHtml = false;//获取或者设置指定邮件正文是否为html + + //设置邮件信息 (指定如何处理待发的电子邮件) + sendSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定如何发邮件 是以网络来发 + sendSmtpClient.EnableSsl = false;//服务器支持安全接连,安全则为true + + sendSmtpClient.UseDefaultCredentials = false;//是否随着请求一起发 + + //用户登录信息 + NetworkCredential myCredential = new NetworkCredential(EPSModel.SendEmail, EPSModel.SendPwd); + sendSmtpClient.Credentials = myCredential;//登录 + sendSmtpClient.Send(mailMessage);//发邮件 + return true;//发送成功 + } + catch (Exception) + { + return false;//发送失败 + } + } + + } +} diff --git a/HJGL_DS/SgManager.AI/Properties/AssemblyInfo.cs b/HJGL_DS/SgManager.AI/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e3c9dff --- /dev/null +++ b/HJGL_DS/SgManager.AI/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("SgManager.AI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SgManager.AI")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("55f4e1e2-5fb3-4ab4-b692-432ce41b3e61")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/HJGL_DS/SgManager.AI/SgManager.AI.csproj b/HJGL_DS/SgManager.AI/SgManager.AI.csproj new file mode 100644 index 0000000..65608c6 --- /dev/null +++ b/HJGL_DS/SgManager.AI/SgManager.AI.csproj @@ -0,0 +1,87 @@ + + + + + Debug + AnyCPU + {55F4E1E2-5FB3-4AB4-B692-432CE41B3E61} + Library + Properties + SgManager.AI + SgManager.AI + v4.6.1 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\FineUIPro\Reference BLL\AipSdk.dll + + + ..\FineUIPro\Reference BLL\AOP.Common.dll + + + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HJGL_DS/SgManager.AI/app.config b/HJGL_DS/SgManager.AI/app.config new file mode 100644 index 0000000..3e98c00 --- /dev/null +++ b/HJGL_DS/SgManager.AI/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/HJGL_DS/SgManager.AI/faceResult.cs b/HJGL_DS/SgManager.AI/faceResult.cs new file mode 100644 index 0000000..e8d2c76 --- /dev/null +++ b/HJGL_DS/SgManager.AI/faceResult.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SgManager.AI +{ + public class faceResult + { + public String errMess { get; set; } + public String user_id { get; set; } + public String user_info { get; set; } + public String errCode { get; set; } + public double score { get; set;} + + } +} diff --git a/HJGL_DS/SgManager.AI/packages.config b/HJGL_DS/SgManager.AI/packages.config new file mode 100644 index 0000000..7f83af3 --- /dev/null +++ b/HJGL_DS/SgManager.AI/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file