Client.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. // This file is auto-generated, don't edit it. Thanks.
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7. using Tea;
  8. using Tea.Utils;
  9. using Alipay.EasySDK.Payment.Common.Models;
  10. namespace Alipay.EasySDK.Payment.Common
  11. {
  12. public class Client
  13. {
  14. protected Alipay.EasySDK.Kernel.Client _kernel;
  15. public Client(Alipay.EasySDK.Kernel.Client kernel)
  16. {
  17. this._kernel = kernel;
  18. }
  19. public AlipayTradeCreateResponse Create(string subject, string outTradeNo, string totalAmount, string buyerId)
  20. {
  21. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  22. {
  23. {"connectTimeout", 15000},
  24. {"readTimeout", 15000},
  25. {"retry", new Dictionary<string, int?>
  26. {
  27. {"maxAttempts", 0},
  28. }},
  29. };
  30. TeaRequest _lastRequest = null;
  31. Exception _lastException = null;
  32. long _now = System.DateTime.Now.Millisecond;
  33. int _retryTimes = 0;
  34. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  35. {
  36. if (_retryTimes > 0)
  37. {
  38. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  39. if (backoffTime > 0)
  40. {
  41. TeaCore.Sleep(backoffTime);
  42. }
  43. }
  44. _retryTimes = _retryTimes + 1;
  45. try
  46. {
  47. TeaRequest request_ = new TeaRequest();
  48. Dictionary<string, string> systemParams = new Dictionary<string, string>
  49. {
  50. {"method", "alipay.trade.create"},
  51. {"app_id", this._kernel.GetConfig("appId")},
  52. {"timestamp", this._kernel.GetTimestamp()},
  53. {"format", "json"},
  54. {"version", "1.0"},
  55. {"alipay_sdk", this._kernel.GetSdkVersion()},
  56. {"charset", "UTF-8"},
  57. {"sign_type", this._kernel.GetConfig("signType")},
  58. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  59. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  60. };
  61. Dictionary<string, object> bizParams = new Dictionary<string, object>
  62. {
  63. {"subject", subject},
  64. {"out_trade_no", outTradeNo},
  65. {"total_amount", totalAmount},
  66. {"buyer_id", buyerId},
  67. };
  68. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  69. request_.Protocol = this._kernel.GetConfig("protocol");
  70. request_.Method = "POST";
  71. request_.Pathname = "/gateway.do";
  72. request_.Headers = new Dictionary<string, string>
  73. {
  74. {"host", this._kernel.GetConfig("gatewayHost")},
  75. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  76. };
  77. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  78. (
  79. new Dictionary<string, string>()
  80. {
  81. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  82. },
  83. systemParams,
  84. textParams
  85. ));
  86. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  87. _lastRequest = request_;
  88. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  89. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.create");
  90. if (this._kernel.IsCertMode())
  91. {
  92. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  93. {
  94. return TeaModel.ToObject<AlipayTradeCreateResponse>(this._kernel.ToRespModel(respMap));
  95. }
  96. }
  97. else
  98. {
  99. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  100. {
  101. return TeaModel.ToObject<AlipayTradeCreateResponse>(this._kernel.ToRespModel(respMap));
  102. }
  103. }
  104. throw new TeaException(new Dictionary<string, string>
  105. {
  106. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  107. });
  108. }
  109. catch (Exception e)
  110. {
  111. if (TeaCore.IsRetryable(e))
  112. {
  113. _lastException = e;
  114. continue;
  115. }
  116. throw e;
  117. }
  118. }
  119. throw new TeaUnretryableException(_lastRequest, _lastException);
  120. }
  121. public async Task<AlipayTradeCreateResponse> CreateAsync(string subject, string outTradeNo, string totalAmount, string buyerId)
  122. {
  123. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  124. {
  125. {"connectTimeout", 15000},
  126. {"readTimeout", 15000},
  127. {"retry", new Dictionary<string, int?>
  128. {
  129. {"maxAttempts", 0},
  130. }},
  131. };
  132. TeaRequest _lastRequest = null;
  133. Exception _lastException = null;
  134. long _now = System.DateTime.Now.Millisecond;
  135. int _retryTimes = 0;
  136. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  137. {
  138. if (_retryTimes > 0)
  139. {
  140. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  141. if (backoffTime > 0)
  142. {
  143. TeaCore.Sleep(backoffTime);
  144. }
  145. }
  146. _retryTimes = _retryTimes + 1;
  147. try
  148. {
  149. TeaRequest request_ = new TeaRequest();
  150. Dictionary<string, string> systemParams = new Dictionary<string, string>
  151. {
  152. {"method", "alipay.trade.create"},
  153. {"app_id", this._kernel.GetConfig("appId")},
  154. {"timestamp", this._kernel.GetTimestamp()},
  155. {"format", "json"},
  156. {"version", "1.0"},
  157. {"alipay_sdk", this._kernel.GetSdkVersion()},
  158. {"charset", "UTF-8"},
  159. {"sign_type", this._kernel.GetConfig("signType")},
  160. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  161. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  162. };
  163. Dictionary<string, object> bizParams = new Dictionary<string, object>
  164. {
  165. {"subject", subject},
  166. {"out_trade_no", outTradeNo},
  167. {"total_amount", totalAmount},
  168. {"buyer_id", buyerId},
  169. };
  170. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  171. request_.Protocol = this._kernel.GetConfig("protocol");
  172. request_.Method = "POST";
  173. request_.Pathname = "/gateway.do";
  174. request_.Headers = new Dictionary<string, string>
  175. {
  176. {"host", this._kernel.GetConfig("gatewayHost")},
  177. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  178. };
  179. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  180. (
  181. new Dictionary<string, string>()
  182. {
  183. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  184. },
  185. systemParams,
  186. textParams
  187. ));
  188. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  189. _lastRequest = request_;
  190. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  191. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.create");
  192. if (this._kernel.IsCertMode())
  193. {
  194. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  195. {
  196. return TeaModel.ToObject<AlipayTradeCreateResponse>(this._kernel.ToRespModel(respMap));
  197. }
  198. }
  199. else
  200. {
  201. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  202. {
  203. return TeaModel.ToObject<AlipayTradeCreateResponse>(this._kernel.ToRespModel(respMap));
  204. }
  205. }
  206. throw new TeaException(new Dictionary<string, string>
  207. {
  208. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  209. });
  210. }
  211. catch (Exception e)
  212. {
  213. if (TeaCore.IsRetryable(e))
  214. {
  215. _lastException = e;
  216. continue;
  217. }
  218. throw e;
  219. }
  220. }
  221. throw new TeaUnretryableException(_lastRequest, _lastException);
  222. }
  223. public AlipayTradeQueryResponse Query(string outTradeNo)
  224. {
  225. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  226. {
  227. {"connectTimeout", 15000},
  228. {"readTimeout", 15000},
  229. {"retry", new Dictionary<string, int?>
  230. {
  231. {"maxAttempts", 0},
  232. }},
  233. };
  234. TeaRequest _lastRequest = null;
  235. Exception _lastException = null;
  236. long _now = System.DateTime.Now.Millisecond;
  237. int _retryTimes = 0;
  238. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  239. {
  240. if (_retryTimes > 0)
  241. {
  242. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  243. if (backoffTime > 0)
  244. {
  245. TeaCore.Sleep(backoffTime);
  246. }
  247. }
  248. _retryTimes = _retryTimes + 1;
  249. try
  250. {
  251. TeaRequest request_ = new TeaRequest();
  252. Dictionary<string, string> systemParams = new Dictionary<string, string>
  253. {
  254. {"method", "alipay.trade.query"},
  255. {"app_id", this._kernel.GetConfig("appId")},
  256. {"timestamp", this._kernel.GetTimestamp()},
  257. {"format", "json"},
  258. {"version", "1.0"},
  259. {"alipay_sdk", this._kernel.GetSdkVersion()},
  260. {"charset", "UTF-8"},
  261. {"sign_type", this._kernel.GetConfig("signType")},
  262. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  263. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  264. };
  265. Dictionary<string, object> bizParams = new Dictionary<string, object>
  266. {
  267. {"out_trade_no", outTradeNo},
  268. };
  269. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  270. request_.Protocol = this._kernel.GetConfig("protocol");
  271. request_.Method = "POST";
  272. request_.Pathname = "/gateway.do";
  273. request_.Headers = new Dictionary<string, string>
  274. {
  275. {"host", this._kernel.GetConfig("gatewayHost")},
  276. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  277. };
  278. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  279. (
  280. new Dictionary<string, string>()
  281. {
  282. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  283. },
  284. systemParams,
  285. textParams
  286. ));
  287. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  288. _lastRequest = request_;
  289. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  290. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.query");
  291. if (this._kernel.IsCertMode())
  292. {
  293. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  294. {
  295. return TeaModel.ToObject<AlipayTradeQueryResponse>(this._kernel.ToRespModel(respMap));
  296. }
  297. }
  298. else
  299. {
  300. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  301. {
  302. return TeaModel.ToObject<AlipayTradeQueryResponse>(this._kernel.ToRespModel(respMap));
  303. }
  304. }
  305. throw new TeaException(new Dictionary<string, string>
  306. {
  307. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  308. });
  309. }
  310. catch (Exception e)
  311. {
  312. if (TeaCore.IsRetryable(e))
  313. {
  314. _lastException = e;
  315. continue;
  316. }
  317. throw e;
  318. }
  319. }
  320. throw new TeaUnretryableException(_lastRequest, _lastException);
  321. }
  322. public async Task<AlipayTradeQueryResponse> QueryAsync(string outTradeNo)
  323. {
  324. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  325. {
  326. {"connectTimeout", 15000},
  327. {"readTimeout", 15000},
  328. {"retry", new Dictionary<string, int?>
  329. {
  330. {"maxAttempts", 0},
  331. }},
  332. };
  333. TeaRequest _lastRequest = null;
  334. Exception _lastException = null;
  335. long _now = System.DateTime.Now.Millisecond;
  336. int _retryTimes = 0;
  337. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  338. {
  339. if (_retryTimes > 0)
  340. {
  341. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  342. if (backoffTime > 0)
  343. {
  344. TeaCore.Sleep(backoffTime);
  345. }
  346. }
  347. _retryTimes = _retryTimes + 1;
  348. try
  349. {
  350. TeaRequest request_ = new TeaRequest();
  351. Dictionary<string, string> systemParams = new Dictionary<string, string>
  352. {
  353. {"method", "alipay.trade.query"},
  354. {"app_id", this._kernel.GetConfig("appId")},
  355. {"timestamp", this._kernel.GetTimestamp()},
  356. {"format", "json"},
  357. {"version", "1.0"},
  358. {"alipay_sdk", this._kernel.GetSdkVersion()},
  359. {"charset", "UTF-8"},
  360. {"sign_type", this._kernel.GetConfig("signType")},
  361. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  362. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  363. };
  364. Dictionary<string, object> bizParams = new Dictionary<string, object>
  365. {
  366. {"out_trade_no", outTradeNo},
  367. };
  368. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  369. request_.Protocol = this._kernel.GetConfig("protocol");
  370. request_.Method = "POST";
  371. request_.Pathname = "/gateway.do";
  372. request_.Headers = new Dictionary<string, string>
  373. {
  374. {"host", this._kernel.GetConfig("gatewayHost")},
  375. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  376. };
  377. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  378. (
  379. new Dictionary<string, string>()
  380. {
  381. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  382. },
  383. systemParams,
  384. textParams
  385. ));
  386. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  387. _lastRequest = request_;
  388. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  389. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.query");
  390. if (this._kernel.IsCertMode())
  391. {
  392. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  393. {
  394. return TeaModel.ToObject<AlipayTradeQueryResponse>(this._kernel.ToRespModel(respMap));
  395. }
  396. }
  397. else
  398. {
  399. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  400. {
  401. return TeaModel.ToObject<AlipayTradeQueryResponse>(this._kernel.ToRespModel(respMap));
  402. }
  403. }
  404. throw new TeaException(new Dictionary<string, string>
  405. {
  406. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  407. });
  408. }
  409. catch (Exception e)
  410. {
  411. if (TeaCore.IsRetryable(e))
  412. {
  413. _lastException = e;
  414. continue;
  415. }
  416. throw e;
  417. }
  418. }
  419. throw new TeaUnretryableException(_lastRequest, _lastException);
  420. }
  421. public AlipayTradeRefundResponse Refund(string outTradeNo, string refundAmount)
  422. {
  423. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  424. {
  425. {"connectTimeout", 15000},
  426. {"readTimeout", 15000},
  427. {"retry", new Dictionary<string, int?>
  428. {
  429. {"maxAttempts", 0},
  430. }},
  431. };
  432. TeaRequest _lastRequest = null;
  433. Exception _lastException = null;
  434. long _now = System.DateTime.Now.Millisecond;
  435. int _retryTimes = 0;
  436. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  437. {
  438. if (_retryTimes > 0)
  439. {
  440. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  441. if (backoffTime > 0)
  442. {
  443. TeaCore.Sleep(backoffTime);
  444. }
  445. }
  446. _retryTimes = _retryTimes + 1;
  447. try
  448. {
  449. TeaRequest request_ = new TeaRequest();
  450. Dictionary<string, string> systemParams = new Dictionary<string, string>
  451. {
  452. {"method", "alipay.trade.refund"},
  453. {"app_id", this._kernel.GetConfig("appId")},
  454. {"timestamp", this._kernel.GetTimestamp()},
  455. {"format", "json"},
  456. {"version", "1.0"},
  457. {"alipay_sdk", this._kernel.GetSdkVersion()},
  458. {"charset", "UTF-8"},
  459. {"sign_type", this._kernel.GetConfig("signType")},
  460. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  461. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  462. };
  463. Dictionary<string, object> bizParams = new Dictionary<string, object>
  464. {
  465. {"out_trade_no", outTradeNo},
  466. {"refund_amount", refundAmount},
  467. };
  468. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  469. request_.Protocol = this._kernel.GetConfig("protocol");
  470. request_.Method = "POST";
  471. request_.Pathname = "/gateway.do";
  472. request_.Headers = new Dictionary<string, string>
  473. {
  474. {"host", this._kernel.GetConfig("gatewayHost")},
  475. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  476. };
  477. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  478. (
  479. new Dictionary<string, string>()
  480. {
  481. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  482. },
  483. systemParams,
  484. textParams
  485. ));
  486. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  487. _lastRequest = request_;
  488. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  489. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.refund");
  490. if (this._kernel.IsCertMode())
  491. {
  492. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  493. {
  494. return TeaModel.ToObject<AlipayTradeRefundResponse>(this._kernel.ToRespModel(respMap));
  495. }
  496. }
  497. else
  498. {
  499. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  500. {
  501. return TeaModel.ToObject<AlipayTradeRefundResponse>(this._kernel.ToRespModel(respMap));
  502. }
  503. }
  504. throw new TeaException(new Dictionary<string, string>
  505. {
  506. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  507. });
  508. }
  509. catch (Exception e)
  510. {
  511. if (TeaCore.IsRetryable(e))
  512. {
  513. _lastException = e;
  514. continue;
  515. }
  516. throw e;
  517. }
  518. }
  519. throw new TeaUnretryableException(_lastRequest, _lastException);
  520. }
  521. public async Task<AlipayTradeRefundResponse> RefundAsync(string outTradeNo, string refundAmount)
  522. {
  523. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  524. {
  525. {"connectTimeout", 15000},
  526. {"readTimeout", 15000},
  527. {"retry", new Dictionary<string, int?>
  528. {
  529. {"maxAttempts", 0},
  530. }},
  531. };
  532. TeaRequest _lastRequest = null;
  533. Exception _lastException = null;
  534. long _now = System.DateTime.Now.Millisecond;
  535. int _retryTimes = 0;
  536. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  537. {
  538. if (_retryTimes > 0)
  539. {
  540. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  541. if (backoffTime > 0)
  542. {
  543. TeaCore.Sleep(backoffTime);
  544. }
  545. }
  546. _retryTimes = _retryTimes + 1;
  547. try
  548. {
  549. TeaRequest request_ = new TeaRequest();
  550. Dictionary<string, string> systemParams = new Dictionary<string, string>
  551. {
  552. {"method", "alipay.trade.refund"},
  553. {"app_id", this._kernel.GetConfig("appId")},
  554. {"timestamp", this._kernel.GetTimestamp()},
  555. {"format", "json"},
  556. {"version", "1.0"},
  557. {"alipay_sdk", this._kernel.GetSdkVersion()},
  558. {"charset", "UTF-8"},
  559. {"sign_type", this._kernel.GetConfig("signType")},
  560. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  561. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  562. };
  563. Dictionary<string, object> bizParams = new Dictionary<string, object>
  564. {
  565. {"out_trade_no", outTradeNo},
  566. {"refund_amount", refundAmount},
  567. };
  568. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  569. request_.Protocol = this._kernel.GetConfig("protocol");
  570. request_.Method = "POST";
  571. request_.Pathname = "/gateway.do";
  572. request_.Headers = new Dictionary<string, string>
  573. {
  574. {"host", this._kernel.GetConfig("gatewayHost")},
  575. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  576. };
  577. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  578. (
  579. new Dictionary<string, string>()
  580. {
  581. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  582. },
  583. systemParams,
  584. textParams
  585. ));
  586. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  587. _lastRequest = request_;
  588. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  589. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.refund");
  590. if (this._kernel.IsCertMode())
  591. {
  592. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  593. {
  594. return TeaModel.ToObject<AlipayTradeRefundResponse>(this._kernel.ToRespModel(respMap));
  595. }
  596. }
  597. else
  598. {
  599. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  600. {
  601. return TeaModel.ToObject<AlipayTradeRefundResponse>(this._kernel.ToRespModel(respMap));
  602. }
  603. }
  604. throw new TeaException(new Dictionary<string, string>
  605. {
  606. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  607. });
  608. }
  609. catch (Exception e)
  610. {
  611. if (TeaCore.IsRetryable(e))
  612. {
  613. _lastException = e;
  614. continue;
  615. }
  616. throw e;
  617. }
  618. }
  619. throw new TeaUnretryableException(_lastRequest, _lastException);
  620. }
  621. public AlipayTradeCloseResponse Close(string outTradeNo)
  622. {
  623. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  624. {
  625. {"connectTimeout", 15000},
  626. {"readTimeout", 15000},
  627. {"retry", new Dictionary<string, int?>
  628. {
  629. {"maxAttempts", 0},
  630. }},
  631. };
  632. TeaRequest _lastRequest = null;
  633. Exception _lastException = null;
  634. long _now = System.DateTime.Now.Millisecond;
  635. int _retryTimes = 0;
  636. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  637. {
  638. if (_retryTimes > 0)
  639. {
  640. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  641. if (backoffTime > 0)
  642. {
  643. TeaCore.Sleep(backoffTime);
  644. }
  645. }
  646. _retryTimes = _retryTimes + 1;
  647. try
  648. {
  649. TeaRequest request_ = new TeaRequest();
  650. Dictionary<string, string> systemParams = new Dictionary<string, string>
  651. {
  652. {"method", "alipay.trade.close"},
  653. {"app_id", this._kernel.GetConfig("appId")},
  654. {"timestamp", this._kernel.GetTimestamp()},
  655. {"format", "json"},
  656. {"version", "1.0"},
  657. {"alipay_sdk", this._kernel.GetSdkVersion()},
  658. {"charset", "UTF-8"},
  659. {"sign_type", this._kernel.GetConfig("signType")},
  660. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  661. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  662. };
  663. Dictionary<string, object> bizParams = new Dictionary<string, object>
  664. {
  665. {"out_trade_no", outTradeNo},
  666. };
  667. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  668. request_.Protocol = this._kernel.GetConfig("protocol");
  669. request_.Method = "POST";
  670. request_.Pathname = "/gateway.do";
  671. request_.Headers = new Dictionary<string, string>
  672. {
  673. {"host", this._kernel.GetConfig("gatewayHost")},
  674. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  675. };
  676. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  677. (
  678. new Dictionary<string, string>()
  679. {
  680. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  681. },
  682. systemParams,
  683. textParams
  684. ));
  685. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  686. _lastRequest = request_;
  687. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  688. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.close");
  689. if (this._kernel.IsCertMode())
  690. {
  691. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  692. {
  693. return TeaModel.ToObject<AlipayTradeCloseResponse>(this._kernel.ToRespModel(respMap));
  694. }
  695. }
  696. else
  697. {
  698. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  699. {
  700. return TeaModel.ToObject<AlipayTradeCloseResponse>(this._kernel.ToRespModel(respMap));
  701. }
  702. }
  703. throw new TeaException(new Dictionary<string, string>
  704. {
  705. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  706. });
  707. }
  708. catch (Exception e)
  709. {
  710. if (TeaCore.IsRetryable(e))
  711. {
  712. _lastException = e;
  713. continue;
  714. }
  715. throw e;
  716. }
  717. }
  718. throw new TeaUnretryableException(_lastRequest, _lastException);
  719. }
  720. public async Task<AlipayTradeCloseResponse> CloseAsync(string outTradeNo)
  721. {
  722. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  723. {
  724. {"connectTimeout", 15000},
  725. {"readTimeout", 15000},
  726. {"retry", new Dictionary<string, int?>
  727. {
  728. {"maxAttempts", 0},
  729. }},
  730. };
  731. TeaRequest _lastRequest = null;
  732. Exception _lastException = null;
  733. long _now = System.DateTime.Now.Millisecond;
  734. int _retryTimes = 0;
  735. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  736. {
  737. if (_retryTimes > 0)
  738. {
  739. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  740. if (backoffTime > 0)
  741. {
  742. TeaCore.Sleep(backoffTime);
  743. }
  744. }
  745. _retryTimes = _retryTimes + 1;
  746. try
  747. {
  748. TeaRequest request_ = new TeaRequest();
  749. Dictionary<string, string> systemParams = new Dictionary<string, string>
  750. {
  751. {"method", "alipay.trade.close"},
  752. {"app_id", this._kernel.GetConfig("appId")},
  753. {"timestamp", this._kernel.GetTimestamp()},
  754. {"format", "json"},
  755. {"version", "1.0"},
  756. {"alipay_sdk", this._kernel.GetSdkVersion()},
  757. {"charset", "UTF-8"},
  758. {"sign_type", this._kernel.GetConfig("signType")},
  759. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  760. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  761. };
  762. Dictionary<string, object> bizParams = new Dictionary<string, object>
  763. {
  764. {"out_trade_no", outTradeNo},
  765. };
  766. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  767. request_.Protocol = this._kernel.GetConfig("protocol");
  768. request_.Method = "POST";
  769. request_.Pathname = "/gateway.do";
  770. request_.Headers = new Dictionary<string, string>
  771. {
  772. {"host", this._kernel.GetConfig("gatewayHost")},
  773. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  774. };
  775. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  776. (
  777. new Dictionary<string, string>()
  778. {
  779. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  780. },
  781. systemParams,
  782. textParams
  783. ));
  784. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  785. _lastRequest = request_;
  786. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  787. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.close");
  788. if (this._kernel.IsCertMode())
  789. {
  790. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  791. {
  792. return TeaModel.ToObject<AlipayTradeCloseResponse>(this._kernel.ToRespModel(respMap));
  793. }
  794. }
  795. else
  796. {
  797. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  798. {
  799. return TeaModel.ToObject<AlipayTradeCloseResponse>(this._kernel.ToRespModel(respMap));
  800. }
  801. }
  802. throw new TeaException(new Dictionary<string, string>
  803. {
  804. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  805. });
  806. }
  807. catch (Exception e)
  808. {
  809. if (TeaCore.IsRetryable(e))
  810. {
  811. _lastException = e;
  812. continue;
  813. }
  814. throw e;
  815. }
  816. }
  817. throw new TeaUnretryableException(_lastRequest, _lastException);
  818. }
  819. public AlipayTradeCancelResponse Cancel(string outTradeNo)
  820. {
  821. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  822. {
  823. {"connectTimeout", 15000},
  824. {"readTimeout", 15000},
  825. {"retry", new Dictionary<string, int?>
  826. {
  827. {"maxAttempts", 0},
  828. }},
  829. };
  830. TeaRequest _lastRequest = null;
  831. Exception _lastException = null;
  832. long _now = System.DateTime.Now.Millisecond;
  833. int _retryTimes = 0;
  834. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  835. {
  836. if (_retryTimes > 0)
  837. {
  838. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  839. if (backoffTime > 0)
  840. {
  841. TeaCore.Sleep(backoffTime);
  842. }
  843. }
  844. _retryTimes = _retryTimes + 1;
  845. try
  846. {
  847. TeaRequest request_ = new TeaRequest();
  848. Dictionary<string, string> systemParams = new Dictionary<string, string>
  849. {
  850. {"method", "alipay.trade.cancel"},
  851. {"app_id", this._kernel.GetConfig("appId")},
  852. {"timestamp", this._kernel.GetTimestamp()},
  853. {"format", "json"},
  854. {"version", "1.0"},
  855. {"alipay_sdk", this._kernel.GetSdkVersion()},
  856. {"charset", "UTF-8"},
  857. {"sign_type", this._kernel.GetConfig("signType")},
  858. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  859. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  860. };
  861. Dictionary<string, object> bizParams = new Dictionary<string, object>
  862. {
  863. {"out_trade_no", outTradeNo},
  864. };
  865. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  866. request_.Protocol = this._kernel.GetConfig("protocol");
  867. request_.Method = "POST";
  868. request_.Pathname = "/gateway.do";
  869. request_.Headers = new Dictionary<string, string>
  870. {
  871. {"host", this._kernel.GetConfig("gatewayHost")},
  872. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  873. };
  874. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  875. (
  876. new Dictionary<string, string>()
  877. {
  878. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  879. },
  880. systemParams,
  881. textParams
  882. ));
  883. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  884. _lastRequest = request_;
  885. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  886. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.cancel");
  887. if (this._kernel.IsCertMode())
  888. {
  889. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  890. {
  891. return TeaModel.ToObject<AlipayTradeCancelResponse>(this._kernel.ToRespModel(respMap));
  892. }
  893. }
  894. else
  895. {
  896. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  897. {
  898. return TeaModel.ToObject<AlipayTradeCancelResponse>(this._kernel.ToRespModel(respMap));
  899. }
  900. }
  901. throw new TeaException(new Dictionary<string, string>
  902. {
  903. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  904. });
  905. }
  906. catch (Exception e)
  907. {
  908. if (TeaCore.IsRetryable(e))
  909. {
  910. _lastException = e;
  911. continue;
  912. }
  913. throw e;
  914. }
  915. }
  916. throw new TeaUnretryableException(_lastRequest, _lastException);
  917. }
  918. public async Task<AlipayTradeCancelResponse> CancelAsync(string outTradeNo)
  919. {
  920. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  921. {
  922. {"connectTimeout", 15000},
  923. {"readTimeout", 15000},
  924. {"retry", new Dictionary<string, int?>
  925. {
  926. {"maxAttempts", 0},
  927. }},
  928. };
  929. TeaRequest _lastRequest = null;
  930. Exception _lastException = null;
  931. long _now = System.DateTime.Now.Millisecond;
  932. int _retryTimes = 0;
  933. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  934. {
  935. if (_retryTimes > 0)
  936. {
  937. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  938. if (backoffTime > 0)
  939. {
  940. TeaCore.Sleep(backoffTime);
  941. }
  942. }
  943. _retryTimes = _retryTimes + 1;
  944. try
  945. {
  946. TeaRequest request_ = new TeaRequest();
  947. Dictionary<string, string> systemParams = new Dictionary<string, string>
  948. {
  949. {"method", "alipay.trade.cancel"},
  950. {"app_id", this._kernel.GetConfig("appId")},
  951. {"timestamp", this._kernel.GetTimestamp()},
  952. {"format", "json"},
  953. {"version", "1.0"},
  954. {"alipay_sdk", this._kernel.GetSdkVersion()},
  955. {"charset", "UTF-8"},
  956. {"sign_type", this._kernel.GetConfig("signType")},
  957. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  958. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  959. };
  960. Dictionary<string, object> bizParams = new Dictionary<string, object>
  961. {
  962. {"out_trade_no", outTradeNo},
  963. };
  964. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  965. request_.Protocol = this._kernel.GetConfig("protocol");
  966. request_.Method = "POST";
  967. request_.Pathname = "/gateway.do";
  968. request_.Headers = new Dictionary<string, string>
  969. {
  970. {"host", this._kernel.GetConfig("gatewayHost")},
  971. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  972. };
  973. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  974. (
  975. new Dictionary<string, string>()
  976. {
  977. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  978. },
  979. systemParams,
  980. textParams
  981. ));
  982. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  983. _lastRequest = request_;
  984. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  985. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.cancel");
  986. if (this._kernel.IsCertMode())
  987. {
  988. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  989. {
  990. return TeaModel.ToObject<AlipayTradeCancelResponse>(this._kernel.ToRespModel(respMap));
  991. }
  992. }
  993. else
  994. {
  995. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  996. {
  997. return TeaModel.ToObject<AlipayTradeCancelResponse>(this._kernel.ToRespModel(respMap));
  998. }
  999. }
  1000. throw new TeaException(new Dictionary<string, string>
  1001. {
  1002. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  1003. });
  1004. }
  1005. catch (Exception e)
  1006. {
  1007. if (TeaCore.IsRetryable(e))
  1008. {
  1009. _lastException = e;
  1010. continue;
  1011. }
  1012. throw e;
  1013. }
  1014. }
  1015. throw new TeaUnretryableException(_lastRequest, _lastException);
  1016. }
  1017. public AlipayTradeFastpayRefundQueryResponse QueryRefund(string outTradeNo, string outRequestNo)
  1018. {
  1019. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  1020. {
  1021. {"connectTimeout", 15000},
  1022. {"readTimeout", 15000},
  1023. {"retry", new Dictionary<string, int?>
  1024. {
  1025. {"maxAttempts", 0},
  1026. }},
  1027. };
  1028. TeaRequest _lastRequest = null;
  1029. Exception _lastException = null;
  1030. long _now = System.DateTime.Now.Millisecond;
  1031. int _retryTimes = 0;
  1032. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  1033. {
  1034. if (_retryTimes > 0)
  1035. {
  1036. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  1037. if (backoffTime > 0)
  1038. {
  1039. TeaCore.Sleep(backoffTime);
  1040. }
  1041. }
  1042. _retryTimes = _retryTimes + 1;
  1043. try
  1044. {
  1045. TeaRequest request_ = new TeaRequest();
  1046. Dictionary<string, string> systemParams = new Dictionary<string, string>
  1047. {
  1048. {"method", "alipay.trade.fastpay.refund.query"},
  1049. {"app_id", this._kernel.GetConfig("appId")},
  1050. {"timestamp", this._kernel.GetTimestamp()},
  1051. {"format", "json"},
  1052. {"version", "1.0"},
  1053. {"alipay_sdk", this._kernel.GetSdkVersion()},
  1054. {"charset", "UTF-8"},
  1055. {"sign_type", this._kernel.GetConfig("signType")},
  1056. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  1057. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  1058. };
  1059. Dictionary<string, object> bizParams = new Dictionary<string, object>
  1060. {
  1061. {"out_trade_no", outTradeNo},
  1062. {"out_request_no", outRequestNo},
  1063. };
  1064. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  1065. request_.Protocol = this._kernel.GetConfig("protocol");
  1066. request_.Method = "POST";
  1067. request_.Pathname = "/gateway.do";
  1068. request_.Headers = new Dictionary<string, string>
  1069. {
  1070. {"host", this._kernel.GetConfig("gatewayHost")},
  1071. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  1072. };
  1073. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  1074. (
  1075. new Dictionary<string, string>()
  1076. {
  1077. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  1078. },
  1079. systemParams,
  1080. textParams
  1081. ));
  1082. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  1083. _lastRequest = request_;
  1084. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  1085. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.fastpay.refund.query");
  1086. if (this._kernel.IsCertMode())
  1087. {
  1088. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  1089. {
  1090. return TeaModel.ToObject<AlipayTradeFastpayRefundQueryResponse>(this._kernel.ToRespModel(respMap));
  1091. }
  1092. }
  1093. else
  1094. {
  1095. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  1096. {
  1097. return TeaModel.ToObject<AlipayTradeFastpayRefundQueryResponse>(this._kernel.ToRespModel(respMap));
  1098. }
  1099. }
  1100. throw new TeaException(new Dictionary<string, string>
  1101. {
  1102. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  1103. });
  1104. }
  1105. catch (Exception e)
  1106. {
  1107. if (TeaCore.IsRetryable(e))
  1108. {
  1109. _lastException = e;
  1110. continue;
  1111. }
  1112. throw e;
  1113. }
  1114. }
  1115. throw new TeaUnretryableException(_lastRequest, _lastException);
  1116. }
  1117. public async Task<AlipayTradeFastpayRefundQueryResponse> QueryRefundAsync(string outTradeNo, string outRequestNo)
  1118. {
  1119. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  1120. {
  1121. {"connectTimeout", 15000},
  1122. {"readTimeout", 15000},
  1123. {"retry", new Dictionary<string, int?>
  1124. {
  1125. {"maxAttempts", 0},
  1126. }},
  1127. };
  1128. TeaRequest _lastRequest = null;
  1129. Exception _lastException = null;
  1130. long _now = System.DateTime.Now.Millisecond;
  1131. int _retryTimes = 0;
  1132. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  1133. {
  1134. if (_retryTimes > 0)
  1135. {
  1136. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  1137. if (backoffTime > 0)
  1138. {
  1139. TeaCore.Sleep(backoffTime);
  1140. }
  1141. }
  1142. _retryTimes = _retryTimes + 1;
  1143. try
  1144. {
  1145. TeaRequest request_ = new TeaRequest();
  1146. Dictionary<string, string> systemParams = new Dictionary<string, string>
  1147. {
  1148. {"method", "alipay.trade.fastpay.refund.query"},
  1149. {"app_id", this._kernel.GetConfig("appId")},
  1150. {"timestamp", this._kernel.GetTimestamp()},
  1151. {"format", "json"},
  1152. {"version", "1.0"},
  1153. {"alipay_sdk", this._kernel.GetSdkVersion()},
  1154. {"charset", "UTF-8"},
  1155. {"sign_type", this._kernel.GetConfig("signType")},
  1156. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  1157. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  1158. };
  1159. Dictionary<string, object> bizParams = new Dictionary<string, object>
  1160. {
  1161. {"out_trade_no", outTradeNo},
  1162. {"out_request_no", outRequestNo},
  1163. };
  1164. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  1165. request_.Protocol = this._kernel.GetConfig("protocol");
  1166. request_.Method = "POST";
  1167. request_.Pathname = "/gateway.do";
  1168. request_.Headers = new Dictionary<string, string>
  1169. {
  1170. {"host", this._kernel.GetConfig("gatewayHost")},
  1171. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  1172. };
  1173. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  1174. (
  1175. new Dictionary<string, string>()
  1176. {
  1177. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  1178. },
  1179. systemParams,
  1180. textParams
  1181. ));
  1182. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  1183. _lastRequest = request_;
  1184. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  1185. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.fastpay.refund.query");
  1186. if (this._kernel.IsCertMode())
  1187. {
  1188. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  1189. {
  1190. return TeaModel.ToObject<AlipayTradeFastpayRefundQueryResponse>(this._kernel.ToRespModel(respMap));
  1191. }
  1192. }
  1193. else
  1194. {
  1195. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  1196. {
  1197. return TeaModel.ToObject<AlipayTradeFastpayRefundQueryResponse>(this._kernel.ToRespModel(respMap));
  1198. }
  1199. }
  1200. throw new TeaException(new Dictionary<string, string>
  1201. {
  1202. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  1203. });
  1204. }
  1205. catch (Exception e)
  1206. {
  1207. if (TeaCore.IsRetryable(e))
  1208. {
  1209. _lastException = e;
  1210. continue;
  1211. }
  1212. throw e;
  1213. }
  1214. }
  1215. throw new TeaUnretryableException(_lastRequest, _lastException);
  1216. }
  1217. public AlipayDataDataserviceBillDownloadurlQueryResponse DownloadBill(string billType, string billDate)
  1218. {
  1219. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  1220. {
  1221. {"connectTimeout", 15000},
  1222. {"readTimeout", 15000},
  1223. {"retry", new Dictionary<string, int?>
  1224. {
  1225. {"maxAttempts", 0},
  1226. }},
  1227. };
  1228. TeaRequest _lastRequest = null;
  1229. Exception _lastException = null;
  1230. long _now = System.DateTime.Now.Millisecond;
  1231. int _retryTimes = 0;
  1232. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  1233. {
  1234. if (_retryTimes > 0)
  1235. {
  1236. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  1237. if (backoffTime > 0)
  1238. {
  1239. TeaCore.Sleep(backoffTime);
  1240. }
  1241. }
  1242. _retryTimes = _retryTimes + 1;
  1243. try
  1244. {
  1245. TeaRequest request_ = new TeaRequest();
  1246. Dictionary<string, string> systemParams = new Dictionary<string, string>
  1247. {
  1248. {"method", "alipay.data.dataservice.bill.downloadurl.query"},
  1249. {"app_id", this._kernel.GetConfig("appId")},
  1250. {"timestamp", this._kernel.GetTimestamp()},
  1251. {"format", "json"},
  1252. {"version", "1.0"},
  1253. {"alipay_sdk", this._kernel.GetSdkVersion()},
  1254. {"charset", "UTF-8"},
  1255. {"sign_type", this._kernel.GetConfig("signType")},
  1256. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  1257. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  1258. };
  1259. Dictionary<string, object> bizParams = new Dictionary<string, object>
  1260. {
  1261. {"bill_type", billType},
  1262. {"bill_date", billDate},
  1263. };
  1264. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  1265. request_.Protocol = this._kernel.GetConfig("protocol");
  1266. request_.Method = "POST";
  1267. request_.Pathname = "/gateway.do";
  1268. request_.Headers = new Dictionary<string, string>
  1269. {
  1270. {"host", this._kernel.GetConfig("gatewayHost")},
  1271. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  1272. };
  1273. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  1274. (
  1275. new Dictionary<string, string>()
  1276. {
  1277. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  1278. },
  1279. systemParams,
  1280. textParams
  1281. ));
  1282. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  1283. _lastRequest = request_;
  1284. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  1285. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.data.dataservice.bill.downloadurl.query");
  1286. if (this._kernel.IsCertMode())
  1287. {
  1288. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  1289. {
  1290. return TeaModel.ToObject<AlipayDataDataserviceBillDownloadurlQueryResponse>(this._kernel.ToRespModel(respMap));
  1291. }
  1292. }
  1293. else
  1294. {
  1295. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  1296. {
  1297. return TeaModel.ToObject<AlipayDataDataserviceBillDownloadurlQueryResponse>(this._kernel.ToRespModel(respMap));
  1298. }
  1299. }
  1300. throw new TeaException(new Dictionary<string, string>
  1301. {
  1302. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  1303. });
  1304. }
  1305. catch (Exception e)
  1306. {
  1307. if (TeaCore.IsRetryable(e))
  1308. {
  1309. _lastException = e;
  1310. continue;
  1311. }
  1312. throw e;
  1313. }
  1314. }
  1315. throw new TeaUnretryableException(_lastRequest, _lastException);
  1316. }
  1317. public async Task<AlipayDataDataserviceBillDownloadurlQueryResponse> DownloadBillAsync(string billType, string billDate)
  1318. {
  1319. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  1320. {
  1321. {"connectTimeout", 15000},
  1322. {"readTimeout", 15000},
  1323. {"retry", new Dictionary<string, int?>
  1324. {
  1325. {"maxAttempts", 0},
  1326. }},
  1327. };
  1328. TeaRequest _lastRequest = null;
  1329. Exception _lastException = null;
  1330. long _now = System.DateTime.Now.Millisecond;
  1331. int _retryTimes = 0;
  1332. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  1333. {
  1334. if (_retryTimes > 0)
  1335. {
  1336. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  1337. if (backoffTime > 0)
  1338. {
  1339. TeaCore.Sleep(backoffTime);
  1340. }
  1341. }
  1342. _retryTimes = _retryTimes + 1;
  1343. try
  1344. {
  1345. TeaRequest request_ = new TeaRequest();
  1346. Dictionary<string, string> systemParams = new Dictionary<string, string>
  1347. {
  1348. {"method", "alipay.data.dataservice.bill.downloadurl.query"},
  1349. {"app_id", this._kernel.GetConfig("appId")},
  1350. {"timestamp", this._kernel.GetTimestamp()},
  1351. {"format", "json"},
  1352. {"version", "1.0"},
  1353. {"alipay_sdk", this._kernel.GetSdkVersion()},
  1354. {"charset", "UTF-8"},
  1355. {"sign_type", this._kernel.GetConfig("signType")},
  1356. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  1357. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  1358. };
  1359. Dictionary<string, object> bizParams = new Dictionary<string, object>
  1360. {
  1361. {"bill_type", billType},
  1362. {"bill_date", billDate},
  1363. };
  1364. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  1365. request_.Protocol = this._kernel.GetConfig("protocol");
  1366. request_.Method = "POST";
  1367. request_.Pathname = "/gateway.do";
  1368. request_.Headers = new Dictionary<string, string>
  1369. {
  1370. {"host", this._kernel.GetConfig("gatewayHost")},
  1371. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  1372. };
  1373. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  1374. (
  1375. new Dictionary<string, string>()
  1376. {
  1377. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  1378. },
  1379. systemParams,
  1380. textParams
  1381. ));
  1382. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  1383. _lastRequest = request_;
  1384. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  1385. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.data.dataservice.bill.downloadurl.query");
  1386. if (this._kernel.IsCertMode())
  1387. {
  1388. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  1389. {
  1390. return TeaModel.ToObject<AlipayDataDataserviceBillDownloadurlQueryResponse>(this._kernel.ToRespModel(respMap));
  1391. }
  1392. }
  1393. else
  1394. {
  1395. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  1396. {
  1397. return TeaModel.ToObject<AlipayDataDataserviceBillDownloadurlQueryResponse>(this._kernel.ToRespModel(respMap));
  1398. }
  1399. }
  1400. throw new TeaException(new Dictionary<string, string>
  1401. {
  1402. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  1403. });
  1404. }
  1405. catch (Exception e)
  1406. {
  1407. if (TeaCore.IsRetryable(e))
  1408. {
  1409. _lastException = e;
  1410. continue;
  1411. }
  1412. throw e;
  1413. }
  1414. }
  1415. throw new TeaUnretryableException(_lastRequest, _lastException);
  1416. }
  1417. public bool? VerifyNotify(Dictionary<string, string> parameters)
  1418. {
  1419. if (this._kernel.IsCertMode())
  1420. {
  1421. return this._kernel.VerifyParams(parameters, this._kernel.ExtractAlipayPublicKey(""));
  1422. }
  1423. else
  1424. {
  1425. return this._kernel.VerifyParams(parameters, this._kernel.GetConfig("alipayPublicKey"));
  1426. }
  1427. }
  1428. /// <summary>
  1429. /// ISV代商户代用,指定appAuthToken
  1430. /// </summary>
  1431. /// <param name="appAuthToken">代调用token</param>
  1432. /// <returns>本客户端,便于链式调用</returns>
  1433. public Client Agent(string appAuthToken)
  1434. {
  1435. _kernel.InjectTextParam("app_auth_token", appAuthToken);
  1436. return this;
  1437. }
  1438. /// <summary>
  1439. /// 用户授权调用,指定authToken
  1440. /// </summary>
  1441. /// <param name="authToken">用户授权token</param>
  1442. /// <returns>本客户端,便于链式调用</returns>
  1443. public Client Auth(string authToken)
  1444. {
  1445. _kernel.InjectTextParam("auth_token", authToken);
  1446. return this;
  1447. }
  1448. /// <summary>
  1449. /// 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  1450. /// </summary>
  1451. /// <param name="url">异步通知回调地址,例如:https://www.test.com/callback </param>
  1452. /// <returns>本客户端,便于链式调用</returns>
  1453. public Client AsyncNotify(string url)
  1454. {
  1455. _kernel.InjectTextParam("notify_url", url);
  1456. return this;
  1457. }
  1458. /// <summary>
  1459. /// 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  1460. /// </summary>
  1461. /// <param name="testUrl">后端系统测试地址</param>
  1462. /// <returns>本客户端,便于链式调用</returns>
  1463. public Client Route(string testUrl)
  1464. {
  1465. _kernel.InjectTextParam("ws_service_url", testUrl);
  1466. return this;
  1467. }
  1468. /// <summary>
  1469. /// 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  1470. /// </summary>
  1471. /// <param name="key">业务请求参数名称(biz_content下的字段名,比如timeout_express)</param>
  1472. /// <param name="value">
  1473. /// 业务请求参数的值,一个可以序列化成JSON的对象
  1474. /// 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用string储存
  1475. /// 如果该字段是一个数值型类型(比如:Number),请使用long储存
  1476. /// 如果该字段是一个复杂类型,请使用嵌套的Dictionary指定各下级字段的值
  1477. /// 如果该字段是一个数组,请使用List储存各个值
  1478. /// 对于更复杂的情况,也支持Dictionary和List的各种组合嵌套,比如参数是值是个List,List中的每种类型是一个复杂对象
  1479. /// </param>
  1480. /// <returns>本客户端,便于链式调用</returns>
  1481. public Client Optional(string key, object value)
  1482. {
  1483. _kernel.InjectBizParam(key, value);
  1484. return this;
  1485. }
  1486. /// <summary>
  1487. /// 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  1488. /// optional方法的批量版本
  1489. /// </summary>
  1490. /// <param name="optionalArgs">可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释</param>
  1491. /// <returns>本客户端,便于链式调用</returns>
  1492. public Client BatchOptional(Dictionary<string, object> optionalArgs)
  1493. {
  1494. foreach (var pair in optionalArgs)
  1495. {
  1496. _kernel.InjectBizParam(pair.Key, pair.Value);
  1497. }
  1498. return this;
  1499. }
  1500. }
  1501. }