微信小程序开发笔记
发布时间:2017-12-09, 10:17:28 分类:HTML | 编辑 off 网址 | 辅助
图集1/12
正文 4248字数 4,266,517阅读
微信小程序开发文档 微信开发者工具 WeUI微信小程序前端框架ui简明入门指南 微信小程序之购物车功能 微信小程序撸图片小试手
小程序让每个页面都有tabbar
写入日志
PHP调式bug
手机网页前端开发者调试面板 vConsole
PHP调式bug
手机网页前端开发者调试面板 vConsole
<?php
function xl_bug_log_text($content){
$file = 'xllog/'.date('Y-m-d').'.txt';//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个
$content .= $content."\r\n";
if($f = file_put_contents($file, $content,FILE_APPEND)){
// 这个函数支持版本(PHP 5)
//echo "写入成功。<br />";
//return true;
}
return $f;
}
xl_bug_log_text('iswtf');
Run code
Cut to clipboard
微信小程序 MD5
md5.js
使用

md5.js
使用
var utilMd5 = require('../../utils/md5.js');
var password = utilMd5.hexMD5(password);
Run code
Cut to clipboard
构造令牌token
1.使用本地时间 注意时区差

2.使用服务器时间戳
小程序不支持wx.request同步请求
小程序为了用户体验,所有的request均为异步请求,不会阻塞程序运行
所以当你需要同步请求,锁死操作时,最好将所有的逻辑写在success:function(){}里面

util.js

ntime.php
服务器解密验证令牌
1.使用本地时间 注意时区差
//构造令牌
// 在需要使用的js文件中,导入js
//var util = require('../../utils/util.js');
var ttken ='JLI5vvqq0KRnzfla';//密钥
var ttime = parseInt(Date.parse(new Date())/1000);//时间 秒
//var ttime = util.ntime();
var ntoken=ttken+ttime;
var token = utilMd5.hexMD5(ntoken);
console.log(token);
//end
Run code
Cut to clipboard
2.使用服务器时间戳
小程序不支持wx.request同步请求
小程序为了用户体验,所有的request均为异步请求,不会阻塞程序运行
所以当你需要同步请求,锁死操作时,最好将所有的逻辑写在success:function(){}里面
//构造令牌 使用服务器时间戳
var util = require('../../utils/util.js');
util.ntime(utilMd5);
Run code
Cut to clipboard
util.js
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
//服务器时间戳
function ntime(utilMd5){
wx.request({
url: 'https://lizhenqiu.com/ntime.php',//请修改为你服务器
data: {
},
header: {
'content-type': 'application/json'
},
success: function (res) {
//return res;
var ttken = 'JLI5vvqq0KRnzfla';//密钥
//var ttime = parseInt(Date.parse(new Date()) / 1000);//时间 秒
var ttime = res;//util.ntime();
var ntoken = ttken + ttime;
var token = utilMd5.hexMD5(ntoken);
console.log(token);
//return token;
}
})
}
//构造令牌
// 在需要使用的js文件中,导入js
//var util = require('../../utils/util.js');
/*var ttken ='JLI5vvqq0KRnzfla';//密钥
var ttime = parseInt(Date.parse(new Date())/1000);//时间 秒
//var ttime = util.ntime();
var ntoken=ttken+ttime;
var token = utilMd5.hexMD5(ntoken);
console.log(token);*/
//end
module.exports = {
formatTime: formatTime,
ntime: ntime
}
Run code
Cut to clipboard
ntime.php
<?PHP
header("Content-type: text/html; charset=utf-8");
echo json_encode(time());
Run code
Cut to clipboard
服务器解密验证令牌
<?php
header("Content-type: text/html; charset=utf-8");
/*d s*/
error_reporting(E_ALL); //E_ALL
function cache_shutdown_error() {
$_error = error_get_last();
if ($_error && in_array($_error['type'], array(1, 4, 16, 64, 256, 4096, E_ALL))) {
echo '<font color=red>你的代码出错了:</font></br>';
echo '致命错误:' . $_error['message'] . '</br>';
echo '文件:' . $_error['file'] . '</br>';
echo '在第' . $_error['line'] . '行</br>';
}
}
register_shutdown_function("cache_shutdown_error");
function dump($vars){
echo '';
print_r($vars);
echo '
';
}
/*d e*/
//返回服务器时间戳
function ntime(){
return time();
}
//令牌验证 $t 时间 +- 范围 分
function xl_c_n_token($token,$t,$key){
$nt=ntime();
$t=($t+0)*60;//分化秒
$io=$nt-$t;
$it=$nt+$t;
for($i=$io;$i<$it;$i++){
$tokenlist[]=md5($key.$i);//所有时间误差返回内的token令牌
}
$iin=in_array($token,$tokenlist);
return $iin;
}
$ctoken=xl_c_n_token('80527e16009444c5d554d76134bf2471',5,'JLI5vvqq0KRnzfla');
//dump(xl_c_n_token('80527e16009444c5d554d76134bf2471',5,'JLI5vvqq0KRnzfla'));
function xl_bug_log_text($content){
$file = 'xllog/'.date('Y-m-d').'.txt';//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个
$content .= $content."\r\n";
if($f = file_put_contents($file, $content,FILE_APPEND)){
// 这个函数支持版本(PHP 5)
//echo "写入成功。<br />";
return true;
}
return $f;
}
//xl_bug_log_text('iswtf');
//echo md5('password');
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 20 条评论 »
<?php if(is_weixin()){ echo "这是微信内部浏览器"; }else{ echo "这是微信外部浏览器"; } function is_weixin(){ if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) { return true; } return false; }
微信小程序版本库过低导致的兼容问题。
存储》Tencent》MicroMsg|微信》Download
调用wx.relaunch报错:fail can not invoke relaunch in background。
reLaunch 在小程序进入后台不能调用。
reLaunch:fail can not invoke reLaunch in background
微信小程序常见Q&A
页面显示/切入前台时触发。
可多次触发,用于后退等刷新操作。
//回到顶部 goTop: function (e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } },
小程序之动态修改页面标题
一:写死的形式 在json直接配置: { "navigationBarTitleText": "标题" } 二:动态修改的形式 onLoad: function (options) { wx.setNavigationBarTitle({ title: this.data._title }) }
<view wx:if="{{a}}">单个条件</view> <view wx:if="{{a || b}}">多个或条件</view> <view wx:if="{{a && b}}">多个且条件</view> wx:if else 的判断 <view wx:if="{{a>5}}">6</view> <view wx:elif="{{a < 5}}">4</view> <view wx:else">5</view>
rpx 是微信小程序解决自适应屏幕尺寸的尺寸单位。微信小程序规定屏幕的宽度为750rpx。
无论是在iPhone6上面还是其他机型上面都是750rpx的屏幕宽度,拿iPhone6来讲,屏幕宽度为375px,把它分为750rpx后, 1rpx = 0.5px。
微信小程序同时也支持rem尺寸单位, rem 规定屏幕的宽度为20rem, 所以 1rem = (750/20)rpx = 37.5 rpx
let s=setTimeout(function(){ clearTimeout(s); let delta=getCurrentPages()-1; wx.navigateBack({ delta: delta }) /*wx.navigateTo({ url: '/pages/user/index' })*/ },2000);
let s=setTimeout(()=>{ clearTimeout(s); this.getfuxm(); },2000);
JSON.stringify(a)!="{}" && JSON.stringify(a)!="[]" && a && a!='null'
命令如下:
use mysql; alter user 'root'@'localhost' identified with mysql_native_password by '********'; flush privileges;
mysqld --initialize --console
执行完成后,会输出 root 用户的初始默认密码,如:
...
2018-04-20T02:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
...
APWCY5ws&hjQ 就是初始密码,后续登录需要用到,你也可以在登陆后修改密码。
输入以下安装命令:
mysqld install
启动输入以下命令即可:
net start mysql
(下载解压mysql后可能要重启,如果提示服务启动失败没有报错信息)