admin/src/Oms.Application/Shared/WeChatRegistrationFieldNormalizer.cs
zzh c2eae1c327
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
feat: 落库微信 UnionID,支持换公众号昵称+手机号迁移 OpenID
注册/绑定写入 UnionID;授权登录可回填。换公众号时昵称命中存量客户可凭手机号确认,更新 WechatOpenid 与 UnionID 后登录。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:34:50 +08:00

38 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Oms.Application.Shared;
/// <summary>
/// 微信注册字段裁剪,避免超出库表长度触发保存失败。
/// </summary>
public static class WeChatRegistrationFieldNormalizer
{
public const int CustomerNameMaxLength = 128;
public const int PhoneMaxLength = 16;
public const int EmailMaxLength = 64;
/// <summary>客户表 WechatAvatar 列长度。</summary>
public const int CustomerWechatAvatarMaxLength = 255;
public const int NicknameMaxLength = 64;
public const int OpenidMaxLength = 64;
public const int UnionidMaxLength = 64;
/// <summary>微信头像仅写入 t_customer;RBAC user.Avatar 列更短,注册时不写入。</summary>
public static string? NormalizeCustomerWechatAvatar(string? avatar) =>
TruncateOptional(avatar, CustomerWechatAvatarMaxLength);
public static string TruncateRequired(string value, int maxLength)
{
var normalized = value.Trim();
return normalized.Length <= maxLength ? normalized : normalized[..maxLength];
}
public static string? TruncateOptional(string? value, int maxLength)
{
var normalized = value?.Trim();
if (string.IsNullOrWhiteSpace(normalized))
{
return null;
}
return normalized.Length <= maxLength ? normalized : normalized[..maxLength];
}
}