代码拉取完成,页面将自动刷新
同步操作将从 吾道建站/lipinwang_demo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
use think\Db;
use think\Session;
use think\Cookie;
use think\Cache;
//判断是否是手机
function isMobile()
{
if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
{
return true;
}
if (isset ($_SERVER['HTTP_VIA']))
{
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
if (isset ($_SERVER['HTTP_USER_AGENT']))
{
$clientkeywords = array ('nokia',
'sony',
'ericsson',
'mot',
'samsung',
'htc',
'sgh',
'lg',
'sharp',
'sie-',
'philips',
'panasonic',
'alcatel',
'lenovo',
'iphone',
'ipod',
'blackberry',
'meizu',
'android',
'netfront',
'symbian',
'ucweb',
'windowsce',
'palm',
'operamini',
'operamobi',
'openwave',
'nexusone',
'cldc',
'midp',
'wap',
'mobile'
);
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
{
return true;
}
}
if (isset ($_SERVER['HTTP_ACCEPT']))
{
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
{
return true;
}
}
return false;
}
/**
* 邮件发送函数
*/
function sendMail($to,$yzm,$title, $content) {
import('Vendor.PHPMailer.smtp');
import('Vendor.PHPMailer.phpmailer');
$mail = new \PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->SMTPDebug =C('SMTPDebug');//开启调试
$mail->Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)
$mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
$mail->Port =C('MAIL_PORT');//服务器的端口号
$mail->SMTPSecure = C('MAIL_SECURE'); //启用smtp认证
$mail->Username = C('MAIL_USERNAME'); //你的邮箱名
$mail->Password = C('MAIL_PASSWORD') ; //邮箱密码
$mail->From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址)
$mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
$mail->AddAddress($to,"尊敬的客户");
$mail->WordWrap = 50; //设置每行字符长度
$mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
$mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
$mail->Subject =$title; //邮件主题
$mail->Body = $content; //邮件内容
$mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
$res=$mail->Send();
if($res){
$db=Db::name('yzm');
$_POST['typeid']=2;
$_POST['username']=$to;
$_POST['yzm']=$yzm;
$_POST['status']=0;
$_POST['sendtime']=time();
if($db->insert($_POST)){
echo "邮箱短信验证码发送成功!";
}
}
return ;
}
//从当前URL中去掉某个参数之后的URL
function filterUrl($param){
// 先取出当前的URL地址
$url = $_SERVER['PHP_SELF'];
// 正则去掉某个参数
$re = "/\/$param\/[^\/]+/";
return preg_replace($re, '', $url);
}
//使用一个表中的数据制作下拉框
function buildSelect($tableName, $selectName, $valueFieldName, $textFieldName, $selectedValue = ''){
$model = D($tableName);
$data = $model->field("$valueFieldName,$textFieldName")->select();
$select = "<select name='$selectName'><option value=''>请选择</option>";
foreach ($data as $k => $v)
{
$value = $v[$valueFieldName];
$text = $v[$textFieldName];
if($selectedValue && $selectedValue==$value)
$selected = 'selected="selected"';
else
$selected = '';
$select .= '<option '.$selected.' value="'.$value.'">'.$text.'</option>';
}
$select .= '</select>';
echo $select;
}
function msectime() {
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000).rand(3);
return $msectime;
}
//上传图片
function uploadimgOne($imgName, $dirName, $thumb = array()){
// 上传LOGO
if(isset($_FILES[$imgName]) && $_FILES[$imgName]['error'] == 0){
$ic = C('IMAGE_CONFIG');
$upload = new \Think\Upload(array(
'rootPath' => $ic['rootPath'],
'maxSize' => $ic['maxSize'],
'exts' => $ic['exts'],
));// 实例化上传类
$upload->saveName ='msectime';
$upload->subName = array('date','Ymd');
$upload->savePath = $dirName . '/'; // 图片二级目录的名称
// 上传文件
// 上传时指定一个要上传的图片的名称,否则会把表单中所有的图片都处理,之后再想其他图片时就再找不到图片了
$info = $upload->upload(array($imgName=>$_FILES[$imgName]));
if(!$info){
return array(
'ok' => 0,
//'error' => $upload->getError(),
);
}else{
$ret['ok'] = 1;
$ret['images'][0] = $logoName = $info[$imgName]['savepath'] . $info[$imgName]['savename'];
// 判断是否生成缩略图
if($thumb){
$image = new \Think\Image();
// 循环生成缩略图
foreach ($thumb as $k => $v){
$ret['images'][$k+1] = $info[$imgName]['savepath'] . 'thumb_'.$k.'_' .$info[$imgName]['savename'];
// 打开要处理的图片
$image->open($ic['rootPath'].$logoName);
$image->thumb($v[0], $v[1],$image::IMAGE_THUMB_FIXED)->save($ic['rootPath'].$ret['images'][$k+1]);
}
}
$ret['newsavepath']= $ic['viewPath'].$ret['images'][0];
return $ret;
}
}
}
//上传文件
function uploadfileOne($imgName, $dirName)
{
// 上传上传文件
if(isset($_FILES[$imgName]) && $_FILES[$imgName]['error'] == 0){
$ic = C('File_CONFIG');
$upload = new \Think\Upload(array(
'rootPath' => $ic['rootPath'],
'maxSize' => $ic['maxSize'],
'exts' => $ic['exts'],
));// 实例化上传类
$upload->subName = array('date','Ymd');
$upload->savePath = $dirName . '/'; // 图片二级目录的名称
// 上传文件
// 上传时指定一个要上传的图片的名称,否则会把表单中所有的图片都处理,之后再想其他图片时就再找不到图片了
$info = $upload->upload(array($imgName=>$_FILES[$imgName]));
if(!$info){
return array(
'ok' => 0,
'error' => $upload->getError(),
);
}else{
$ret['ok'] = 1;
$ret['images'][0] = $logoName = $info[$imgName]['savepath'] . $info[$imgName]['savename'];
$ret['newsavepath']= $ic['viewPath'].$ret['images'][0];
return $ret;
}
}
}
/**
* 生成随机数
*/
function random($length, $numeric = 0) {
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
} else {
$hash = '';
$chars = '0123456789';
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
//获取导航URL
function get_nav_url($pid,$ty,$tty){
if($tty){
$mc=get_zd_name("templet","sort","id={$ty}");
$str=url('List/'.$mc,"pid={$pid}/ty/{$ty}/tty/{$ty}/tty/{$tty}");
}elseif($ty){
//$mc=get_sort_zd($ty,'inlinkurl');
$mc=get_zd_name("templet","sort","id={$ty}");
$str=url('List/'.$mc,"pid/{$pid}/ty/{$ty}");
}else{
//$mc=get_sort_zd($pid,'inlinkurl');
$mc=get_zd_name("templet","sort","id={$pid}");
$str=url('List/'.$mc,"pid/{$pid}");
}
return $str;
}
//字符截取
function cutstr_html($string, $sublen){
$string = htmlspecialchars_decode($string);
$string = strip_tags($string);
$string = preg_replace ('/\n/is', '', $string);
$string = preg_replace ('/ | /is', '', $string);
$string = preg_replace ('/ /is', '', $string);
preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $t_string);
if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen))."…";
else $string = join('', array_slice($t_string[0], 0, $sublen));
return $string;
}
function cutstr($string, $length, $dot='...') {
global $charset;
if(strlen($string) <= $length) {
return $string;
}
$string = str_replace(array('&', '"', ''', '<', '>'), array('&', '"', '\'', '<', '>'), $string);
$string = str_replace(' ', ' ', $string);
$strcut = '';
if(strtolower($charset) == 'utf-8') {
$n = $tn = $noc = 0;
while($n < strlen($string)) {
$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1; $n++; $noc++;
} elseif(194 <= $t && $t <= 223) {
$tn = 2; $n += 2; $noc += 2;
} elseif(224 <= $t && $t < 239) {
$tn = 3; $n += 3; $noc += 2;
} elseif(240 <= $t && $t <= 247) {
$tn = 4; $n += 4; $noc += 2;
} elseif(248 <= $t && $t <= 251) {
$tn = 5; $n += 5; $noc += 2;
} elseif($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
}
if($noc >= $length) {
break;
}
}
if($noc > $length) {
$n -= $tn;
}
$strcut = substr($string, 0, $n);
} else {
for($i = 0; $i < $length - strlen($dot) - 1; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
}
$strcut = str_replace(array('&', '"', '\'', '<', '>'), array('&', '"', ''', '<', '>'), $strcut);
return $strcut.$dot;
}
//获取新闻表字段内容
function get_single_content($pid,$ty,$tty=0,$ttty=0,$zd='content'){
$str="";
if($pid) $sqlkey=" AND pid={$pid}";
if($ty) $sqlkey.=" AND ty={$ty}";
if($tty) $sqlkey.=" AND tty={$tty}";
if($ttty) $sqlkey.=" AND ttty={$ttty}";
$list=Db::name('news')->field($zd)->where("status=1{$sqlkey}")->find();
return $list;
}
//获取关联信息
function get_titlepics($pid,$zd="*",$num=8,$limit=0,$desc='desc'){
$str="";
if($pid){
$list=Db::name('titlepic')->field($zd)->where("status=1 AND pid={$pid}")->order("id {$desc}")->limit($limit,$num)->select();
return $list;
}
}
//获取新闻列表
function get_news_good($pid,$ty,$tty=0,$ttty=0,$zd="*",$num=8,$limit=0,$desc='desc'){
$str="";
$q=trim($_GET['q']);
if($pid) $sqlkey=" AND pid={$pid}";
if($ty) $sqlkey.=" AND ty={$ty}";
if($tty) $sqlkey.=" AND tty={$tty}";
if($ttty) $sqlkey.=" AND ttty={$ttty}";
if($q) $sqlkey .= " and title like '%".$q."%'";
$list=Db::name('news')->field($zd)->where("status=1 AND isgood=1{$sqlkey}")->order("disorder desc,id {$desc}")->limit($limit,$num)->select();
return $list;
}
//自定义表读取
function get_mytable($table,$num=10,$where,$zd="*",$limit=0,$order="id desc"){
$list=Db::name($table)->field($zd)->where("status=1{$where}")->order($order)->limit($limit,$num)->select();
return $list;
}
//获取新闻列表
function get_news($pid,$ty,$tty=0,$ttty=0,$zd="*",$num=8,$limit=0,$desc='desc'){
$str="";
$q=input('q');
if($pid) $sqlkey=" AND pid={$pid}";
if($ty) $sqlkey.=" AND ty={$ty}";
if($tty) $sqlkey.=" AND tty={$tty}";
if($ttty) $sqlkey.=" AND ttty={$ttty}";
if($q) $sqlkey .= " and title like '%".$q."%'";
$list=Db::name('news')->field($zd)->where("status=1{$sqlkey}")->order("disorder desc,id {$desc}")->limit($limit,$num)->select();
return $list;
}
//获取新闻列表
function get_news_pic($pid,$ty,$tty=0,$ttty=0,$zd="*",$num=8,$limit=0,$desc='desc'){
$str="";
$q=trim($_GET['q']);
if($pid) $sqlkey=" AND pid={$pid}";
if($ty) $sqlkey.=" AND ty={$ty}";
if($tty) $sqlkey.=" AND tty={$tty}";
if($ttty) $sqlkey.=" AND ttty={$ttty}";
if($q) $sqlkey .= " and title like '%".$q."%'";
$list=Db::name('news')->field($zd)->where("status=1 AND img1<>''{$sqlkey}")->order("disorder desc,id {$desc}")->limit($limit,$num)->select();
return $list;
}
//获取新闻列表
function get_news_fy($pagesize=8,$pid,$ty,$tty=0,$ttty=0,$zd='*',$desc='desc'){
$sqlkey='';
$gpid=input('pid',0);
$gty=input('ty',0);
$gtty=input('tty',0);
$gttty=input('ttty',0);
$q=trim($_GET['q']);
if($gpid) $pid=$gpid;else $pid=$pid;
if($gty) $ty=$gty;else $ty=$ty;
if($gtty) $tty=$gtty;else $tty=$tty;
if($gttty) $ttty=$gttty;else $ttty=$ttty;
if($q) $sqlkey .= " and title like '%".$q."%'";
$sqlkey="status=1";
if($pid) $sqlkey.=" AND pid={$pid}";
if($ty) $sqlkey.=" AND ty={$ty}";
if($tty) $sqlkey.=" AND tty={$tty}";
if($ttty) $sqlkey.=" AND ttty={$ttty}";
$list = Db::name('news')->field($zd)->where($sqlkey)->order("disorder desc,id {$desc}")->paginate($pagesize);
return $list;
}
//获取新闻分页
function get_news_fym($pagesize=8,$pid,$ty,$tty=0,$ttty=0){
$db=D('news');
$gpid=I('get.pid',0);
$gty=I('get.ty',0);
$gtty=I('get.tty',0);
$gttty=I('get.ttty',0);
$q=trim($_GET['q']);
if($gpid) $pid=$gpid;else $pid=$pid;
if($gty) $ty=$gty;else $ty=$ty;
if($gtty) $tty=$gtty;else $tty=$tty;
if($gttty) $ttty=$gttty;else $ttty=$ttty;
$sqlkey="status=1";
if($pid) $sqlkey.=" AND pid={$pid}";
if($ty) $sqlkey.=" AND ty={$ty}";
if($tty) $sqlkey.=" AND tty={$tty}";
if($ttty) $sqlkey.=" AND ttty={$ttty}";
if($q) $sqlkey .= " and title like '%".$q."%'";
$count = $db->where($sqlkey)->count();
$Page = new \Think\WebPage($count,$pagesize);
$Pageshow = $Page->show();
return $Pageshow;
}
//获取指定URL链接
function get_cur($pid,$str,$vpid){
if($pid==input('pid',0)&&$pid>0||$pid==$vpid&&$pid>0||$pid==$vpid&&$pid==0&&input('get.pid')==0) $cur=$str;else $cur='';
return $cur;
}
//获取指定URL链接
function get_url($id,$c='List',$m='View'){
$myurl=url("{$c}/{$m}/id/{$id}");
return $myurl;
}
//获取指定URL链接
function get_sort_url($pid,$ty,$tty,$m='View',$c='List'){
$myurl=url("{$c}/{$m}/pid/{$pid}/ty/{$ty}/tty/{$tty}");
return $myurl;
}
//获取指定图片
function get_img($v,$defaultimg='/Uploads/nopic.jpg'){
if($v) $myimg=$v;else $myimg=$defaultimg;
return $myimg;
}
//获取指定见时间
function get_time($v,$default='Y-m-d'){
if($v) $mytime=date($default,$v);
return $mytime;
}
//获取指定见时间
function get_content($v,$len='0'){
if($len) $myvalue=cutstr_html($v,$len);else $myvalue=$v;
return $myvalue;
}
//我的上一篇
function get_prev($id){
$db=Db::name('news');
$v=$db->where("status=1 AND id={$id}")->find();
if($v['disorder']) $ss1=" and disorder>{$v['disorder']} ";else $ss1=" and id>{$id}";
$list=$db->field('id,title')->where("pid={$v['pid']} and ty={$v['ty']} and status=1 {$ss1}")->order("disorder asc,id asc")->limit(1)->select();
return $list;
}
//我的下一篇
function get_next($id){
$db=Db::name('news');
$v=$db->where("status=1 AND id={$id}")->find();
if($v['disorder']) $ss1=" and disorder<{$v['disorder']} ";else $ss1=" and id<{$id}";
$list=$db->field('id,title')->where("pid={$v['pid']} and ty={$v['ty']} and status=1 {$ss1}")->order("disorder desc,id desc")->limit(1)->select();
return $list;
}
//我的详情
function get_view($myid,$table="news"){
$db=Db::name($table);
if($myid) $id=$myid;else $id=I('get.id',0);
$v=$db->where("status=1 AND id={$id}")->limit(1)->select();
$count=$db->where("status=1 AND id={$id}")->count();
if($v&&$count){
if($table=='news'){
$sqls="update tp_news set hits=hits+1 where id={$id}";
Db()->execute($sqls);
}
}else{
echo "<script>alert('访问出错');location.href='/'</script>";
exit();
}
return $v;
}
//生成orderid
function get_orderid(){
$curDateTime = date("ymdHis");
$strDate = date("ymd");
$strTime = date("His");
//4位隨機數
$randNum = rand(1000, 9999);
//10位序列號,可以自行調整。
$strReq = $strTime . $randNum;
/* 商家的定單號 */
$orderid = $curDateTime . $randNum;
return $orderid;
}
//封装https请求(GET和POST)
function https_requests($url,$data=null){
//1、初始化curl
$ch = curl_init();
//2、设置传输选项
curl_setopt($ch, CURLOPT_URL, $url);//请求的url地址
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//将请求的结果以文件流的形式返回
if(!empty($data))
{
curl_setopt($ch,CURLOPT_POST,1);//请求POST方式
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//POST提交的内容
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);////设定是否显示头信息
curl_setopt($ch,CURLOPT_HEADER,false);//设定是否输出页面内容
//3、执行请求并处理结果
$outopt = curl_exec($ch);
if($outopt===false){
echo "error".curl_error($ch)."<br>";
}
//4、关闭curl
curl_close($ch);
return $outopt;
}
function https_request($url,$data=null){
$ch = curl_init(); //初始化curl
curl_setopt($ch,CURLOPT_URL, $url);//请求的url地址
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization:Bearer 2cdaddd100f2a7feaa4172a8b2d199ab48eb7ec0a0f056a77a38473ced357bf8','Content-Type:application/json'));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//将请求的结果以文件流的形式返回
curl_setopt($ch,CURLOPT_POST,1);//请求POST方式
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//POST提交的内容
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);////设定是否显示头信息
curl_setopt($ch,CURLOPT_HEADER,false);//设定是否输出页面内容
$outopt = curl_exec($ch); //执行请求并处理结果
if($outopt===false){
echo "error".curl_error($ch)."<br>";
}
curl_close($ch); //关闭curl
return $outopt;
}
function randoms($length = 6 , $numeric = 0) {
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
} else {
$hash = '';
/* $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';*/
$chars = '0123456789';
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
//PHP stdClass Object转array
function object_array($array) {
if(is_object($array)) {
$array = (array)$array;
} if(is_array($array)) {
foreach($array as $key=>$value) {
$array[$key] = object_array($value);
}
}
return $array;
}
//短信发送
function sendSms($tel,$yzm,$code) {
import('Vendor.Sms.SignatureHelper');
$params = array ();
// *** 需用户填写部分 ***
// fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
$accessKeyId = "LTAI4Fhh995iPVKCQh8bBymo";
$accessKeySecret = "tdRzpdn3SQV9WpJOdJ1ECd2wowfVNc";
// fixme 必填: 短信接收号码
$params["PhoneNumbers"] = $tel;
// fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
$params["SignName"] = "东联和信";
// fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
$params["TemplateCode"] = $code;
// fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
$params['TemplateParam'] = Array (
"code" => $yzm
);
// fixme 可选: 设置发送短信流水号
$params['OutId'] = "12345";
// fixme 可选: 上行短信扩展码, 扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段
$params['SmsUpExtendCode'] = "1234567";
// *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
$params["TemplateParam"] = json_encode($params["TemplateParam"]);
}
// 初始化SignatureHelper实例用于设置参数,签名以及发送请求
$helper = new \SignatureHelper();
// 此处可能会抛出异常,注意catch
$content = $helper->request(
$accessKeyId,
$accessKeySecret,
"dysmsapi.aliyuncs.com",
array_merge($params, array(
"RegionId" => "cn-hangzhou",
"Action" => "SendSms",
"Version" => "2017-05-25",
))
);
$arr=object_array($content);
if($arr['Code']=='OK'){
$db=Db::name('yzm');
$_POST['typeid']=1;
$_POST['username']=$tel;
$_POST['yzm']=$yzm;
$_POST['status']=0;
$_POST['sendtime']=time();
if($db->insert($_POST)){
echo "手机短信验证码发送成功!";
}
}
//return $content;
}
function sms_send($data){
//print_r($data);
$ch = curl_init();
/* 设置验证方式 */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
/* 设置返回结果为流 */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/* 设置超时时间*/
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
/* 设置通信方式 */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$outopt = curl_exec($ch);
if($outopt===false){
echo "error".curl_error($ch);
}
return $outopt;
}
//导航选中状态
function get_on($v1,$v2,$c){
$arr=explode("|",$v2);
//echo count($arr);
if(count($arr)>1){
for($i=0;$i<=count($arr);$i++){
if($arr[$i]==$v1) return $c;
}
}else{
if($v1==$v2) return $c;
}
}
//类别id
function get_son_count($typeid=0,$fid,$table="type"){
if($typeid) $sqlkey=" AND typeid={$typeid}";
$arr=Db::name($table)->where("pid={$fid}{$sqlkey}")->count();
return (int)$arr;
}
//获取指定表内容
function get_zd_name($zd='',$table='',$where){
$list=Db::name($table)->field($zd)->where($where)->find();
return $list[$zd];
}
//获取系统设置参数
function sys($varname){
$str="";
$str=Cache::get("{$varname}");
return $str;
}
//获取产品分类
function get_nextid($pid=0){
$arr=Db::name('sort')->field('id')->order('disorder asc,id asc')->where("status=1 and pid={$pid}")->find();
return $arr['id'];
}
//我的默认值
function get_my_value($myvalue,$default){
if($myvalue) $str=$myvalue;else $str=$default;
return $str;
}
//我的默认值
function get_my_checked($myvalue,$default){
if($myvalue==$default) $check_str='checked'; else $check_str='';
return $check_str;
}
//根据条件获取
function get_table_list($table,$sqlkey,$zd="*",$limit="999999999"){
$list=Db::name($table)->field($zd)->where("status=1{$sqlkey}")->order('id asc')->limit($limit)->select();
return $list;
}
//获取分类相关字段
function get_sort_zd($id,$zd='catname'){
$arr=Cache::get("sort_{$id}");
if($zd<>'catname'){
$str=$arr[$zd];
}else{
if($arr[$zd]) $str=$arr[$zd];elseif($zd<>'imgsize'&&$zd<>'imgname') $str=$arr['catname'];else $str='';
}
return $str;
}
//获取分类相关字段
function get_forms_zd($id,$zd='tablename'){
$arr=Cache::get("forms_{$id}");
$str=$arr[$zd];
return $str;
}
//获取类别相关字段
function get_type_zd($id,$zd='catname'){
$arr=Cache::get("type_{$id}");
return $arr[$zd];
}
//获取模块相关字段
function get_model_zd($module_id,$zd='model_name'){
$arr=Cache::get("model_{$module_id}");
return $arr[$zd];
}
//获取角色相关字段
function get_role_zd($role_id,$zd='role_name'){
$arr=Cache::get("role_{$role_id}",$zd);
return $arr[$zd];
}
//获取会员相关字段
function get_user_zd($uid,$zd='nickname'){
//if($uid) $uid=$uid;else $uid=cookie('user_id');
//$arr=F("user_{$uid}", '', TEMP_PATH);
$arr=D('user')->field($zd)->find($uid);
return $arr[$zd];
}
//按条件获取数量
function get_count($table,$where){
$count=Db::name($table)->where($where)->count();
return (int)$count;
}
//调用会员表中的资料信息
function get_user_list($zd='*',$guid){
$uid=cookie('user_id');
if($guid) $uid=$guid;else $uid=$uid;
$users=Db::name('user')->field($zd)->find($uid);
$users['tx']=$users['img1']?$users['img1']:'Uploads/nophoto.jpg';
return $users;
}
//购物车商品数
function get_cart_count(){
//$orderid=session('temp_orderid');
$uid=cookie('user_id');
if($uid){
$count=Db::name('tempdata')->where("uid={$uid}")->count();
}else{
$count=0;
}
return (int)$count;
}
//图片下载
function http_down($url, $filename, $timeout = 60) {
$path = dirname($filename);
if (!is_dir($path) && !mkdir($path, 0755, true)) {
return false;
}
$fp = fopen($filename, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return $filename;
}
//购物车商品价格
function get_cart_momey($ids){
if($ids) $where=" AND id in(".$ids.")";
$uid=cookie('user_id');
$orderid=session('temp_orderid');
$arr=Db::name('tempdata')->field('sum(buynum*buyprice) as money')->where("orderid={$orderid} AND uid={$uid}{$where} ")->find();
return $arr['money'];
}
//购物车商品税费
function get_cart_tax_momey($ids){
if($ids) $where=" AND id in(".$ids.")";
$uid=cookie('user_id');
$orderid=session('temp_orderid');
$arr=Db::name('tempdata')->field('sum(buynum*buytaxprice) as money')->where("orderid={$orderid} AND uid={$uid}{$where} ")->find();
//print_r($arr);
return $arr['money'];
}
//购物车商品总价格带运费
function get_cart_all_momey($ids){
if($ids) $where=" AND id in(".$ids.")";
$uid=cookie('user_id');
$orderid=session('temp_orderid');
$arr=Db::name('tempdata')->field('sum(buynum*buyprice+buynum*buytaxprice) as money')->where("orderid={$orderid} AND uid={$uid}{$where} ")->find();
return $arr['money']+get_user_zd(cookie('user_id'),'fare');
}
//购物车商品总价格不带运费
function get_cart_all_momeyno(){
$orderid=session('temp_orderid');
$arr=Db::name('tempdata')->field('sum(buynum*buyprice+buynum*buytaxprice) as money')->where("orderid={$orderid}")->find();
return $arr['money'];
}
//获取封面图片
function get_coverimage($id){
$v=Db::name('photo')->field('img1')->where("pid={$id}")->find();
if($v['img1']) $str=$v['img1'];else $str='/Uploads/nopic.jpg';
return $str;
}
//评论列表
function get_comments_list($typeid=0,$pid=0,$limit=10){
$str="";
$list=M()->table("dy_comments c,dy_user u")->field('c.title,c.img1,c.img2,c.img3,c.content,c.rating1,c.rating2,u.nickname,u.img1 as tx')->where("c.uid=u.id AND c.status=1 AND c.typeid={$typeid} AND c.pid={$pid}")->order('c.id desc')->select();
return $list;
}
//留言列表
function get_message_list($typeid=0,$pid=0,$limit=10){
$str="";
$list=Db::name('message')->where("status=1 AND pid={$pid} AND typeid={$typeid}")->limit($limit)->select();
return $list;
}
//评论数量
function get_comments_count($typeid=0,$pid=0,$limit=10){
$str="";
$list=M()->table("dy_comments c,dy_user u")->field('c.title,c.img1,c.img2,c.img3,c.content,c.rating1,c.rating2,u.nickname,u.img1 as tx')->where("c.uid=u.id AND c.status=1 AND c.typeid={$typeid} AND c.pid={$pid}")->order('c.id desc')->count();
return $list;
}
//留言数量
function get_message_count($typeid=0,$pid=0,$limit=10){
$str="";
$list=Db::name('message')->where("status=1 AND pid={$pid} AND typeid={$typeid}")->limit($limit)->count();
return $list;
}
//获取产品分类
function get_sort_list($pid=0,$num=0,$limit=0){
$list=Db::name('sort')->field('id,catname,outlinkurl,inlinkurl,img1,img2,seodescription,encatname,pid')->order('disorder asc,id asc')->where("status=1 and pid={$pid}")->limit($limit,$num)->select();
foreach ((array)$list as $k => $v){
if($v['outlinkurl']) $linkurl=$v['outlinkurl'];else $linkurl=$v['inlinkurl'];
$list[$k]['linkurl'] = $linkurl;
}
return $list;
}
//获取产品分类
function get_type_list($pid){
$list=Db::name('sort')->field('id,catname,pid')->order('disorder asc,id asc')->where("status=1 and pid={$pid}")->select();
return $list;
}
//获取新闻表字段内容
function get_html($string){
$str=html_entity_decode($string);
return $str;
}
//获取权限名称
function get_role_auth_name($ids){
$str="";
$list=Db::name('sort')->field('catname')->where("status=1 AND id in (".$ids.")")->select();
foreach((array)$list as $key=>$arr){
$str.=$arr['catname']."、";
}
return $str;
}
//获取导航
function get_location($pid,$ty,$tty){
$str="";
if($pid) $str="<em>></em><a>".get_type_zd($pid)."</a>";
if($ty) $str.="<em>></em><a>".get_type_zd($ty)."</a>";
if($tty) $str.="<em>></em><a>".get_type_zd($tty)."</a>";
return $str;
}
/**
* 计算几分钟前、几小时前、几天前、几月前、几年前。
* $agoTime string Unix时间
* @author tangxinzhuan
* @version 2016-10-28
*/
function time_ago($agoTime){
$agoTime = (int)$agoTime;
// 计算出当前日期时间到之前的日期时间的毫秒数,以便进行下一步的计算
$time = time() - $agoTime;
if ($time >= 31104000) { // N年前
$num = (int)($time / 31104000);
return $num.'年前';
}
if ($time >= 2592000) { // N月前
$num = (int)($time / 2592000);
return $num.'月前';
}
if ($time >= 86400) { // N天前
$num = (int)($time / 86400);
return $num.'天前';
}
if ($time >= 3600) { // N小时前
$num = (int)($time / 3600);
return $num.'小时前';
}
if ($time > 60) { // N分钟前
$num = (int)($time / 60);
return $num.'分钟前';
}
return '1分钟前';
}
//获取回复内容
function get_reply_message_list($fid){
$uid=cookie('user_id');
$list=Db::name('letter')->field('id,title,content,sendtime')->order('id desc')->where("uid={$uid} AND fid={$fid}")->select();
return $list;
}
//查看图片
function get_img_show($img1){
$path=get_photo($img1);
if($img1)
$str=" <a href=\"{$path}\" target=\"_blank\" style=\"color:blue\">查看图片</a>";
else
$str="";
echo $str;
}
//查看图片
function get_imgs_show($img1){
if($img1)
$str=" <a href=\"{$img1}\" target=\"_blank\" style=\"color:blue\">查看图片</a>";
else
$str="";
echo $str;
}
//求两个日期之间相差的天数
function diffBetweenTwoDays ($day1, $day2){
$second1 = strtotime($day1);
$second2 = strtotime($day2);
if ($second1 < $second2) {
$tmp = $second2;
$second2 = $second1;
$second1 = $tmp;
}
return ($second1 - $second2) / 86400;
}
//会员类型
function get_user_type($typeid,$isbroker=0,$isgoddess=0){
if($typeid==2&&$isgoddess==0) $usertype='平面模特';
elseif($typeid==2&&$isgoddess==1) $usertype='女神模特';
elseif($typeid==3&&$isbroker==0) $usertype='企业';
elseif($typeid==4&&$isbroker==0) $usertype='个人';
elseif($typeid==3&&$isbroker==1) $usertype='经纪公司';
elseif($typeid==4&&$isbroker==1) $usertype='个人经纪人';
return $usertype;
}
//会员类型
function get_admin_list($typeid,$isbroker=0,$isgoddess=0){
$arr=explode(",",$typeid);
$strs='';
foreach ($arr as $k => $v){
if($k==0) $zt="";else $zt="、";
$strs.=$zt.get_user_type($v,$isbroker,$isgoddess);
}
return $strs;
}
//产品参数
function get_pc_cs($nr){
$arr=explode(",",$nr);
$strs='';
foreach ($arr as $k => $v){
$strs.="<div class=\"swiper-slide\"><span>{$v}</span></div>\n";
}
return $strs;
}
//产品参数
function get_wap_cs($nr){
$arr=explode("\r\n",$nr);
$strs='';
foreach ($arr as $k => $v){
$strs.="{$v} ; ";
}
return $strs;
}
//表单构建
function frm_out_put($arr,$nm,$tag,$value='',$js="",$firstNode=""){
/***********************************
功能:从初始化到表单的生成
参数
***********************************/
$value=trim($value);
switch($tag){
case 'option':
$str="<select name=\"info[$nm]\" id=\"{$nm}\" ".$js.">\n";
if($firstNode){
$str.="\t<option value='99'>".$firstNode."</option>\n";
}
foreach ($arr as $k => $v) {
if($value==$k&&$value!=''){
$str .= "\t<$tag value='$k' selected>$v</$tag>\n";
}else{
$str .= "\t<$tag value='$k' $defaultCk>$v</$tag>\n";
}
}
$str.="</select>";
break;
case 'radio':
$i=0;
foreach ($arr as $k => $v) {
if($value==$k&&$value!=''){
$str .= "\n<input type='".$tag."' name='".$nm."' id='".$nm.$k."' class='radio' checked='checked' value='".$k."' ".$js."> ".$v."</input>\n ";
}else{
if($i==0 && $value==''){$defaultCk = 'checked';$i++;}
$str .= "\n<input type='".$tag."' name='".$nm."' id='".$nm.$k."' class='radio' value='".$k."' ".$js." $defaultCk> ".$v."</input>\n ";
$defaultCk='';
}
}
break;
case 'checkbox':
if($value)
$arrValue = explode(',',$value);
else
$arrValue = array();
$checkTag=0;
foreach ($arr as $k => $v) {
for($i=0;$i<count($arrValue);$i++){
if($arrValue[$i]==$k&&$value!=''){
$str .= "\n<input type='".$tag."' name='".$nm."[]' value='".$k."' checked='checked' ".$js.">".$v." \n";
$checkTag++;
}
}
if($checkTag==0){
$str .= "\n<input type='".$tag."' name='".$nm."[]' value='".$k."' ".$js.">".$v."</input> \n";
}
$checkTag=0;
}
break;
}
return $str;
}
//远程下载
function getFile($url,$path='',$filename='',$type=0){
if($url==''){return false;}
//获取远程文件数据
if($type===0){
$ch=curl_init();
$timeout=5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);//最长执行时间
curl_setopt($ch,CURLOPT_TIMEOUT,$timeout);//最长等待时间
$img=curl_exec($ch);
curl_close($ch);
}
if($type===1){
ob_start();
readfile($url);
$img=ob_get_contents();
ob_end_clean();
}
if($type===2){
$img=file_get_contents($url);
}
//判断下载的数据 是否为空 下载超时问题
if(empty($img)){
throw new \Exception("下载错误,无法获取下载文件!");
}
//没有指定路径则默认当前路径
if($path===''){
$path="./";
}
//如果命名为空
if($filename===""){
$filename=md5($img);
}
//获取后缀名
$ext=substr($url, strrpos($url, '.'));
if($ext && strlen($ext)<5){
$filename.=$ext;
}
//防止"/"没有添加
$path=rtrim($path,"/")."/";
//var_dump($path.$filename);die();
$fp2=@fopen($path.$filename,'a');
fwrite($fp2,$img);
fclose($fp2);
//echo "finish";
return $filename;
}
/**
+----------------------------------------------------------
* 浏览记录按照时间排序
+----------------------------------------------------------
*/
function my_sort($a, $b){
$a = substr($a,1);
$b = substr($b,1);
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
/**
+----------------------------------------------------------
* 网页浏览记录生成
+----------------------------------------------------------
*/
function cookie_history($id,$title,$price,$oldprice,$img,$url){
$dealinfo['title'] = $title;
$dealinfo['price'] = $price;
$dealinfo['oldprice'] = $oldprice;
$dealinfo['img'] = $img;
$dealinfo['url'] = $url;
$time = 't'.NOW_TIME;
$cookie_history = array($time => json_encode($dealinfo)); //设置cookie
if (!cookie('history')){//cookie空,初始一个
cookie('history',$cookie_history);
}else{
$new_history = array_merge(cookie('history'),$cookie_history);//添加新浏览数据
uksort($new_history, "my_sort");//按照浏览时间排序
$history = array_unique($new_history);
if (count($history) > 4){
$history = array_slice($history,0,4);
}
cookie('history',$history);
}
}
/**
+----------------------------------------------------------
* 网页浏览记录读取
+----------------------------------------------------------
*/
function cookie_history_read(){
$arr = cookie('history');
foreach ((array)$arr as $k => $v){
$list[$k] = json_decode($v,true);
}
return $list;
}
// 获取指定表字段
function get_columns($table){
$sql="SHOW FIELDS FROM __PREFIX__{$table}";
$arr=M()->query($sql);
foreach ($arr as $k => $v) {
if($k) $str.=",{$v['Field']}";
}
$str=ltrim($str,",");
return $str;
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。