xml地图|网站地图|网站标签 [设为首页] [加入收藏]

智能家电

当前位置:美高梅游戏网站 > 智能家电 > PHP生成随机密码类分享_php实例_脚本之家

PHP生成随机密码类分享_php实例_脚本之家

来源:http://www.gd-chuangmei.com 作者:美高梅游戏网站 时间:2019-11-26 20:32

经常有这样的需求,就是需要在生成推广海报,包含指定的二维码,分享出去别人扫码之后就可以确定用户推荐关系。

length = $length; $this->configure(true, true, true, false, false); } /** * 配置 */ function configure($uppercase = false, $lowercase = false, $number = false, $special = false, $extra = false ) { $this->chars = array(); $this->upper_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" ); $this->lower_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" ); $this->number_chars = array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ); $this->special_chars = array( "!", "@", "#", "$", "%", "^", "&", "*", "; $this->extra_chars = array( "[", "]", "{", "}", "-", "_", "+", "=", "", "?", "/", "`", "~", "|", ",", ".", ";", ":" ); if (($this->uppercase = $uppercase) === true) { $this->chars = array_merge($this->chars, $this->upper_chars); } if (($this->lowercase = $lowercase) === true) { $this->chars = array_merge($this->chars, $this->lower_chars); } if (($this->number = $number) === true) { $this->chars = array_merge($this->chars, $this->number_chars); } if (($this->special = $special) === true) { $this->chars = array_merge($this->chars, $this->special_chars); } if (($this->extra = $extra) === true) { $this->chars = array_merge($this->chars, $this->extra_chars); } $this->chars = array_unique; } /** * 从字符列中生成随机密码 * * @return string **/ function generate() { if  { return false; } $hash = ''; $totalChars = count - 1; for ($i = 0; $i < $this->length; $i++) { $hash .= $this->chars[$this->random]; } return $hash; } /** * 生成随机数字 * * @return int */ function random { $max_random = 4294967295; $random = uniqid . mt_rand; $random = sha1; $value = substr; $value = abs; if  { $value = $min +  * $value / ; } return abs; }}

generate(); //FS4yq74e2LeE

仔细分析一下,推广海报必要的要素就是海报背景图和二维码,这两者都容易生成,但要两者结合到一起组合成为一张图二维还要可以保存到本地便于分享出去,这就是难点了,在H5中可以借助canvas画出来完成类似于截图的功能,但放到小程序里边很多局限性。那么我们直接在后台生成海报,前台直接调用。

1.海报背景图,背景图一般存服务器,程序本地读取;2.推广二维码,可以是二维码图片链接,也可以是字符串图像流,如果自己生成二维码,详见:使用phpqrcode生成二维码。

/**生成宣传海报@param array 参数,包括图片和文字@param string $filename 生成海报文件名,不传此参数则不生成文件,直接输出图片@return [type] [description]*/function createPoster,$filename=""){//如果要看报什么错,可以先注释调这个headerif header("content-type: image/png");$imageDefault = array('left'=>0,'top'=>0,'right'=>0,'bottom'=>0,'width'=>100,'height'=>100,'opacity'=>100);$textDefault = array('text'=>'','left'=>0,'top'=>0,'fontSize'=>32, //字号'fontColor'=>'255,255,255', //字体颜色'angle'=>0,);$background = $config['background'];//海报最底层得背景//背景方法$backgroundInfo = getimagesize;$backgroundFun = 'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);$background = $backgroundFun;$backgroundWidth = imagesx; //背景宽度$backgroundHeight = imagesy; //背景高度$imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight);$color = imagecolorallocate;imagefill($imageRes, 0, 0, $color);// imageColorTransparent; //颜色透明imagecopyresampled($imageRes,$background,0,0,0,0,imagesx,imagesy,imagesx,imagesy;//处理了图片if(!empty{foreach ($config['image'] as $key => $val) {$val = array_merge;$info = getimagesize;$function = 'imagecreatefrom'.image_type_to_extension;if{ //如果传的是字符串图像流$info = getimagesizefromstring;$function = 'imagecreatefromstring';}$res = $function;$resWidth = $info[0];$resHeight = $info[1];//建立画板 ,缩放图片至指定尺寸$canvas=imagecreatetruecolor($val['width'], $val['height']);imagefill($canvas, 0, 0, $color);//关键函数,参数(目标资源,源,目标资源的开始坐标x,y, 源资源的开始坐标x,y,目标资源的宽高w,h,源资源的宽高w,h)imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'],$resWidth,$resHeight);$val['left'] = $val['left']<0?$backgroundWidth- abs - $val['width']:$val['left'];$val['top'] = $val['top']<0?$backgroundHeight- abs - $val['height']:$val['top'];//放置图像imagecopymerge($imageRes,$canvas, $val['left'],$val['top'],$val['right'],$val['bottom'],$val['width'],$val['height'],$val['opacity']);//左,上,右,下,宽度,高度,透明度}}//处理文字if(!empty{foreach ($config['text'] as $key => $val) {$val = array_merge;list = explode(',', $val['fontColor']);$fontColor = imagecolorallocate($imageRes, $R, $G, $B);$val['left'] = $val['left']<0?$backgroundWidth- abs:$val['left'];$val['top'] = $val['top']<0?$backgroundHeight- abs:$val['top'];imagettftext($imageRes,$val['fontSize'],$val['angle'],$val['left'],$val['top'],$fontColor,$val['fontPath'],$val['text']);}}//生成图片if{$res = imagejpeg ($imageRes,$filename,90); //保存到本地imagedestroy return false;return $filename;}else{imagejpeg ; //在浏览器上显示imagedestroy;}}

本文由美高梅游戏网站发布于智能家电,转载请注明出处:PHP生成随机密码类分享_php实例_脚本之家

关键词: