From 3802a1c9738e383014614c17d2d5c7d82ba4a66e Mon Sep 17 00:00:00 2001 From: Anonymous Date: Wed, 23 Oct 2019 00:09:50 +0800 Subject: [PATCH] update --- app/Http/Controllers/InviteController.php | 2 +- app/Utils/Helper.php | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index ba13433a..c03b4190 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -17,7 +17,7 @@ class InviteController extends Controller } $inviteCode = new InviteCode(); $inviteCode->user_id = $request->session()->get('id'); - $inviteCode->code = Helper::guid(); + $inviteCode->code = Helper::randomChar(8); return response([ 'data' => $inviteCode->save() ]); diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index 1cdf9a41..8040e44a 100755 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -22,4 +22,31 @@ class Helper $result = json_decode($result, true); 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; + } }