AlipayConfigTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. require_once '../aop/AlipayConfig.php';
  3. require_once '../aop/AopCertClient.php';
  4. require_once '../aop/AopClient.php';
  5. require_once '../aop/request/AlipayTradePrecreateRequest.php';
  6. $app_cert_path="your_cert_path";
  7. $alipay_cert_path="your_alipay_cert_path";
  8. $alipay_root_cert_path="your_root_cert_path";
  9. $url = "https://openapi.alipaydev.com/gateway.do";
  10. $app_id="your_app_ID";
  11. $privateKey="your_privateKey";
  12. // 证书模式的测试
  13. $alipayConfig = new AlipayConfig();
  14. $alipayConfig->setAppId($app_id);
  15. $alipayConfig->setCharset("utf-8");
  16. $alipayConfig->setFormat("json");
  17. $alipayConfig->setSignType("RSA2");
  18. $alipayConfig->setServerUrl($url);
  19. $alipayConfig->setPrivateKey($privateKey);
  20. // content 和 path 只需要设置一个即可
  21. $alipayConfig->setAppCertPath($app_cert_path);
  22. //$alipayConfig->setAppCertContent()
  23. $alipayConfig->setAlipayPublicCertPath($alipay_cert_path);
  24. //$alipayConfig->setAlipayPublicCertContent()
  25. $alipayConfig->setRootCertPath($alipay_root_cert_path);
  26. //$alipayConfig->setRootCertContent()
  27. $aop = new AopCertClient($alipayConfig);
  28. $aop->isCheckAlipayPublicCert = true;
  29. $parameter = "{" .
  30. "\"out_trade_no\":\"20140320010107002\"," .
  31. "\"total_amount\":\"12225\"," .
  32. "\"subject\":\"Iphone6 65G\"," .
  33. "\"store_id\":\"CD_001\"," .
  34. "\"timeout_express\":\"100m\"}";
  35. $request = new AlipayTradePrecreateRequest ();
  36. $request->setBizContent($parameter);
  37. $response = $aop->execute($request);
  38. $responseApiName = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  39. // 拿到结果
  40. $responseResult = $response->$responseApiName;
  41. echo var_dump($responseResult),PHP_EOL;
  42. //普通方式的测试
  43. $$url = "https://openapi.alipaydev.com/gateway.do";
  44. $app_id="your_appId";
  45. $privateKey="your_privateKey";
  46. $publicKey ="your_publicKey";
  47. $config = new AlipayConfig();
  48. $config->setAppId($app_id);
  49. $config->setCharset("utf-8");
  50. $config->setFormat("json");
  51. $config->setSignType("RSA2");
  52. $config->setServerUrl($url);
  53. $config->setPrivateKey($privateKey);
  54. $config->setAlipayPublicKey($publicKey);
  55. $aop = new AopClient($config);
  56. $parameter = "{" .
  57. "\"out_trade_no\":\"20140320010107002\"," .
  58. "\"total_amount\":\"12225\"," .
  59. "\"subject\":\"Iphone6 65G\"," .
  60. "\"store_id\":\"CD_001\"," .
  61. "\"timeout_express\":\"100m\"}";
  62. $request = new AlipayTradePrecreateRequest ();
  63. $request->setBizContent($parameter);
  64. $response = $aop->execute($request);
  65. $responseApiName = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  66. // 拿到结果
  67. $responseResult = $response->$responseApiName;
  68. echo var_dump($responseResult),PHP_EOL;