package sign import "time" func GetACSignature(oneSite, oneNonce, uaN string, oneTimeStamp int64) string { if oneTimeStamp == 0 { oneTimeStamp = time.Now().Unix() } calOneStr := func(s string, iv int) int { k := iv for _, ch := range s { k = int(((k ^ int(ch)) * 65599) & 0xFFFFFFFF) } return k } calOneStr3 := func(s string, iv int) int { k := iv for _, ch := range s { k = int((int64(k)*65599 + int64(ch)) & 0xFFFFFFFF) } return k } getOneChr := func(code int) string { code &= 0x3F if code < 26 { return string(rune('A' + code)) } else if code < 52 { return string(rune('a' + code - 26)) } else if code < 62 { return string(rune('0' + code - 52)) } else if code == 62 { return "+" } return "/" } encNumToStr := func(val uint32) string { var s string for i := 24; i >= 0; i -= 6 { s += getOneChr(int((val >> uint(i)) & 0x3F)) } return s } signHead := "_02B4Z6wo00f01" timeStampS := itoa(oneTimeStamp) a := calOneStr(oneSite, calOneStr(timeStampS, 0)) % 65521 xorVal := uint32(oneTimeStamp) ^ uint32(a*65521) b := uint64(0x80F0) << 32 | uint64(xorVal) bStr := itoa(int64(b)) c := calOneStr(bStr, 0) d := encNumToStr(uint32(b >> 2)) e := uint32((b >> 32) & 0xFFFFFFFF) f := encNumToStr(uint32((b << 28) | (uint64(e) >> 4))) g := uint32(0x22AA7A58) ^ uint32(b&0xFFFFFFFF) h := encNumToStr(uint32((e << 26) | (g >> 6))) i := getOneChr(int(g & 0x3F)) j := (uint32(calOneStr(uaN, c)%65521) << 16) | uint32(calOneStr(oneNonce, c)%65521) k := encNumToStr(j >> 2) l := encNumToStr(uint32((j << 28) | ((0x8000 ^ uint32(b&0xFFFFFFFF)) >> 4))) m := encNumToStr(uint32(a)) n := signHead + d + f + h + i + k + l + m oHex := itoa(int64(calOneStr3(n, 0))) if len(oHex) < 2 { oHex = "00" } o := oHex[len(oHex)-2:] return n + o } func itoa(v int64) string { if v == 0 { return "0" } var digits []byte n := v if n < 0 { n = -n } for n > 0 { digits = append([]byte{byte('0' + n%10)}, digits...) n /= 10 } return string(digits) }