You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
3.0 KiB

  1. <?php
  2. namespace addons\epay\controller;
  3. use addons\epay\library\Service;
  4. use addons\unishop\model\Config;
  5. use fast\Random;
  6. use think\addons\Controller;
  7. use think\Hook;
  8. use Yansongda\Pay\Log;
  9. use Yansongda\Pay\Pay;
  10. use Exception;
  11. /**
  12. * 微信支付宝插件首页
  13. *
  14. * 此控制器仅用于开发展示说明和体验,建议自行添加一个新的控制器进行处理返回和回调事件,同时删除此控制器文件
  15. *
  16. * Class Index
  17. * @package addons\epay\controller
  18. */
  19. class Index extends Controller
  20. {
  21. protected $layout = 'default';
  22. protected $config = [];
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. }
  27. public function index()
  28. {
  29. $this->view->assign("title", "FastAdmin微信支付宝整合插件");
  30. return $this->view->fetch();
  31. }
  32. /**
  33. * 体验,仅供开发测试
  34. */
  35. public function experience()
  36. {
  37. $amount = $this->request->request('amount');
  38. $type = $this->request->request('type');
  39. $method = $this->request->request('method');
  40. if (!$amount || $amount < 0) {
  41. $this->error("支付金额必须大于0");
  42. }
  43. if (!$type || !in_array($type, ['alipay', 'wechat'])) {
  44. $this->error("支付类型不能为空");
  45. }
  46. //订单号
  47. $out_trade_no = date("YmdHis") . mt_rand(100000, 999999);
  48. //订单标题
  49. $title = 'FastAdmin测试订单';
  50. //回调链接
  51. $notifyurl = $this->request->root(true) . '/addons/epay/index/notifyx/paytype/' . $type;
  52. $returnurl = $this->request->root(true) . '/addons/epay/index/returnx/paytype/' . $type . '/out_trade_no/' . $out_trade_no;
  53. return Service::submitOrder($amount, $out_trade_no, $type, $title, $notifyurl, $returnurl, $method);
  54. }
  55. /**
  56. * 支付成功,仅供开发测试
  57. */
  58. public function notifyx()
  59. {
  60. $paytype = $this->request->param('paytype');
  61. $pay = \addons\epay\library\Service::checkNotify($paytype);
  62. if (!$pay) {
  63. echo '签名错误';
  64. return;
  65. }
  66. $data = $pay->verify();
  67. try {
  68. $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
  69. $out_trade_no = $data['out_trade_no'];
  70. //你可以在此编写订单逻辑
  71. } catch (Exception $e) {
  72. }
  73. echo $pay->success();
  74. }
  75. /**
  76. * 支付返回,仅供开发测试
  77. */
  78. public function returnx()
  79. {
  80. $paytype = $this->request->param('paytype');
  81. $out_trade_no = $this->request->param('out_trade_no');
  82. $pay = \addons\epay\library\Service::checkReturn($paytype);
  83. if (!$pay) {
  84. $this->error('签名错误');
  85. }
  86. //你可以在这里通过out_trade_no去验证订单状态
  87. //但是不可以在此编写订单逻辑!!!
  88. $this->success("请返回网站查看支付结果", addon_url("epay/index/index"));
  89. }
  90. }