AlipayFunctionForHD.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.Collections.Generic;
  3. using Aop.Api;
  4. using Library;
  5. using Microsoft.AspNetCore.Http;
  6. using Aop.Api.Request;
  7. using Aop.Api.Response;
  8. using Aop.Api.Util;
  9. using MySystem.Models;
  10. using System.Linq;
  11. using MySystem.Models.Main;
  12. namespace MySystem
  13. {
  14. public class AlipayFunctionForHD
  15. {
  16. public readonly static AlipayFunctionForHD Instance = new AlipayFunctionForHD();
  17. private AlipayFunctionForHD()
  18. { }
  19. // public string Pid = "2088720140260314";
  20. private string AppId = "2021004109682585";
  21. private string PrivateKey = "MIIEpAIBAAKCAQEAvf75JGQL9IDg8xu2C6qWrIO3H4roSwpvwUeh6y2kQ8iH0gqQXlyLj13ku8pzY1H9JTSeARCsHSD/VJFxMoPOBO+/xGDV3CSdxhOE5Fu5E30ZZMA5XmnMKyN8q+MEh7refGuCmldedTmzr9mNw4HDjS1uqJoqYRl3eUEaC/Syl620iiaSh7Q9/rsT/qNcnP5hO9P3DWionNt78elmjLt0sBdBkQ10o2XwC5RuzBfP8DCBEdL/DPOOE4vtmLP1IdDI7qtjBhX8PdL+/IRxe/4OGvYSPnHW7JNlN970h2UN5i0Yu0AkidJvlS59nX9C1WJ4U37HiMnkMNXLB/Ubi5BkgQIDAQABAoIBAQC1itVKpWIa/a5z/Q2EtjqEmtK2jAcL9Ov11dlsm07zCcBlvXxW/bzIf6IYogiBZY0qKM21HNYoeygeCV8NMo3/f4pQPWr7j+1Fn88CWHZOneFOuLHYeeUBb0YoA6KHgtImNqAzk7oI7tq383uWzP4qfrfW2IAYCbp0HPWjaOvhKw7qrejcTPW0oCsPjm6nkjzW6FzjkPCwiiivvpC67Ez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SwpvwUeh6y2kQ8iH0gqQXlyLj13ku8pzY1H9JTSeARCsHSD/VJFxMoPOBO+/xGDV3CSdxhOE5Fu5E30ZZMA5XmnMKyN8q+MEh7refGuCmldedTmzr9mNw4HDjS1uqJoqYRl3eUEaC/Syl620iiaSh7Q9/rsT/qNcnP5hO9P3DWionNt78elmjLt0sBdBkQ10o2XwC5RuzBfP8DCBEdL/DPOOE4vtmLP1IdDI7qtjBhX8PdL+/IRxe/4OGvYSPnHW7JNlN970h2UN5i0Yu0AkidJvlS59nX9C1WJ4U37HiMnkMNXLB/Ubi5BkgQIDAQAB";
  23. public string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiXVtTk6opnYllnH/X40k/jSw/82WZ+lGbYQLYH/nVONFJ7Gr9C/dlKpJFIbS+vNDn+YLtM923KmEVSgf8zU0WrTkRjWvKEiyLswWZVqSZW5Jfon1e2SfjNrAVi6XBZa7urAItKQsdD2vFFuyG/ohlXBL103xC1wnjvECD/iholoruEFOLyfobJKTY/6iyrKeOElem1V7OWl6gdjG2oozj3nbVZhtkQvPJECYlolH96eK2mieTkFK82aZ5Tdzx1LPk/3hxRAmzz/9X7xfXdOly88hKBmW8LC9RhTlOWbrXJhhFz13A4brnbnOiY/X7b2OkAYifammc2uh0AIJlCmBTQIDAQAB";
  24. //"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";
  25. #region 商家认证申请单提交
  26. public string AuthOrderCreate(MerchantAddInfo info, string MerToken)
  27. {
  28. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  29. AlipayMerchantIndirectAuthorderCreateRequest request = new AlipayMerchantIndirectAuthorderCreateRequest();
  30. string out_biz_no = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  31. string identity_type = info.SubjectType;
  32. if (identity_type == "SUBJECT_TYPE_ENTERPRISE") identity_type = "ENTERPRISE";
  33. if (identity_type == "SUBJECT_TYPE_INDIVIDUAL") identity_type = "IND_BIZ";
  34. if (identity_type == "SUBJECT_TYPE_SMALL") identity_type = "MSE";
  35. string PeriodEnd = info.PeriodEnd.Value.ToString("yyyy-MM-dd");
  36. if (PeriodEnd.Substring(0, 4) == "2050")
  37. {
  38. PeriodEnd = "forever";
  39. }
  40. string CardPeriodEnd = info.CardPeriodEnd.Value.ToString("yyyy-MM-dd");
  41. if (CardPeriodEnd.Substring(0, 4) == "2050")
  42. {
  43. CardPeriodEnd = "forever";
  44. }
  45. string BizContent = "{" +
  46. " \"out_biz_no\":\"" + out_biz_no + "\"," +
  47. " \"contact_person_info\":{" +
  48. " \"contact_name\":\"" + info.CertLegalPerson + "\"," +
  49. " \"contact_phone_no\":\"" + info.MobilePhone + "\"," +
  50. " \"contact_card_no\":\"" + info.IdCardNumber + "\"," +
  51. " \"contact_cert_type\":\"RESIDENT\"" +
  52. " }," +
  53. " \"auth_identity_info\":{" +
  54. " \"identity_type\":\"" + identity_type + "\"," +
  55. " \"is_financial_org\":false," +
  56. " \"certificate_type\":\"BUSINESS_CERT\"," +
  57. " \"certificate_info\":{" +
  58. " \"cert_type\":\"UNIT_SOCIAL_CREDIT\"," +
  59. " \"cert_no\":\"" + info.LicenseNumber + "\"," +
  60. " \"cert_image\":\"" + UploadPic(info.LicenseCopy) + "\"," +
  61. " \"merchant_name\":\"" + info.CertMerchantName + "\"," +
  62. " \"legal_person_name\":\"" + info.CertLegalPerson + "\"," +
  63. " \"register_address\":\"" + info.BizAddressCode.Replace(",", "") + info.BizStoreAddress + "\"," +
  64. " \"effect_time\":\"" + info.PeriodBegin.Value.ToString("yyyy-MM-dd") + "\"," +
  65. " \"expire_time\":\"" + PeriodEnd + "\"" +
  66. " },";
  67. if (info.SubjectType == "SUBJECT_TYPE_SMALL")
  68. {
  69. string bizAddressCode = info.BizAddressCode;
  70. string province_code = "", city_code = "", district_code = "";
  71. string province = "", city = "", district = "";
  72. WebCMSEntities db = new WebCMSEntities();
  73. OpenBankCityTable cityItem = db.OpenBankCityTable.FirstOrDefault(m => m.CityName.EndsWith(bizAddressCode));
  74. if (cityItem != null)
  75. {
  76. district_code = cityItem.Code;
  77. city_code = district_code.Substring(0, 4) + "00";
  78. province_code = district_code.Substring(0, 2) + "0000";
  79. string[] CityNames = cityItem.CityName.Split(',');
  80. district = CityNames[CityNames.Length - 3];
  81. city = CityNames[CityNames.Length - 2];
  82. province = CityNames[CityNames.Length - 1];
  83. }
  84. BizContent += " \"support_credentials\":{" +
  85. " \"merchant_type\":\"STORE\"," +
  86. " \"store_name\":\"" + info.BizStoreName + "\"," +
  87. " \"province_code\":\"" + province_code + "\"," +
  88. " \"province\":\"" + province + "\"," +
  89. " \"city_code\":\"" + city_code + "\"," +
  90. " \"city\":\"" + city + "\"," +
  91. " \"district_code\":\"" + district_code + "\"," +
  92. " \"district\":\"" + district + "\"," +
  93. " \"store_address\":\"" + info.BizStoreAddress + "\"," +
  94. " \"store_door_img\":\"" + UploadPic(info.StoreEntrancePic.Split(',')[0]) + "\"," +
  95. " \"store_inner_img\":\"" + UploadPic(info.IndoorPic.Split(',')[0]) + "\"" +
  96. " }";
  97. }
  98. BizContent += " }," +
  99. " \"legal_person_info\":{" +
  100. " \"legal_type\":\"LEGAL_PERSON\"," +
  101. " \"card_type\":\"RESIDENT\"," +
  102. " \"person_name\":\"" + info.CertLegalPerson + "\"," +
  103. " \"card_no\":\"" + info.IdCardNumber + "\"," +
  104. " \"effect_time\":\"" + info.CardPeriodBegin.Value.ToString("yyyy-MM-dd") + "\"," +
  105. " \"expire_time\":\"" + CardPeriodEnd + "\"," +
  106. " \"card_front_img\":\"" + UploadPic(info.IdCardCopy) + "\"," +
  107. " \"card_back_img\":\"" + UploadPic(info.IdCardNational) + "\"," +
  108. " \"is_benefit_person\":true" +
  109. " }" +
  110. "}";
  111. request.BizContent = BizContent;
  112. LogHelper.Instance.WriteLog(BizContent, "支付宝开户意愿确认");
  113. string result = "";
  114. try
  115. {
  116. AlipayMerchantIndirectAuthorderCreateResponse response = client.Execute(request);
  117. result = response.Body;
  118. LogHelper.Instance.WriteLog(result, "支付宝开户意愿确认");
  119. }
  120. catch (Exception ex)
  121. {
  122. LogHelper.Instance.WriteLog(ex.ToString(), "支付宝开户意愿确认异常");
  123. result = "";
  124. }
  125. return result;
  126. }
  127. #endregion
  128. #region 查询商家认证申请单状态
  129. public string AuthOrderQuery(string OrderNo)
  130. {
  131. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  132. AlipayMerchantIndirectAuthorderQuerystatusRequest request = new AlipayMerchantIndirectAuthorderQuerystatusRequest();
  133. request.BizContent = "{" +
  134. " \"order_no\":\"" + OrderNo + "\"" +
  135. "}";
  136. LogHelper.Instance.WriteLog(request.BizContent, "查询支付宝商家认证申请单状态");
  137. string result = "";
  138. try
  139. {
  140. AlipayMerchantIndirectAuthorderQuerystatusResponse response = client.Execute(request);
  141. result = response.Body;
  142. LogHelper.Instance.WriteLog(result, "查询支付宝商家认证申请单状态");
  143. }
  144. catch (Exception ex)
  145. {
  146. LogHelper.Instance.WriteLog(ex.ToString(), "查询支付宝商家认证申请单状态异常");
  147. result = "";
  148. }
  149. return result;
  150. }
  151. #endregion
  152. #region 图片上传
  153. public string UploadPic(string path)
  154. {
  155. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  156. string fileName = path.Substring(path.LastIndexOf("/") + 1);
  157. string imageBase64 = function.imageToBase64String(function.getPath(path));
  158. // imageBase64 = imageBase64.Substring(imageBase64.IndexOf(";base64,") + 8);
  159. AntMerchantExpandIndirectImageUploadRequest request = new AntMerchantExpandIndirectImageUploadRequest();
  160. FileItem imageContent = new FileItem(fileName, Convert.FromBase64String(imageBase64));
  161. request.ImageContent = imageContent;
  162. request.ImageType = "jpg";
  163. AntMerchantExpandIndirectImageUploadResponse response = client.Execute(request);
  164. return fileName;
  165. }
  166. #endregion
  167. }
  168. }