一个卡密生成器[前台源码]
演示例子:http://jxidc.wang/?/card/
拿dz的步骤来制作,以为很难,就动手试研究研究,。本来加在后台,生成卡密然后可以使用的。
就先拿来做前台来做实验了。
后台也打算访一个dz的卡密程序。
也不知道代码算简单还是算复杂。
新建文件夹 ``/app/ka/``
文件 ``main.php``
加入方法 头文件我就不写了
{{{
public function make_action(){
//提交表单页面
if(!$_POST['num']){
H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入数量')));
}else{
if(intval($_POST['num']) == 0){
H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入正确的数量')));
}
}
for ($i = 1; $i < $_POST['num'] + 1; $i++) {
$ka = $this->model('ka')->make($_POST['card'],strlen($_POST['card']));
if(strlen($ka) != 0){
//生成成功
$ad .= "<br>".$i."-".$ka;
}else{
//生成失败
$ad .="<br>".$i."-失败";
}
}
H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t($ad)));
}
}}}
{{{
public function index_action(){
$this->crumb(AWS_APP::lang()->_t('在线卡密生成器'), '/ka/');
//加载模板,就自己写了吧,就提交表单 提交到 ka/make/
TPL::output('ka/index');
}
}}}
models 新建个 ``ka.php``
{{{
<?php
if (!defined('IN_ANWSION'))
{
die;
}
class ka_class extends AWS_MODEL
{
var $rulekey = array("str"=>"\@", "num"=>"\#", "full"=>"\*");
var $sysrule = '';
var $rule = '';
var $rulemap_str = "ABCDEFGHIJKLMNPQRSTUVWXYZ";
var $rulemap_num = "123456789";
var $rulereturn = array();
public function make($rule = '', $num = 1) {
$this->sysrule = "^[A-Z0-9".implode('|', $this->rulekey)."]+$";
for($i = 0; $i < $num ; $i++) {
if($this->checkrule($rule)) {
$this->rule = $rule;
$card = $rule;
foreach($this->rulereturn AS $key => $val) {
$search = array();
foreach($val AS $skey => $sval) {
$search[] = '/'.$this->rulekey[$key].'/';
}
$card = preg_replace($search, $val, $card, 1);
}
} else {
return 0;
}
}
return $card;
}
public function checkrule($rule, $type = '0') {
if(!preg_match("/(".$this->sysrule.")/i", $rule)){
return $rule;
}
if($type == 0) {
foreach($this->rulekey AS $key => $val) {
$match = array();
preg_match_all("/(".$val."){1}/i", $rule, $match);
$number[$key] = count($match[0]);
if($number[$key] > 0) {
for($i = 0; $i < $number[$key]; $i++) {
switch($key) {
case 'str':
$rand = mt_rand(0, (strlen($this->rulemap_str) - 1));
$this->rulereturn[$key][$i] = $this->rulemap_str[$rand];
break;
case 'num':
$rand = mt_rand(0, (strlen($this->rulemap_num) - 1));
$this->rulereturn[$key][$i] = $this->rulemap_num[$rand];
break;
case 'full':
$fullstr = $this->rulemap_str.$this->rulemap_num;
$rand = mt_rand(0,(strlen($fullstr) - 1));
$this->rulereturn[$key][$i] = $fullstr[$rand];
break;
}
}
}
}
}
return true;
}
}
?>
}}}
就这点代码 你说这多呢 还是少呢,你说要给我赞呢还是不给我赞呢?
2014-12-07 22:52
2014-12-07 22:37
2014-12-07 22:29
2014-12-07 22:20