'默认商户', 'mch_id' => $old_config['mch_id'], 'keys' => $old_config['keys'], 'order_prefix' => $old_config['order_prefix'] ?? 'MYH', 'weight' => 1 ]; } } // 获取微信AppID $appid = ''; if (!empty($wechat_setting) && !empty($wechat_setting['appid'])) { $appid = $wechat_setting['appid']; } else if (!empty($old_config) && !empty($old_config['appid'])) { $appid = $old_config['appid']; } return [ 'merchant' => $merchant, 'appid' => $appid ]; } /** * 获取固定的微信支付配置(基于订单前缀) * * @param string $order_prefix 订单前缀,如果提供则返回对应前缀的商户信息 * @return array 包含固定商户信息和appid */ public static function getFixedWxPayConfig($order_prefix = '') { $wechat_setting = getConfig('wechat_setting'); $weixinpay_setting = getConfig('weixinpay_setting'); // 尝试查找与订单前缀匹配的商户 $merchant = null; if (!empty($order_prefix) && !empty($weixinpay_setting) && !empty($weixinpay_setting['merchants'])) { foreach ($weixinpay_setting['merchants'] as $m) { if (!empty($m['order_prefix']) && $m['order_prefix'] === $order_prefix) { $merchant = $m; break; } } } // 如果没有找到匹配的商户,则使用随机选择 if (empty($merchant)) { return self::getWxPayConfig(); } // 获取微信AppID $appid = ''; if (!empty($wechat_setting) && !empty($wechat_setting['appid'])) { $appid = $wechat_setting['appid']; } else { $old_config = getConfig('weixinpay'); if (!empty($old_config) && !empty($old_config['appid'])) { $appid = $old_config['appid']; } } return [ 'merchant' => $merchant, 'appid' => $appid ]; } /** * 从订单号中提取商户前缀 * * @param string $order_no 订单号(格式如 MH_ABC20240529...) * @return string|null 商户前缀,如果无法提取则返回null */ public static function extractOrderPrefix($order_no) { if (strpos($order_no, 'MH_') === 0) { // 尝试提取MH_后的3个字符作为商户前缀 $prefix = substr($order_no, 3, 3); if (!empty($prefix) && strlen($prefix) === 3) { return $prefix; } } return null; } }