PayEnum::BALANCE_PAY]; } switch ($payWay) { case PayEnum::WECHAT_PAY: // $payService = (new WeChatPayService($terminal, $order['uid'] ?? null)); // $order['pay_sn'] = $paySn; // $order['redirect_url'] = $redirectUrl; // $result = $payService->pay($from, $order); $auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty(); $order = [ 'out_trade_no' => $paySn, 'description' => '商品', 'amount' => [ 'total' => intval($order['actual'] * 100), 'currency' => 'CNY', ], "payer" => [ "openid" => $auth['openid'] ?? 0 ], 'attach' => $from ]; $config = Config::get('payment'); Pay::config($config); $result = Pay::wechat()->mini($order)->toArray(); break; default: self::$error = '订单异常'; $result = false; } // if (false === $result && !self::hasError()) { // d($payService->getError()); // self::setError($payService->getError()); // } return $result; } /** * @notes 设置订单号 支付回调时截取前面的单号 18个 * @param $orderSn * @param $terminal * @return string * @author 段誉 * @date 2023/3/1 16:31 * @remark 回调时使用了不同的回调地址,导致跨客户端支付时(例如小程序,公众号)可能出现201,商户订单号重复错误 */ public static function formatOrderSn($orderSn, $terminal) { $suffix = mb_substr(time(), -4); return $orderSn . $terminal . $suffix; } }