TestAccount.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Alipay\EasySDK\Test;
  3. use Alipay\EasySDK\Kernel\Config;
  4. class TestAccount
  5. {
  6. public function getTestAccount()
  7. {
  8. $options = new Config();
  9. $options->protocol = 'https';
  10. $options->gatewayHost = 'openapi.alipay.com';
  11. $options->appId = '<-- 请填写您的AppId,例如:2019022663440152 -->';
  12. $options->signType = 'RSA2';
  13. $options->alipayPublicKey = '<-- 请填写您的支付宝公钥,例如:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAumX1EaLM4ddn1Pia4SxTRb62aVYxU8I2mHMqrcpQU6F01mIO/DjY7R4xUWcLi0I2oH/BK/WhckEDCFsGrT7mO+JX8K4sfaWZx1aDGs0m25wOCNjp+DCVBXotXSCurqgGI/9UrY+QydYDnsl4jB65M3p8VilF93MfS01omEDjUW+1MM4o3FP0khmcKsoHnYGs21btEeh0LK1gnnTDlou6Jwv3Ew36CbCNY2cYkuyPAW0j47XqzhWJ7awAx60fwgNBq6ZOEPJnODqH20TAdTLNxPSl4qGxamjBO+RuInBy+Bc2hFHq3pNv6hTAfktggRKkKzDlDEUwgSLE7d2eL7P6rwIDAQAB -->';
  14. $options->merchantPrivateKey = $this->getPrivateKey($options->appId);
  15. return $options;
  16. }
  17. public function getTestCertAccount()
  18. {
  19. $options = new Config();
  20. $options->protocol = 'https';
  21. $options->gatewayHost = 'openapi.alipay.com';
  22. $options->appId = '<-- 请填写您的AppId,例如:2019051064521003 -->';
  23. $options->signType = 'RSA2';
  24. $options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:dirname(__FILE__) . "/resources/fixture/alipayCertPublicKey_RSA2.crt" -->';
  25. $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:dirname(__FILE__) . "/resources/fixture/alipayRootCert.crt" -->';
  26. $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:dirname(__FILE__) . "/resources/fixture/appCertPublicKey_2019051064521003.crt" -->';
  27. $options->merchantPrivateKey = $this->getPrivateKey($options->appId);
  28. return $options;
  29. }
  30. private function getPrivateKey($appId)
  31. {
  32. $filePath = dirname(__FILE__) . '/resources/fixture/privateKey.json';
  33. $stream = fopen($filePath, 'r');
  34. fwrite($stream, '$filePath');
  35. $result = json_decode(stream_get_contents($stream));
  36. return $result->$appId;
  37. }
  38. }