微信(weixin)大转盘抽奖页面、数据库以及抽奖算法(PHP源码...
在做http://www.111cn.net/list-271/的过程中用到了微信抽奖,看了其他的作者都只是吧微信抽奖的页面共享出来了。作者现在把转盘抽奖程序和微信抽奖页面都共享出来,有需要的自己把两者组合一下即可。
http://uni-key.com/c/data/attachment/forum/201501/29/171243c356lp35mz5chg33.jpg **2014030702013262.jpg** _(35.14 KB, 下载次数: 0)_
http://uni-key.com/c/forum.php?mod=attachment&aid=Mnw0OGQyNmM1OXwxNDIyODQzMDc5fDExfDIy¬humb=yes
4 天前 上传
部份源码:配置文件
return array (
'DB_TYPE' => 'mysql',
'DB_HOST' => '127.0.0.1',
'DB_NAME' => 'ites',
'DB_USER' => 'root',
'DB_PWD' => '111111',
'DB_PORT' => 3306,
'DB_PREFIX' => 'it_',
'APP_DEBUG' => 1,
'SHOW_ERROR_MSG' => 1,
'SHOW_PAGE_TRACE' => 1,
'DATA_CACHE_TYPE' => 'Redis',
'REDIS_HOST' => '127.0.0.1',
'REDIS_PORT' => 6379,
'DATA_CACHE_TIME' => 3600,
'URL_CASE_INSENSITIVE' => true,
'TMPL_STRIP_SPACE' => false,
'URL_HTML_SUFFIX' => '',
'SITE_NAME' => '11111',
'SITE_URL' => 'http://www.111cn.net/',
'WECHAT_TOKEN' => '你的',
'WECHAT_APPID' => '你的',
'WECHAT_APPSECRET' => '你的',
'DATA_AUTH_KEY' => 'abcdddd',
);
?>
_复制代码_
commond.php文件
function isMobile($mobile) {
return preg_match("/^(?:13d|14d|15d|18)-?d{5}(d{3}|*{3})$/", $mobile);
}
function isEmail($email) {
return strlen($email) > 6 && preg_match("/^+@+(.w+)+$/", $email);
}
/**
* 发送HTTP请求方法,目前只支持CURL发送请求
* @param string $url 请求URL
* @param array $params 请求参数
* @param string $method 请求方法GET/POST
* @return array $data 响应数据
*/
function http($url, $params, $method = 'GET', $header = array(), $multi = false){
$opts = array(
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $header
);
/* 根据请求类型设置特定参数 */
switch(strtoupper($method)){
case 'GET':
$opts = $url . '?' . http_build_query($params);
break;
case 'POST':
//判断是否传输文件
//$params = $multi ? $params : http_build_query($params);
$opts = $url;
$opts = 1;
$opts = $params;
break;
default:
throw new Exception('不支持的请求方式!');
}
/* 初始化并执行curl请求 */
$ch = curl_init();
curl_setopt_array($ch, $opts);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if($error) throw new Exception('请求发生错误:' . $error);
return $data;
}
/**
* 不转义中文字符和/的 json 编码方法
* @param array $arr 待编码数组
* @return string
*/
function jsencode($arr) {
$str = str_replace ( "\/", "/", json_encode ( $arr ) );
$search = "#\u(+)#ie";
if (strpos ( strtoupper(PHP_OS), 'WIN' ) === false) {
$replace = "iconv('UCS-2BE', 'UTF-8', pack('H4', '\1'))";//LINUX
} else {
$replace = "iconv('UCS-2', 'UTF-8', pack('H4', '\1'))";//WINDOWS
}
return preg_replace ( $search, $replace, $str );
}
// 数据保存到文件
function data2file($filename, $arr=''){
if(is_array($arr)){
$con = var_export($arr,true);
$con = "";
} else{
$con = $arr;
$con = "";
}
write_file($filename, $con);
}
/**
* 系统加密方法
* @param string $data 要加密的字符串
* @param string $key 加密密钥
* @param int $expire 过期时间 单位 秒
* @return string
* @author winky
*/
function encrypt($data, $key = '', $expire = 0) {
$key = md5(empty($key) ? C('DATA_AUTH_KEY') : $key);
$data = base64_encode($data);
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) $x = 0;
$char .= substr($key, $x, 1);
$x++;
}
$str = sprintf('%010d', $expire ? $expire + time():0);
for ($i = 0; $i < $len; $i++) {
$str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1)))%256);
}
return str_replace(array('+','/','='),array('-','_',''),base64_encode($str));
}
/**
* 系统解密方法
* @param string $data 要解密的字符串 (必须是encrypt方法加密的字符串)
* @param string $key 加密密钥
* @return string
* @author winky
*/
function decrypt($data, $key = ''){
$key = md5(empty($key) ? C('DATA_AUTH_KEY') : $key);
$data = str_replace(array('-','_'),array('+','/'),$data);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
$data = base64_decode($data);
$expire = substr($data,0,10);
$data = substr($data,10);
if($expire > 0 && $expire < time()) {
return '';
}
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = $str = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) $x = 0;
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1))
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
}else{
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return base64_decode($str);
}
function getTaskStatusStr($status = 0,$type = 'apply' , $company = ''){
if ($type == 'comment') return '尚未作出评价';
switch ($status) {
case 0:
return $type == 'apply' ? '已发出任务申请' : $company.'对你发出了任务邀请';
break;
case 1:
return $type == 'apply' ? '企业已通过申请' : '已同意企业的邀请';
break;
case 2:
return $type == 'apply' ? '企业已忽略你的申请' : '你已经忽略企业的邀请';
break;
case 3:
return $type == 'apply' ? '你已完成该任务' : '该任务已经完成';
break;
default:
return '未知的状态';
break;
}
}
function getArea($cache = true){
$area = S ( 'S_Area' );
if (empty ( $area ) || ! $cache) {
// 缓存不存在,或者参数读取缓存。
$areaModel = D('Area');
$area = $areaModel -> where ('status = 3')->order ( 'sort,itemid' )->getField('itemid,title,pid,arrparentid,child');
//把市的省拚出来
foreach ($area as $k=>$v){
//如果是顶级
if ($v==0){
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
//上级
$areaArr[$v] = $v;
$areaArr[$v] = $v;
}
//查出上级的名称和ID
else {
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
//上级
$areaArr[$v] = $area[$v];
$areaArr[$v] = $area[$v];
}
}
$area = $areaArr;
S ( 'S_Area' , $area );
}
return $area;
}
?>
_复制代码_
附件由于附件过大,请在作者发布链接下载
转自:http://www.111cn.net/phper/php-cy/58547.htm
http://uni-key.com/c/data/attachment/forum/201501/29/171243c356lp35mz5chg33.jpg **2014030702013262.jpg** _(35.14 KB, 下载次数: 0)_
http://uni-key.com/c/forum.php?mod=attachment&aid=Mnw0OGQyNmM1OXwxNDIyODQzMDc5fDExfDIy¬humb=yes
4 天前 上传
部份源码:配置文件
return array (
'DB_TYPE' => 'mysql',
'DB_HOST' => '127.0.0.1',
'DB_NAME' => 'ites',
'DB_USER' => 'root',
'DB_PWD' => '111111',
'DB_PORT' => 3306,
'DB_PREFIX' => 'it_',
'APP_DEBUG' => 1,
'SHOW_ERROR_MSG' => 1,
'SHOW_PAGE_TRACE' => 1,
'DATA_CACHE_TYPE' => 'Redis',
'REDIS_HOST' => '127.0.0.1',
'REDIS_PORT' => 6379,
'DATA_CACHE_TIME' => 3600,
'URL_CASE_INSENSITIVE' => true,
'TMPL_STRIP_SPACE' => false,
'URL_HTML_SUFFIX' => '',
'SITE_NAME' => '11111',
'SITE_URL' => 'http://www.111cn.net/',
'WECHAT_TOKEN' => '你的',
'WECHAT_APPID' => '你的',
'WECHAT_APPSECRET' => '你的',
'DATA_AUTH_KEY' => 'abcdddd',
);
?>
_复制代码_
commond.php文件
function isMobile($mobile) {
return preg_match("/^(?:13d|14d|15d|18)-?d{5}(d{3}|*{3})$/", $mobile);
}
function isEmail($email) {
return strlen($email) > 6 && preg_match("/^+@+(.w+)+$/", $email);
}
/**
* 发送HTTP请求方法,目前只支持CURL发送请求
* @param string $url 请求URL
* @param array $params 请求参数
* @param string $method 请求方法GET/POST
* @return array $data 响应数据
*/
function http($url, $params, $method = 'GET', $header = array(), $multi = false){
$opts = array(
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $header
);
/* 根据请求类型设置特定参数 */
switch(strtoupper($method)){
case 'GET':
$opts = $url . '?' . http_build_query($params);
break;
case 'POST':
//判断是否传输文件
//$params = $multi ? $params : http_build_query($params);
$opts = $url;
$opts = 1;
$opts = $params;
break;
default:
throw new Exception('不支持的请求方式!');
}
/* 初始化并执行curl请求 */
$ch = curl_init();
curl_setopt_array($ch, $opts);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if($error) throw new Exception('请求发生错误:' . $error);
return $data;
}
/**
* 不转义中文字符和/的 json 编码方法
* @param array $arr 待编码数组
* @return string
*/
function jsencode($arr) {
$str = str_replace ( "\/", "/", json_encode ( $arr ) );
$search = "#\u(+)#ie";
if (strpos ( strtoupper(PHP_OS), 'WIN' ) === false) {
$replace = "iconv('UCS-2BE', 'UTF-8', pack('H4', '\1'))";//LINUX
} else {
$replace = "iconv('UCS-2', 'UTF-8', pack('H4', '\1'))";//WINDOWS
}
return preg_replace ( $search, $replace, $str );
}
// 数据保存到文件
function data2file($filename, $arr=''){
if(is_array($arr)){
$con = var_export($arr,true);
$con = "";
} else{
$con = $arr;
$con = "";
}
write_file($filename, $con);
}
/**
* 系统加密方法
* @param string $data 要加密的字符串
* @param string $key 加密密钥
* @param int $expire 过期时间 单位 秒
* @return string
* @author winky
*/
function encrypt($data, $key = '', $expire = 0) {
$key = md5(empty($key) ? C('DATA_AUTH_KEY') : $key);
$data = base64_encode($data);
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) $x = 0;
$char .= substr($key, $x, 1);
$x++;
}
$str = sprintf('%010d', $expire ? $expire + time():0);
for ($i = 0; $i < $len; $i++) {
$str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1)))%256);
}
return str_replace(array('+','/','='),array('-','_',''),base64_encode($str));
}
/**
* 系统解密方法
* @param string $data 要解密的字符串 (必须是encrypt方法加密的字符串)
* @param string $key 加密密钥
* @return string
* @author winky
*/
function decrypt($data, $key = ''){
$key = md5(empty($key) ? C('DATA_AUTH_KEY') : $key);
$data = str_replace(array('-','_'),array('+','/'),$data);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
$data = base64_decode($data);
$expire = substr($data,0,10);
$data = substr($data,10);
if($expire > 0 && $expire < time()) {
return '';
}
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = $str = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) $x = 0;
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1))
}else{
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return base64_decode($str);
}
function getTaskStatusStr($status = 0,$type = 'apply' , $company = ''){
if ($type == 'comment') return '尚未作出评价';
switch ($status) {
case 0:
return $type == 'apply' ? '已发出任务申请' : $company.'对你发出了任务邀请';
break;
case 1:
return $type == 'apply' ? '企业已通过申请' : '已同意企业的邀请';
break;
case 2:
return $type == 'apply' ? '企业已忽略你的申请' : '你已经忽略企业的邀请';
break;
case 3:
return $type == 'apply' ? '你已完成该任务' : '该任务已经完成';
break;
default:
return '未知的状态';
break;
}
}
function getArea($cache = true){
$area = S ( 'S_Area' );
if (empty ( $area ) || ! $cache) {
// 缓存不存在,或者参数读取缓存。
$areaModel = D('Area');
$area = $areaModel -> where ('status = 3')->order ( 'sort,itemid' )->getField('itemid,title,pid,arrparentid,child');
//把市的省拚出来
foreach ($area as $k=>$v){
//如果是顶级
if ($v==0){
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
//上级
$areaArr[$v] = $v;
$areaArr[$v] = $v;
}
//查出上级的名称和ID
else {
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
$areaArr[$v] = $v;
//上级
$areaArr[$v] = $area[$v];
$areaArr[$v] = $area[$v];
}
}
$area = $areaArr;
S ( 'S_Area' , $area );
}
return $area;
}
?>
_复制代码_
附件由于附件过大,请在作者发布链接下载
转自:http://www.111cn.net/phper/php-cy/58547.htm
没有找到相关结果
已邀请:
0 个回复