AlipayFunction.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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 AlipayFunction
  14. {
  15. public readonly static AlipayFunction Instance = new AlipayFunction();
  16. private AlipayFunction()
  17. { }
  18. public string Pid = "2088720140260314";
  19. private string AppId = "2021004100667901";
  20. private string PrivateKey = "MIIEowIBAAKCAQEAhw2C7AypN/cSBNZU1LU2th58fzvLlhlfg7jZz3xNJQwpICtSF6hXXB2qChecEZv7ZGyiuuamTn/c+ZAKJAl3EZ8fMEgTrdK9M8+3DX6FIzWywCuPktsnxLIkTj4Lt/LjPI3P3yZLESuWzHIQ+TGnwEgm/Fx5ESWribFOddLRnNpINk36y+gtaVoXpQ742Wt6Yg1l4FZrzCAOHjLfVeTyAzmXXm8TGdzep83fyCqSBp+rdpb1CGQukHYpCapyk52hM4wqsAVdndAqO5qoRi5BfuyiV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b3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";
  24. #region 代商家签约
  25. //(开启事务)接口创建应用事务,返回生成代商户操作事务编号 batch_no
  26. public string GetBatchNo(string Name, string Mobile, string Email)
  27. {
  28. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  29. AlipayOpenAgentCreateRequest request = new AlipayOpenAgentCreateRequest();
  30. request.BizContent = "{" +
  31. "\"account\":\"" + Email + "\"," +
  32. "\"contact_info\":{" +
  33. "\"contact_name\":\"" + Name + "\"," +
  34. "\"contact_mobile\":\"" + Mobile + "\"," +
  35. "\"contact_email\":\"" + Email + "\"" +
  36. "}" +
  37. "}";
  38. string result = "";
  39. try
  40. {
  41. AlipayOpenAgentCreateResponse response = client.Execute(request);
  42. result = response.Body;
  43. LogHelper.Instance.WriteLog(result, "开启事务");
  44. //{"alipay_open_agent_create_response":{"code":"10000","msg":"Success","batch_no":"2022021011321326200059849","batch_status":"init"},"sign":"su+weyK1CZEXES8mdckalg16J4BELTQeVNJSpXVYg3nh5g3E7jDh/mQctkjH8HbM0RybQSahZ2j60aUTossPMXqdq2nPRkR4c/kM34toFFNU/2p7jqo9k/MbB1JotW+qFI+C/GCX/9mZQqm2tSQdYIiZlCsEtP13ZP2EQ6momEZrApyLQYUl1H54PojJgqo6zGKDXTnXuZcpi/VPP5YoWhYMx8WPFMS6+T3zr+LNPDOI94j5vDdUHQdjFAGiQMyyhfNOBcFFi18bAfWhPqlLWwblCZamTHN/QaOHo+fkBZeo9uKqrnSHPn8XW0tDAIf1qNUfY2eBzYZUIqWKbz509A=="}
  45. }
  46. catch (Exception ex)
  47. {
  48. LogHelper.Instance.WriteLog(ex.ToString(), "接口创建应用事务异常");
  49. result = "";
  50. }
  51. return result;
  52. }
  53. //提交代商户签约、创建应用事务
  54. public string AgentConfirm(string BatchNo)
  55. {
  56. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  57. AlipayOpenAgentConfirmRequest request = new AlipayOpenAgentConfirmRequest();
  58. request.BizContent = "{" +
  59. " \"batch_no\":\"" + BatchNo + "\"" +
  60. "}";
  61. string result = "";
  62. try
  63. {
  64. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(request), "提交代商户签约");
  65. AlipayOpenAgentConfirmResponse response = client.Execute(request);
  66. result = response.Body;
  67. LogHelper.Instance.WriteLog(result + "\n\n", "提交代商户签约");
  68. }
  69. catch (Exception ex)
  70. {
  71. LogHelper.Instance.WriteLog(ex.ToString(), "提交代商户签约异常");
  72. result = "";
  73. }
  74. return result;
  75. }
  76. //代签约产品通用接口,代商家发起签约产品申请
  77. // public string CommonSign(string BatchNo, string MccCode, string BusinessLicenseNo = "", string BusinessLicensePicPath = "", string SpecialLicensePicPath = "", string ShopScenePicPath = "", string ShopSignBoardPicPath = "")
  78. // {
  79. // IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  80. // AlipayOpenAgentCommonSignRequest request = new AlipayOpenAgentCommonSignRequest();
  81. // request.BatchNo = BatchNo;
  82. // request.MccCode = MccCode; //软件系统商 D_D05_7372
  83. // if(string.IsNullOrEmpty(SpecialLicensePicPath)) SpecialLicensePicPath = BusinessLicensePicPath;
  84. // FileItem SpecialLicensePic = new FileItem(SpecialLicensePicPath);
  85. // request.SpecialLicensePic = SpecialLicensePic;
  86. // if (!string.IsNullOrEmpty(BusinessLicenseNo))
  87. // {
  88. // request.BusinessLicenseNo = BusinessLicenseNo; //营业执照号码
  89. // }
  90. // if (!string.IsNullOrEmpty(BusinessLicensePicPath))
  91. // {
  92. // FileItem BusinessLicensePic = new FileItem(BusinessLicensePicPath);
  93. // request.BusinessLicensePic = BusinessLicensePic; //营业执照图片。被代创建商户运营主体为个人账户必填,企业账户无需填写
  94. // }
  95. // FileItem BusinessLicenseAuthPic = new FileItem(BusinessLicensePicPath);
  96. // request.BusinessLicenseAuthPic = BusinessLicenseAuthPic;
  97. // request.LongTerm = true;
  98. // request.DateLimitation = "长期";
  99. // if (!string.IsNullOrEmpty(ShopScenePicPath))
  100. // {
  101. // FileItem ShopScenePic = new FileItem(ShopScenePicPath);
  102. // request.ShopScenePic = ShopScenePic;
  103. // }
  104. // if (!string.IsNullOrEmpty(ShopSignBoardPicPath))
  105. // {
  106. // FileItem ShopSignBoardPic = new FileItem(ShopSignBoardPicPath);
  107. // request.ShopSignBoardPic = ShopSignBoardPic;
  108. // }
  109. // request.ProductCode = "FACE_TO_FACE_PAYMENT"; //isv要代商户签约产品码,产品码是支付宝内部对产品的唯一标识,例如:QUICK_WAP_WAY:手机网站支付,FACE_TO_FACE_PAYMENT:当面付
  110. // request.AppName = "客小爽";
  111. // // FileItem AppDemo = new FileItem(BusinessLicensePicPath);
  112. // // request.AppDemo = AppDemo;
  113. // List<string> WebSites = new List<string>();
  114. // WebSites.Add("http://www.kexiaoshuang.com/");
  115. // request.WebSites = WebSites;
  116. // request.AlipayLifeName = "客小爽";
  117. // request.WechatOfficialAccountName = "客小爽";
  118. // // FileItem WebSitesLoa = new FileItem(BusinessLicensePicPath);
  119. // // request.WebSitesLoa = WebSitesLoa;
  120. // request.WebTestAccount = "testAccount";
  121. // request.WebTestAccountPassword = "testPassword";
  122. // FileItem WebHomeScreenshot = new FileItem(BusinessLicensePicPath);
  123. // request.WebHomeScreenshot = WebHomeScreenshot;
  124. // FileItem WebItemScreenshot = new FileItem(BusinessLicensePicPath);
  125. // request.WebItemScreenshot = WebItemScreenshot;
  126. // FileItem WebPayScreenshot = new FileItem(BusinessLicensePicPath);
  127. // request.WebPayScreenshot = WebPayScreenshot;
  128. // request.WebStatus = "已上线";
  129. // string result = "";
  130. // try
  131. // {
  132. // AlipayOpenAgentCommonSignResponse response = client.Execute(request);
  133. // result = response.Body;
  134. // LogHelper.Instance.WriteLog(result, "代商家发起签约产品申请");
  135. // //{"alipay_open_agent_common_sign_response":{"code":"10000","msg":"Success"},"sign":"qt0DiXFXIJ7mX+W2+IX+cyYXx8ROGe8yxesXHGNltxpEv/s/zW16xzf4HQLtUlaAiWf3DiD2QV7Hj+REyoZw9AcktDAmlobcjQ28lTYufPECZoUJHpkn9VpGB932FC0hScVwCbsxQakH84MGT4cmjr1hCuSs7+XogdhlCTIKjau1e7ZglLnt7f1NqT8JnljVhmvkkE9gJTLq5H+Zq6XbFfBVptvM9w09HdjfhrsxAXJyQ4yU6JYX2tUYsRGz8ZrveDQMvXKTN9jnwKE9hh8ik6Sq49eUqfutV9GkKqhC96+Vy3nOTOTnPoECXZkco1wP5jsqHottWVsRV+NxdylnTw=="}
  136. // }
  137. // catch (Exception ex)
  138. // {
  139. // LogHelper.Instance.WriteLog(ex.ToString(), "代签约产品通用接口异常");
  140. // result = "";
  141. // }
  142. // return result;
  143. // }
  144. public string CommonSign(string BatchNo, string MccCode, string BusinessLicenseNo = "", string BusinessLicensePicPath = "", string SpecialLicensePicPath = "", string ShopScenePicPath = "", string ShopSignBoardPicPath = "")
  145. {
  146. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  147. AlipayOpenAgentFacetofaceSignRequest request = new AlipayOpenAgentFacetofaceSignRequest() ;
  148. request.BatchNo = BatchNo;
  149. request.MccCode = MccCode;
  150. if (!string.IsNullOrEmpty(BusinessLicenseNo))
  151. {
  152. request.BusinessLicenseNo = BusinessLicenseNo; //营业执照号码
  153. }
  154. if (!string.IsNullOrEmpty(BusinessLicensePicPath))
  155. {
  156. // FileItem BusinessLicensePic = new FileItem(function.getPath(BusinessLicensePicPath));
  157. FileItem BusinessLicensePic = PublicFunction.GetNetFileItem(AppConfig.Base.OssHost + BusinessLicensePicPath);
  158. request.BusinessLicensePic = BusinessLicensePic; //营业执照图片。被代创建商户运营主体为个人账户必填,企业账户无需填写
  159. // FileItem BusinessLicenseAuthPic = new FileItem(function.getPath(BusinessLicensePicPath));
  160. FileItem BusinessLicenseAuthPic = PublicFunction.GetNetFileItem(AppConfig.Base.OssHost + BusinessLicensePicPath);
  161. request.BusinessLicenseAuthPic = BusinessLicenseAuthPic;
  162. }
  163. if (!string.IsNullOrEmpty(SpecialLicensePicPath))
  164. {
  165. // FileItem SpecialLicensePic = new FileItem(function.getPath(SpecialLicensePicPath));
  166. FileItem SpecialLicensePic = PublicFunction.GetNetFileItem(AppConfig.Base.OssHost + SpecialLicensePicPath);
  167. request.SpecialLicensePic = SpecialLicensePic;
  168. }
  169. if (!string.IsNullOrEmpty(ShopScenePicPath))
  170. {
  171. if(ShopScenePicPath.Contains(","))
  172. {
  173. ShopScenePicPath = ShopScenePicPath.Split(',')[0];
  174. }
  175. // FileItem ShopScenePic = new FileItem(function.getPath(ShopScenePicPath));
  176. FileItem ShopScenePic = PublicFunction.GetNetFileItem(AppConfig.Base.OssHost + ShopScenePicPath);
  177. request.ShopScenePic = ShopScenePic;
  178. }
  179. if (!string.IsNullOrEmpty(ShopSignBoardPicPath))
  180. {
  181. if(ShopSignBoardPicPath.Contains(","))
  182. {
  183. ShopSignBoardPicPath = ShopSignBoardPicPath.Split(',')[0];
  184. }
  185. // FileItem ShopSignBoardPic = new FileItem(function.getPath(ShopSignBoardPicPath));
  186. FileItem ShopSignBoardPic = PublicFunction.GetNetFileItem(AppConfig.Base.OssHost + ShopSignBoardPicPath);
  187. request.ShopSignBoardPic = ShopSignBoardPic;
  188. }
  189. // FileItem SpecialLicensePic = new FileItem("C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg");
  190. // request.setSpecialLicensePic = "-";
  191. request.Rate = "0.38";
  192. // request.SignAndAuth = true;
  193. // request.BusinessLicenseNo = "1532501100006302";
  194. // FileItem BusinessLicensePic = new FileItem("C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg");
  195. // request.setBusinessLicensePic = "-";
  196. // FileItem BusinessLicenseAuthPic = new FileItem("C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg");
  197. // request.setBusinessLicenseAuthPic = "-";
  198. // request.LongTerm = true;
  199. // request.DateLimitation = "2017-11-11";
  200. // FileItem ShopScenePic = new FileItem("C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg");
  201. // request.setShopScenePic = "-";
  202. // FileItem ShopSignBoardPic = new FileItem("C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg");
  203. // request.setShopSignBoardPic = "-";
  204. // request.ShopName = "-";
  205. // SignAddressInfo signAddressInfo = new SignAddressInfo();
  206. // signAddressInfo.country_code = "156";
  207. // signAddressInfo.province_code = "370000";
  208. // signAddressInfo.city_code = "371000";
  209. // signAddressInfo.district_code = "371002";
  210. // signAddressInfo.detail_address = "xx街道xx小区xx楼xx号";
  211. // signAddressInfo.longitude = "120.760001";
  212. // signAddressInfo.latitude = "60.270001";
  213. // request.shop_address = signAddressInfo;
  214. // request.BusinessLicenseMobile = "13189652239";
  215. string result = "";
  216. try
  217. {
  218. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(request), "代商家发起签约产品申请");
  219. AlipayOpenAgentFacetofaceSignResponse response = client.Execute(request);
  220. result = response.Body;
  221. LogHelper.Instance.WriteLog(result, "代商家发起签约产品申请");
  222. }
  223. catch (Exception ex)
  224. {
  225. LogHelper.Instance.WriteLog(ex.ToString(), "代签约产品通用接口异常");
  226. result = "";
  227. }
  228. return result;
  229. }
  230. //代商户签约,提交信息确认接口
  231. public string CommonSignConfirm(string BatchNo)
  232. {
  233. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  234. AlipayOpenAgentCommonsignConfirmRequest request= new AlipayOpenAgentCommonsignConfirmRequest();
  235. request.BizContent="{" +
  236. "\"batch_no\":\"" + BatchNo + "\"" +
  237. "}";
  238. string result = "";
  239. try
  240. {
  241. AlipayOpenAgentCommonsignConfirmResponse response = client.Execute(request);
  242. result = response.Body;
  243. LogHelper.Instance.WriteLog(result, "提交信息确认");
  244. //{"alipay_open_agent_order_query_response":{"code":"10000","msg":"Success","order_no":"20220210034000100000015895929361","product_agent_status_infos":[{"product_code":"QUICK_WAP_WAY","product_name":"手机网站支付","status":"WAIT_CONFIRM"}],"order_status":"MERCHANT_CONFIRM","confirm_url":"https:\/\/openhome.alipay.com\/isv\/settling\/confirm.htm?orderNo=20220210034000100000015895929361","merchant_pid":"2088012934025363"},"sign":"mgdhauHMV9352S3FVrQmesXvHOrk633FX/EOXRYdc2ix5phCBZJ2KZRRP9MWJ566YEtWbnQlAJzHVS9X29hjgiJWOQ/wCidql4AoSAYYeqPtxiqKAZw/QEM/du5AdbWC0xBmmkQljXF9Hx8cm+IrOyPMSJXIw4Tqpm/T96YBwhsjw4Xr5dcUcvF6HX9h/i5FSdIJODxQ26PJcqQ98GQ3Y50YhTpPQkIPDFVE2QzcL6dvuhBOpwu5KbTxvgzS8Wtm3G6nMbzJ33Cv/I2lhTCIMHz90c9bvyjJpWxPWBzywO2zzv7+EZCbDkZGkdRic9l5s6qac+ZVMHkPbveaZ2wyig=="}
  245. }
  246. catch (Exception ex)
  247. {
  248. LogHelper.Instance.WriteLog(ex.ToString(), "接口创建应用事务异常");
  249. result = "";
  250. }
  251. return result;
  252. }
  253. #endregion
  254. #region (查询申请单状态)查询签约申请的结果
  255. public string QuerySignStatus(string BatchNo)
  256. {
  257. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  258. AlipayOpenAgentOrderQueryRequest request= new AlipayOpenAgentOrderQueryRequest() ;
  259. request.BizContent="{" +
  260. " \"batch_no\":\"" + BatchNo + "\"" +
  261. "}";
  262. string result = "";
  263. try
  264. {
  265. AlipayOpenAgentOrderQueryResponse response = client.Execute(request);
  266. result = response.Body;
  267. LogHelper.Instance.WriteLog(result, "查询签约申请的结果");
  268. }
  269. catch (Exception ex)
  270. {
  271. LogHelper.Instance.WriteLog(ex.ToString(), "查询签约申请的结果异常");
  272. result = "";
  273. }
  274. return result;
  275. //{"alipay_open_agent_order_query_response":{"code":"10000","msg":"Success","order_no":"20230613034000100000035309978329","product_agent_status_infos":[{"product_code":"FACE_TO_FACE_PAYMENT","product_name":"当面付","status":"WAIT_CONFIRM"}],"order_status":"MERCHANT_CONFIRM","confirm_url":"https:\/\/b.alipay.com\/page\/message\/messageList?type=todoTasks","merchant_pid":"2088641405724089"},"sign":"nwPLGsIQRV25znCK+3G8Pf/sgF7G11jh2QQWwq+UsP2K3FyG9e14x3pPwf0NLOinFHV0AVRI8FhZLbChNl/PUjPzrhoa1OHwB1n4lvo/2uvYVU3KPPV6NKUuxy3YAB6jHDi1AuSqFVOckfm0tvm6p4a/5RYF+3pNEufDISueTdduyvOabcuf7PqQs9J4/7lAmvJxNdxkrgaHrQ4mWk102k2tc657wrRLguUULFF6+j7HtGA4WrAWxrA+KLkzjbFlFu4qtwwZUHpF666mPMQSV0IDEtqiEn3PYDtBztUu9JKTfEoUxlm36pbpp7zynthXAFyMCR8nchsFXxU4bXJcng=="}
  276. }
  277. #endregion
  278. #region 小程序支付请调用MySystemLib下的统一收单交易创建,返回交易号返给小程序请求支付my.tradePay
  279. public string GetToken()
  280. {
  281. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  282. AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();
  283. request.BizContent = "{" +
  284. "\"grant_type\":\"authorization_code\"," +
  285. "\"code\":\"P16be77ee92264acc99553528b8a7103\"" +
  286. " }";
  287. string result = "";
  288. try
  289. {
  290. AlipayOpenAuthTokenAppResponse response = client.Execute(request);
  291. result = response.Body;
  292. //{"alipay_open_auth_token_app_response":{"code":"10000","msg":"Success","tokens":[{"app_auth_token":"202202BBd8c1365cd09b4a27a0c0f0b7f8cabX03","app_refresh_token":"202202BB539f0f5aa99f4b509aa3628b0af25X03","auth_app_id":"2021003116654736","expires_in":31536000,"re_expires_in":32140800,"user_id":"2088141704579033"}]},"sign":"VZINXguZZFvVDyhVp/iMK5BWXYnDYLvxYEMEZTZOVUl9MUy6xQesDzpwBBUclLLU+QgrKpeekaxj9zgwRXdh7cKlVot2lkVPkGdfkqcK/B9t8kxPXa13WIszcROCqIutlcBZW9pCIUAbWRjorDvzRCc5rLNfSBAjEldZDA0rGOPeWJXM/5uLi/70oTwyO6eaEbKdRyHLjUwp0qtolhXIvyf9HL1HbZMGtyY/Hzq35BmhB/jQ4XIVdcOEpFtNoC/1S/viLOsBCD2m4aNCGUY0i24lr92dRsEinZlCxAQq+FK6ILNUnDmBUjNkPTycDrJFw+w9sEC6AcZodNB6OC8XTw=="}
  293. }
  294. catch (Exception ex)
  295. {
  296. LogHelper.Instance.WriteLog(ex.ToString(), "支付宝统一收单交易创建(获取authtoken)异常");
  297. result = "";
  298. }
  299. return result;
  300. }
  301. public string CreateTrade(string OrderNo, string Subject, string Amount, string BuyerId, string Notify_Url, string Token)
  302. {
  303. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  304. AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
  305. request.SetNotifyUrl(Notify_Url);
  306. request.BizContent = "{" +
  307. "\"out_trade_no\":\"" + OrderNo + "\"," +
  308. "\"total_amount\":" + Amount + "," +
  309. "\"subject\":\"" + Subject + "\"," +
  310. "\"buyer_id\":\"" + BuyerId + "\"," +
  311. "\"timeout_express\":\"10m\"" +
  312. "}";
  313. string result = "";
  314. try
  315. {
  316. AlipayTradeCreateResponse response = client.Execute(request, null, Token);
  317. result = response.Body;
  318. }
  319. catch (Exception ex)
  320. {
  321. LogHelper.Instance.WriteLog(ex.ToString(), "支付宝统一收单交易创建异常");
  322. result = "";
  323. }
  324. return result;
  325. }
  326. public string QueryTrade(string OrderNo, string Token)
  327. {
  328. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  329. AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
  330. request.BizContent = "{" +
  331. "\"out_trade_no\":\"" + OrderNo + "\"" +
  332. "}";
  333. string result = "";
  334. try
  335. {
  336. AlipayTradeQueryResponse response = client.Execute(request, null, Token);
  337. result = response.Body;
  338. }
  339. catch (Exception ex)
  340. {
  341. LogHelper.Instance.WriteLog(ex.ToString(), "统一收单线下交易查询异常");
  342. result = "";
  343. }
  344. return result;
  345. }
  346. #endregion
  347. #region 退款
  348. public string Refund(string TradeNo, string RefundNo, string Amount, string Reason, string MerToken)
  349. {
  350. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  351. AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
  352. request.BizContent = "{" +
  353. "\"trade_no\":\"" + TradeNo + "\"," +
  354. "\"refund_amount\":" + Amount + "," +
  355. "\"out_request_no\":\"" + RefundNo + "\"," +
  356. "\"refund_reason\":\"" + Reason + "\"" +
  357. // "\"refund_royalty_parameters\":[{" +
  358. // "\"royalty_type\":\"transfer\"," +
  359. // "\"trans_out_type\":\"userId\"," +
  360. // "\"trans_out\":\"" + MerPid + "\"," +
  361. // "\"amount\":" + Amount + "," +
  362. // "\"desc\":\"" + Reason + "\"" +
  363. // "}]" +
  364. "}";
  365. string result = "";
  366. try
  367. {
  368. AlipayTradeRefundResponse response = client.Execute(request, null, MerToken);
  369. result = response.Body;
  370. }
  371. catch (Exception ex)
  372. {
  373. LogHelper.Instance.WriteLog(ex.ToString(), "退款异常");
  374. result = "";
  375. }
  376. return result;
  377. }
  378. #endregion
  379. #region 分账
  380. public string Settle(string OrderNo, string TradeNo, List<RoyaltyParameters> Parameters, string MerToken)
  381. {
  382. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  383. AlipayTradeOrderSettleRequest request= new AlipayTradeOrderSettleRequest();
  384. string royalty_parameters = "";
  385. foreach (RoyaltyParameters Parameter in Parameters)
  386. {
  387. royalty_parameters += " {" +
  388. // " \"royalty_type\":\"transfer\"," +
  389. // " \"trans_in_type\":\"loginName\"," +
  390. " \"trans_in\":\"" + Parameter.Account + "\"," +
  391. " \"amount\":" + Parameter.Amount + "" +
  392. // " \"trans_in_name\":\"" + Parameter.Name + "\"" +
  393. " },";
  394. }
  395. request.BizContent = "{" +
  396. " \"out_request_no\":\"" + OrderNo + "\"," +
  397. " \"trade_no\":\"" + TradeNo + "\"," +
  398. " \"royalty_parameters\":[" +
  399. royalty_parameters.TrimEnd(',') +
  400. " ]" +
  401. "}";
  402. string result = "";
  403. try
  404. {
  405. AlipayTradeOrderSettleResponse response = client.Execute(request, null, MerToken);
  406. result = response.Body;
  407. }
  408. catch (Exception ex)
  409. {
  410. LogHelper.Instance.WriteLog(ex.ToString(), "分账异常");
  411. result = "";
  412. }
  413. return result;
  414. }
  415. #endregion
  416. #region 绑定分账关系
  417. public string BindSettleRelation(string RequestNo, string Account, string MerToken)
  418. {
  419. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  420. AlipayTradeRoyaltyRelationBindRequest request = new AlipayTradeRoyaltyRelationBindRequest();
  421. request.BizContent="{" +
  422. " \"receiver_list\":[" +
  423. " {" +
  424. " \"type\":\"userId\"," +
  425. " \"account\":\"" + Account + "\"" +
  426. // " \"name\":\"测试名称\"," +
  427. // " \"memo\":\"分账给测试商户\"," +
  428. // " \"login_name\":\"test@alitest.xyz\"," +
  429. // " \"bind_login_name\":\"test@alitest.xyz\"" +
  430. " }" +
  431. " ]," +
  432. " \"out_request_no\":\"" + RequestNo + "\"" +
  433. "}";
  434. string result = "";
  435. try
  436. {
  437. AlipayTradeRoyaltyRelationBindResponse response = client.Execute(request, null, MerToken);
  438. result = response.Body;
  439. }
  440. catch (Exception ex)
  441. {
  442. LogHelper.Instance.WriteLog(ex.ToString(), "绑定分账关系异常");
  443. result = "";
  444. }
  445. return result;
  446. }
  447. #endregion
  448. #region 查看分账
  449. public string QuerySettle(string OrderNo, string TradeNo, string MerToken)
  450. {
  451. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  452. AlipayTradeOrderSettleQueryRequest request = new AlipayTradeOrderSettleQueryRequest();
  453. request.BizContent="{" +
  454. " \"out_request_no\":\"" + OrderNo + "\"," +
  455. " \"trade_no\":\"" + TradeNo + "\"" +
  456. "}";
  457. string result = "";
  458. try
  459. {
  460. AlipayTradeOrderSettleQueryResponse response = client.Execute(request, null, MerToken);
  461. result = response.Body;
  462. LogHelper.Instance.WriteLog(request.BizContent + "\n" + result, "支付宝查询分账结果");
  463. }
  464. catch (Exception ex)
  465. {
  466. LogHelper.Instance.WriteLog(ex.ToString(), "分账异常");
  467. result = "";
  468. }
  469. return result;
  470. }
  471. #endregion
  472. }
  473. }