可爱熊个人博客

Archive for 十二月, 2018

判断页面必须在微信中打开

<html>
<head>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1, user-scalable=0″>
<script src=”https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js”></script>
</head>
<body>
<script type=”text/javascript”>
$(function(){
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf(‘micromessenger’) != -1;
if (!isWeixin) {
document.head.innerHTML =
‘<title>抱歉,出错了</title><meta charset=”utf-8″><meta name=”viewport” content=”width=device-width, initial-scale=1, user-scalable=0″><link rel=”stylesheet” type=”text/css” href=”https://res.wx.qq.com/connect/zh_CN/htmledition/style/wap_err1a9853.css”>’;
document.body.innerHTML =
‘<div class=”page_msg”><div class=”inner”><span class=”msg_icon_wrp”><i class=”icon80_smile”></i></span><div class=”msg_content”><h4>请在微信客户端打开链接</h4></div></div></div>’;
}
})
</script>
</body>
</html>

js时间戳转时间(年-月-日 时:分:秒)

var t=1521694261;
timestampToTime(t)
function timestampToTime(timestamp) {
var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
Y = date.getFullYear() + ‘-‘;
M = (date.getMonth() + 1 < 10 ? ‘0’ + (date.getMonth() + 1) : date.getMonth() + 1) + ‘-‘;
D = change(date.getDate()) + ‘ ‘;
h = change(date.getHours()) + ‘:’;
m = change(date.getMinutes()) + ‘:’;
s = change(date.getSeconds());
return Y + M + D + h + m + s;
}
function change(t) {
if (t < 10) {
return “0” + t;
} else {
return t;
}
}

 

 

centos7安装nginx

使用yum安装nginx

yum install -y nginx

启动nginx

systemctl start nginx.service

停止nginx

systemctl stop nginx.service

修改nginx配置

vi /etc/nginx/nginx.conf

entos7 mysql数据库安装和配置

官网下载安装mysql-server

  1. # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  2. # rpm -ivh mysql-community-release-el7-5.noarch.rpm
  3. # yum install mysql-community-server

安装成功后重启mysql服务。

# service mysqld restart

初次安装mysql,root账户没有密码。

设置密码 Read More…

php写app接口并返回json数据

第一步:conn.php文件,用于连接数据库并定义接口格式,代码如下:

<?php
header(“charset=utf-8″);
$servername=”localhost”;
$username=”root”;
$password=”root”;
$dbname=”test”;
$conn = mysql_connect($servername,$username,$password);
if(!$conn){
echo “数据库连接失败!”;
}
mysql_select_db($dbname);
class Response{
public static function json($code,$message=””,$data=array()){
$result=array(
‘code’=>$code,
‘message’=>$message,
‘data’=>$data
);
//输出json
echo json_encode($result);
exit;
}
}

?>
Read More…