PayEnum::BALANCE_PAY]; } switch ($payWay) { case PayEnum::WECHAT_PAY: $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 ]; $wechat = new PayService(1); $result = $wechat->wechat->mini($order)->toArray(); break; default: self::$error = '订单异常'; $result = false; } return $result; } /** * 微信条码支付 */ public static function codepay($auth_code, $order) { $pattern = '/^(10|11|12|13|14|15)\d{16}$/'; if (!preg_match($pattern, (string)$auth_code)) { self::$error = '请使用正确的微信收付款条码'; return false; } $order = [ 'description' => '条码商品', 'out_trade_no' => $order['number'], 'payer' => [ 'auth_code' => (string)$auth_code ], 'amount' => [ 'total' => intval($order['actual'] * 100), ], 'scene_info' => [ "store_info" => [ 'id' => (string)$order['merchant'] ] ], ]; $wechat = new PayService(1); try { $result = $wechat->wechat->pos($order)->toArray(); } catch (ExceptionException $e) { if (getenv('APP_DEBUG') == true) { self::$error = $e->extra['message'] ?? $e->getMessage(); } else { self::$error = $e->getMessage(); } return false; } return $result; } /** * 支付宝条码支付 */ public static function ali_auth_code($auth_code, $order) { $pattern = '/^(25|26|27|28|29|30)[0-9A-Za-z]{14,23}$/'; if (!preg_match($pattern, (string)$auth_code)) { self::$error = '请使用正确的支付宝收付款条码'; return false; } $order = [ 'subject' => '条码商品', 'out_trade_no' => $order['number'], 'auth_code' => (string)$auth_code, 'total_amount' => $order['actual'], 'extend_params'=>['attach'=>'alipay_cashier'] ]; $wechat = new PayService(); try { $result = $wechat->alipay->pos($order)->toArray(); } catch (ExceptionException $e) { if (getenv('APP_DEBUG') == true) { self::$error = $e->extra['message'] ?? $e->getMessage(); } else { self::$error = $e->getMessage(); } return false; } return $result; } }