aliLife.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. date_default_timezone_set('Asia/Shanghai');
  3. header('Content-type:text/html;charset=utf-8');
  4. require './class/common.php';
  5. require './class/AliLife.php';
  6. class Test
  7. {
  8. // 统一下单接口
  9. public function orderPay()
  10. {
  11. $client = new AliLife;
  12. // 参数
  13. $client->body = array(
  14. 'orderCode' => 'Y20181204170925675836',
  15. 'totalAmount' => '000000000101', //代表1.01元
  16. 'subject' => '1.01商品',
  17. 'body' => '1.01商品',
  18. 'payMode' => 'sand_alipay',
  19. 'payExtra' => array(
  20. 'subAppid' => 'wx86466ERH8461',
  21. 'userId' => 'oEl4G1XFFERHIHSXS63P-_09y',
  22. ),
  23. 'clientIp' => '127.0.0.1',
  24. 'notifyUrl' => 'http://192.168.22.171/sandpay-qr-phpdemo.bak',
  25. 'frontUrl' => 'http://192.168.22.171/sandpay-qr-phpdemo.bak',
  26. );
  27. // 返回结果
  28. $ret = $client->request('orderPay');
  29. echo '<pre>';
  30. print_r($ret);
  31. echo '</pre>';
  32. }
  33. // 订单查询
  34. public function orderQuery()
  35. {
  36. $client = new AliLife;
  37. // 参数, 每次需要重新赋值
  38. $client->body = array(
  39. 'orderCode' => '2017091551423473', //订单号
  40. 'extend' => ''
  41. );
  42. // 返回结果
  43. $ret = $client->request('orderQuery');
  44. echo '<pre>';
  45. print_r($ret);
  46. echo '</pre>';
  47. }
  48. // 退款申请
  49. public function orderRefund()
  50. {
  51. $client = new AliLife;
  52. // 参数
  53. $client->body = array(
  54. 'orderCode' => 'Y20181204170925675836', //新的订单号
  55. 'oriOrderCode' => '2017091551421977', //原订单号
  56. 'refundAmount' => '000000000012', //退款金额
  57. 'refundMarketAmount' => '000000000012', //退营销金额
  58. 'notifyUrl' => 'http://192.168.22.171/sandpay-qr-phpdemo.bak/test/dist/notifyUrl.php',
  59. 'refundReason' => 'test',
  60. 'extend' => ''
  61. );
  62. // 返回结果
  63. $ret = $client->request('orderRefund');
  64. echo '<pre>';
  65. print_r($ret);
  66. echo '</pre>';
  67. }
  68. // 异步通知通用接口
  69. public function notify()
  70. {
  71. // 实例化客户端
  72. $client = new AliLife;
  73. $sign = $_POST['sign']; //签名
  74. $data = stripslashes($_POST['data']); //支付数据
  75. // 验签
  76. try {
  77. $verifyFlag = $client->verify($data, $sign);
  78. if (!$verifyFlag) throw new Exception('签名失败');
  79. } catch (\Exception $e) {
  80. exit('签名失败');
  81. }
  82. // 回调数据
  83. echo '<pre>';
  84. print_r($data);
  85. echo '</pre>';
  86. }
  87. // 对账单申请接口
  88. public function clearfileDownload()
  89. {
  90. // 实例化客户端
  91. $client = new AliLife;
  92. // 参数
  93. $client->body = array(
  94. 'clearDate' => '20200611', // 结算日期
  95. 'fileType' => '1', // 文件返回类型
  96. 'extend' => ''
  97. );
  98. // 返回值
  99. $ret = $client->request('clearfileDownload');
  100. echo '<pre>';
  101. print_r($ret);
  102. echo '</pre>';
  103. }
  104. }
  105. $test = new Test();
  106. // $test->orderPay();
  107. // $test->orderQuery();
  108. // $test->orderRefund();
  109. // $test->clearfileDownload();