Client.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.App.Models;
  10. namespace Alipay.EasySDK.Payment.App
  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 AlipayTradeAppPayResponse Pay(string subject, string outTradeNo, string totalAmount)
  20. {
  21. Dictionary<string, string> systemParams = new Dictionary<string, string>
  22. {
  23. {"method", "alipay.trade.app.pay"},
  24. {"app_id", this._kernel.GetConfig("appId")},
  25. {"timestamp", this._kernel.GetTimestamp()},
  26. {"format", "json"},
  27. {"version", "1.0"},
  28. {"alipay_sdk", this._kernel.GetSdkVersion()},
  29. {"charset", "UTF-8"},
  30. {"sign_type", this._kernel.GetConfig("signType")},
  31. {"app_cert_sn", this._kernel.GetMerchantCertSN()},
  32. {"alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN()},
  33. };
  34. Dictionary<string, object> bizParams = new Dictionary<string, object>
  35. {
  36. {"subject", subject},
  37. {"out_trade_no", outTradeNo},
  38. {"total_amount", totalAmount},
  39. };
  40. Dictionary<string, string> textParams = new Dictionary<string, string>(){};
  41. string sign = this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey"));
  42. Dictionary<string, string> response = new Dictionary<string, string>
  43. {
  44. {"body", this._kernel.GenerateOrderString(systemParams, bizParams, textParams, sign)},
  45. };
  46. return TeaModel.ToObject<AlipayTradeAppPayResponse>(response);
  47. }
  48. /// <summary>
  49. /// ISV代商户代用,指定appAuthToken
  50. /// </summary>
  51. /// <param name="appAuthToken">代调用token</param>
  52. /// <returns>本客户端,便于链式调用</returns>
  53. public Client Agent(string appAuthToken)
  54. {
  55. _kernel.InjectTextParam("app_auth_token", appAuthToken);
  56. return this;
  57. }
  58. /// <summary>
  59. /// 用户授权调用,指定authToken
  60. /// </summary>
  61. /// <param name="authToken">用户授权token</param>
  62. /// <returns>本客户端,便于链式调用</returns>
  63. public Client Auth(string authToken)
  64. {
  65. _kernel.InjectTextParam("auth_token", authToken);
  66. return this;
  67. }
  68. /// <summary>
  69. /// 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  70. /// </summary>
  71. /// <param name="url">异步通知回调地址,例如:https://www.test.com/callback </param>
  72. /// <returns>本客户端,便于链式调用</returns>
  73. public Client AsyncNotify(string url)
  74. {
  75. _kernel.InjectTextParam("notify_url", url);
  76. return this;
  77. }
  78. /// <summary>
  79. /// 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  80. /// </summary>
  81. /// <param name="testUrl">后端系统测试地址</param>
  82. /// <returns>本客户端,便于链式调用</returns>
  83. public Client Route(string testUrl)
  84. {
  85. _kernel.InjectTextParam("ws_service_url", testUrl);
  86. return this;
  87. }
  88. /// <summary>
  89. /// 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  90. /// </summary>
  91. /// <param name="key">业务请求参数名称(biz_content下的字段名,比如timeout_express)</param>
  92. /// <param name="value">
  93. /// 业务请求参数的值,一个可以序列化成JSON的对象
  94. /// 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用string储存
  95. /// 如果该字段是一个数值型类型(比如:Number),请使用long储存
  96. /// 如果该字段是一个复杂类型,请使用嵌套的Dictionary指定各下级字段的值
  97. /// 如果该字段是一个数组,请使用List储存各个值
  98. /// 对于更复杂的情况,也支持Dictionary和List的各种组合嵌套,比如参数是值是个List,List中的每种类型是一个复杂对象
  99. /// </param>
  100. /// <returns>本客户端,便于链式调用</returns>
  101. public Client Optional(string key, object value)
  102. {
  103. _kernel.InjectBizParam(key, value);
  104. return this;
  105. }
  106. /// <summary>
  107. /// 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  108. /// optional方法的批量版本
  109. /// </summary>
  110. /// <param name="optionalArgs">可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释</param>
  111. /// <returns>本客户端,便于链式调用</returns>
  112. public Client BatchOptional(Dictionary<string, object> optionalArgs)
  113. {
  114. foreach (var pair in optionalArgs)
  115. {
  116. _kernel.InjectBizParam(pair.Key, pair.Value);
  117. }
  118. return this;
  119. }
  120. }
  121. }