Client.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. {"connectTimeout", 100000},
  24. {"readTimeout", 100000},
  25. {"retry", new Dictionary<string, int?>
  26. {
  27. {"maxAttempts", 0},
  28. }},
  29. };
  30. TeaRequest _lastRequest = null;
  31. Exception _lastException = null;
  32. long _now = System.DateTime.Now.Millisecond;
  33. int _retryTimes = 0;
  34. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  35. {
  36. if (_retryTimes > 0)
  37. {
  38. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  39. if (backoffTime > 0)
  40. {
  41. TeaCore.Sleep(backoffTime);
  42. }
  43. }
  44. _retryTimes = _retryTimes + 1;
  45. try
  46. {
  47. TeaRequest request_ = new TeaRequest();
  48. Dictionary<string, string> systemParams = new Dictionary<string, string>
  49. {
  50. {"method", "alipay.offline.material.image.upload"},
  51. {"app_id", this._kernel.GetConfig("appId")},
  52. {"timestamp", this._kernel.GetTimestamp()},
  53. {"format", "json"},
  54. {"version", "1.0"},
  55. {"alipay_sdk", this._kernel.GetSdkVersion()},
  56. {"charset", "UTF-8"},
  57. {"sign_type", this._kernel.GetConfig("signType")},
  58. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  59. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  60. };
  61. Dictionary<string, object> bizParams = new Dictionary<string, object>(){};
  62. Dictionary<string, string> textParams = new Dictionary<string, string>
  63. {
  64. {"image_type", "jpg"},
  65. {"image_name", imageName},
  66. };
  67. Dictionary<string, string> fileParams = new Dictionary<string, string>
  68. {
  69. {"image_content", imageFilePath},
  70. };
  71. string boundary = this._kernel.GetRandomBoundary();
  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", this._kernel.ConcatStr("multipart/form-data;charset=utf-8;boundary=", boundary)},
  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. ));
  88. request_.Body = this._kernel.ToMultipartRequestBody(textParams, fileParams, boundary);
  89. _lastRequest = request_;
  90. TeaResponse response_ = TeaCore.DoAction(request_, runtime_);
  91. Dictionary<string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.offline.material.image.upload");
  92. if (this._kernel.IsCertMode())
  93. {
  94. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  95. {
  96. return TeaModel.ToObject<AlipayOfflineMaterialImageUploadResponse>(this._kernel.ToRespModel(respMap));
  97. }
  98. }
  99. else
  100. {
  101. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  102. {
  103. return TeaModel.ToObject<AlipayOfflineMaterialImageUploadResponse>(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<AlipayOfflineMaterialImageUploadResponse> UploadAsync(string imageName, string imageFilePath)
  124. {
  125. Dictionary<string, object> runtime_ = new Dictionary<string, object>
  126. {
  127. {"connectTimeout", 100000},
  128. {"readTimeout", 100000},
  129. {"retry", new Dictionary<string, int?>
  130. {
  131. {"maxAttempts", 0},
  132. }},
  133. };
  134. TeaRequest _lastRequest = null;
  135. Exception _lastException = null;
  136. long _now = System.DateTime.Now.Millisecond;
  137. int _retryTimes = 0;
  138. while (TeaCore.AllowRetry((IDictionary) runtime_["retry"], _retryTimes, _now))
  139. {
  140. if (_retryTimes > 0)
  141. {
  142. int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
  143. if (backoffTime > 0)
  144. {
  145. TeaCore.Sleep(backoffTime);
  146. }
  147. }
  148. _retryTimes = _retryTimes + 1;
  149. try
  150. {
  151. TeaRequest request_ = new TeaRequest();
  152. Dictionary<string, string> systemParams = new Dictionary<string, string>
  153. {
  154. {"method", "alipay.offline.material.image.upload"},
  155. {"app_id", this._kernel.GetConfig("appId")},
  156. {"timestamp", this._kernel.GetTimestamp()},
  157. {"format", "json"},
  158. {"version", "1.0"},
  159. {"alipay_sdk", this._kernel.GetSdkVersion()},
  160. {"charset", "UTF-8"},
  161. {"sign_type", this._kernel.GetConfig("signType")},
  162. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  163. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  164. };
  165. Dictionary<string, object> bizParams = new Dictionary<string, object>(){};
  166. Dictionary<string, string> textParams = new Dictionary<string, string>
  167. {
  168. {"image_type", "jpg"},
  169. {"image_name", imageName},
  170. };
  171. Dictionary<string, string> fileParams = new Dictionary<string, string>
  172. {
  173. {"image_content", imageFilePath},
  174. };
  175. string boundary = this._kernel.GetRandomBoundary();
  176. request_.Protocol = this._kernel.GetConfig("protocol");
  177. request_.Method = "POST";
  178. request_.Pathname = "/gateway.do";
  179. request_.Headers = new Dictionary<string, string>
  180. {
  181. {"host", this._kernel.GetConfig("gatewayHost")},
  182. {"content-type", this._kernel.ConcatStr("multipart/form-data;charset=utf-8;boundary=", boundary)},
  183. };
  184. request_.Query = this._kernel.SortMap(TeaConverter.merge<string>
  185. (
  186. new Dictionary<string, string>()
  187. {
  188. {"sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"))},
  189. },
  190. systemParams
  191. ));
  192. request_.Body = this._kernel.ToMultipartRequestBody(textParams, fileParams, boundary);
  193. _lastRequest = request_;
  194. TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);
  195. Dictionary<string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.offline.material.image.upload");
  196. if (this._kernel.IsCertMode())
  197. {
  198. if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
  199. {
  200. return TeaModel.ToObject<AlipayOfflineMaterialImageUploadResponse>(this._kernel.ToRespModel(respMap));
  201. }
  202. }
  203. else
  204. {
  205. if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
  206. {
  207. return TeaModel.ToObject<AlipayOfflineMaterialImageUploadResponse>(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. /// <summary>
  228. /// ISV代商户代用,指定appAuthToken
  229. /// </summary>
  230. /// <param name="appAuthToken">代调用token</param>
  231. /// <returns>本客户端,便于链式调用</returns>
  232. public Client Agent(string appAuthToken)
  233. {
  234. _kernel.InjectTextParam("app_auth_token", appAuthToken);
  235. return this;
  236. }
  237. /// <summary>
  238. /// 用户授权调用,指定authToken
  239. /// </summary>
  240. /// <param name="authToken">用户授权token</param>
  241. /// <returns>本客户端,便于链式调用</returns>
  242. public Client Auth(string authToken)
  243. {
  244. _kernel.InjectTextParam("auth_token", authToken);
  245. return this;
  246. }
  247. /// <summary>
  248. /// 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  249. /// </summary>
  250. /// <param name="url">异步通知回调地址,例如:https://www.test.com/callback </param>
  251. /// <returns>本客户端,便于链式调用</returns>
  252. public Client AsyncNotify(string url)
  253. {
  254. _kernel.InjectTextParam("notify_url", url);
  255. return this;
  256. }
  257. /// <summary>
  258. /// 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  259. /// </summary>
  260. /// <param name="testUrl">后端系统测试地址</param>
  261. /// <returns>本客户端,便于链式调用</returns>
  262. public Client Route(string testUrl)
  263. {
  264. _kernel.InjectTextParam("ws_service_url", testUrl);
  265. return this;
  266. }
  267. /// <summary>
  268. /// 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  269. /// </summary>
  270. /// <param name="key">业务请求参数名称(biz_content下的字段名,比如timeout_express)</param>
  271. /// <param name="value">
  272. /// 业务请求参数的值,一个可以序列化成JSON的对象
  273. /// 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用string储存
  274. /// 如果该字段是一个数值型类型(比如:Number),请使用long储存
  275. /// 如果该字段是一个复杂类型,请使用嵌套的Dictionary指定各下级字段的值
  276. /// 如果该字段是一个数组,请使用List储存各个值
  277. /// 对于更复杂的情况,也支持Dictionary和List的各种组合嵌套,比如参数是值是个List,List中的每种类型是一个复杂对象
  278. /// </param>
  279. /// <returns>本客户端,便于链式调用</returns>
  280. public Client Optional(string key, object value)
  281. {
  282. _kernel.InjectBizParam(key, value);
  283. return this;
  284. }
  285. /// <summary>
  286. /// 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  287. /// optional方法的批量版本
  288. /// </summary>
  289. /// <param name="optionalArgs">可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释</param>
  290. /// <returns>本客户端,便于链式调用</returns>
  291. public Client BatchOptional(Dictionary<string, object> optionalArgs)
  292. {
  293. foreach (var pair in optionalArgs)
  294. {
  295. _kernel.InjectBizParam(pair.Key, pair.Value);
  296. }
  297. return this;
  298. }
  299. }
  300. }