ClientTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Alipay\EasySDK\Test\util\generic;
  3. use Alipay\EasySDK\Kernel\Factory;
  4. use Alipay\EasySDK\Test\TestAccount;
  5. use PHPUnit\Framework\TestCase;
  6. class ClientTest extends TestCase
  7. {
  8. public function __construct($name = null, array $data = [], $dataName = '')
  9. {
  10. parent::__construct($name, $data, $dataName);
  11. $account = new TestAccount();
  12. Factory::setOptions($account->getTestAccount());
  13. }
  14. public function testExecuteWithoutAppAuthToken()
  15. {
  16. $result = Factory::util()->generic()->execute("alipay.trade.create", null, $this->getBizParams(microtime()));
  17. $this->assertEquals('10000', $result->code);
  18. $this->assertEquals('Success', $result->msg);
  19. }
  20. public function testExecuteWithAppAuthToken()
  21. {
  22. $result = Factory::util()->generic()->execute("alipay.trade.create", $this->getTextParams(), $this->getBizParams(microtime()));
  23. $this->assertEquals('20001', $result->code);
  24. $this->assertEquals('Insufficient Token Permissions', $result->msg);
  25. $this->assertEquals('aop.invalid-app-auth-token', $result->subCode);
  26. $this->assertEquals('无效的应用授权令牌', $result->subMsg);
  27. }
  28. //设置系统参数(OpenAPI中非biz_content里的参数)
  29. private function getTextParams()
  30. {
  31. return array("app_auth_token" => "201712BB_D0804adb2e743078d1822d536956X34");
  32. }
  33. private function getBizParams($outTradeNo)
  34. {
  35. $bizParams = array(
  36. "subject" => "Iphone6 16G",
  37. "out_trade_no" => $outTradeNo,
  38. "total_amount" => "0.10",
  39. "buyer_id" => "2088002656718920",
  40. "extend_params" => $this->getHuabeiParams()
  41. );
  42. return $bizParams;
  43. }
  44. private function getHuabeiParams()
  45. {
  46. $extendParams = array("hb_fq_num" => "3", "hb_fq_seller_percent" => "3");
  47. return $extendParams;
  48. }
  49. }