/**
*生成激活码
*/
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位数唯一的激活码的更多相关文章

  1. PHP 生成唯一的激活码

    <? php /** * 生成永远唯一的激活码 * @return string */ function create_guid($namespace = null) { static $gui ...

  2. Python3.7 练习题(-) 如何使用Python生成200个优惠卷(激活码)

    # 如何使用Python生成200个优惠卷(激活码) import random import string # string.ascii_letters 26个大小写 # -9数字 # 获得激活码中 ...

  3. PHP 生成唯一激活码

    <?php /** * 从来没有产生一个唯一的激活码 * @return string */ function create_guid($namespace = null) { static $ ...

  4. Python 练习册--生成唯一激活码(邀请码)

    题目是这样子的: 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? 分析 其实要生成 ...

  5. c# 自定义位数生成激活码

    Random random = new Random(~unchecked((int)DateTime.Now.Ticks));private string CreateAndCheckCode(Ra ...

  6. php生成 优惠券 激活码

    /** * 生成vip激活码 * @param int $nums 生成多少个优惠码 * @param array $exist_array 排除指定数组中的优惠码 * @param int $cod ...

  7. java生成随机六位数的验证码&随机生成十位数ValidCode码,用于邮件的验证&检查是不是符合为合法的中国的手机号码

    package com.demo.test1; import java.security.NoSuchAlgorithmException; import java.security.SecureRa ...

  8. python3 生成随即激活码

    import string import random #激活码中的字符和数字 field = string.ascii_letters + string.digits #获得四个字母和数字的随即组合 ...

  9. 如何使用Python生成200个优惠券(激活码)

    解析: 常见的优惠券(激活码)是由数字.字母(大小写)组成: string.ascii_letters   26个大小写字母: string.digits 0-9数字: 随机组合 使用random.s ...

随机推荐

  1. [POI2014]Solar Panels

    题目大意: $T(T\le1000)$组询问,每次给出$A,B,C,D(A,B,C,D\le10^9)$,求满足$A\le x\le B,C\le y\le D$的最大的$\gcd(x,y)$. 思路 ...

  2. SQL表操作习题1

    建表

  3. sql server 性能调优 资源等待之网络I/O

    原文:sql server 性能调优 资源等待之网络I/O 一.概述 与网络I/O相关的等待的主要是ASYNC_NETWORK_IO,是指当sql server返回数据结果集给客户端的时候,会先将结果 ...

  4. Kyle 的 iOS 面试题

    1.简单介绍下你对swizzling方法的了解,一般你什么时候使用. 2.有三个对象 A,B,C..:A retain B, B retain C, C retain B..当 A release B ...

  5. IntelliJ全家桶修改terminal字体的方法

    IntelliJ IDEA 设置Terminal 窗口字体大小 我在Setting中查看了所有和Terminal字样有关的设置,都没有找到设置字体大小的方法,原来Terminal也只需要设置Conso ...

  6. webstorm编辑器设置为vim的方法

    首先有这个插件,其设置如下,选中即可 打开和关闭方法: https://www.jetbrains.com/help/webstorm/vim-emulation.html https://plugi ...

  7. api.js

    ylbtech-JavaScript-util: api.js API 代理接口 1.A,JS-效果图返回顶部   1.B,JS-Source Code(源代码)返回顶部 1.B.1, m.yinta ...

  8. 记一次有惊无险的Linux数据恢复过程

    问题阶段 起因: 昨天晚上思路不是很清晰(上了一天班回来有点蒙),还是强忍着疲惫想搞事情,结果悲剧了… … 本来想拿SD卡做一张linux烧录卡,烧录脚本是很久以前写的,有git记录,一直不成功,就回 ...

  9. spring boot 缺点优点?

    作者:八面山人链接:https://www.zhihu.com/question/39483566/answer/246333825来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  10. ES集群爆红,有未分配的片

    curl GET http://192.168.46.166:9200/_cluster/health?level=indices curl -XPUT '192.168.46.166:9200/_c ...