- 云开发 Date 时区问题
背景:使用云函数从云数据库获取日期为大于今天00:00时,小于今天23:59时的数据,发现取出的数据异常,有间隔8小时规律 实际探究结论: 在云函数中,new Date(), 返回的是 UTC标准时间-0时区 在云函数查询数据库,返回值中的Date类型,返回的也是 UTC标准时间-0时区 而在云数据库界面上操作的是填写时候看到的是RFC-2822格式标准, 东八区时间, 而直接查询返回的是ISO-8601格式标准, UTC标准时间-0时区。举例,在云数据库界面上填写并展示的是 Wed Nov 21 2018 00:02:00 GMT+0800 (CST), 而通过查询返回的时间是 2018-11-20T16:02:00.000Z。 所以假设今天日期为 2018-11-21 当某条数据在云数据库的时间显示为, Wed Nov 21 2018 00:02:00 GMT+0800 (CST),由上述结论得出实际的UTC时间为 2018-11-20T16:02:00.000Z, 根据我的业务逻辑(查询今日的数据),我需要做如下操作 [代码] [代码][代码]const now = [代码][代码]new[代码] [代码]Date(); // 云函数当前的 UTC 0时区 标准时间, [代码] [代码] //例如当前时间为2018-11-21 9:00:00, 则now= 2018-11-21T01:00:00.000Z[代码] [代码] [代码][代码]const now_gone = [代码] [代码] + 8 * 3600000 // 东八区与0时区的时间差[代码] [代码] + now.getUTCHours() * 3600000 [代码] [代码] + now.getUTCMinutes() * 1000 * 60 [代码] [代码] + now.getUTCSeconds() * 1000 // 总和为 UTC今天已走过的时间 + 东八区时间差, 也就是东八区已经走过的时间[代码] [代码] [代码] [代码] [代码][代码]const startDate = [代码][代码]new[代码] [代码]Date(now - now_gone);[代码] [代码] [代码] [代码] [代码][代码]const endDate = [代码][代码]new[代码] [代码]Date(now - now_gone + 24 * 3600000);[代码][代码] [代码][代码]return[代码] [代码]db.collection([代码][代码]'***'[代码][代码]).where({[代码][代码] **[代码][代码]Date: _.and(_.gt(startDate), _.lt(endDate))[代码][代码] [代码][代码]}).get()[代码] 其实总结下来,就是 云函数 new Date(),是0时区的时间,与中国东八区时间由8小时间隔,计算的时候需要处理一下
2018-11-21 - iphone5s利用canvas压缩照片截取不全
- 当前 Bug 的表现(可附上截图) - 预期表现 - 复现路径 - 提供一个最简复现 Demo 在做图片上传的功能时,需要通过canvas对图片进行压缩再上传,其他机型都是可以正常压缩的,但是在iphone5s下只能截取照片的一部分,不知道这个问题怎么解决。 小米note3显示的图片 [图片] iphone5s显示的图片,只能截取左上角的部分 [图片]
2019-02-20 - 小程序页面跳转深度最多为10层,超过后任何跳转都无法响应
小程序页面跳转层级最多为10层,超过后任何跳转都无法响应,除了返回,因此应用内跳转层级需要严格控制
2018-05-08 - 小程序现在的页面栈还是不能超过 5 层吗
有些业务比较复杂可能5层满足不了也无需求,现在微信限制的最高层级是多少
2018-09-19 - 2019-03-07
- 云开发支付的代码,有需要的进。
真机测试已通过。你照抄就行,保证可通过。 最新完美版本可供参考: https://developers.weixin.qq.com/community/develop/article/doc/0004c4a50a03107eaa79f03cc56c13 小程序端: wx.cloud.callFunction({ name: 'getPay' , data: { total_fee: parseFloat(0.01).toFixed(2) * 100, attach: 'anything', body: 'whatever' } }) .then( res => { wx.requestPayment({ appId: res.result.appid, timeStamp: res.result.timeStamp, nonceStr: res.result.nonce_str, package: 'prepay_id=' + res.result.prepay_id, signType: 'MD5', paySign: res.result.paySign, success: res => { console.log(res) } }) }) 云函数:getPay getPay目录下共两个文件: 1、index.js 2、package.json index.js代码如下: const key = "YOURKEY1234YOURKEY1234YOURKEY123"//这是商户的key,不是小程序的密钥,32位。 const mch_id = "1413090000" //你的商户号 //将以上的两个参数换成你的,然后以下可以不用改一个字照抄 const rp = require('request-promise') const crypto = require('crypto') function paysign({ ...args }) { let sa = [] for (let k in args) sa.push( k + '=' + args[k]) sa.push( 'key=' + key) return crypto.createHash('md5').update(sa.join('&'), 'utf8').digest('hex').toUpperCase() } exports.main = async (event, context) => { const appid = event.userInfo.appId const openid = event.userInfo.openId const attach = event.attach const body = event.body const total_fee = event.total_fee const notify_url = "https://whatever.com/notify" const spbill_create_ip = "118.89.40.200" const nonce_str = Math.random().toString(36).substr(2, 15) const timeStamp = parseInt(Date.now() / 1000) + '' const out_trade_no = "otn" + nonce_str + timeStamp let formData = "<xml>" formData += "<appid>" + appid + "</appid>" formData += "<attach>" + attach + "</attach>" formData += "<body>" + body + "</body>" formData += "<mch_id>" + mch_id + "</mch_id>" formData += "<nonce_str>" + nonce_str + "</nonce_str>" formData += "<notify_url>" + notify_url + "</notify_url>" formData += "<openid>" + openid + "</openid>" formData += "<out_trade_no>" + out_trade_no + "</out_trade_no>" formData += "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>" formData += "<total_fee>" + total_fee + "</total_fee>" formData += "<trade_type>JSAPI</trade_type>" formData += "<sign>" + paysign({ appid, attach, body, mch_id, nonce_str, notify_url, openid, out_trade_no, spbill_create_ip, total_fee, trade_type: 'JSAPI' }) + "</sign>" formData += "</xml>" let res = await rp({ url: "https://api.mch.weixin.qq.com/pay/unifiedorder", method: 'POST',body: formData}) let xml = res.toString("utf-8") if (xml.indexOf('prepay_id')<0) return xml let prepay_id = xml.split("<prepay_id>")[1].split("</prepay_id>")[0].split('[')[2].split(']')[0] let paySign = paysign({ appId: appid, nonceStr: nonce_str, package: ('prepay_id=' + prepay_id), signType: 'MD5', timeStamp: timeStamp }) return { appid, nonce_str, timeStamp, prepay_id, paySign } } package.json 代码如下: { "name": "getPay", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "youself", "license": "ISC", "dependencies": { "crypto": "^1.0.1", "request-promise": "^4.2.2" } } 最后选择:上传和部署:云端安装依赖。
2019-12-14