在app.js中獲取到設備寬高
-
// 設備信息
wx.getSystemInfo({
success: function(res) {
that.screenWidth = res.windowWidth;
that.screenHeight = res.windowHeight;
that.pixelRatio = res.pixelRatio;
}
});
|
然后挖坑在布局頁面
<view class="sidebar" style="height: {{sidebarHeight}}px;">
<dt>
<image src="{{item.avatar.attributes.url}}" mode="scaleToFit" bindtap="avatarTap" data-object-id="{{item.objectId}}" style="width:{{imageWidth}}px; height: {{imageWidth}}px;"/>
</dt>
|
最后在js中實現數值
setImageWidth: function () {
var screenWidth = getApp().screenWidth;
var imageWidth = (screenWidth - 130) / 3;
this.setData({
imageWidth: imageWidth
});
},
setSideHeight: function () {
this.setData({
sidebarHeight: getApp().screenHeight
});
},
|
如圖:

源碼下載:http://git.oschina.net/dotton/lendoo-wx,本文涉及代碼存于/pages/category/category文件夾中。
二:tomcat http 轉 https
作者:angrypanda_panpan,來自原文地址 由于小程序需要使用https協議,在使用用騰訊云的服務器時,負載均衡服務器(SSL證書部署在此服務器上)與業務服務器上的apache之間使用的是http,apache與tomcat之間也使用的是http,這樣導致兩個問題,tomcat 在redirect的時會跳轉到http://127.0.0.1上

解決方案: 1.在tomcat,service.xml中Connector 增加proxyName,proxyPort-->解決跳轉到127.0.0.1的問題
-
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyName="test9.icolor.com.cn"
proxyPort="443"
redirectPort="8443" />
|
2.在apache的config中增加 RequestHeader set X-Forwarded-Proto "https"-->解決http轉https的問題
-
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
RequestHeader set X-Forwarded-Proto "https"
|
三:加密解密算法的nodejs實現
作者:大球和二憨,來自授權地址 接口如果涉及敏感數據(如wx.getUserInfo當中的 openid ),接口的明文內容將不包含敏感數據。開發者如需要獲取敏感數據,需要對接口返回的加密數據( encryptData )進行對稱解密。 解密算法如下:
對稱解密使用的算法為 AES-128-CBC,數據采用PKCS#7填充。 對稱解密的目標密文為 Base64_Decode(encryptData), 對稱解密秘鑰 aeskey = Base64_Decode(session_key), aeskey 是16字節 對稱解密算法初始向量 iv = aeskey, 同樣是16字節
-
module.exports={
getSessionKeyByCode:{
url:"https://api.weixin.qq.com/sns/jscode2session",
method:"GET",
params: {
appid:"wx408ea534cb79567e",
secret:"e4fe5b9c97b2d7e1a68e14163e48ac8b",
js_code:'',
grant_type:"authorization_code"
}
}}
exports.service = function (req, res) {
var code = req.query.code;
var encryptData = decodeURIComponent(req.query.encryptData);
reqInfo.getSessionKeyByCode.params.js_code = code;
httpUtil.get(reqInfo.getSessionKeyByCode).then(function (data) {
var aeskey = new Buffer(data.session_key, 'base64');
var iv = aeskey;
// AES-128-CBC對稱解密算法
var decrypt = function (a, b, crypted){
crypted = new Buffer(crypted, 'base64');
var decipher = crypto.createDecipheriv('aes-128-cbc', a, b);
var decoded = decipher.update(crypted,'base64','utf8');
decoded += decipher.final('utf8');
return decoded;
};
var dec = decrypt(aeskey,iv,encryptData);
var result = {};
try{
result = JSON.parse(dec);
}catch(e){
logger.error(e);
result = {};
}
res.json({
code: 1,
data: result
});
}).catch(function(err){
logger.error(err);
res.json({
code: 0,
data: {}
});
})
};
|
PS 目前微信小程序開發者文檔中,已給出各種語言的解密代碼。并且解密密鑰規定也有所調整。
|