AlipayController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\api\controller;
  3. use app\Request;
  4. use crmeb\repositories\PaymentRepositories;
  5. use crmeb\services\AlipayService;
  6. use crmeb\services\SystemConfigService;
  7. use crmeb\utils\Hook;
  8. class AlipayController
  9. {
  10. public function Notify()
  11. {
  12. $alipay = SystemConfigService::more(['alipay_app_id', 'alipay_pub_key', 'alipay_private_key', 'alipay_key']);
  13. $Pay = new AlipayService();
  14. $Pay->setAlipayPublicKey($alipay['alipay_key']);
  15. $result = $Pay->rsaCheck($_POST, $_POST['sign_type']);
  16. if ($result === true && $_POST['trade_status'] == 'TRADE_SUCCESS') {
  17. $out_trade_no = input('out_trade_no', '');
  18. if (($count = strpos(input('out_trade_no'), '_')) !== false) {
  19. $out_trade_no = substr(input('out_trade_no'), $count + 1);
  20. }
  21. parse_str(input('passback_params'), $attach);
  22. (new Hook(PaymentRepositories::class, 'ali'))->listen($attach['attach'], $out_trade_no);
  23. echo 'success';
  24. exit();
  25. } else {
  26. echo 'error';
  27. exit();
  28. }
  29. }
  30. }