Client.cs 74 KB

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