import transaction from wechat pay billing file

This commit is contained in:
MaysWind
2024-10-14 01:18:17 +08:00
parent 44fe7778b6
commit b9b501edfa
11 changed files with 481 additions and 3 deletions
+16
View File
@@ -3,9 +3,14 @@ package utils
import (
"crypto/rand"
"math/big"
"regexp"
"strings"
)
var (
numberPattern = regexp.MustCompile("(-?\\d+)(\\.\\d+)?")
)
// GetRandomInteger returns a random number, the max parameter represents upper limit
func GetRandomInteger(max int) (int, error) {
result, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
@@ -17,6 +22,17 @@ func GetRandomInteger(max int) (int, error) {
return int(result.Int64()), nil
}
// ParseFirstConsecutiveNumber returns the first consecutive number in the specified string
func ParseFirstConsecutiveNumber(str string) (string, bool) {
result := numberPattern.FindAllString(str, 1)
if len(result) > 0 {
return result[0], true
} else {
return "", false
}
}
// TrimTrailingZerosInDecimal returns a textual number without trailing zeros in decimal
func TrimTrailingZerosInDecimal(num string) string {
if len(num) < 1 {