Client.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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.Member.Identification.Models;
  10. namespace Alipay.EasySDK.Member.Identification
  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 AlipayUserCertifyOpenInitializeResponse Init(string outerOrderNo, string bizCode, IdentityParam identityParam, MerchantConfig merchantConfig)
  20. {
  21. identityParam.Validate();
  22. merchantConfig.Validate();
  23. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  24. {
  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.user.certify.open.initialize"},
  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. {"outer_order_no", outerOrderNo},
  66. {"biz_code", bizCode},
  67. {"identity_param", identityParam},
  68. {"merchant_config", merchantConfig},
  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.user.certify.open.initialize");
  92. if (this._kernel.IsCertMode())
  93. {
  94. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  95. {
  96. return TeaModel.ToObject<AlipayUserCertifyOpenInitializeResponse>(this._kernel.ToRespModel(respMap));
  97. }
  98. }
  99. else
  100. {
  101. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  102. {
  103. return TeaModel.ToObject<AlipayUserCertifyOpenInitializeResponse>(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<AlipayUserCertifyOpenInitializeResponse> InitAsync(string outerOrderNo, string bizCode, IdentityParam identityParam, MerchantConfig merchantConfig)
  124. {
  125. identityParam.Validate();
  126. merchantConfig.Validate();
  127. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  128. {
  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.user.certify.open.initialize"},
  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. {"outer_order_no", outerOrderNo},
  170. {"biz_code", bizCode},
  171. {"identity_param", identityParam},
  172. {"merchant_config", merchantConfig},
  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.user.certify.open.initialize");
  196. if (this._kernel.IsCertMode())
  197. {
  198. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  199. {
  200. return TeaModel.ToObject<AlipayUserCertifyOpenInitializeResponse>(this._kernel.ToRespModel(respMap));
  201. }
  202. }
  203. else
  204. {
  205. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  206. {
  207. return TeaModel.ToObject<AlipayUserCertifyOpenInitializeResponse>(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 AlipayUserCertifyOpenQueryResponse Query(string certifyId)
  228. {
  229. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  230. {
  231. {"connectTimeout", 15000},
  232. {"readTimeout", 15000},
  233. {"retry", new Dictionary<string, int?>
  234. {
  235. {"maxAttempts", 0},
  236. }},
  237. };
  238. TeaRequest _lastRequest = null;
  239. Exception _lastException = null;
  240. long _now = System.DateTime.Now.Millisecond;
  241. int _retryTimes = 0;
  242. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  243. {
  244. if (_retryTimes > 0)
  245. {
  246. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  247. if (backoffTime > 0)
  248. {
  249. TeaCore.Sleep(backoffTime);
  250. }
  251. }
  252. _retryTimes = _retryTimes + 1;
  253. try
  254. {
  255. TeaRequest request_ = new TeaRequest();
  256. Dictionary<string, string> systemParams = new Dictionary<string, string>
  257. {
  258. {"method", "alipay.user.certify.open.query"},
  259. {"app_id", this._kernel.GetConfig("appId")},
  260. {"timestamp", this._kernel.GetTimestamp()},
  261. {"format", "json"},
  262. {"version", "1.0"},
  263. {"alipay_sdk", this._kernel.GetSdkVersion()},
  264. {"charset", "UTF-8"},
  265. {"sign_type", this._kernel.GetConfig("signType")},
  266. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  267. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  268. };
  269. Dictionary<string, object> bizParams = new Dictionary<string, object>
  270. {
  271. {"certify_id", certifyId},
  272. };
  273. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  274. request_.Protocol = this._kernel.GetConfig("protocol");
  275. request_.Method = "POST";
  276. request_.Pathname = "/gateway.do";
  277. request_.Headers = new Dictionary<string, string>
  278. {
  279. {"host", this._kernel.GetConfig("gatewayHost")},
  280. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  281. };
  282. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  283. (
  284. new Dictionary<string, string>()
  285. {
  286. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  287. },
  288. systemParams,
  289. textParams
  290. ));
  291. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  292. _lastRequest = request_;
  293. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  294. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.user.certify.open.query");
  295. if (this._kernel.IsCertMode())
  296. {
  297. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  298. {
  299. return TeaModel.ToObject<AlipayUserCertifyOpenQueryResponse>(this._kernel.ToRespModel(respMap));
  300. }
  301. }
  302. else
  303. {
  304. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  305. {
  306. return TeaModel.ToObject<AlipayUserCertifyOpenQueryResponse>(this._kernel.ToRespModel(respMap));
  307. }
  308. }
  309. throw new TeaException(new Dictionary<string, string>
  310. {
  311. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  312. });
  313. }
  314. catch (Exception e)
  315. {
  316. if (TeaCore.IsRetryable(e))
  317. {
  318. _lastException = e;
  319. continue;
  320. }
  321. throw e;
  322. }
  323. }
  324. throw new TeaUnretryableException(_lastRequest, _lastException);
  325. }
  326. public async Task<AlipayUserCertifyOpenQueryResponse> QueryAsync(string certifyId)
  327. {
  328. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  329. {
  330. {"connectTimeout", 15000},
  331. {"readTimeout", 15000},
  332. {"retry", new Dictionary<string, int?>
  333. {
  334. {"maxAttempts", 0},
  335. }},
  336. };
  337. TeaRequest _lastRequest = null;
  338. Exception _lastException = null;
  339. long _now = System.DateTime.Now.Millisecond;
  340. int _retryTimes = 0;
  341. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  342. {
  343. if (_retryTimes > 0)
  344. {
  345. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  346. if (backoffTime > 0)
  347. {
  348. TeaCore.Sleep(backoffTime);
  349. }
  350. }
  351. _retryTimes = _retryTimes + 1;
  352. try
  353. {
  354. TeaRequest request_ = new TeaRequest();
  355. Dictionary<string, string> systemParams = new Dictionary<string, string>
  356. {
  357. {"method", "alipay.user.certify.open.query"},
  358. {"app_id", this._kernel.GetConfig("appId")},
  359. {"timestamp", this._kernel.GetTimestamp()},
  360. {"format", "json"},
  361. {"version", "1.0"},
  362. {"alipay_sdk", this._kernel.GetSdkVersion()},
  363. {"charset", "UTF-8"},
  364. {"sign_type", this._kernel.GetConfig("signType")},
  365. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  366. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  367. };
  368. Dictionary<string, object> bizParams = new Dictionary<string, object>
  369. {
  370. {"certify_id", certifyId},
  371. };
  372. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  373. request_.Protocol = this._kernel.GetConfig("protocol");
  374. request_.Method = "POST";
  375. request_.Pathname = "/gateway.do";
  376. request_.Headers = new Dictionary<string, string>
  377. {
  378. {"host", this._kernel.GetConfig("gatewayHost")},
  379. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  380. };
  381. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  382. (
  383. new Dictionary<string, string>()
  384. {
  385. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  386. },
  387. systemParams,
  388. textParams
  389. ));
  390. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  391. _lastRequest = request_;
  392. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  393. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.user.certify.open.query");
  394. if (this._kernel.IsCertMode())
  395. {
  396. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  397. {
  398. return TeaModel.ToObject<AlipayUserCertifyOpenQueryResponse>(this._kernel.ToRespModel(respMap));
  399. }
  400. }
  401. else
  402. {
  403. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  404. {
  405. return TeaModel.ToObject<AlipayUserCertifyOpenQueryResponse>(this._kernel.ToRespModel(respMap));
  406. }
  407. }
  408. throw new TeaException(new Dictionary<string, string>
  409. {
  410. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  411. });
  412. }
  413. catch (Exception e)
  414. {
  415. if (TeaCore.IsRetryable(e))
  416. {
  417. _lastException = e;
  418. continue;
  419. }
  420. throw e;
  421. }
  422. }
  423. throw new TeaUnretryableException(_lastRequest, _lastException);
  424. }
  425. public AlipayUserCertifyOpenCertifyResponse Certify(string certifyId)
  426. {
  427. Dictionary<string, string> systemParams = new Dictionary<string, string>
  428. {
  429. {"method", "alipay.user.certify.open.certify"},
  430. {"app_id", this._kernel.GetConfig("appId")},
  431. {"timestamp", this._kernel.GetTimestamp()},
  432. {"format", "json"},
  433. {"version", "1.0"},
  434. {"alipay_sdk", this._kernel.GetSdkVersion()},
  435. {"charset", "UTF-8"},
  436. {"sign_type", this._kernel.GetConfig("signType")},
  437. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  438. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  439. };
  440. Dictionary<string, object> bizParams = new Dictionary<string, object>
  441. {
  442. {"certify_id", certifyId},
  443. };
  444. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  445. string sign = this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"));
  446. Dictionary<string, string> response = new Dictionary<string, string>
  447. {
  448. {"body", this._kernel.GeneratePage("GET", systemParams, bizParams, textParams, sign)},
  449. };
  450. return TeaModel.ToObject<AlipayUserCertifyOpenCertifyResponse>(response);
  451. }
  452. /// <summary>
  453. /// ISV代商户代用,指定appAuthToken
  454. /// </summary>
  455. /// <param name="appAuthToken">代调用token</param>
  456. /// <returns>本客户端,便于链式调用</returns>
  457. public Client Agent(string appAuthToken)
  458. {
  459. _kernel.InjectTextParam("app_auth_token", appAuthToken);
  460. return this;
  461. }
  462. /// <summary>
  463. /// 用户授权调用,指定authToken
  464. /// </summary>
  465. /// <param name="authToken">用户授权token</param>
  466. /// <returns>本客户端,便于链式调用</returns>
  467. public Client Auth(string authToken)
  468. {
  469. _kernel.InjectTextParam("auth_token", authToken);
  470. return this;
  471. }
  472. /// <summary>
  473. /// 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  474. /// </summary>
  475. /// <param name="url">异步通知回调地址,例如:https://www.test.com/callback </param>
  476. /// <returns>本客户端,便于链式调用</returns>
  477. public Client AsyncNotify(string url)
  478. {
  479. _kernel.InjectTextParam("notify_url", url);
  480. return this;
  481. }
  482. /// <summary>
  483. /// 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  484. /// </summary>
  485. /// <param name="testUrl">后端系统测试地址</param>
  486. /// <returns>本客户端,便于链式调用</returns>
  487. public Client Route(string testUrl)
  488. {
  489. _kernel.InjectTextParam("ws_service_url", testUrl);
  490. return this;
  491. }
  492. /// <summary>
  493. /// 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  494. /// </summary>
  495. /// <param name="key">业务请求参数名称(biz_content下的字段名,比如timeout_express)</param>
  496. /// <param name="value">
  497. /// 业务请求参数的值,一个可以序列化成JSON的对象
  498. /// 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用string储存
  499. /// 如果该字段是一个数值型类型(比如:Number),请使用long储存
  500. /// 如果该字段是一个复杂类型,请使用嵌套的Dictionary指定各下级字段的值
  501. /// 如果该字段是一个数组,请使用List储存各个值
  502. /// 对于更复杂的情况,也支持Dictionary和List的各种组合嵌套,比如参数是值是个List,List中的每种类型是一个复杂对象
  503. /// </param>
  504. /// <returns>本客户端,便于链式调用</returns>
  505. public Client Optional(string key, object value)
  506. {
  507. _kernel.InjectBizParam(key, value);
  508. return this;
  509. }
  510. /// <summary>
  511. /// 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  512. /// optional方法的批量版本
  513. /// </summary>
  514. /// <param name="optionalArgs">可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释</param>
  515. /// <returns>本客户端,便于链式调用</returns>
  516. public Client BatchOptional(Dictionary<string, object> optionalArgs)
  517. {
  518. foreach (var pair in optionalArgs)
  519. {
  520. _kernel.InjectBizParam(pair.Key, pair.Value);
  521. }
  522. return this;
  523. }
  524. }
  525. }