Client.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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.Base.Qrcode.Models;
  10. namespace Alipay.EasySDK.Base.Qrcode
  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 AlipayOpenAppQrcodeCreateResponse Create(string urlParam, string queryParam, string describe)
  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.open.app.qrcode.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. {"url_param", urlParam},
  66. {"query_param", queryParam},
  67. {"describe", describe},
  68. };
  69. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  70. request_.Protocol = this._kernel.GetConfig("protocol");
  71. request_.Method = "POST";
  72. request_.Pathname = "/gateway.do";
  73. request_.Headers = new Dictionary<string, string>
  74. {
  75. {"host", this._kernel.GetConfig("gatewayHost")},
  76. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  77. };
  78. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  79. (
  80. new Dictionary<string, string>()
  81. {
  82. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  83. },
  84. systemParams,
  85. textParams
  86. ));
  87. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  88. _lastRequest = request_;
  89. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  90. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.open.app.qrcode.create");
  91. if (this._kernel.IsCertMode())
  92. {
  93. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  94. {
  95. return TeaModel.ToObject<AlipayOpenAppQrcodeCreateResponse>(this._kernel.ToRespModel(respMap));
  96. }
  97. }
  98. else
  99. {
  100. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  101. {
  102. return TeaModel.ToObject<AlipayOpenAppQrcodeCreateResponse>(this._kernel.ToRespModel(respMap));
  103. }
  104. }
  105. throw new TeaException(new Dictionary<string, string>
  106. {
  107. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  108. });
  109. }
  110. catch (Exception e)
  111. {
  112. if (TeaCore.IsRetryable(e))
  113. {
  114. _lastException = e;
  115. continue;
  116. }
  117. throw e;
  118. }
  119. }
  120. throw new TeaUnretryableException(_lastRequest, _lastException);
  121. }
  122. public async Task<AlipayOpenAppQrcodeCreateResponse> CreateAsync(string urlParam, string queryParam, string describe)
  123. {
  124. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  125. {
  126. {"ignoreSSL", this._kernel.GetConfig("ignoreSSL")},
  127. {"httpProxy", this._kernel.GetConfig("httpProxy")},
  128. {"connectTimeout", 15000},
  129. {"readTimeout", 15000},
  130. {"retry", new Dictionary<string, int?>
  131. {
  132. {"maxAttempts", 0},
  133. }},
  134. };
  135. TeaRequest _lastRequest = null;
  136. Exception _lastException = null;
  137. long _now = System.DateTime.Now.Millisecond;
  138. int _retryTimes = 0;
  139. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  140. {
  141. if (_retryTimes > 0)
  142. {
  143. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  144. if (backoffTime > 0)
  145. {
  146. TeaCore.Sleep(backoffTime);
  147. }
  148. }
  149. _retryTimes = _retryTimes + 1;
  150. try
  151. {
  152. TeaRequest request_ = new TeaRequest();
  153. Dictionary<string, string> systemParams = new Dictionary<string, string>
  154. {
  155. {"method", "alipay.open.app.qrcode.create"},
  156. {"app_id", this._kernel.GetConfig("appId")},
  157. {"timestamp", this._kernel.GetTimestamp()},
  158. {"format", "json"},
  159. {"version", "1.0"},
  160. {"alipay_sdk", this._kernel.GetSdkVersion()},
  161. {"charset", "UTF-8"},
  162. {"sign_type", this._kernel.GetConfig("signType")},
  163. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  164. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  165. };
  166. Dictionary<string, object> bizParams = new Dictionary<string, object>
  167. {
  168. {"url_param", urlParam},
  169. {"query_param", queryParam},
  170. {"describe", describe},
  171. };
  172. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  173. request_.Protocol = this._kernel.GetConfig("protocol");
  174. request_.Method = "POST";
  175. request_.Pathname = "/gateway.do";
  176. request_.Headers = new Dictionary<string, string>
  177. {
  178. {"host", this._kernel.GetConfig("gatewayHost")},
  179. {"content-type", "application/x-www-form-urlencoded;charset=utf-8"},
  180. };
  181. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  182. (
  183. new Dictionary<string, string>()
  184. {
  185. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  186. },
  187. systemParams,
  188. textParams
  189. ));
  190. request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
  191. _lastRequest = request_;
  192. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  193. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.open.app.qrcode.create");
  194. if (this._kernel.IsCertMode())
  195. {
  196. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  197. {
  198. return TeaModel.ToObject<AlipayOpenAppQrcodeCreateResponse>(this._kernel.ToRespModel(respMap));
  199. }
  200. }
  201. else
  202. {
  203. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  204. {
  205. return TeaModel.ToObject<AlipayOpenAppQrcodeCreateResponse>(this._kernel.ToRespModel(respMap));
  206. }
  207. }
  208. throw new TeaException(new Dictionary<string, string>
  209. {
  210. {"message", "验签失败,请检查支付宝公钥设置是否正确。"},
  211. });
  212. }
  213. catch (Exception e)
  214. {
  215. if (TeaCore.IsRetryable(e))
  216. {
  217. _lastException = e;
  218. continue;
  219. }
  220. throw e;
  221. }
  222. }
  223. throw new TeaUnretryableException(_lastRequest, _lastException);
  224. }
  225. /// <summary>
  226. /// ISV代商户代用,指定appAuthToken
  227. /// </summary>
  228. /// <param name="appAuthToken">代调用token</param>
  229. /// <returns>本客户端,便于链式调用</returns>
  230. public Client Agent(string appAuthToken)
  231. {
  232. _kernel.InjectTextParam("app_auth_token", appAuthToken);
  233. return this;
  234. }
  235. /// <summary>
  236. /// 用户授权调用,指定authToken
  237. /// </summary>
  238. /// <param name="authToken">用户授权token</param>
  239. /// <returns>本客户端,便于链式调用</returns>
  240. public Client Auth(string authToken)
  241. {
  242. _kernel.InjectTextParam("auth_token", authToken);
  243. return this;
  244. }
  245. /// <summary>
  246. /// 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  247. /// </summary>
  248. /// <param name="url">异步通知回调地址,例如:https://www.test.com/callback </param>
  249. /// <returns>本客户端,便于链式调用</returns>
  250. public Client AsyncNotify(string url)
  251. {
  252. _kernel.InjectTextParam("notify_url", url);
  253. return this;
  254. }
  255. /// <summary>
  256. /// 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  257. /// </summary>
  258. /// <param name="testUrl">后端系统测试地址</param>
  259. /// <returns>本客户端,便于链式调用</returns>
  260. public Client Route(string testUrl)
  261. {
  262. _kernel.InjectTextParam("ws_service_url", testUrl);
  263. return this;
  264. }
  265. /// <summary>
  266. /// 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  267. /// </summary>
  268. /// <param name="key">业务请求参数名称(biz_content下的字段名,比如timeout_express)</param>
  269. /// <param name="value">
  270. /// 业务请求参数的值,一个可以序列化成JSON的对象
  271. /// 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用string储存
  272. /// 如果该字段是一个数值型类型(比如:Number),请使用long储存
  273. /// 如果该字段是一个复杂类型,请使用嵌套的Dictionary指定各下级字段的值
  274. /// 如果该字段是一个数组,请使用List储存各个值
  275. /// 对于更复杂的情况,也支持Dictionary和List的各种组合嵌套,比如参数是值是个List,List中的每种类型是一个复杂对象
  276. /// </param>
  277. /// <returns>本客户端,便于链式调用</returns>
  278. public Client Optional(string key, object value)
  279. {
  280. _kernel.InjectBizParam(key, value);
  281. return this;
  282. }
  283. /// <summary>
  284. /// 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  285. /// optional方法的批量版本
  286. /// </summary>
  287. /// <param name="optionalArgs">可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释</param>
  288. /// <returns>本客户端,便于链式调用</returns>
  289. public Client BatchOptional(Dictionary<string, object> optionalArgs)
  290. {
  291. foreach (var pair in optionalArgs)
  292. {
  293. _kernel.InjectBizParam(pair.Key, pair.Value);
  294. }
  295. return this;
  296. }
  297. }
  298. }