Zypay.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Http\Controllers\Gateway;
  3. use App\Models\Payment;
  4. use Auth;
  5. use Illuminate\Http\JsonResponse;
  6. use Illuminate\Http\Request;
  7. use Response;
  8. use Http;
  9. use Log;
  10. class Zypay extends AbstractPayment
  11. {
  12. public function purchase(Request $request): JsonResponse
  13. {
  14. $payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
  15. // switch ($request->input('type')) {
  16. // case 2:
  17. // $type = 'qqpay';
  18. // break;
  19. // case 3:
  20. // $type = 'wxpay';
  21. // break;
  22. // case 1:
  23. // default:
  24. // $type = 'alipay';
  25. // break;
  26. // }
  27. // Log::info("[河马支付]请求金额". var_export($payment->amount, true));
  28. // Log::info("[河马支付]格式化金额". var_export(number_format($payment->amount,2,'.',''), true));
  29. $key = "ef32cf2c4b1a352b7340a2465a563cdc9daaf3af";
  30. $data = [
  31. 'version' => '1.0',
  32. 'customerid' => "11635",
  33. 'sdorderno' => $payment->trade_no,
  34. 'total_fee' => number_format($payment->amount,2,'.',''),
  35. 'notifyurl' => route('payment.notify', ['method' => 'zpay']),
  36. 'returnurl' => route('invoice'),
  37. 'paytype' => 'alipay',
  38. 'bankcode' => '',
  39. 'remark' => '测试',
  40. 'get_code' => 1,
  41. ];
  42. #ksort($data);
  43. // 构建签名字符串
  44. $signStr = 'version=' . $data["version"] .
  45. '&customerid=' . $data["customerid"] .
  46. '&total_fee=' . $data["total_fee"] .
  47. '&sdorderno=' . $data["sdorderno"] .
  48. '&notifyurl=' . $data["notifyurl"] .
  49. '&returnurl=' . $data["returnurl"] .
  50. '&' . $key;
  51. Log::info("[河马支付]原始构建签名字符串". var_export($data, true));
  52. Log::info("[河马支付]构建签名字符串". var_export($signStr, true));
  53. // 计算签名
  54. $data['sign'] = md5($signStr);
  55. Log::info("[河马支付]构建参数". var_export($data, true));
  56. $response = Http::get('http://pay.mssdk.com/apisubmit', $data);
  57. if ($response->ok()) {
  58. $result = $response->json();
  59. Log::error('【河马支付】 返回错误信息:'.var_export($result, true));
  60. if ($result['status'] === 1) {
  61. /**
  62. (
  63. 'status' => 1,
  64. 'code_url' => 'http://pay.mssdk.com/pay/ali_scan/pay.php?orderid=m2023092814174271459&price=30.00&sign=cc58bd605c76c1380c1aaba95d3f4b61',
  65. 'code_img_url' => 'http://pay.mssdk.com/pay/qrcode/get.php?data=http%3A%2F%2Fpay.mssdk.com%2Fpay%2Fali_scan%2Fpay.php%3Forderid%3Dm2023092814174271459%26price%3D30.00%26sign%3Dcc58bd605c76c1380c1aaba95d3f4b61',
  66. 'page_url' => 'http://pay.mssdk.com/pay/ali_scan/send.php?orderid=m2023092814174271459&price=30.00&sign=cc58bd605c76c1380c1aaba95d3f4b61',
  67. )
  68. [2023-09-28
  69. */
  70. return Response::json(['status' => 'success', 'url' => $result['page_url'], 'message' => '创建订单成功!']);
  71. }
  72. }
  73. return Response::json(['status' => 'fail', 'message' => '创建在线订单失败,请工单通知管理员!']);
  74. }
  75. public function notify(Request $request): void
  76. {
  77. if (!$this->verifySign($request->post())){
  78. exit('signerr');
  79. }
  80. if ($request->has(['sdorderno']) && $this->paymentReceived($request->input(['sdorderno'])) ) {
  81. $this->addPamentCallback($request->input('sdorderno'),$request->input('sdpayno'),"");
  82. Log::info('【河马支付】paymentReceived:'.var_export($request->all(), true));
  83. exit('success');
  84. } else {
  85. exit('fail');
  86. }
  87. }
  88. function verifySign($params)
  89. {
  90. $key = "ef32cf2c4b1a352b7340a2465a563cdc9daaf3af";
  91. $sign = $params['sign'];
  92. // 构建签名字符串
  93. $signStr = 'customerid=' . $params["customerid"] .
  94. '&status=' . $params["status"] .
  95. '&sdpayno=' . $params["sdpayno"] .
  96. '&sdorderno=' . $params["sdorderno"] .
  97. '&total_fee=' . $params["total_fee"] .
  98. '&paytype=' . $params["paytype"] .
  99. '&' . $key;
  100. $newsign = md5($signStr);
  101. Log::info("原始签名". var_export($sign, true));
  102. Log::info("新原始签名". var_export($newsign, true));
  103. //$str = http_build_query($data) . '&' . $key;
  104. if ($sign !== $newsign) {
  105. return false;
  106. }
  107. return true;
  108. }
  109. }