/** * Generate activation Code **/ functionShowgenerationactivationcode () {#Channel type ID $channel _id=$_post[' Channel ']; #query channel name according to channel ID $channelInfo= Load_mysql ("Channelinfo" ); $_res=$channelInfo->getinfobyid ($channel _id); $en _name=$_res[' En_name ']; #type of activity $type=$_post[' Active_type ']; #number of builds $nub=$_post[' Nub ']; #an array that accepts the generated activation code $array _activationcode=$this->showunique_rand (10000000,99999999,$nub); #Generate code Array $code _array=$this->showalgorithm_activationcode ($type,$channel _id,$array _activationcode); #Connect to Redis $redis=NewRedis (); $redis->connect (' 192.168.1.131 ', 8899); //Authorized $redis->auth ("funova2014"); } /** * Generate code algorithm *TYPE: Activity type [fetch top three] *channel_id: Channel id[take top three bits, not 0 padding] *array_activationcode: Activation code array *code algorithm format = activity type + Channel Tao Id+array_activationcode; An array of *return code*/ functionShowalgorithm_activationcode ($type,$channel _id,$array _activationcode){ #intercept activity type front bit string $type=MB_SUBSTR ($type, 0,3, ' Utf-8 '); #Channel id[take top three, insufficient left with 0 padding] $channel _id=Str_pad($channel _id, 3, ' 0 ',str_pad_left); #define an array of code algorithms $code _array=Array(); for($i= 0;$i<Count($array _activationcode);$i++){ $code _array[$i]=$type.‘‘.$channel _id.‘‘.$array _activationcode[$i]; } return $code _array; } /** * Generate 8-digit activation code algorithm*/ functionShowunique_rand ($min,$max,$num) { $count= 0; $return=Array(); while($count<$num) { $return[] =Mt_rand($min,$max); $return=Array_flip(Array_flip($return)); $count=Count($return); } return $return; }
PHP generates a 8-digit unique activation code