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 ...
随机推荐
- Java字符串(String)
从表面上看,字符串就是双引号之间的数据,例如“微学苑”.“http://www.weixueyuan.net”等.在Java中,可以使用下面的方法定义字符串: String stringName ...
- 解决android模拟器连接本机服务器”Connection refused”问题
在本机用模拟器连接 localhost 的服务器不成功,经查询是我反了一个小错误. android 模拟器其本身的localhost就是它自己的ip,而如果我要连接本机的localhost则需要将 ...
- /usr/local/lib/libz.a: could not read symbols: Bad value(64 位 Linux)
/usr/local/lib/libz.a: could not read symbols: Bad value(64 位 Linux) /usr/bin/ld: /usr/local/lib/lib ...
- 【spring boot】【mybatis】spring boot中mybatis打印sql语句
spring boot中mybatis打印sql语句,怎么打印出来?[参考:https://www.cnblogs.com/sxdcgaq8080/p/9100178.html] 在applicati ...
- SimpleDateFormat关于时间类的一些常用处理
项目中经常会出现对时间类的一些处理,记录一下: 实例一:/** * 获取当前时间是星期几? * * @param args */ public static void main(String[] ar ...
- python 中的 sorted
1) 输入help(sorted)可以得到下面类容: ------------------------------------------------------------------------- ...
- 基于Redis的Bloomfilter去重(转载)
转载:http://blog.csdn.net/bone_ace/article/details/53107018 前言 “去重”是日常工作中会经常用到的一项技能,在爬虫领域更是常用,并且规模一般都比 ...
- Node.js 网页瘸腿稍强点爬虫再体验
这回爬虫走得好点了,每次正常读取文章数目总是一样的,但是有程序僵住了情况,不知什么原因. 代码如下: // 内置http模块,提供了http服务器和客户端功能 var http=require(&qu ...
- 累加按钮,自加1&&输入两个数字,比较大小
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Windows虚拟内存如何设置
当我们在运行一些大型的软件,或者是刚刚退出游戏的时候经常会提示"你的虚拟内存过低"的提示,出现这种情况一般是:一:你的物理内存比较小,运行大的软件比较吃力:二:你运行了许多窗口或者 ...