This commit is contained in:
Anonymous 2019-10-23 00:09:50 +08:00
parent 7c5a1bbcc5
commit 3802a1c973
2 changed files with 28 additions and 1 deletions

View File

@ -17,7 +17,7 @@ class InviteController extends Controller
} }
$inviteCode = new InviteCode(); $inviteCode = new InviteCode();
$inviteCode->user_id = $request->session()->get('id'); $inviteCode->user_id = $request->session()->get('id');
$inviteCode->code = Helper::guid(); $inviteCode->code = Helper::randomChar(8);
return response([ return response([
'data' => $inviteCode->save() 'data' => $inviteCode->save()
]); ]);

View File

@ -22,4 +22,31 @@ class Helper
$result = json_decode($result, true); $result = json_decode($result, true);
return $result['rates'][$to]; return $result['rates'][$to];
} }
public static function randomChar($len, $special=false){
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
if($special){
$chars = array_merge($chars, array(
"!", "@", "#", "$", "?", "|", "{", "/", ":", ";",
"%", "^", "&", "*", "(", ")", "-", "_", "[", "]",
"}", "<", ">", "~", "+", "=", ",", "."
));
}
$charsLen = count($chars) - 1;
shuffle($chars);
$str = '';
for($i=0; $i<$len; $i++){
$str .= $chars[mt_rand(0, $charsLen)];
}
return $str;
}
} }