wapCharge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * The file is part of the payment lib.
  4. *
  5. * (c) Leo <dayugog@gmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. require_once __DIR__ . '/../../vendor/autoload.php';
  11. date_default_timezone_set('Asia/Shanghai');
  12. $aliConfig = require_once __DIR__ . '/../aliconfig.php';
  13. // 交易信息
  14. $tradeNo = time() . rand(1000, 9999);
  15. $payData = [
  16. 'body' => 'ali wap pay',
  17. 'subject' => '测试支付宝手机网站支付',
  18. 'trade_no' => $tradeNo,
  19. 'time_expire' => time() + 600, // 表示必须 600s 内付款
  20. 'amount' => '0.01', // 单位为元 ,最小为0.01
  21. 'return_param' => 'tata', // 一定不要传入汉字,只能是 字母 数字组合
  22. // 'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',// 客户地址
  23. 'goods_type' => '1', // 0—虚拟类商品,1—实物类商品
  24. 'store_id' => '',
  25. 'quit_url' => 'https://dayutalk.cn', // 收银台的返回按钮(用户打断支付操作时返回的地址,4.0.3版本新增)
  26. ];
  27. // 使用
  28. try {
  29. $client = new \Payment\Client(\Payment\Client::ALIPAY, $aliConfig);
  30. $res = $client->pay(\Payment\Client::ALI_CHANNEL_WAP, $payData);
  31. } catch (InvalidArgumentException $e) {
  32. echo $e->getMessage();
  33. exit;
  34. } catch (\Payment\Exceptions\GatewayException $e) {
  35. echo $e->getMessage();
  36. var_dump($e->getRaw());
  37. exit;
  38. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  39. echo $e->getMessage();
  40. exit;
  41. } catch (Exception $e) {
  42. echo $e->getMessage();
  43. exit;
  44. }
  45. header('Location:' . $res);