AopCertClientTest.php 7.9 KB

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