Client.cs 14 KB

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