using System; using System.Collections.Generic; using Aop.Api; using Library; using Microsoft.AspNetCore.Http; using Aop.Api.Request; using Aop.Api.Response; using Aop.Api.Util; using MySystem.Models; using System.Linq; namespace MySystem { public class AlipayFunctionForHD { public readonly static AlipayFunctionForHD Instance = new AlipayFunctionForHD(); private AlipayFunctionForHD() { } public string Pid = "2088720140260314"; private string AppId = "2021004100667901"; 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/UNuLXUoEjcXA4YXM1CPW4uSKpPm8j3S0eNT6vE8+DGViLrH5u5YxiLOlFMdkTsdyoq9teQDQl8eCW6skCgYEAxc8hbktBDnMLyEi+6JCzMDTQ5S16fhR8fjahXP5D+2gZZcNSu4X/Z5/WEWSHwH8YOGCXeXEujXe8bEy1dJ8B8c3KDDg2xU9NsxA9N1B4BHkva/3PzhzQGjST1OIYwLZAwMDJlQxtmUNT5Ab55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Vs2BR6Oe+8iF4rD5FJ/Wk6QguemWX8C/4jTnuNs1YsFuCTHqYwr8k8J6ekEdgwIDAQAB"; public string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxuS3Edgrruau8SO2DsK0f2KcE+A6pGJ1f8CdL395qwoX5RnEx9yRUotkwN0ZF6qMUojFKu/J/X2DpxBWBc6jIa+cnFwPUykefXcXj/AQsgiIbFzNXBH9NSz+hngXP6xDs8D1u9h+fJB+TYD+WFXKwOcGwcx23uHLHUDi1UIEZOhT2Eui+aMCYVygUWH7JynTtbFQZyZcSsD2Dxj5OJNJlK110jarFgvqY98WxqtaRtB9Y8whwRRlGfa5GP2r/Vt3xbGeAflRl5khFgRLZgeFIfxJpEj1TZV2tCtpFS0uhXJGEQbMnzFynx8UaOx/0hBCyik1MQuu3flym6nx7XxPSQIDAQAB"; //"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB"; #region 商家认证申请单提交 public string AuthOrderCreate(MerchantAddInfo info, string MerToken) { IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false); AlipayMerchantIndirectAuthorderCreateRequest request = new AlipayMerchantIndirectAuthorderCreateRequest() ; string out_biz_no = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); string identity_type = info.SubjectType; if(identity_type == "SUBJECT_TYPE_ENTERPRISE") identity_type = "ENTERPRISE"; if(identity_type == "SUBJECT_TYPE_INDIVIDUAL") identity_type = "IND_BIZ"; if(identity_type == "SUBJECT_TYPE_SMALL") identity_type = "MSE"; string PeriodEnd = info.PeriodEnd.Value.ToString("yyyy-MM-dd"); if(PeriodEnd.Substring(0, 4) == "2050") { PeriodEnd = "forever"; } string CardPeriodEnd = info.CardPeriodEnd.Value.ToString("yyyy-MM-dd"); if(CardPeriodEnd.Substring(0, 4) == "2050") { CardPeriodEnd = "forever"; } string BizContent = "{" + " \"out_biz_no\":\"" + out_biz_no + "\"," + " \"contact_person_info\":{" + " \"contact_name\":\"" + info.CertLegalPerson + "\"," + " \"contact_phone_no\":\"" + info.MobilePhone + "\"," + " \"contact_card_no\":\"" + info.IdCardNumber + "\"," + " \"contact_cert_type\":\"RESIDENT\"" + " }," + " \"auth_identity_info\":{" + " \"identity_type\":\"" + identity_type + "\"," + " \"is_financial_org\":false," + " \"certificate_type\":\"BUSINESS_CERT\"," + " \"certificate_info\":{" + " \"cert_type\":\"UNIT_SOCIAL_CREDIT\"," + " \"cert_no\":\"" + info.LicenseNumber + "\"," + " \"cert_image\":\"" + UploadPic(info.LicenseCopy) + "\"," + " \"merchant_name\":\"" + info.CertMerchantName + "\"," + " \"legal_person_name\":\"" + info.CertLegalPerson + "\"," + " \"register_address\":\"" + info.BizAddressCode.Replace(",", "") + info.BizStoreAddress + "\"," + " \"effect_time\":\"" + info.PeriodBegin.Value.ToString("yyyy-MM-dd") + "\"," + " \"expire_time\":\"" + PeriodEnd + "\"" + " },"; if(info.SubjectType == "SUBJECT_TYPE_SMALL") { string bizAddressCode = info.BizAddressCode; string province_code = "", city_code = "", district_code = ""; string province = "", city = "", district = ""; WebCMSEntities db = new WebCMSEntities(); OpenBankCityTable cityItem = db.OpenBankCityTable.FirstOrDefault(m => m.CityName.EndsWith(bizAddressCode)); if(cityItem != null) { district_code = cityItem.Code; city_code = district_code.Substring(0, 4) + "00"; province_code = district_code.Substring(0, 2) + "0000"; string[] CityNames = cityItem.CityName.Split(','); district = CityNames[CityNames.Length - 3]; city = CityNames[CityNames.Length - 2]; province = CityNames[CityNames.Length - 1]; } BizContent += " \"support_credentials\":{" + " \"merchant_type\":\"STORE\"," + " \"store_name\":\"" + info.BizStoreName + "\"," + " \"province_code\":\"" + province_code + "\"," + " \"province\":\"" + province + "\"," + " \"city_code\":\"" + city_code + "\"," + " \"city\":\"" + city + "\"," + " \"district_code\":\"" + district_code + "\"," + " \"district\":\"" + district + "\"," + " \"store_address\":\"" + info.BizStoreAddress + "\"," + " \"store_door_img\":\"" + UploadPic(info.StoreEntrancePic.Split(',')[0]) + "\"," + " \"store_inner_img\":\"" + UploadPic(info.IndoorPic.Split(',')[0]) + "\"" + " }"; } BizContent += " }," + " \"legal_person_info\":{" + " \"legal_type\":\"LEGAL_PERSON\"," + " \"card_type\":\"RESIDENT\"," + " \"person_name\":\"" + info.CertLegalPerson + "\"," + " \"card_no\":\"" + info.IdCardNumber + "\"," + " \"effect_time\":\"" + info.CardPeriodBegin + "\"," + " \"expire_time\":\"" + CardPeriodEnd + "\"," + " \"card_front_img\":\"" + UploadPic(info.IdCardCopy) + "\"," + " \"card_back_img\":\"" + UploadPic(info.IdCardNational) + "\"," + " \"is_benefit_person\":true" + " }" + "}"; request.BizContent = BizContent; string result = ""; try { AlipayMerchantIndirectAuthorderCreateResponse response = client.Execute(request, null, MerToken); result = response.Body; } catch (Exception ex) { function.WriteLog(ex.ToString(), "商家认证申请单提交异常"); result = ""; } return result; } #endregion #region 图片上传 public string UploadPic(string path) { IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false); string fileName = path.Substring(path.LastIndexOf("/") + 1); string imageBase64 = function.imageToBase64String(function.getPath(path)); imageBase64 = imageBase64.Substring(imageBase64.IndexOf(";base64,") + 8); AntMerchantExpandIndirectImageUploadRequest request = new AntMerchantExpandIndirectImageUploadRequest(); FileItem imageContent = new FileItem(fileName,Convert.FromBase64String(imageBase64)); request.ImageContent = imageContent; request.ImageType = "jpg"; AntMerchantExpandIndirectImageUploadResponse response = client.Execute(request); return fileName; } #endregion } }