Client.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. // This file is auto-generated, don't edit it. Thanks.
  3. namespace Alipay\EasySDK\Base\Video;
  4. use Alipay\EasySDK\Kernel\EasySDKKernel;
  5. use AlibabaCloud\Tea\Tea;
  6. use AlibabaCloud\Tea\Request;
  7. use AlibabaCloud\Tea\Exception\TeaError;
  8. use \Exception;
  9. use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
  10. use Alipay\EasySDK\Base\Video\Models\AlipayOfflineMaterialImageUploadResponse;
  11. use AlibabaCloud\Tea\Response;
  12. class Client {
  13. protected $_kernel;
  14. public function __construct($kernel){
  15. $this->_kernel = $kernel;
  16. }
  17. /**
  18. * @param string $videoName
  19. * @param string $videoFilePath
  20. * @return AlipayOfflineMaterialImageUploadResponse
  21. * @throws TeaError
  22. * @throws Exception
  23. * @throws TeaUnableRetryError
  24. */
  25. public function upload($videoName, $videoFilePath){
  26. $_runtime = [
  27. "ignoreSSL" => $this->_kernel->getConfig("ignoreSSL"),
  28. "httpProxy" => $this->_kernel->getConfig("httpProxy"),
  29. "connectTimeout" => 100000,
  30. "readTimeout" => 100000,
  31. "retry" => [
  32. "maxAttempts" => 0
  33. ]
  34. ];
  35. $_lastRequest = null;
  36. $_lastException = null;
  37. $_now = time();
  38. $_retryTimes = 0;
  39. while (Tea::allowRetry(@$_runtime["retry"], $_retryTimes, $_now)) {
  40. if ($_retryTimes > 0) {
  41. $_backoffTime = Tea::getBackoffTime(@$_runtime["backoff"], $_retryTimes);
  42. if ($_backoffTime > 0) {
  43. Tea::sleep($_backoffTime);
  44. }
  45. }
  46. $_retryTimes = $_retryTimes + 1;
  47. try {
  48. $_request = new Request();
  49. $systemParams = [
  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. $bizParams = [];
  62. $textParams = [
  63. "image_type" => "mp4",
  64. "image_name" => $videoName
  65. ];
  66. $fileParams = [
  67. "image_content" => $videoFilePath
  68. ];
  69. $boundary = $this->_kernel->getRandomBoundary();
  70. $_request->protocol = $this->_kernel->getConfig("protocol");
  71. $_request->method = "POST";
  72. $_request->pathname = "/gateway.do";
  73. $_request->headers = [
  74. "host" => $this->_kernel->getConfig("gatewayHost"),
  75. "content-type" => $this->_kernel->concatStr("multipart/form-data;charset=utf-8;boundary=", $boundary)
  76. ];
  77. $_request->query = $this->_kernel->sortMap(Tea::merge([
  78. "sign" => $this->_kernel->sign($systemParams, $bizParams, $textParams, $this->_kernel->getConfig("merchantPrivateKey"))
  79. ], $systemParams));
  80. $_request->body = $this->_kernel->toMultipartRequestBody($textParams, $fileParams, $boundary);
  81. $_lastRequest = $_request;
  82. $_response= Tea::send($_request, $_runtime);
  83. $respMap = $this->_kernel->readAsJson($_response, "alipay.offline.material.image.upload");
  84. if ($this->_kernel->isCertMode()) {
  85. if ($this->_kernel->verify($respMap, $this->_kernel->extractAlipayPublicKey($this->_kernel->getAlipayCertSN($respMap)))) {
  86. return AlipayOfflineMaterialImageUploadResponse::fromMap($this->_kernel->toRespModel($respMap));
  87. }
  88. }
  89. else {
  90. if ($this->_kernel->verify($respMap, $this->_kernel->getConfig("alipayPublicKey"))) {
  91. return AlipayOfflineMaterialImageUploadResponse::fromMap($this->_kernel->toRespModel($respMap));
  92. }
  93. }
  94. throw new TeaError([
  95. "message" => "验签失败,请检查支付宝公钥设置是否正确。"
  96. ]);
  97. }
  98. catch (Exception $e) {
  99. if (!($e instanceof TeaError)) {
  100. $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
  101. }
  102. if (Tea::isRetryable($e)) {
  103. $_lastException = $e;
  104. continue;
  105. }
  106. throw $e;
  107. }
  108. }
  109. throw new TeaUnableRetryError($_lastRequest, $_lastException);
  110. }
  111. /**
  112. * ISV代商户代用,指定appAuthToken
  113. *
  114. * @param $appAuthToken String 代调用token
  115. * @return $this 本客户端,便于链式调用
  116. */
  117. public function agent($appAuthToken)
  118. {
  119. $this->_kernel->injectTextParam("app_auth_token", $appAuthToken);
  120. return $this;
  121. }
  122. /**
  123. * 用户授权调用,指定authToken
  124. *
  125. * @param $authToken String 用户授权token
  126. * @return $this
  127. */
  128. public function auth($authToken)
  129. {
  130. $this->_kernel->injectTextParam("auth_token", $authToken);
  131. return $this;
  132. }
  133. /**
  134. * 设置异步通知回调地址,此处设置将在本调用中覆盖Config中的全局配置
  135. *
  136. * @param $url String 异步通知回调地址,例如:https://www.test.com/callback
  137. * @return $this
  138. */
  139. public function asyncNotify($url)
  140. {
  141. $this->_kernel->injectTextParam("notify_url", $url);
  142. return $this;
  143. }
  144. /**
  145. * 将本次调用强制路由到后端系统的测试地址上,常用于线下环境内外联调,沙箱与线上环境设置无效
  146. *
  147. * @param $testUrl String 后端系统测试地址
  148. * @return $this
  149. */
  150. public function route($testUrl)
  151. {
  152. $this->_kernel->injectTextParam("ws_service_url", $testUrl);
  153. return $this;
  154. }
  155. /**
  156. * 设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  157. *
  158. * @param $key String 业务请求参数名称(biz_content下的字段名,比如timeout_express)
  159. * @param $value object 业务请求参数的值,一个可以序列化成JSON的对象
  160. * 如果该字段是一个字符串类型(String、Price、Date在SDK中都是字符串),请使用String储存
  161. * 如果该字段是一个数值型类型(比如:Number),请使用Long储存
  162. * 如果该字段是一个复杂类型,请使用嵌套的array指定各下级字段的值
  163. * 如果该字段是一个数组,请使用array储存各个值
  164. * @return $this
  165. */
  166. public function optional($key, $value)
  167. {
  168. $this->_kernel->injectBizParam($key, $value);
  169. return $this;
  170. }
  171. /**
  172. * 批量设置API入参中没有的其他可选业务请求参数(biz_content下的字段)
  173. * optional方法的批量版本
  174. *
  175. * @param $optionalArgs array 可选参数集合,每个参数由key和value组成,key和value的格式请参见optional方法的注释
  176. * @return $this
  177. */
  178. public function batchOptional($optionalArgs)
  179. {
  180. foreach ($optionalArgs as $key => $value) {
  181. $this->_kernel->injectBizParam($key, $value);
  182. }
  183. return $this;
  184. }
  185. }