alipay_h5.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. class alipay_h5 {
  3. //配置
  4. private $config = array();
  5. public function __construct($payment_info = array()) {
  6. if (!empty($payment_info)) {
  7. $this->config = array(
  8. //应用ID,您的APPID。
  9. 'app_id' => $payment_info['payment_config']['alipay_appid'],
  10. //商户私钥
  11. 'merchant_private_key' => $payment_info['payment_config']['private_key'],
  12. //异步通知地址
  13. 'notify_url' => str_replace('/index.php', '', HOME_SITE_URL) . '/payment/alipay_h5_notify.html',
  14. //编码格式
  15. 'charset' => "UTF-8",
  16. //签名方式
  17. 'sign_type' => "RSA2",
  18. //支付宝网关
  19. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  20. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  21. 'app_cert_path' => $payment_info['payment_config']['app_cert_path'],
  22. 'alipay_cert_path' => $payment_info['payment_config']['alipay_cert_path'],
  23. 'root_cert_path' => $payment_info['payment_config']['root_cert_path'],
  24. );
  25. }
  26. }
  27. public function get_payform($order_info) {
  28. require_once PLUGINS_PATH . '/payments/alipay/aop/AopCertClient.php';
  29. require_once PLUGINS_PATH . '/payments/alipay/aop/request/AlipayTradeWapPayRequest.php';
  30. $aop = new AopCertClient ();
  31. $appCertPath = $this->config['app_cert_path'];
  32. $alipayCertPath = $this->config['alipay_cert_path'];
  33. $rootCertPath = $this->config['root_cert_path'];
  34. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  35. $aop->appId = $this->config['app_id'];
  36. $aop->rsaPrivateKey = $this->config['merchant_private_key'];
  37. $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
  38. $aop->apiVersion = '1.0';
  39. $aop->signType = 'RSA2';
  40. $aop->postCharset = 'utf-8';
  41. $aop->format = 'json';
  42. $aop->isCheckAlipayPublicCert = true; //是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  43. $aop->appCertSN = $aop->getCertSN($appCertPath); //调用getCertSN获取证书序列号
  44. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath); //调用getRootCertSN获取支付宝根证书序列号
  45. $request = new AlipayTradeWapPayRequest ();
  46. $request->setNotifyUrl($this->config['notify_url']);
  47. //不同订单支付成功对应的跳转界面
  48. if($order_info['order_type'] == 'real_order'){
  49. $url = config('ds_config.h5_site_url').'/pages/member/order/OrderList';
  50. }elseif ($order_info['order_type'] == 'vr_order') {
  51. $url = config('ds_config.h5_site_url').'/pages/member/vrorder/OrderList';
  52. } elseif ($order_info['order_type'] == 'pd_order') {
  53. $url = config('ds_config.h5_site_url').'/pages/member/recharge/RechargeList';
  54. } elseif ($order_info['order_type'] == 'sj_order') {
  55. $url = config('ds_config.h5_store_site_url').'/pages/seller/index/Index';
  56. }
  57. if(input('param.uniapp')){
  58. $url = preg_replace('/^(http|https):\/\//','dsmall://',$url);
  59. }
  60. $request->setReturnUrl($url);
  61. $request->setBizContent("{" .
  62. "\"total_amount\":" . round($order_info['api_pay_amount'],2) . "," .
  63. "\"subject\":\"" . $order_info['subject'] . "\"," .
  64. "\"body\":\"" . $order_info['order_type'] . "\"," .
  65. "\"out_trade_no\":\"" . $order_info['order_type'] . '-' . $order_info['pay_sn'] . "\"," .
  66. "\"timeout_express\":\"1m\"," .
  67. "\"product_code\":\"QUICK_WAP_WAY\"" .
  68. " }");
  69. $result = $aop->pageExecute($request);
  70. echo $result;exit;
  71. }
  72. /**
  73. * 获取return信息
  74. */
  75. public function verify_return() {
  76. require_once PLUGINS_PATH . '/payments/alipay/aop/AopCertClient.php';
  77. $arr = $_GET;
  78. $aop = new AopCertClient ();
  79. $appCertPath = $this->config['app_cert_path'];
  80. $alipayCertPath = $this->config['alipay_cert_path'];
  81. $rootCertPath = $this->config['root_cert_path'];
  82. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  83. $aop->appId = $this->config['app_id'];
  84. $aop->rsaPrivateKey = $this->config['merchant_private_key'];
  85. $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
  86. $aop->apiVersion = '1.0';
  87. $aop->signType = 'RSA2';
  88. $aop->postCharset = 'utf-8';
  89. $aop->format = 'json';
  90. $aop->isCheckAlipayPublicCert = true; //是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  91. $aop->appCertSN = $aop->getCertSN($appCertPath); //调用getCertSN获取证书序列号
  92. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath); //调用getRootCertSN获取支付宝根证书序列号
  93. $result = $aop->rsaCheckV1($arr, $aop->alipayrsaPublicKey, $aop->signType);
  94. if ($result) {
  95. return true;
  96. }
  97. return false;
  98. }
  99. }