Client.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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.FaceToFace.Models;
  10. namespace Alipay.EasySDK.Payment.FaceToFace
  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 AlipayTradePayResponse Pay(string subject, string outTradeNo, string totalAmount, string authCode)
  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.pay"},
  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. {"auth_code", authCode},
  69. {"scene", "bar_code"},
  70. };
  71. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  72. request_.Protocol = this._kernel.GetConfig("protocol");
  73. request_.Method = "POST";
  74. request_.Pathname = "/gateway.do";
  75. request_.Headers = new Dictionary<string, string>
  76. {
  77. {"host", this._kernel.GetConfig("gatewayHost")},
  78. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  79. };
  80. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  81. (
  82. new Dictionary<string, string>()
  83. {
  84. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  85. },
  86. systemParams,
  87. textParams
  88. ));
  89. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  90. _lastRequest = request_;
  91. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  92. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.pay");
  93. if (this._kernel.IsCertMode())
  94. {
  95. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  96. {
  97. return TeaModel.ToObject<AlipayTradePayResponse>(this._kernel.ToRespModel(respMap));
  98. }
  99. }
  100. else
  101. {
  102. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  103. {
  104. return TeaModel.ToObject<AlipayTradePayResponse>(this._kernel.ToRespModel(respMap));
  105. }
  106. }
  107. throw new TeaException(new Dictionary<string, string>
  108. {
  109. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  110. });
  111. }
  112. catch (Exception e)
  113. {
  114. if (TeaCore.IsRetryable(e))
  115. {
  116. _lastException = e;
  117. continue;
  118. }
  119. throw e;
  120. }
  121. }
  122. throw new TeaUnretryableException(_lastRequest, _lastException);
  123. }
  124. public async Task<AlipayTradePayResponse> PayAsync(string subject, string outTradeNo, string totalAmount, string authCode)
  125. {
  126. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  127. {
  128. {"ignoreSSL", this._kernel.GetConfig("ignoreSSL")},
  129. {"httpProxy", this._kernel.GetConfig("httpProxy")},
  130. {"connectTimeout", 15000},
  131. {"readTimeout", 15000},
  132. {"retry", new Dictionary<string, int?>
  133. {
  134. {"maxAttempts", 0},
  135. }},
  136. };
  137. TeaRequest _lastRequest = null;
  138. Exception _lastException = null;
  139. long _now = System.DateTime.Now.Millisecond;
  140. int _retryTimes = 0;
  141. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  142. {
  143. if (_retryTimes > 0)
  144. {
  145. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  146. if (backoffTime > 0)
  147. {
  148. TeaCore.Sleep(backoffTime);
  149. }
  150. }
  151. _retryTimes = _retryTimes + 1;
  152. try
  153. {
  154. TeaRequest request_ = new TeaRequest();
  155. Dictionary<string, string> systemParams = new Dictionary<string, string>
  156. {
  157. {"method", "alipay.trade.pay"},
  158. {"app_id", this._kernel.GetConfig("appId")},
  159. {"timestamp", this._kernel.GetTimestamp()},
  160. {"format", "json"},
  161. {"version", "1.0"},
  162. {"alipay_sdk", this._kernel.GetSdkVersion()},
  163. {"charset", "UTF-8"},
  164. {"sign_type", this._kernel.GetConfig("signType")},
  165. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  166. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  167. };
  168. Dictionary<string, object> bizParams = new Dictionary<string, object>
  169. {
  170. {"subject", subject},
  171. {"out_trade_no", outTradeNo},
  172. {"total_amount", totalAmount},
  173. {"auth_code", authCode},
  174. {"scene", "bar_code"},
  175. };
  176. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  177. request_.Protocol = this._kernel.GetConfig("protocol");
  178. request_.Method = "POST";
  179. request_.Pathname = "/gateway.do";
  180. request_.Headers = new Dictionary<string, string>
  181. {
  182. {"host", this._kernel.GetConfig("gatewayHost")},
  183. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  184. };
  185. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  186. (
  187. new Dictionary<string, string>()
  188. {
  189. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  190. },
  191. systemParams,
  192. textParams
  193. ));
  194. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  195. _lastRequest = request_;
  196. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  197. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.pay");
  198. if (this._kernel.IsCertMode())
  199. {
  200. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  201. {
  202. return TeaModel.ToObject<AlipayTradePayResponse>(this._kernel.ToRespModel(respMap));
  203. }
  204. }
  205. else
  206. {
  207. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  208. {
  209. return TeaModel.ToObject<AlipayTradePayResponse>(this._kernel.ToRespModel(respMap));
  210. }
  211. }
  212. throw new TeaException(new Dictionary<string, string>
  213. {
  214. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  215. });
  216. }
  217. catch (Exception e)
  218. {
  219. if (TeaCore.IsRetryable(e))
  220. {
  221. _lastException = e;
  222. continue;
  223. }
  224. throw e;
  225. }
  226. }
  227. throw new TeaUnretryableException(_lastRequest, _lastException);
  228. }
  229. public AlipayTradePrecreateResponse PreCreate(string subject, string outTradeNo, string totalAmount)
  230. {
  231. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  232. {
  233. {"ignoreSSL", this._kernel.GetConfig("ignoreSSL")},
  234. {"httpProxy", this._kernel.GetConfig("httpProxy")},
  235. {"connectTimeout", 15000},
  236. {"readTimeout", 15000},
  237. {"retry", new Dictionary<string, int?>
  238. {
  239. {"maxAttempts", 0},
  240. }},
  241. };
  242. TeaRequest _lastRequest = null;
  243. Exception _lastException = null;
  244. long _now = System.DateTime.Now.Millisecond;
  245. int _retryTimes = 0;
  246. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  247. {
  248. if (_retryTimes > 0)
  249. {
  250. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  251. if (backoffTime > 0)
  252. {
  253. TeaCore.Sleep(backoffTime);
  254. }
  255. }
  256. _retryTimes = _retryTimes + 1;
  257. try
  258. {
  259. TeaRequest request_ = new TeaRequest();
  260. Dictionary<string, string> systemParams = new Dictionary<string, string>
  261. {
  262. {"method", "alipay.trade.precreate"},
  263. {"app_id", this._kernel.GetConfig("appId")},
  264. {"timestamp", this._kernel.GetTimestamp()},
  265. {"format", "json"},
  266. {"version", "1.0"},
  267. {"alipay_sdk", this._kernel.GetSdkVersion()},
  268. {"charset", "UTF-8"},
  269. {"sign_type", this._kernel.GetConfig("signType")},
  270. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  271. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  272. };
  273. Dictionary<string, object> bizParams = new Dictionary<string, object>
  274. {
  275. {"subject", subject},
  276. {"out_trade_no", outTradeNo},
  277. {"total_amount", totalAmount},
  278. };
  279. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  280. request_.Protocol = this._kernel.GetConfig("protocol");
  281. request_.Method = "POST";
  282. request_.Pathname = "/gateway.do";
  283. request_.Headers = new Dictionary<string, string>
  284. {
  285. {"host", this._kernel.GetConfig("gatewayHost")},
  286. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  287. };
  288. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  289. (
  290. new Dictionary<string, string>()
  291. {
  292. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  293. },
  294. systemParams,
  295. textParams
  296. ));
  297. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  298. _lastRequest = request_;
  299. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  300. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.trade.precreate");
  301. if (this._kernel.IsCertMode())
  302. {
  303. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  304. {
  305. return TeaModel.ToObject<AlipayTradePrecreateResponse>(this._kernel.ToRespModel(respMap));
  306. }
  307. }
  308. else
  309. {
  310. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  311. {
  312. return TeaModel.ToObject<AlipayTradePrecreateResponse>(this._kernel.ToRespModel(respMap));
  313. }
  314. }
  315. throw new TeaException(new Dictionary<string, string>
  316. {
  317. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  318. });
  319. }
  320. catch (Exception e)
  321. {
  322. if (TeaCore.IsRetryable(e))
  323. {
  324. _lastException = e;
  325. continue;
  326. }
  327. throw e;
  328. }
  329. }
  330. throw new TeaUnretryableException(_lastRequest, _lastException);
  331. }
  332. public async Task<AlipayTradePrecreateResponse> PreCreateAsync(string subject, string outTradeNo, string totalAmount)
  333. {
  334. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  335. {
  336. {"ignoreSSL", this._kernel.GetConfig("ignoreSSL")},
  337. {"httpProxy", this._kernel.GetConfig("httpProxy")},
  338. {"connectTimeout", 15000},
  339. {"readTimeout", 15000},
  340. {"retry", new Dictionary<string, int?>
  341. {
  342. {"maxAttempts", 0},
  343. }},
  344. };
  345. TeaRequest _lastRequest = null;
  346. Exception _lastException = null;
  347. long _now = System.DateTime.Now.Millisecond;
  348. int _retryTimes = 0;
  349. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  350. {
  351. if (_retryTimes > 0)
  352. {
  353. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  354. if (backoffTime > 0)
  355. {
  356. TeaCore.Sleep(backoffTime);
  357. }
  358. }
  359. _retryTimes = _retryTimes + 1;
  360. try
  361. {
  362. TeaRequest request_ = new TeaRequest();
  363. Dictionary<string, string> systemParams = new Dictionary<string, string>
  364. {
  365. {"method", "alipay.trade.precreate"},
  366. {"app_id", this._kernel.GetConfig("appId")},
  367. {"timestamp", this._kernel.GetTimestamp()},
  368. {"format", "json"},
  369. {"version", "1.0"},
  370. {"alipay_sdk", this._kernel.GetSdkVersion()},
  371. {"charset", "UTF-8"},
  372. {"sign_type", this._kernel.GetConfig("signType")},
  373. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  374. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  375. };
  376. Dictionary<string, object> bizParams = new Dictionary<string, object>
  377. {
  378. {"subject", subject},
  379. {"out_trade_no", outTradeNo},
  380. {"total_amount", totalAmount},
  381. };
  382. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  383. request_.Protocol = this._kernel.GetConfig("protocol");
  384. request_.Method = "POST";
  385. request_.Pathname = "/gateway.do";
  386. request_.Headers = new Dictionary<string, string>
  387. {
  388. {"host", this._kernel.GetConfig("gatewayHost")},
  389. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  390. };
  391. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  392. (
  393. new Dictionary<string, string>()
  394. {
  395. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  396. },
  397. systemParams,
  398. textParams
  399. ));
  400. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  401. _lastRequest = request_;
  402. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  403. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.trade.precreate");
  404. if (this._kernel.IsCertMode())
  405. {
  406. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  407. {
  408. return TeaModel.ToObject<AlipayTradePrecreateResponse>(this._kernel.ToRespModel(respMap));
  409. }
  410. }
  411. else
  412. {
  413. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  414. {
  415. return TeaModel.ToObject<AlipayTradePrecreateResponse>(this._kernel.ToRespModel(respMap));
  416. }
  417. }
  418. throw new TeaException(new Dictionary<string, string>
  419. {
  420. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  421. });
  422. }
  423. catch (Exception e)
  424. {
  425. if (TeaCore.IsRetryable(e))
  426. {
  427. _lastException = e;
  428. continue;
  429. }
  430. throw e;
  431. }
  432. }
  433. throw new TeaUnretryableException(_lastRequest, _lastException);
  434. }
  435. /// <summary>
  436. /// ISV代商户代用,指定appAuthToken
  437. /// </summary>
  438. /// <param name="appAuthToken">代调用token</param>
  439. /// <returns>本客户端,便于链式调用</returns>
  440. public Client Agent(string appAuthToken)
  441. {
  442. _kernel.InjectTextParam("app_auth_token", appAuthToken);
  443. return this;
  444. }
  445. /// <summary>
  446. /// 用户授权调用,指定authToken
  447. /// </summary>
  448. /// <param name="authToken">用户授权token</param>
  449. /// <returns>本客户端,便于链式调用</returns>
  450. public Client Auth(string authToken)
  451. {
  452. _kernel.InjectTextParam("auth_token", authToken);
  453. return this;
  454. }
  455. /// <summary>
  456. /// 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  457. /// </summary>
  458. /// <param name="url">异步通知回调地址,例如:https://www.test.com/callback </param>
  459. /// <returns>本客户端,便于链式调用</returns>
  460. public Client AsyncNotify(string url)
  461. {
  462. _kernel.InjectTextParam("notify_url", url);
  463. return this;
  464. }
  465. /// <summary>
  466. /// 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  467. /// </summary>
  468. /// <param name="testUrl">后端系统测试地址</param>
  469. /// <returns>本客户端,便于链式调用</returns>
  470. public Client Route(string testUrl)
  471. {
  472. _kernel.InjectTextParam("ws_service_url", testUrl);
  473. return this;
  474. }
  475. /// <summary>
  476. /// 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  477. /// </summary>
  478. /// <param name="key">业务请求参数名称(biz_content下的字段名,比如timeout_express)</param>
  479. /// <param name="value">
  480. /// 业务请求参数的值,一个可以序列化成JSON的对象
  481. /// 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用string储存
  482. /// 如果该字段是一个数值型类型(比如:Number),请使用long储存
  483. /// 如果该字段是一个复杂类型,请使用嵌套的Dictionary指定各下级字段的值
  484. /// 如果该字段是一个数组,请使用List储存各个值
  485. /// 对于更复杂的情况,也支持Dictionary和List的各种组合嵌套,比如参数是值是个List,List中的每种类型是一个复杂对象
  486. /// </param>
  487. /// <returns>本客户端,便于链式调用</returns>
  488. public Client Optional(string key, object value)
  489. {
  490. _kernel.InjectBizParam(key, value);
  491. return this;
  492. }
  493. /// <summary>
  494. /// 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  495. /// optional方法的批量版本
  496. /// </summary>
  497. /// <param name="optionalArgs">可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释</param>
  498. /// <returns>本客户端,便于链式调用</returns>
  499. public Client BatchOptional(Dictionary<string, object> optionalArgs)
  500. {
  501. foreach (var pair in optionalArgs)
  502. {
  503. _kernel.InjectBizParam(pair.Key, pair.Value);
  504. }
  505. return this;
  506. }
  507. }
  508. }