Created
April 15, 2015 02:38
-
-
Save tklee1975/29595d20f9cbbbd3d665 to your computer and use it in GitHub Desktop.
Token Generator; Example usage: pageToken for a long result set like the APIs of Google Place API
This file contains 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
public static String generateToken(String prefix, int uid) | |
{ | |
long now = System.currentTimeMillis(); | |
// Shorten integer values | |
String nowStr = Base64.encodeLong(now); | |
String uidStr = Base64.encodeInt(uid); | |
// Concatenate | |
String token = prefix + nowStr + uidStr; | |
// replace some special symbols | |
token = token.replaceAll("[\n =]", "_"); | |
return token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment