OperationApiTest.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * OperationApiTest
  4. * PHP version 7.4
  5. *
  6. * @category Class
  7. * @package Alipay\OpenAPISDK
  8. * @author OpenAPI Generator team
  9. * @link https://openapi-generator.tech
  10. */
  11. /**
  12. * 支付宝开放平台API
  13. *
  14. * 支付宝开放平台v3协议文档
  15. *
  16. * The version of the OpenAPI document: 1.0
  17. * Generated by: https://openapi-generator.tech
  18. * OpenAPI Generator version: 6.0.0
  19. */
  20. /**
  21. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  22. * https://openapi-generator.tech
  23. * Please update the test case below to test the endpoint.
  24. */
  25. namespace Alipay\OpenAPISDK\Test\Api;
  26. use Alipay\OpenAPISDK\Api\AlipayTradeApi;
  27. use \Alipay\OpenAPISDK\Configuration;
  28. use \Alipay\OpenAPISDK\ApiException;
  29. use Alipay\OpenAPISDK\Model\AlipayTradePayModel;
  30. use \Alipay\OpenAPISDK\ObjectSerializer;
  31. use Alipay\OpenAPISDK\Util\AlipayConfigUtil;
  32. use Alipay\OpenAPISDK\Util\GenericExecuteApi;
  33. use Alipay\OpenAPISDK\Util\Model\AlipayConfig;
  34. use Alipay\OpenAPISDK\Util\Model\CustomizedParams;
  35. use Alipay\OpenAPISDK\Util\Model\OpenApiGenericRequest;
  36. use GuzzleHttp\Client;
  37. use GuzzleHttp\Exception\GuzzleException;
  38. use PHPUnit\Framework\TestCase;
  39. /**
  40. * OperationApiTest Class Doc Comment
  41. *
  42. * @category Class
  43. * @package Alipay\OpenAPISDK
  44. * @author OpenAPI Generator team
  45. * @link https://openapi-generator.tech
  46. */
  47. class OperationApiTest extends TestCase
  48. {
  49. private $apiInstance;
  50. /**
  51. * Setup before running any test cases
  52. */
  53. public static function setUpBeforeClass(): void
  54. {
  55. }
  56. /**
  57. * Setup before running each test case
  58. */
  59. public function setUp(): void
  60. {
  61. $alipayConfig = new AlipayConfig();
  62. $alipayConfig->setServerUrl('https://openapipre.alipay.com');
  63. $alipayConfig->setAppId('2021003126691367');
  64. $alipayConfig->setPrivateKey('');
  65. $alipayConfig->setAlipayPublicKey('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlr+2Mir816Ye8ybsC8QgIigrG2oqVTwYeCjiJQPGP0x7iRVVwQuuM54rO+OyyfJcvI5UWFtfcpy+si+3JyaInKP69DA0AS4XkVPV/81xcIHMZP/CJAYOtLFLhhyEwp1CMoN45BtJes5lG65UXz/7QzVjcF+6AC+qVKx66HKSsT9b5HyWRxfDkOYixy1gZt39w+sgxaAPVt6pf7UZHX+ENE/gYpTCHHflVPzPfl8TIXTZmEMGqjBLY8GFXVJkvATX3h12VX3AwUlIndY4gJND9l1isFV9BfpmZYyv864z14UH6Kq9u8WVWdF5bsJevo4oU0Q0UB8EmyOdlxBPTDiOzwIDAQAB');
  66. // $alipayConfig->setEncryptKey('');
  67. // $alipayConfig->setAppId('2021003156675030');
  68. // $alipayConfig->setPrivateKey('');
  69. // $alipayConfig->setAlipayPublicCertPath('test/cert/alipayCertPublicKey_RSA2.crt');
  70. // $alipayConfig->setAppCertPath('test/cert/appCertPublicKey_2021003156675030.crt');
  71. // $alipayConfig->setRootCertPath('test/cert/alipayRootCert.crt');
  72. // $alipayConfig->setEncryptKey('');
  73. $alipayConfigUtil = new AlipayConfigUtil($alipayConfig);
  74. $this->apiInstance = new AlipayTradeApi(
  75. // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
  76. // This is optional, `GuzzleHttp\Client` will be used as default.
  77. new Client()
  78. );
  79. $this->apiInstance->setAlipayConfigUtil($alipayConfigUtil);
  80. }
  81. /**
  82. * Clean up after running each test case
  83. */
  84. public function tearDown(): void
  85. {
  86. }
  87. /**
  88. * Clean up after running all test cases
  89. */
  90. public static function tearDownAfterClass(): void
  91. {
  92. }
  93. /**
  94. * Test case for query
  95. *
  96. * 测试路由转发closelyrzone.
  97. *
  98. */
  99. public function testQuery()
  100. {
  101. $customizedParams = new CustomizedParams();
  102. $customizedParams->setHeaderParams(["alipay-request-id"=>"222"]);
  103. $model = new AlipayTradePayModel();
  104. $model->setOutTradeNo('20210817010101001');
  105. $model->setTotalAmount('0.011');
  106. $model->setSubject('测试商品');
  107. $model->setScene('bar_code');
  108. $model->setAuthCode('28763443825664394');
  109. try {
  110. $result = $this->apiInstance->pay($model, $customizedParams);
  111. print_r($result);
  112. } catch (ApiException $e) {
  113. var_dump($e->getResponseBody());
  114. echo 'Exception when calling AlipayTradeApi->pay: ', $e->getMessage(), PHP_EOL;
  115. echo 'body: ', $e->getResponseBody(), PHP_EOL;
  116. echo 'header: ', $e->getResponseHeaders(), PHP_EOL;
  117. }
  118. }
  119. public function testPageExecute(){
  120. $execute = new GenericExecuteApi($this->apiInstance->getAlipayConfigUtil());
  121. $execute->setLoadTest(true);
  122. $customizedParams = new CustomizedParams();
  123. $queryParams = ['notify_url' => 'https://www.aaa.com',
  124. 'return_url' => 'https://www.bbb.com'];
  125. $customizedParams->setQueryParams($queryParams);
  126. // $customizedParams->setBodyContent("{" .
  127. // " \"body\":\"对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。\"," .
  128. // " \"subject\":\"测试\"," .
  129. // " \"out_trade_no\":\"70501111111S001111119\"," .
  130. // " \"timeout_express\":\"90m\"," .
  131. // " \"total_amount\":9.00," .
  132. // " \"product_code\":\"QUICK_WAP_WAY\"" .
  133. // " }");
  134. $bizParams = [];
  135. $otherParams = [];
  136. $otherParams['body'] = '对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。';
  137. $otherParams['out_trade_no'] = '70501111111S001111119';
  138. $otherParams['timeout_express'] = '90m';
  139. $otherParams['total_amount'] = 9.00;
  140. $otherParams['product_code'] = 'QUICK_WAP_WAY';
  141. $bizParams['biz_content'] = $otherParams;
  142. // $alipayMarketingActivityOrdervoucherAppendModel = new \Alipay\OpenAPISDK\Model\AlipayMarketingActivityOrdervoucherAppendModel(); // \Alipay\OpenAPISDK\Model\AlipayMarketingActivityOrdervoucherAppendModel
  143. // $alipayMarketingActivityOrdervoucherAppendModel->setOutBizNo('1231xxq12312ty111112xxxxqqewx');
  144. // $alipayMarketingActivityOrdervoucherAppendModel->setProductVersion('2.0.0');
  145. // $alipayMarketingActivityOrdervoucherAppendModel->setVoucherQuantity(15);
  146. // $bizParams['biz_content'] = $alipayMarketingActivityOrdervoucherAppendModel;
  147. $pageExecute = $execute->pageExecute("alipay.trade.wap.pay", "POST", $bizParams, "123sdc", null, $customizedParams);
  148. var_dump($pageExecute);
  149. $pageExecute2 = $execute->pageExecute("alipay.trade.wap.pay", "GET", $bizParams, "123sdc", null, $customizedParams);
  150. var_dump($pageExecute2);
  151. $sdkExecute = $execute->sdkExecute("alipay.trade.wap.pay", $bizParams, "123sdc", null, $customizedParams);
  152. var_dump($sdkExecute);
  153. }
  154. public function testExecute(){
  155. $execute = new GenericExecuteApi(
  156. $this->apiInstance->getAlipayConfigUtil(),
  157. new Client());
  158. $request = new OpenApiGenericRequest();
  159. $pathParams['activity_id'] = '123';
  160. $pathParams['voucher_code'] = '券码1';
  161. $request->setPathParams($pathParams);
  162. $queryParams['return_url'] = 'www.baidu.com';
  163. $request->setQueryParams($queryParams);
  164. $bizParams['merchant_access_mode'] = 'AGENCY_MODE';
  165. $bizParams['biz_dt'] = '2017-01-01 00:00:01';
  166. $bizParams['out_biz_no'] = '1002600620019090123143254436';
  167. $bizParams['total_fee'] = '999.99';
  168. $request->setBizParams($bizParams);
  169. $response = $execute->execute('/v3/alipay/marketing/activity/{activity_id}/ordervoucher/{voucher_code}/refund', 'POST', $request);
  170. var_dump($response);
  171. }
  172. public function testFileExecute(){
  173. $execute = new GenericExecuteApi(
  174. $this->apiInstance->getAlipayConfigUtil(),
  175. new Client());
  176. $request = new OpenApiGenericRequest();
  177. $queryParams['return_url'] = 'www.baidu.com';
  178. $request->setQueryParams($queryParams);
  179. $fileParams['app_logo'] = 'test/cert/pic.jpg';
  180. $request->setFileParams($fileParams);
  181. $bizParams['app_category_ids'] = '11_12;12_13';
  182. $bizParams['app_english_name'] = 'demoexample';
  183. $bizParams['app_name'] = '杭州支小宝潮流女装店';
  184. $bizParams['service_email'] = 'example@mail.com';
  185. $request->setBizParams($bizParams);
  186. try {
  187. $response = $execute->execute('/v3/alipay/open/mini/baseinfo/modify', 'POST', $request);
  188. var_dump($response);
  189. } catch (ApiException $e) {
  190. var_dump($e->getResponseBody());
  191. }
  192. }
  193. }