PubController.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Http;
  5. using System.DrawingCore.Imaging;
  6. using System.IO;
  7. using Library;
  8. using System.Collections;
  9. using LitJson;
  10. using System.Globalization;
  11. using System.Web;
  12. using System.Security.Cryptography;
  13. using System.Text;
  14. using Aliyun.OSS;
  15. namespace MySystem.Areas.Api.Controllers
  16. {
  17. [Area("Api")]
  18. [Route("Api/[controller]/[action]")]
  19. public class PubController : BaseController
  20. {
  21. public PubController(IHttpContextAccessor accessor) : base(accessor)
  22. {
  23. }
  24. #region OCR识别-营业执照
  25. public JsonResult BusinessLicenseOcr(string value)
  26. {
  27. value = DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. string Url = data["Url"].ToString();
  30. if(string.IsNullOrEmpty(Url))
  31. {
  32. return Json(new AppResultJson() { Status = "-1", Info = "营业执照识别异常,请手动填写" });
  33. }
  34. string content = AliyunOcr.Check(Url);
  35. if(string.IsNullOrEmpty(content))
  36. {
  37. return Json(new AppResultJson() { Status = "-1", Info = "营业执照识别异常,请手动填写" });
  38. }
  39. Dictionary<string, object> Obj = new Dictionary<string, object>();
  40. Obj.Add("OcrData", content);
  41. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  42. }
  43. #endregion
  44. #region 活体认证
  45. public string initFaceVerify(string value)
  46. {
  47. function.WriteLog(value, "活体认证提交");
  48. value = DesDecrypt(value);
  49. JsonData data = JsonMapper.ToObject(value);
  50. int targetId = int.Parse(data["targetId"].ToString());
  51. string realName = data["realName"].ToString();
  52. string idCard = data["idCard"].ToString();
  53. string metaInfo = data["metaInfo"].ToString();
  54. string accessToken = data["accessToken"].ToString();
  55. string jsonString = "{\"targetId\":" + targetId + ",\"realName\":\"" + realName + "\",\"idCard\":\"" + idCard + "\",\"metaInfo\":\"" + metaInfo + "\"}";
  56. string jsonData = AesEncrypt(jsonString);
  57. jsonData = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonData));
  58. Dictionary<string, string> header = new Dictionary<string, string>();
  59. header.Add("Authorization", "Bearer " + accessToken);
  60. string result = function.PostWebRequest(ConfigurationManager.AppSettings["LkbHost"] + "/v1/lkb/mchServer/faceVerify/initFaceVerify", jsonData, header, "application/json");
  61. return result;
  62. }
  63. public string queryFaceVerify(string value)
  64. {
  65. function.WriteLog(value, "活体认证查询");
  66. value = DesDecrypt(value);
  67. JsonData data = JsonMapper.ToObject(value);
  68. int targetId = int.Parse(data["targetId"].ToString());
  69. string accessToken = data["accessToken"].ToString();
  70. string jsonString = "{\"targetId\":" + targetId + "}";
  71. string jsonData = AesEncrypt(jsonString);
  72. jsonData = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonData));
  73. Dictionary<string, string> header = new Dictionary<string, string>();
  74. header.Add("Authorization", "Bearer " + accessToken);
  75. string result = function.GetWebRequest(ConfigurationManager.AppSettings["LkbHost"] + "/v1/lkb/mchServer/faceVerify/query?value=" + jsonData, header);
  76. return result;
  77. }
  78. public string AesEncrypt(string str)
  79. {
  80. if (string.IsNullOrEmpty(str)) return null;
  81. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  82. string key = "CBTU1dD4Kd5pyiGWTsI10jRQ3SvKusSV";
  83. string iv = "DYgjCEIMVrj2W9xN";
  84. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  85. {
  86. Key = Encoding.UTF8.GetBytes(key),
  87. IV = Encoding.UTF8.GetBytes(iv),
  88. Mode = System.Security.Cryptography.CipherMode.CBC,
  89. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  90. };
  91. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  92. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  93. return Convert.ToBase64String(resultArray, 0, resultArray.Length);
  94. }
  95. #endregion
  96. }
  97. }