diff --git a/application/onlinechip/controller/traits/alinPay.php b/application/onlinechip/controller/traits/alinPay.php index aaf0f2a..2cdbeb7 100644 --- a/application/onlinechip/controller/traits/alinPay.php +++ b/application/onlinechip/controller/traits/alinPay.php @@ -84,7 +84,13 @@ trait alinPay $alinPay = new \pay\AlinPay(); $result = $alinPay->createOrder($pay_orderid, sprintf('%.2f', $money), $notify_url, 'uid:' . $user_id); - if (is_array($result) && isset($result['code']) && $result['code'] == 200) { + // 空响应处理(curl失败/DNS/超时等) + if (!is_array($result)) { + addLogToFile('代收下单:API无响应或返回非JSON,result=' . var_export($result, true), 'alin_error', 'alin'); + return json(['status' => 0, 'message' => '支付通道无响应,请稍后再试']); + } + + if (isset($result['code']) && $result['code'] == 200) { $returnUrl = $result['data']['url'] ?? ''; if (!$returnUrl) { @@ -120,12 +126,13 @@ trait alinPay return json(['status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $returnUrl]); } else { - $errMsg = $result['message'] ?? '未知错误'; + $errMsg = isset($result['message']) ? $result['message'] : '未知错误(code=' . ($result['code'] ?? 'null') . ')'; + addLogToFile('代收下单失败:' . json_encode($result, JSON_UNESCAPED_UNICODE), 'alin_error', 'alin'); return json(['status' => 0, 'message' => '支付发起失败:' . $errMsg]); } } catch (\Exception $e) { - addLogToFile('代收下单异常:' . $e->getMessage(), 'alin_error', 'alin'); - return json(['status' => 0, 'message' => '支付发起失败,请稍后再试']); + addLogToFile('代收下单异常:' . $e->getMessage() . ' | file:' . $e->getFile() . ':' . $e->getLine(), 'alin_error', 'alin'); + return json(['status' => 0, 'message' => '支付发起失败[' . $e->getMessage() . ']']); } } diff --git a/extend/pay/AlinPay.php b/extend/pay/AlinPay.php index b8a657a..f7dd384 100644 --- a/extend/pay/AlinPay.php +++ b/extend/pay/AlinPay.php @@ -148,13 +148,13 @@ class AlinPay public function createOrder($orderNo, $amount, $notifyUrl, $desc = '') { $params = [ - 'app_id' => $this->config['app_id'], - 'product_id' => $this->config['collection_product_id'], // 代收 product_id=11 - 'out_trade_no' => $orderNo, - 'notify_url' => $notifyUrl, - 'amount' => $amount, - 'time' => time(), - 'desc' => $desc, + 'app_id' => strval($this->config['app_id']), + 'product_id' => strval($this->config['collection_product_id']), // 代收 product_id=11 + 'out_trade_no' => strval($orderNo), + 'notify_url' => strval($notifyUrl), + 'amount' => strval($amount), + 'time' => intval(time()), + 'desc' => strval($desc), ]; $params['sign'] = $this->generateSign($params); @@ -199,13 +199,13 @@ class AlinPay public function createPayment($orderNo, $amount, $accountName, $accountNumber, $bankCode, $bankName, $notifyUrl, $desc = '') { $params = [ - 'app_id' => $this->config['app_id'], - 'product_id' => $this->config['payment_product_id'], // 代付 product_id=14 - 'out_trade_no' => $orderNo, - 'notify_url' => $notifyUrl, - 'amount' => $amount, - 'time' => time(), - 'desc' => $desc, + 'app_id' => strval($this->config['app_id']), + 'product_id' => strval($this->config['payment_product_id']), // 代付 product_id=14 + 'out_trade_no' => strval($orderNo), + 'notify_url' => strval($notifyUrl), + 'amount' => strval($amount), + 'time' => intval(time()), + 'desc' => strval($desc), ]; $params['sign'] = $this->generateSign($params);