AopCertClientTest.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. require_once '../AopCertClient.php';
  3. require_once '../AopCertification.php';
  4. require_once '../request/AlipayTradeQueryRequest.php';
  5. require_once '../request/AlipayTradeWapPayRequest.php';
  6. require_once '../request/AlipayTradeAppPayRequest.php';
  7. /**
  8. * 证书类型AopCertClient功能方法使用测试,特别注意支付宝根证书预计2037年会过期,请在适当时间下载更新支付更证书
  9. * 1、execute 证书模式调用示例
  10. * 2、sdkExecute 证书模式调用示例
  11. * 3、pageExecute 证书模式调用示例
  12. */
  13. //1、execute 使用
  14. $aop = new AopCertClient ();
  15. $appCertPath = "应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
  16. $alipayCertPath = "支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
  17. $rootCertPath = "支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
  18. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  19. $aop->appId = '你的appid';
  20. $aop->rsaPrivateKey = '你的应用私钥';
  21. $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
  22. $aop->apiVersion = '1.0';
  23. $aop->signType = 'RSA2';
  24. $aop->postCharset = 'utf-8';
  25. $aop->format = 'json';
  26. $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  27. $aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
  28. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
  29. $request = new AlipayTradeQueryRequest ();
  30. $request->setBizContent("{" .
  31. "\"out_trade_no\":\"20150320010101001\"," .
  32. "\"trade_no\":\"2014112611001004680 073956707\"," .
  33. "\"org_pid\":\"2088101117952222\"," .
  34. " \"query_options\":[" .
  35. " \"TRADE_SETTE_INFO\"" .
  36. " ]" .
  37. " }");
  38. $result = $aop->execute($request);
  39. echo $result;
  40. //2、sdkExecute 测试
  41. $aop = new AopCertClient ();
  42. $appCertPath = "应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
  43. $alipayCertPath = "支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
  44. $rootCertPath = "支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
  45. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  46. $aop->appId = '你的appid';
  47. $aop->rsaPrivateKey = '你的应用私钥';
  48. $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
  49. $aop->apiVersion = '1.0';
  50. $aop->signType = 'RSA2';
  51. $aop->postCharset = 'utf-8';
  52. $aop->format = 'json';
  53. $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  54. $aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
  55. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
  56. $request = new AlipayTradeAppPayRequest ();
  57. $request->setBizContent("{" .
  58. "\"timeout_express\":\"90m\"," .
  59. "\"total_amount\":\"9.00\"," .
  60. "\"product_code\":\"QUICK_MSECURITY_PAY\"," .
  61. "\"body\":\"Iphone6 16G\"," .
  62. "\"subject\":\"大乐透\"," .
  63. "\"out_trade_no\":\"70501111111S001111119\"," .
  64. "\"time_expire\":\"2016-12-31 10:05\"," .
  65. "\"goods_type\":\"0\"," .
  66. "\"promo_params\":\"{\\\"storeIdType\\\":\\\"1\\\"}\"," .
  67. "\"passback_params\":\"merchantBizType%3d3C%26merchantBizNo%3d2016010101111\"," .
  68. "\"extend_params\":{" .
  69. "\"sys_service_provider_id\":\"2088511833207846\"," .
  70. "\"hb_fq_num\":\"3\"," .
  71. "\"hb_fq_seller_percent\":\"100\"," .
  72. "\"industry_reflux_info\":\"{\\\\\\\"scene_code\\\\\\\":\\\\\\\"metro_tradeorder\\\\\\\",\\\\\\\"channel\\\\\\\":\\\\\\\"xxxx\\\\\\\",\\\\\\\"scene_data\\\\\\\":{\\\\\\\"asset_name\\\\\\\":\\\\\\\"ALIPAY\\\\\\\"}}\"," .
  73. "\"card_type\":\"S0JP0000\"" .
  74. " }," .
  75. "\"merchant_order_no\":\"20161008001\"," .
  76. "\"enable_pay_channels\":\"pcredit,moneyFund,debitCardExpress\"," .
  77. "\"store_id\":\"NJ_001\"," .
  78. "\"specified_channel\":\"pcredit\"," .
  79. "\"disable_pay_channels\":\"pcredit,moneyFund,debitCardExpress\"," .
  80. " \"goods_detail\":[{" .
  81. " \"goods_id\":\"apple-01\"," .
  82. "\"alipay_goods_id\":\"20010001\"," .
  83. "\"goods_name\":\"ipad\"," .
  84. "\"quantity\":1," .
  85. "\"price\":2000," .
  86. "\"goods_category\":\"34543238\"," .
  87. "\"categories_tree\":\"124868003|126232002|126252004\"," .
  88. "\"body\":\"特价手机\"," .
  89. "\"show_url\":\"http://www.alipay.com/xxx.jpg\"" .
  90. " }]," .
  91. "\"ext_user_info\":{" .
  92. "\"name\":\"李明\"," .
  93. "\"mobile\":\"16587658765\"," .
  94. "\"cert_type\":\"IDENTITY_CARD\"," .
  95. "\"cert_no\":\"362334768769238881\"," .
  96. "\"min_age\":\"18\"," .
  97. "\"fix_buyer\":\"F\"," .
  98. "\"need_check_info\":\"F\"" .
  99. " }," .
  100. "\"business_params\":\"{\\\"data\\\":\\\"123\\\"}\"," .
  101. "\"agreement_sign_params\":{" .
  102. "\"personal_product_code\":\"CYCLE_PAY_AUTH_P\"," .
  103. "\"sign_scene\":\"INDUSTRY|DIGITAL_MEDIA\"," .
  104. "\"external_agreement_no\":\"test20190701\"," .
  105. "\"external_logon_id\":\"13852852877\"," .
  106. "\"access_params\":{" .
  107. "\"channel\":\"ALIPAYAPP\"" .
  108. " }," .
  109. "\"sub_merchant\":{" .
  110. "\"sub_merchant_id\":\"2088123412341234\"," .
  111. "\"sub_merchant_name\":\"滴滴出行\"," .
  112. "\"sub_merchant_service_name\":\"滴滴出行免密支付\"," .
  113. "\"sub_merchant_service_description\":\"免密付车费,单次最高500\"" .
  114. " }," .
  115. "\"period_rule_params\":{" .
  116. "\"period_type\":\"DAY\"," .
  117. "\"period\":3," .
  118. "\"execute_time\":\"2019-01-23\"," .
  119. "\"single_amount\":10.99," .
  120. "\"total_amount\":600," .
  121. "\"total_payments\":12" .
  122. " }" .
  123. " }" .
  124. " }");
  125. $result = $aop->sdkExecute($request);
  126. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  127. echo $responseNode;
  128. //3、pageExecute 测试
  129. $aop = new AopCertClient ();
  130. $appCertPath = "应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
  131. $alipayCertPath = "支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
  132. $rootCertPath = "支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
  133. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  134. $aop->appId = '你的appid';
  135. $aop->rsaPrivateKey = '你的应用私钥';
  136. $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
  137. $aop->apiVersion = '1.0';
  138. $aop->signType = 'RSA2';
  139. $aop->postCharset = 'utf-8';
  140. $aop->format = 'json';
  141. $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  142. $aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
  143. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
  144. $request = new AlipayTradeWapPayRequest ();
  145. $request->setBizContent("{" .
  146. " \"body\":\"对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。\"," .
  147. " \"subject\":\"测试\"," .
  148. " \"out_trade_no\":\"70501111111S001111119\"," .
  149. " \"timeout_express\":\"90m\"," .
  150. " \"total_amount\":9.00," .
  151. " \"product_code\":\"QUICK_WAP_WAY\"" .
  152. " }");
  153. $result = $aop->pageExecute($request);
  154. echo $result;