保管中のセキュリティカード
<ol class="dp-c"> <li class="alt"><span><span class="vars">$this</span><span>->load->model(</span><span class="string">"admin/m_mibao"</span><span>); </span></span></li> <li><span> </span></li> <li class="alt"><span><span class="vars">$data</span><span> = </span><span class="keyword">array</span><span>(); </span></span></li> <li><span><span class="comment">//生成随机横坐标</span><span> </span></span></li> <li class="alt"><span><span class="vars">$rand_str</span><span> = </span><span class="vars">$this</span><span>->_rand_str(10); </span></span></li> <li><span> </span></li> <li class="alt"><span><span class="vars">$arr</span><span> = </span><span class="keyword">array</span><span>(); </span></span></li> <li><span><span class="keyword">for</span><span>(</span><span class="vars">$k</span><span>=0;</span><span class="vars">$k</span><span><</span><span class="func">strlen</span><span>(</span><span class="vars">$rand_str</span><span>);</span><span class="vars">$k</span><span>++) </span></span></li><li class="alt"><span>{ </span></li><li><span> <span class="keyword">for</span><span> (</span><span class="vars">$i</span><span> = 1;</span><span class="vars">$i</span><span> < 9;</span><span class="vars">$i</span><span>++) </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="vars">$rand</span><span> = </span><span class="vars">$this</span><span>->_rand_num(3); </span></span></li> <li class="alt"><span> <span class="comment">//赋给所有code的容器</span><span> </span></span></li> <li><span> <span class="vars">$arr</span><span>[</span><span class="vars">$rand_str</span><span>{</span><span class="vars">$k</span><span>} . </span><span class="vars">$i</span><span>] = </span><span class="vars">$rand</span><span>; </span></span></li> <li class="alt"><span> } </span></li> <li><span>} </span></li> <li class="alt"><span> </span></li> <li><span><span class="vars">$data</span><span>[</span><span class="string">"code"</span><span>] = serialize(</span><span class="vars">$arr</span><span>); </span><span class="comment">//序列化后将信息入库</span><span> </span></span></li> <li class="alt"><span><span class="vars">$data</span><span>[</span><span class="string">"letter"</span><span>] = </span><span class="vars">$rand_str</span><span>; </span></span></li> <li><span> </span></li> <li class="alt"><span><span class="comment">//避免重复序列号</span><span> </span></span></li> <li><span><span class="keyword">while</span><span> (TRUE) </span></span></li> <li class="alt"><span>{ </span></li> <li><span> <span class="vars">$data</span><span>[</span><span class="string">"card_num"</span><span>] = </span><span class="vars">$this</span><span>->_rand_num(20); </span></span></li> <li class="alt"><span> <span class="comment">//判断序列号是否重复存在</span><span> </span></span></li> <li><span> <span class="keyword">if</span><span>(</span><span class="vars">$this</span><span>->m_mibao->has_card_num(</span><span class="vars">$data</span><span>[</span><span class="string">"card_num"</span><span>]) == 0) </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="keyword">break</span><span>; </span></span></li> <li class="alt"><span> } </span></li> <li><span>} </span></li> <li class="alt"><span> </span></li> <li><span><span class="vars">$data</span><span>[</span><span class="string">"add_time"</span><span>] = TIME; </span></span></li> <li class="alt"><span><span class="vars">$data</span><span>[</span><span class="string">"user_id"</span><span>] = </span><span class="vars">$uid</span><span>; </span></span></li> <li><span> </span></li> <li class="alt"><span><span class="func">echo</span><span> </span><span class="vars">$this</span><span>->mibao->insert(</span><span class="vars">$data</span><span>); </span></span></li> </ol>
シークレットカード画像生成
<ol class="dp-c"> <li class="alt"><span><span class="comment">//就是算坐标</span><span> </span></span></li> <li><span> <span class="keyword">public</span><span> </span><span class="keyword">function</span><span> show(</span><span class="vars">$user_id</span><span>) </span></span></li> <li class="alt"><span>{ </span></li> <li><span> <span class="vars">$this</span><span>->load->model(</span><span class="string">"admin/m_mibao"</span><span>); </span></span></li> <li class="alt"><span> <span class="vars">$info</span><span> = </span><span class="vars">$this</span><span>->m_mibao->get_by_uid(</span><span class="vars">$user_id</span><span>); </span></span></li> <li><span> <span class="keyword">if</span><span>(</span><span class="keyword">empty</span><span class="func">empty</span><span>(</span><span class="vars">$info</span><span>)) </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="vars">$this</span><span>->msg(</span><span class="string">"该用户无密保卡!"</span><span>,</span><span class="string">"admin-index"</span><span>); </span></span></li> <li class="alt"><span> } </span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$codes</span><span> = unserialize(</span><span class="vars">$info</span><span>[</span><span class="string">"code"</span><span>]); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="comment">//图片初始值</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$bit</span><span> = 3; </span><span class="comment">//密保卡位数</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$height</span><span> = 332; </span><span class="comment">//图片高度</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$width</span><span> = 626; </span><span class="comment">//图片宽度</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$im</span><span> = imagecreatetruecolor(</span><span class="vars">$width</span><span>,</span><span class="vars">$height</span><span>); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$linecolor</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>, 229,229,229); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$fontcolor</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>, 0, 0, 0); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$top_rectangle_color</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>,241,254,237); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$top_letter_color</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>,54,126,76); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$left_rectangle_color</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>,243,247,255); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$left_num_color</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>,4,68,192); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$logo_str_color</span><span> = imagecolorallocate(</span><span class="vars">$im</span><span>,0,0,0); </span></span></li> <li><span> </span></li> <li class="alt"><span> imagefill(<span class="vars">$im</span><span>,0,0,imagecolorallocate(</span><span class="vars">$im</span><span>,255,255,255)); </span><span class="comment">//图片背景色</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$font</span><span> = </span><span class="string">"./public/baomi/fonts/simsun.ttc"</span><span>; </span><span class="comment">//字体</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$font_en</span><span> = </span><span class="string">"./public/baomi/fonts/CONSOLA.TTF"</span><span>; </span><span class="comment">//英文字体</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$font2</span><span> = </span><span class="string">"./public/baomi/fonts/simhei.ttf"</span><span>; </span><span class="comment">//密保卡上方黑体</span><span> </span></span></li> <li><span> </span></li> <li class="alt"><span> </span></li> <li><span> <span class="vars">$dst</span><span> = imagecreatefromjpeg(</span><span class="string">"./public/baomi/120.jpg"</span><span>); </span></span></li> <li class="alt"><span> </span></li> <li><span> </span></li> <li class="alt"><span> </span></li> <li><span> imagecopymerge(<span class="vars">$im</span><span>,</span><span class="vars">$dst</span><span>,120,15,0,0,193,55,100); </span></span></li> <li class="alt"><span> </span></li> <li><span> imageline(<span class="vars">$im</span><span>,10,72,</span><span class="vars">$width</span><span>-10,72,</span><span class="vars">$linecolor</span><span>); </span></span></li> <li class="alt"><span> </span></li> <li><span> <span class="vars">$ltext</span><span> = </span><span class="string">"电子密保卡"</span><span>; </span></span></li> <li class="alt"><span> </span></li> <li><span> <span class="keyword">if</span><span>(!imagettftext(</span><span class="vars">$im</span><span>,10,0,340,47,</span><span class="vars">$logo_str_color</span><span>,</span><span class="vars">$font2</span><span>,</span><span class="vars">$ltext</span><span>)) { </span></span></li> <li class="alt"><span> <span class="func">exit</span><span>(</span><span class="string">"error"</span><span>); </span></span></li> <li><span> } </span></li> <li class="alt"><span> </span></li> <li><span> <span class="comment">//写入卡号</span><span> </span></span></li> <li class="alt"><span> </span></li> <li><span> <span class="vars">$b</span><span> = </span><span class="string">"1000"</span><span> . </span><span class="vars">$info</span><span>[</span><span class="string">"card_num"</span><span>]; </span></span></li> <li class="alt"><span> </span></li> <li><span> <span class="keyword">for</span><span>(</span><span class="vars">$i</span><span>=0;</span><span class="vars">$i</span><span><7;</span><span class="vars">$i</span><span>++){ </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$p</span><span>.= </span><span class="func">substr</span><span>(</span><span class="vars">$b</span><span>,3*</span><span class="vars">$i</span><span>,4). </span><span class="string">" "</span><span>; </span></span></li><li class="alt"><span> </span></li><li><span> } </span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$x</span><span> = 40; </span><span class="vars">$y</span><span> = 95; </span><span class="comment">//序列号位置</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> imagettftext(<span class="vars">$im</span><span>,10,0,</span><span class="vars">$x</span><span>,</span><span class="vars">$y</span><span>,</span><span class="vars">$color</span><span>,</span><span class="vars">$font</span><span>,</span><span class="string">"序列号"</span><span>); </span></span></li><li class="alt"><span> </span></li><li><span> imagettftext(<span class="vars">$im</span><span>,11,0,</span><span class="vars">$x</span><span>+50,</span><span class="vars">$y</span><span>,</span><span class="vars">$color</span><span>,</span><span class="vars">$font_en</span><span>,</span><span class="vars">$p</span><span>); </span></span></li><li class="alt"><span> </span></li><li><span> <span class="comment">//颜色框</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> imagefilledrectangle(<span class="vars">$im</span><span>,10,106,</span><span class="vars">$width</span><span>-10,128,</span><span class="vars">$top_rectangle_color</span><span>); </span></span></li><li class="alt"><span> </span></li><li><span> imagefilledrectangle(<span class="vars">$im</span><span>,10,129,65,</span><span class="vars">$height</span><span>-10,</span><span class="vars">$left_rectangle_color</span><span>); </span></span></li><li class="alt"><span> </span></li><li><span> <span class="comment">//写入最上排英文字母及竖线</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> <span class="keyword">for</span><span>(</span><span class="vars">$i</span><span>=1;</span><span class="vars">$i</span><span><=10;</span><span class="vars">$i</span><span>++){ </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$x</span><span> = </span><span class="vars">$i</span><span>*55+35; </span><span class="vars">$y</span><span> = 123; </span><span class="vars">$float_size</span><span> = 11; </span><span class="comment">//字母位置参数 </span><span> </span></span></li><li class="alt"><span> </span></li><li><span> imagettftext(<span class="vars">$im</span><span>,</span><span class="vars">$float_size</span><span>,0,</span><span class="vars">$x</span><span>,</span><span class="vars">$y</span><span>,</span><span class="vars">$top_letter_color</span><span>,</span><span class="vars">$font_en</span><span>,</span><span class="vars">$info</span><span>[</span><span class="string">"letter"</span><span>]{</span><span class="vars">$i</span><span>-1});</span><span class="comment">//写入最上排英文字母</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> } </span></li><li class="alt"><span> </span></li><li><span> <span class="keyword">for</span><span>(</span><span class="vars">$i</span><span>=0;</span><span class="vars">$i</span><span><=9;</span><span class="vars">$i</span><span>++){ </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$linex</span><span> = </span><span class="vars">$i</span><span>*55+65; </span><span class="vars">$liney</span><span> = 105; </span><span class="vars">$liney2</span><span> = </span><span class="vars">$height</span><span>-10; </span><span class="comment">//竖线位置参数</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> imageline(<span class="vars">$im</span><span>,</span><span class="vars">$linex</span><span>,</span><span class="vars">$liney</span><span>,</span><span class="vars">$linex</span><span>,</span><span class="vars">$liney2</span><span>,</span><span class="vars">$linecolor</span><span>);</span><span class="comment">//划入竖线</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> } </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> <span class="comment">//写入竖排数字及填入矩阵数据 划横线</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> <span class="keyword">for</span><span>(</span><span class="vars">$j</span><span>=0;</span><span class="vars">$j</span><span><8;</span><span class="vars">$j</span><span>++){ </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$jj</span><span>=</span><span class="vars">$j</span><span>+1; </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$x</span><span>=35; </span><span class="vars">$y</span><span>=(</span><span class="vars">$jj</span><span>*24)+123; </span><span class="comment">//左排数字及横线位置参数</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> imagettftext(<span class="vars">$im</span><span>, </span><span class="vars">$float_size</span><span>, 0, </span><span class="vars">$x</span><span>, </span><span class="vars">$y</span><span>, </span><span class="vars">$left_num_color</span><span>, </span><span class="vars">$font_en</span><span>, </span><span class="vars">$jj</span><span>);</span><span class="comment">//写入左排数字</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> <span class="keyword">for</span><span>(</span><span class="vars">$i</span><span>=1;</span><span class="vars">$i</span><span><=10;</span><span class="vars">$i</span><span>++){ </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$float_size2</span><span>=11; </span><span class="vars">$x</span><span> = </span><span class="vars">$i</span><span>*55+27; </span><span class="vars">$sy</span><span>=</span><span class="vars">$y</span><span>; </span><span class="comment">//填入矩阵数据位置参数</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$s</span><span> = </span><span class="vars">$info</span><span>[</span><span class="string">"letter"</span><span>]{</span><span class="vars">$i</span><span>-1}; </span></span></li><li class="alt"><span> <span class="vars">$s</span><span> .= </span><span class="vars">$j</span><span> + 1; </span></span></li><li><span> imagettftext(<span class="vars">$im</span><span>,</span><span class="vars">$float_size2</span><span>,0,</span><span class="vars">$x</span><span>,</span><span class="vars">$sy</span><span>,</span><span class="vars">$fontcolor</span><span>,</span><span class="vars">$font_en</span><span>,</span><span class="vars">$codes</span><span>[</span><span class="vars">$s</span><span>]);</span><span class="comment">//写入矩阵数据</span><span> </span></span></li><li class="alt"><span> </span></li><li><span> } </span></li><li class="alt"><span> } </span></li><li><span> </span></li><li class="alt"><span> <span class="keyword">for</span><span>(</span><span class="vars">$j</span><span>=0;</span><span class="vars">$j</span><span><10;</span><span class="vars">$j</span><span>++){ </span></span></li><li><span> </span></li><li class="alt"><span> <span class="vars">$line_x</span><span>=10; </span><span class="vars">$line_x2</span><span>=</span><span class="vars">$width</span><span>-10;</span><span class="vars">$y</span><span>=</span><span class="vars">$j</span><span>*24+105; </span><span class="comment">//横线位置参数 y坐标数据同上</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> imageline(<span class="vars">$im</span><span>,</span><span class="vars">$line_x</span><span>,</span><span class="vars">$y</span><span>,</span><span class="vars">$line_x2</span><span>,</span><span class="vars">$y</span><span>,</span><span class="vars">$linecolor</span><span>);</span><span class="comment">//划入横线</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> } </span></li><li><span> </span></li><li class="alt"><span> <span class="comment">//外框边线</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> imageline(<span class="vars">$im</span><span>,10,10,</span><span class="vars">$width</span><span>-10,10,</span><span class="vars">$linecolor</span><span>);</span><span class="comment">//横线</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> <span class="comment">//imageline($im,10,$height-10,$width-10,$height-10,$linecolor);</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> imageline(<span class="vars">$im</span><span>,10,10,10,</span><span class="vars">$height</span><span>-10,</span><span class="vars">$linecolor</span><span>);</span><span class="comment">//竖线</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> imageline(<span class="vars">$im</span><span>,</span><span class="vars">$width</span><span>-10,10,</span><span class="vars">$width</span><span>-10,</span><span class="vars">$height</span><span>-10,</span><span class="vars">$linecolor</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span> <span class="comment">//生成图片</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> ob_clean(); </span></li><li><span> header(<span class="string">"Content-type: image/jpeg"</span><span>); </span></span></li><li class="alt"><span> imagejpeg(<span class="vars">$im</span><span>,null,100); </span></span></li><li><span> imagedestroy(<span class="vars">$im</span><span>); </span></span></li><li class="alt"><span>} </span></li></ol>
セキュリティカードの認証
<ol class="dp-c"><li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">function</span><span> test1(</span><span class="vars">$uid</span><span>) </span></span></li><li><span>{ </span></li><li class="alt"><span> </span></li><li><span> <span class="vars">$this</span><span>->load->model(</span><span class="string">"admin/m_users"</span><span>); </span></span></li> <li class="alt"><span> <span class="vars">$user</span><span> = </span><span class="vars">$this</span><span>->m_users->sel(</span><span class="vars">$uid</span><span>); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="comment">//post提交过来验证</span><span> </span></span></li> <li><span> <span class="keyword">if</span><span>(</span><span class="vars">$this</span><span>->is_post()) </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="vars">$codes</span><span> = </span><span class="vars">$this</span><span>->m_mibao->get_codes_by_uid(</span><span class="vars">$uid</span><span>); </span></span></li> <li class="alt"><span> <span class="vars">$codes</span><span> = unserialize(</span><span class="vars">$codes</span><span>); </span></span></li> <li><span> </span></li> <li class="alt"><span> <span class="vars">$is_true</span><span> = true; </span></span></li> <li><span> <span class="keyword">foreach</span><span>(</span><span class="vars">$_SESSION</span><span>[</span><span class="string">"mibao"</span><span>][</span><span class="string">"keys"</span><span>] </span><span class="keyword">as</span><span> </span><span class="vars">$key</span><span>) </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="keyword">if</span><span>(</span><span class="vars">$codes</span><span>[</span><span class="vars">$key</span><span>] != </span><span class="vars">$_POST</span><span>[</span><span class="string">"values"</span><span>][</span><span class="vars">$key</span><span>]) </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="vars">$is_true</span><span> = false; </span></span></li> <li class="alt"><span> } </span></li> <li><span> } </span></li> <li class="alt"><span> </span></li> <li><span> <span class="keyword">if</span><span>(</span><span class="vars">$is_true</span><span>) </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="keyword">die</span><span>(</span><span class="string">"正确"</span><span>); </span></span></li> <li class="alt"><span> } </span></li> <li><span> <span class="keyword">else</span><span> </span></span></li> <li class="alt"><span> { </span></li> <li><span> </span></li> <li class="alt"><span> <span class="keyword">die</span><span>(</span><span class="string">"错误"</span><span>); </span></span></li> <li><span> } </span></li> <li class="alt"><span> } </span></li> <li><span> <span class="keyword">else</span><span> </span></span></li> <li class="alt"><span> { </span></li> <li><span> <span class="comment">//渲染视图</span><span> </span></span></li> <li class="alt"><span> <span class="vars">$info</span><span> = </span><span class="vars">$this</span><span>->m_mibao->get_by_uid(</span><span class="vars">$uid</span><span>); </span></span></li> <li><span> <span class="vars">$data</span><span> = </span><span class="keyword">array</span><span>(); </span></span></li> <li class="alt"><span> <span class="vars">$data</span><span>[</span><span class="string">"keys"</span><span>] = </span><span class="vars">$this</span><span>->m_mibao->get_rand_keys(</span><span class="vars">$info</span><span>[</span><span class="string">"letter"</span><span>]); </span></span></li> <li><span> <span class="vars">$_SESSION</span><span>[</span><span class="string">"mibao"</span><span>][</span><span class="string">"keys"</span><span>] = </span><span class="vars">$data</span><span>[</span><span class="string">"keys"</span><span>]; </span></span></li> <li class="alt"><span> <span class="vars">$data</span><span>[</span><span class="string">"uid"</span><span>] = </span><span class="vars">$uid</span><span>; </span></span></li> <li><span> <span class="vars">$this</span><span>->load->view(</span><span class="string">"test1"</span><span>,</span><span class="vars">$data</span><span>); </span></span></li> <li class="alt"><span> } </span></li> </ol>