Created
August 18, 2016 02:22
-
-
Save neilwong2012/34177c9c817fe58b68c4e70afe1490c3 to your computer and use it in GitHub Desktop.
兑换码生成
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
/* | |
* params $typeId 批次id | |
* params $id id | |
* return $code | |
*/ | |
function initCode($typeId, $id) { | |
$arr = array('n', 'w', 't', 'b', 's', '9', '8', 'g', '6', 'd', 'k', 'm', '2', '5', 'p', 'q', 'y', 'r', 'u', 'e', '4', '7', 'c', 'j', 'z', 'f', 'h', 'y', 'a', '3', 'x'); | |
$length = count($arr); | |
$codeArr = array(); | |
for($i = 0, $int = $typeId; $i < 2; $i++) { | |
$index = $int%$length; | |
$codeArr[] = $arr[$index]; | |
$int = $int/$length; | |
} | |
for($i = 0, $int = $id; $i < 4; $i++) { | |
$index = $int%$length; | |
$codeArr[] = $arr[$index]; | |
$int = $int/$length; | |
} | |
for($i = 0; $i < 4; $i ++) { | |
$index = rand(0, $length-1); | |
$codeArr[] = $arr[$index]; | |
} | |
return strtoupper(join($codeArr, '')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment