AlipayController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller;
  3. use app\models\store\StoreOrder;
  4. use app\models\user\UserBill;
  5. use app\phpPay\hpay\pay\AliLife;
  6. use app\Request;
  7. use crmeb\repositories\PaymentRepositories;
  8. use crmeb\services\AlipayService;
  9. use crmeb\services\SystemConfigService;
  10. use crmeb\services\UtilService;
  11. use crmeb\utils\Hook;
  12. class AlipayController
  13. {
  14. public function Notify()
  15. {
  16. $alipay = SystemConfigService::more(['alipay_app_id', 'alipay_pub_key', 'alipay_private_key', 'alipay_key']);
  17. $Pay = new AlipayService();
  18. $Pay->setAlipayPublicKey($alipay['alipay_key']);
  19. $result = $Pay->rsaCheck($_POST, $_POST['sign_type']);
  20. if ($result === true && $_POST['trade_status'] == 'TRADE_SUCCESS') {
  21. $out_trade_no = input('out_trade_no', '');
  22. if (($count = strpos(input('out_trade_no'), '_')) !== false) {
  23. $out_trade_no = substr(input('out_trade_no'), $count + 1);
  24. }
  25. parse_str(input('passback_params'), $attach);
  26. (new Hook(PaymentRepositories::class, 'wechat'))->listen($attach['attach'], $out_trade_no);
  27. echo 'success';
  28. exit();
  29. } else {
  30. echo 'error';
  31. exit();
  32. }
  33. }
  34. public function sdNotify(Request $request)
  35. {
  36. $post = $request->post();
  37. $data = json_decode($post['data']);
  38. $sing = json_decode($post['sign']);
  39. // $client = new AliLife();
  40. // //验签
  41. // try {
  42. // $verifyFlag = $client->verify($data, $sing);
  43. // if (!$verifyFlag) throw new Exception('签名失败');
  44. // } catch (\Exception $e) {
  45. // exit('签名失败');
  46. // }
  47. if ($data->body->orderStatus == 1) {
  48. $order = strstr($data->body->orderCode, '-', -1);
  49. if (StoreOrder::be(['order_id' => $order, 'paid' => 1])) return true;
  50. $res = StoreOrder::paySuccess($order, 'sdpay');
  51. if ($res){
  52. echo 'respCode=000000';
  53. exit();
  54. }else{
  55. echo 'error';
  56. exit();
  57. }
  58. }
  59. echo 'error';
  60. exit();
  61. }
  62. }