Last active
June 18, 2025 22:26
-
-
Save arantesxyz/b78f00ac3589f93deeefa331e1f1fdb3 to your computer and use it in GitHub Desktop.
BCB PIX End To End Identification Generation in Golang.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package helpers | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "time" | |
| "unsafe" | |
| ) | |
| const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" | |
| const ( | |
| letterIdxBits = 6 | |
| letterIdxMask = 1<<letterIdxBits - 1 | |
| letterIdxMax = 63 / letterIdxBits | |
| ) | |
| var src = rand.NewSource(time.Now().UnixNano()) | |
| // Receive a transaction type and ISPB and returns a 32 characters string. | |
| // TransactionType should contain a single character. | |
| // ISPB should be 8 characters. | |
| func GenerateE2E(transactionType string, ispb string) (string) { | |
| location := time.FixedZone("GMT-3", -3*60*60) | |
| date := time.Now().In(location).Format("200601021504") | |
| randString := randString(11) | |
| return fmt.Sprintf("%s%s%s%s", transactionType, ispb, date, randString) | |
| } | |
| func randString(n int) string { | |
| b := make([]byte, n) | |
| for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { | |
| if remain == 0 { | |
| cache, remain = src.Int63(), letterIdxMax | |
| } | |
| if idx := int(cache & letterIdxMask); idx < len(letterBytes) { | |
| b[i] = letterBytes[idx] | |
| i-- | |
| } | |
| cache >>= letterIdxBits | |
| remain-- | |
| } | |
| return *(*string)(unsafe.Pointer(&b)) | |
| } |
Author
Author
As mesmas instruções podem ser utilizadas para gerar o MessageIdentification MsgId, apenas a data e hora não são obrigatórios, mas não fazem diferença, BCB só irá validar se é único.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PACS.008
<EndToEndId>description:Sendo que o primeiro caractere
Epode ser substituído porDna PACS.004 no campo<RtrId>Fonte: https://www.bcb.gov.br/estabilidadefinanceira/comunicacaodados