TradeCreateDemo.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use llianpay\accp\client\LLianPayClient;
  3. use llianpay\accp\params\TradeCreateParams;
  4. use llianpay\accp\params\TradeCreateOrderInfo;
  5. use llianpay\accp\params\TradeCreatePayeeInfo;
  6. require '../vendor/autoload.php';
  7. require '../src/cfg.php';
  8. require '../src/client/LLianPayClient.php';
  9. require '../src/params/TradeCreateParams.php';
  10. require '../src/params/TradeCreateOrderInfo.php';
  11. require '../src/params/TradeCreatePayeeInfo.php';
  12. // 测试“统一支付创单”接口https://open.lianlianpay.com/docs/accp/accpstandard/accp-tradecreate.html
  13. function test_tradeCreate()
  14. {
  15. // 构建请求参数
  16. $params = new TradeCreateParams();
  17. $current = date("YmdHis");
  18. $params->timestamp = $current;
  19. $params->oid_partner = OID_PARTNER;
  20. $params->txn_type = 'GENERAL_CONSUME';
  21. $params->user_id = 'LLianPayTest-In-User-12345';
  22. $params->notify_url = 'https://test.lianlianpay.com/notify';
  23. $params->return_url = 'https://test.lianlianpay.com/return';
  24. $orderInfo = new TradeCreateOrderInfo();
  25. $orderInfo->txn_seqno = 'LLianPayTest' . $current;
  26. $orderInfo->txn_time = $current;
  27. $orderInfo->total_amount = 2.00;
  28. $params->orderInfo = $orderInfo;
  29. $u_payeeInfo = new TradeCreatePayeeInfo();
  30. $u_payeeInfo->payee_id = 'LLianPayTest-En-User-12345';
  31. $u_payeeInfo->payee_type = 'USER';
  32. $u_payeeInfo->payee_amount = '1.00';
  33. $m_payeeInfo = new TradeCreatePayeeInfo();
  34. $m_payeeInfo->payee_id = OID_PARTNER;
  35. $m_payeeInfo->payee_type = 'MERCHANT';
  36. $m_payeeInfo->payee_amount = '1.00';
  37. $params->payeeInfo = array($u_payeeInfo, $m_payeeInfo);
  38. // 测试环境地址
  39. $url = 'https://accpapi-ste.lianlianpay-inc.com/v1/txn/tradecreate';
  40. $result = LLianPayClient::sendRequest($url, json_encode($params));
  41. echo $result;
  42. }
  43. test_tradeCreate();