AlipayFunctionForHD.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. namespace MySystem
  12. {
  13. public class AlipayFunctionForHD
  14. {
  15. public readonly static AlipayFunctionForHD Instance = new AlipayFunctionForHD();
  16. private AlipayFunctionForHD()
  17. { }
  18. public string Pid = "2088720140260314";
  19. private string AppId = "2021004100667901";
  20. private string PrivateKey = "MIIEowIBAAKCAQEAhw2C7AypN/cSBNZU1LU2th58fzvLlhlfg7jZz3xNJQwpICtSF6hXXB2qChecEZv7ZGyiuuamTn/c+ZAKJAl3EZ8fMEgTrdK9M8+3DX6FIzWywCuPktsnxLIkTj4Lt/LjPI3P3yZLESuWzHIQ+TGnwEgm/Fx5ESWribFOddLRnNpINk36y+gtaVoXpQ742Wt6Yg1l4FZrzCAOHjLfVeTyAzmXXm8TGdzep83fyCqSBp+rdpb1CGQukHYpCapyk52hM4wqsAVdndAqO5qoRi5BfuyiVs2BR6Oe+8iF4rD5FJ/Wk6QguemWX8C/4jTnuNs1YsFuCTHqYwr8k8J6ekEdgwIDAQABAoIBAEob/PsBW56NYwLqhnSO2G4JvrGnI2nDlKlYt5VnFYI98RdpDkxTIVU4JgYRvJ/hI4uRHZ9IUHyFJ8J+60GpPACce+Xnt3zMRuz2j/HEutR+dA+GF+wzfNgwFUImRBH2JAIno6lFfy316HNaKLxGJlKahWI4cGsba81MUczQGhxi04XD9eVZNdeoRpt9eXTEuojjZIQB4JImHXI6jYxjhowP86D/hQ1lz78mC9mflSF0MC5gHtjdR0MScIKsewbJlRWpOw/UNuLX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F6hXXB2qChecEZv7ZGyiuuamTn/c+ZAKJAl3EZ8fMEgTrdK9M8+3DX6FIzWywCuPktsnxLIkTj4Lt/LjPI3P3yZLESuWzHIQ+TGnwEgm/Fx5ESWribFOddLRnNpINk36y+gtaVoXpQ742Wt6Yg1l4FZrzCAOHjLfVeTyAzmXXm8TGdzep83fyCqSBp+rdpb1CGQukHYpCapyk52hM4wqsAVdndAqO5qoRi5BfuyiVs2BR6Oe+8iF4rD5FJ/Wk6QguemWX8C/4jTnuNs1YsFuCTHqYwr8k8J6ekEdgwIDAQAB";
  22. public string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxuS3Edgrruau8SO2DsK0f2KcE+A6pGJ1f8CdL395qwoX5RnEx9yRUotkwN0ZF6qMUojFKu/J/X2DpxBWBc6jIa+cnFwPUykefXcXj/AQsgiIbFzNXBH9NSz+hngXP6xDs8D1u9h+fJB+TYD+WFXKwOcGwcx23uHLHUDi1UIEZOhT2Eui+aMCYVygUWH7JynTtbFQZyZcSsD2Dxj5OJNJlK110jarFgvqY98WxqtaRtB9Y8whwRRlGfa5GP2r/Vt3xbGeAflRl5khFgRLZgeFIfxJpEj1TZV2tCtpFS0uhXJGEQbMnzFynx8UaOx/0hBCyik1MQuu3flym6nx7XxPSQIDAQAB";
  23. //"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";
  24. #region 商家认证申请单提交
  25. public string AuthOrderCreate(MerchantAddInfo info, string MerToken)
  26. {
  27. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  28. AlipayMerchantIndirectAuthorderCreateRequest request = new AlipayMerchantIndirectAuthorderCreateRequest() ;
  29. string out_biz_no = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  30. string identity_type = info.SubjectType;
  31. if(identity_type == "SUBJECT_TYPE_ENTERPRISE") identity_type = "ENTERPRISE";
  32. if(identity_type == "SUBJECT_TYPE_INDIVIDUAL") identity_type = "IND_BIZ";
  33. if(identity_type == "SUBJECT_TYPE_SMALL") identity_type = "MSE";
  34. string PeriodEnd = info.PeriodEnd.Value.ToString("yyyy-MM-dd");
  35. if(PeriodEnd.Substring(0, 4) == "2050")
  36. {
  37. PeriodEnd = "forever";
  38. }
  39. string CardPeriodEnd = info.CardPeriodEnd.Value.ToString("yyyy-MM-dd");
  40. if(CardPeriodEnd.Substring(0, 4) == "2050")
  41. {
  42. CardPeriodEnd = "forever";
  43. }
  44. string BizContent = "{" +
  45. " \"out_biz_no\":\"" + out_biz_no + "\"," +
  46. " \"contact_person_info\":{" +
  47. " \"contact_name\":\"" + info.CertLegalPerson + "\"," +
  48. " \"contact_phone_no\":\"" + info.MobilePhone + "\"," +
  49. " \"contact_card_no\":\"" + info.IdCardNumber + "\"," +
  50. " \"contact_cert_type\":\"RESIDENT\"" +
  51. " }," +
  52. " \"auth_identity_info\":{" +
  53. " \"identity_type\":\"" + identity_type + "\"," +
  54. " \"is_financial_org\":false," +
  55. " \"certificate_type\":\"BUSINESS_CERT\"," +
  56. " \"certificate_info\":{" +
  57. " \"cert_type\":\"UNIT_SOCIAL_CREDIT\"," +
  58. " \"cert_no\":\"" + info.LicenseNumber + "\"," +
  59. " \"cert_image\":\"" + UploadPic(info.LicenseCopy) + "\"," +
  60. " \"merchant_name\":\"" + info.CertMerchantName + "\"," +
  61. " \"legal_person_name\":\"" + info.CertLegalPerson + "\"," +
  62. " \"register_address\":\"" + info.BizAddressCode.Replace(",", "") + info.BizStoreAddress + "\"," +
  63. " \"effect_time\":\"" + info.PeriodBegin.Value.ToString("yyyy-MM-dd") + "\"," +
  64. " \"expire_time\":\"" + PeriodEnd + "\"" +
  65. " },";
  66. if(info.SubjectType == "SUBJECT_TYPE_SMALL")
  67. {
  68. string bizAddressCode = info.BizAddressCode;
  69. string province_code = "", city_code = "", district_code = "";
  70. string province = "", city = "", district = "";
  71. WebCMSEntities db = new WebCMSEntities();
  72. OpenBankCityTable cityItem = db.OpenBankCityTable.FirstOrDefault(m => m.CityName.EndsWith(bizAddressCode));
  73. if(cityItem != null)
  74. {
  75. district_code = cityItem.Code;
  76. city_code = district_code.Substring(0, 4) + "00";
  77. province_code = district_code.Substring(0, 2) + "0000";
  78. string[] CityNames = cityItem.CityName.Split(',');
  79. district = CityNames[CityNames.Length - 3];
  80. city = CityNames[CityNames.Length - 2];
  81. province = CityNames[CityNames.Length - 1];
  82. }
  83. BizContent += " \"support_credentials\":{" +
  84. " \"merchant_type\":\"STORE\"," +
  85. " \"store_name\":\"" + info.BizStoreName + "\"," +
  86. " \"province_code\":\"" + province_code + "\"," +
  87. " \"province\":\"" + province + "\"," +
  88. " \"city_code\":\"" + city_code + "\"," +
  89. " \"city\":\"" + city + "\"," +
  90. " \"district_code\":\"" + district_code + "\"," +
  91. " \"district\":\"" + district + "\"," +
  92. " \"store_address\":\"" + info.BizStoreAddress + "\"," +
  93. " \"store_door_img\":\"" + UploadPic(info.StoreEntrancePic.Split(',')[0]) + "\"," +
  94. " \"store_inner_img\":\"" + UploadPic(info.IndoorPic.Split(',')[0]) + "\"" +
  95. " }";
  96. }
  97. BizContent += " }," +
  98. " \"legal_person_info\":{" +
  99. " \"legal_type\":\"LEGAL_PERSON\"," +
  100. " \"card_type\":\"RESIDENT\"," +
  101. " \"person_name\":\"" + info.CertLegalPerson + "\"," +
  102. " \"card_no\":\"" + info.IdCardNumber + "\"," +
  103. " \"effect_time\":\"" + info.CardPeriodBegin + "\"," +
  104. " \"expire_time\":\"" + CardPeriodEnd + "\"," +
  105. " \"card_front_img\":\"" + UploadPic(info.IdCardCopy) + "\"," +
  106. " \"card_back_img\":\"" + UploadPic(info.IdCardNational) + "\"," +
  107. " \"is_benefit_person\":true" +
  108. " }" +
  109. "}";
  110. request.BizContent = BizContent;
  111. string result = "";
  112. try
  113. {
  114. AlipayMerchantIndirectAuthorderCreateResponse response = client.Execute(request, null, MerToken);
  115. result = response.Body;
  116. }
  117. catch (Exception ex)
  118. {
  119. function.WriteLog(ex.ToString(), "商家认证申请单提交异常");
  120. result = "";
  121. }
  122. return result;
  123. }
  124. #endregion
  125. #region 图片上传
  126. public string UploadPic(string path)
  127. {
  128. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  129. string fileName = path.Substring(path.LastIndexOf("/") + 1);
  130. string imageBase64 = function.imageToBase64String(function.getPath(path));
  131. // imageBase64 = imageBase64.Substring(imageBase64.IndexOf(";base64,") + 8);
  132. AntMerchantExpandIndirectImageUploadRequest request = new AntMerchantExpandIndirectImageUploadRequest();
  133. FileItem imageContent = new FileItem(fileName,Convert.FromBase64String(imageBase64));
  134. request.ImageContent = imageContent;
  135. request.ImageType = "jpg";
  136. AntMerchantExpandIndirectImageUploadResponse response = client.Execute(request);
  137. return fileName;
  138. }
  139. #endregion
  140. }
  141. }