'http://www.wdfintl.com/payment/order/confirmOrder/mId/' . $this->pay_gateway['app_id'],//支付请求地址 'debug' => 1,//调试 'logDir' => to_linux_path(storage_path() . '/logs/'), 'mch_id' => $this->pay_gateway['app_id'], //客户交易者账号 'token' => $this->pay_gateway['app_key'], 'return_url' => action('Pay\PayController@returnNotify', ['type' => $type]), 'notify_url' => action('Pay\PayController@notify', ['type' => $type]), ]; $citpay = Usdtpay::make($config); $this->pay_model = $citpay; } //统一下单支付 public function pay($pay_data) { $array = [ // 在citpay平台中获取 "orderNo" => $pay_data['order_no'],//订单号 'customerId' => $pay_data['user_id'], "orderCurrency" => "CNY",//订单币种,固定值:USDT或CNY "orderAmount" => $pay_data['total_amount'],//金额 ]; $res = $this->pay_model->orderBuy($array); return redirect()->away($res['redirect_url']);//跳转支付 } //统一验证签名 public function verify() { $para = $this->result_data; $para['orderAmount'] = $this->order['order_money'];//订单金额必须跟支付金额一致 $r = $this->pay_model->checkSign($para); if ($r == 1) { return 1; } else { return false; } } //返回给支付商的成功 public function success() { echo 'success'; } //统一回调处理 /** * 回调第一部,如果是同步,直接回传 * @param $return * @param $pay_type * @param $request * @return bool|\Illuminate\Http\RedirectResponse */ public function notify($return, $pay_type, $request) { $this->setLogName($pay_type); $this->debugLog('回调原始数据', $request->all()); $this->pay_type = $pay_type; $this->request = $request; //取得订单,是否有此订单,如果没有直接返回空 $order_sn = $request->input('orderNo'); //取得订单 $this->getOrder($order_sn); $return = ($return) ? 1 : 0; if ($return) { //判断是否是商户id if ($this->order->merchant_id == 0) { return redirect()->route('web.user.index'); } // return $this->merchantReturnSend(); } /* $this->order = Order::where('order_sn', $order_sn)->first(); if(empty($this->order)) { return false; }*/ //取得通道id $this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id]; //dd($this->gateway); //取得支付配置 $this->payConfig($this->pay_type); $this->result_data = $request->all(); //dump($this->result_data); //进行验证签名 if (!$this->verify()) { $this->debugLog('签名验证失败'); return false; } return $this->payNotify(); } /** * 同步回调 * @return \Illuminate\Http\RedirectResponse */ public function returnPay() { //判断是否是商户id if ($this->order->merchant_id == 0) { return redirect()->route('web.user.index'); } // return $this->merchantReturnSend(); } //异步回调 /** * 获得通道信息,取得支付配置模型,验证签名, * @return bool|void */ public function payNotify() { //取得通道信息内容 //判断有没支付成功先,没有的话,直接就没有下一步了 $pay_status = $this->result_data['status']; //dd($this->result_data); if ($pay_status != 'success') { $this->debugLog('usdt订单支付失败', $this->request->all()); return false; } $data = $this->result_data; $this->pay_data = $this->result_data; //如果应答状态不是01/A6表示支付失败 $this->debugLog('-------------' . $this->order->order_sn . '--选择----' . $this->pay_type . '----' . $this->pay_method . '----开始回调处理-------------------------'); if (empty($data)) { return $this->debugLog('验证签名失败', $data); } try { $pay_cn_name = ''; //统一格式化 $this->unionHandle($data); //支付返回信息 $this->pay_data = $data; $this->debugLog('验证签名成功,数据', $data); //更新订单 $this->updateOrder(); $this->debugLog('updateOrder Ok'); } catch (\Exception $exception) { $this->debugLog('失败异常内容:' . $exception->getMessage()); if (!in_array($data['respCode'], ['00', 'A6'])) { $this->debugLog('订单支付失败', $this->request->all()); return false;//支付失败 } $this->order->notify_status = 1;//支付回调成功 $this->order->pay_status = 1;//支付状态 $this->order->pay_ok_at = date('Y-m-d H:i:s'); $this->order->save();//保存 Log::channel('pay_success')->info($pay_cn_name . '支付成功,但处理订单失败', ['data' => json_encode($data)]); } } /** * 统一格式化 */ public function unionHandle($data) { $result = [ 'order_sn' => $data['orderNo'], 'pay_order_sn' => $data['transactionId'], 'pay_money' => $data['orderAmount'], 'pay_type' => 'usdtpay', 'account' => '' ]; $this->setResult($result); Log::channel('pay_success')->info('citpay支付成功', [ 'pay_type' => $result['pay_type'], 'pay_money' => $result['pay_money'], 'account' => $result['account'], 'order_sn' => $result['order_sn'], 'pay_order_sn' => $result['pay_order_sn']]); } /** * 这个调试需要配置在config/logging.php * @param $pay_type */ public function setLogName($pay_type) { $name = ''; switch ($pay_type) { case 'usdtpay': $name = 'usdtpay_'; break; } $this->log_name = $name; } }