30 lines
940 B
Dart
30 lines
940 B
Dart
|
import 'dart:math';
|
||
|
import 'package:crypto/crypto.dart';
|
||
|
import 'dart:convert';
|
||
|
|
||
|
class CommonUtil {
|
||
|
static String generateMd5(String input) {
|
||
|
List<int> bytes = utf8.encode(input); // 将字符串转换为字节码
|
||
|
Digest md5Hash = md5.convert(bytes); // 对字节码进行MD5加密
|
||
|
String encryptedString = md5Hash.toString(); // 获取加密后的字符串
|
||
|
return encryptedString;
|
||
|
}
|
||
|
|
||
|
static String generateTicketNumber() {
|
||
|
Random random = Random();
|
||
|
|
||
|
int randomTwoDigitNumber = random.nextInt(99);
|
||
|
String twoDigitNumber = randomTwoDigitNumber.toString().padLeft(2, '0');
|
||
|
|
||
|
// 格式化数字串
|
||
|
String formattedNumber =
|
||
|
'${random.nextInt(9999999).toString().padLeft(7, '0')}${random.nextInt(9999999).toString().padLeft(7, '0')}-$twoDigitNumber';
|
||
|
|
||
|
return formattedNumber;
|
||
|
}
|
||
|
|
||
|
static String firstUppercase(String text) {
|
||
|
return '${text[0].toUpperCase()}${text.substring(1)}';
|
||
|
}
|
||
|
}
|