php 生成8位数唯一的激活码
/**
*生成激活码
*/
function showGenerationActivationCode(){
#渠道类型id
$channel_id=$_POST['channel'];
#根据渠道id去查询渠道英文名称
$channelInfo = load_mysql ( "channelInfo" );
$_res=$channelInfo->getInfoById($channel_id);
$en_name=$_res['en_name'];
#活动类型
$type=$_POST['active_type'];
#生成数量
$nub=$_POST['nub'];
#连接redis
$redis=new Redis();
$redis->connect('192.168.1.133',8899);
#授权
$redis->auth("XXXXXX");
#存入数据
for($i=0;$i<$nub;$i++){
#接受生成的激活码
$ActivationCode=$this->showunique_rand(10000000,99999999,1);
#生成code
$code=$this->showAlgorithm_ActivationCode($type,$channel_id,$ActivationCode);
#写入redis
$redis->hmset('hash','code_hash',array('code'=>$code));
}
#写入redis
$redis->hmset('hash', 'channel_hash', array($en_name=> $channel_id ));
$this->PromptMsg = "生成成功!";
$this->UrlJump = "./index.php?module=operation&action=ActivationCode&menuId=168";
$this->promptMsg ();
}
/**
*生成code算法
*type:活动类型[取前三位]
*channel_id:渠道id[取前三位,不足以0填充]
*array_ActivationCode:激活码数组
*code算法格式=活动类型+渠道id+array_ActivationCode;
*return code的数组
*/
function showAlgorithm_ActivationCode($type,$channel_id,$ActivationCode){
#截取活动类型前位字符串
$type=mb_substr($type,0,3,'utf-8');
#渠道id[取前三位,不足左边以0填充]
$channel_id=str_pad($channel_id,3,'0',STR_PAD_LEFT);
#拼接code
$code=$type.''.$channel_id.''.$ActivationCode;
return $code;
}
/**
*生成8位数的激活码算法
*/
function showunique_rand($min, $max, $num=1) {
$count = 0;
$return = array();
while ($count < $num) {
$return[] = mt_rand($min, $max);
$return = array_flip(array_flip($return));
$count = count($return);
}
return $return[0];
}
php 生成8位数唯一的激活码的更多相关文章
- PHP 生成唯一的激活码
<? php /** * 生成永远唯一的激活码 * @return string */ function create_guid($namespace = null) { static $gui ...
- Python3.7 练习题(-) 如何使用Python生成200个优惠卷(激活码)
# 如何使用Python生成200个优惠卷(激活码) import random import string # string.ascii_letters 26个大小写 # -9数字 # 获得激活码中 ...
- PHP 生成唯一激活码
<?php /** * 从来没有产生一个唯一的激活码 * @return string */ function create_guid($namespace = null) { static $ ...
- Python 练习册--生成唯一激活码(邀请码)
题目是这样子的: 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? 分析 其实要生成 ...
- c# 自定义位数生成激活码
Random random = new Random(~unchecked((int)DateTime.Now.Ticks));private string CreateAndCheckCode(Ra ...
- php生成 优惠券 激活码
/** * 生成vip激活码 * @param int $nums 生成多少个优惠码 * @param array $exist_array 排除指定数组中的优惠码 * @param int $cod ...
- java生成随机六位数的验证码&随机生成十位数ValidCode码,用于邮件的验证&检查是不是符合为合法的中国的手机号码
package com.demo.test1; import java.security.NoSuchAlgorithmException; import java.security.SecureRa ...
- python3 生成随即激活码
import string import random #激活码中的字符和数字 field = string.ascii_letters + string.digits #获得四个字母和数字的随即组合 ...
- 如何使用Python生成200个优惠券(激活码)
解析: 常见的优惠券(激活码)是由数字.字母(大小写)组成: string.ascii_letters 26个大小写字母: string.digits 0-9数字: 随机组合 使用random.s ...
随机推荐
- red-lang
Red is a next-generation programming language strongly inspired by Rebol, but with a broader field o ...
- JAVA常见算法题(七)
package com.xiaowu.demo; /** * 输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. * * @author WQ * */ public class De ...
- depth linear
float ConvertDepth( float depthFromTex, float4 cameraParams ){ const float near = cameraParams.z; co ...
- 转: Eclispe的远程开发
from: http://www.thinksaas.cn/topics/0/528/528009.html 新项目中用到了所谓的Eclipse远程开发.参考: http://www.eclipse. ...
- 自己动手写android图片异步载入库
尊重他人劳动成果,转载请说明出处:http://blog.csdn.net/bingospunky/article/details/44344085 接触android有半年了.关于图片异步载入.一直 ...
- ubuntu18.04 安装mysql时'root'@'localhost'无法获取登录权限
查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password mysql> sel ...
- 使用SQLite存储数据
一.SQLiteAndroid 为了让我们能够更加方便地管理数据库, 专门提供了一个SQLiteOpenHelper 帮助类,借助这个类就可以非常简单地对数据库进行创建和升级. 1.SQLiteOpe ...
- 网络编程readn、writen和readline函数的编写
readn 在Linux中,read的声明为: ssize_t read(int fd, void *buf, size_t count); 它的返回值有以下情形: 1.大于0,代表成功读取的字节 ...
- List装form
List<MemberPrivilegeForm> formlist = new ArrayList<MemberPrivilegeForm>(); int status = ...
- 使用ByteRef加速String类型DocValues的载入
眼下商户索引DocValues很大,warmup时花费70-80秒(在beta环境),有62秒在载入DocValues,发现当中有54秒时间在载入string docvalues,string doc ...