GoopagoController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. //use App\Http\logic\api\UuPayCashierLogic;
  4. use App\dao\Pay\AccountPayInfo;
  5. use App\Http\logic\api\GoopagoCashierLogic;
  6. use App\Http\logic\api\GoopagoLogic;
  7. use App\Inter\PayMentInterFace;
  8. use App\Notification\DingDingRobot;
  9. use App\Notification\TelegramBot;
  10. use App\Services\PayConfig;
  11. use App\Util;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\Log;
  14. use Illuminate\Support\Facades\Redis;
  15. class GoopagoController implements PayMentInterFace
  16. {
  17. private $retryTimes=0;
  18. public function pay_order($userId, $payAmt, $userName, $userEmail, $userPhone, $GiftsID, $buyIP, $AdId, $eventType, $pay_method = '')
  19. {
  20. $logic = new GoopagoLogic();
  21. try {
  22. $res = $logic->pay_order($userId, $payAmt, $userPhone, $userEmail, $userName, $GiftsID, $buyIP, $AdId, $eventType);
  23. } catch (\Exception $exception) {
  24. Util::WriteLog('goopago_error', $exception);
  25. TelegramBot::getDefault()->sendProgramNotify("Goopago Except ",$exception->getMessage(),$exception );
  26. return apiReturnFail($logic->getError());
  27. }
  28. //$res = $logic->pay_order($userId, $payAmt, $userPhone, $userEmail, $userName, $GiftsID,$buyIP,$AdId,$eventType);
  29. if ($res === false) {
  30. // TelegramBot::getDefault()->sendProgramNotify("Goopago false ", $logic->getError(), $res);
  31. return apiReturnFail($logic->getError());
  32. }
  33. // return $data['resCode'] == 'SUCCESS'?$data['url']:false;
  34. if (!empty($res) && $res['resCode'] == 'SUCCESS') {
  35. $data = [
  36. 'content' => urldecode($res['reference']),
  37. 'money' => $payAmt,
  38. 'prdOrdNo' => $res['merchantOrderId'],
  39. ];
  40. return apiReturnSuc($data);
  41. // header("Location: {$res['url']}");
  42. } else {
  43. if($this->retryTimes>1) {
  44. TelegramBot::getDefault()->sendProgramNotify("Goopago RetrunFail ", $logic->getError(), $res);
  45. return apiReturnFail($logic->getError());
  46. }else{
  47. $this->retryTimes++;
  48. return $this->pay_order($userId, $payAmt, $userName, $userEmail, $userPhone, $GiftsID, $buyIP, $AdId, $eventType);
  49. }
  50. }
  51. }
  52. // 支付异步回调
  53. public function notify(Request $request)
  54. {
  55. $post = $request->post();
  56. if (!is_array($post)) {
  57. $post = \GuzzleHttp\json_decode($post, true);
  58. }
  59. Util::WriteLog('goopago', 'Goopago回调订单');
  60. Util::WriteLog('goopago', $post);
  61. $order_sn = $post['orderId'];
  62. $redis = Redis::connection();
  63. // if ($redis->exists($order_sn)) {
  64. // Util::WriteLog('goopago', 'Goopago 重复回调订单:' . $order_sn);
  65. // return 'SUCCESS';
  66. // }
  67. $logic = new GoopagoLogic();
  68. try {
  69. $ret= $logic->notify($post);
  70. if($ret=='SUCCESS')$redis->set($order_sn, $order_sn, 3600 * 24);
  71. return $ret;
  72. }catch (\Exception $exception){
  73. TelegramBot::getDefault()->sendProgramNotify("Goopago 订单回调执行 异常 ", json_encode($post),$exception);
  74. Util::WriteLog("goopago_error",$post);
  75. return '{"success":false,"message":"商户自定义出错信息"}';
  76. }
  77. }
  78. public function sync_notify(Request $request)
  79. {
  80. Log::info('同步回调');
  81. echo '同步回调';
  82. }
  83. // 提现异步回调
  84. public function cash_notify(Request $request)
  85. {
  86. $post = $request->post();
  87. if (!is_array($post)) {
  88. $post = \GuzzleHttp\json_decode($post, true);
  89. }
  90. // Log::info(var_export('Goopago cash 异步回调:', true), $post);
  91. Util::WriteLog('goopago', 'Goopago cash 异步回调:');
  92. Util::WriteLog('goopago', $post);
  93. // $order_sn = $post['mchOrderNo'] . 'new';
  94. // $redis = Redis::connection();
  95. // if ($redis->exists($order_sn)) {
  96. // Log::info('Goopago 重复回调订单:' . $order_sn);
  97. // return '{"success":false,"message":"商户自定义出错信息"}';
  98. // }
  99. // $redis->set($order_sn, $order_sn, 3600 * 24);
  100. $logic = new GoopagoCashierLogic();
  101. try {
  102. return $logic->notify($post);
  103. }catch (\Exception $exception){
  104. TelegramBot::getDefault()->sendProgramNotify("Goopago 提现异步回调执行 异常 ", json_encode($post),$exception);
  105. Util::WriteLog("goopago_error",$post);
  106. return '{"success":false,"message":"商户自定义出错信息"}';
  107. }
  108. }
  109. }