alipay_app.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class alipay_app {
  3. private $config;
  4. public function __construct($payment_info = array(), $order_info = array()) {
  5. if (!empty($payment_info)) {
  6. $this->config = array(
  7. //应用ID,您的APPID。
  8. 'app_id' => $payment_info['payment_config']['alipay_appid'],
  9. //商户私钥
  10. 'merchant_private_key' => $payment_info['payment_config']['private_key'],
  11. //异步通知地址
  12. 'notify_url' => str_replace('/index.php', '', HOME_SITE_URL) . '/payment/alipay_app_notify.html',
  13. //编码格式
  14. 'charset' => "UTF-8",
  15. //签名方式
  16. 'sign_type' => "RSA2",
  17. //支付宝网关
  18. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  19. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  20. 'app_cert_path' => $payment_info['payment_config']['app_cert_path'],
  21. 'alipay_cert_path' => $payment_info['payment_config']['alipay_cert_path'],
  22. 'root_cert_path' => $payment_info['payment_config']['root_cert_path'],
  23. );
  24. }
  25. }
  26. function get_payform($order_info) {
  27. require_once PLUGINS_PATH . '/payments/alipay/aop/AopCertClient.php';
  28. require_once PLUGINS_PATH . '/payments/alipay/aop/request/AlipayTradeAppPayRequest.php';
  29. $aop = new AopCertClient ();
  30. $appCertPath = $this->config['app_cert_path'];
  31. $alipayCertPath = $this->config['alipay_cert_path'];
  32. $rootCertPath = $this->config['root_cert_path'];
  33. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  34. $aop->appId = $this->config['app_id'];
  35. $aop->rsaPrivateKey = $this->config['merchant_private_key'];
  36. $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
  37. $aop->apiVersion = '1.0';
  38. $aop->signType = 'RSA2';
  39. $aop->postCharset = 'utf-8';
  40. $aop->format = 'json';
  41. $aop->isCheckAlipayPublicCert = true; //是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
  42. $aop->appCertSN = $aop->getCertSN($appCertPath); //调用getCertSN获取证书序列号
  43. $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath); //调用getRootCertSN获取支付宝根证书序列号
  44. $request = new AlipayTradeAppPayRequest ();
  45. $request->setNotifyUrl($this->config['notify_url']);
  46. $request->setBizContent("{" .
  47. "\"total_amount\":" . round($order_info['api_pay_amount'],2) . "," .
  48. "\"subject\":\"" . $order_info['subject'] . "\"," .
  49. "\"body\":\"" . $order_info['order_type'] . "\"," .
  50. "\"out_trade_no\":\"" . $order_info['order_type'] . '-' . $order_info['pay_sn'] . "\"," .
  51. "\"timeout_express\":\"1m\"," .
  52. "\"product_code\":\"QUICK_MSECURITY_PAY\"" .
  53. " }");
  54. $result = $aop->sdkExecute($request);
  55. ds_json_encode(10000,'',array('content'=>$result));
  56. }
  57. }
  58. ?>