Generate.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Meta;
  4. use App\Models\Serialize;
  5. use BlockMatrix\EosRpc\ChainFactory;
  6. use BlockMatrix\EosRpc\EosRpc;
  7. use BlockMatrix\EosRpc\WalletFactory;
  8. use Carbon\Carbon;
  9. use GuzzleHttp\Client;
  10. use Illuminate\Console\Command;
  11. use Illuminate\Support\Facades\Log;
  12. use Illuminate\Support\Facades\Storage;
  13. use Org\Multilinguals\Apollo\Client\ApolloClient;
  14. use ZanySoft\Zip\Zip;
  15. class Generate extends Command
  16. {
  17. /**
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'generate:randstr';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '生成序列串';
  29. /**
  30. * Create a new command instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. parent::__construct();
  37. }
  38. /**
  39. * Execute the console command.
  40. *
  41. * @return mixed
  42. */
  43. public function handle()
  44. {
  45. ini_set('memory_limit','128M');
  46. $this->line('-----------start---------');
  47. $pass=[];
  48. $data=[];
  49. do{
  50. $str = $this->getRandomString(3);
  51. //生成3位,并且最少包含一位数字
  52. $preg = '/^(?=[a-z]*[0-9])(?=[0-9]*[a-z])[a-z0-9]{3,3}$/';
  53. if(preg_match($preg,$str)){
  54. if(!in_array($str,$pass)){
  55. $pass[] = $str;
  56. $data['serialize'] = $str;
  57. Serialize::create($data);
  58. }
  59. }
  60. }while (count($pass)<20000);
  61. $this->line('-----------end--------');
  62. }
  63. private function getRandomString($len, $chars=null)
  64. {
  65. if (is_null($chars)){
  66. $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  67. }
  68. mt_srand(10000000*(double)microtime());
  69. for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
  70. $str .= $chars[mt_rand(0, $lc)];
  71. }
  72. return $str;
  73. }
  74. }