private void sendMiniApps(String articlePk, String title, String content,
String url, Bitmap icon) {
WXMiniProgramObject miniProgram = new WXMiniProgramObject();
//低版本微信打开 URL
miniProgram.webpageUrl = url;
//跳转的小程序的原始 ID
miniProgram.userName = WechatShareUtils.MINI_APPS_ID;
//小程序的 Path
miniProgram.path = WechatShareUtils.getMiniAppPath(articlePk);
WXMediaMessage msg = new WXMediaMessage(miniProgram);
final String shareTitle = WechatShareUtils.getValidTitle(title);
if (!TextUtils.isEmpty(shareTitle)) {
msg.title = title;
}
final String shareDescription = WechatShareUtils.getValidDescription(content);
if (!TextUtils.isEmpty(shareDescription)) {
msg.description = shareDescription;
}
if (icon != null) {
msg.setThumbImage(icon);
} else {
Bitmap temp = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_wechat);
msg.setThumbImage(temp);
}
Log.i("TAG", "sendMiniApps title: " + title);
//使用此方法会出现无法分享的问题
// Bitmap thumbBmp = Bitmap.createScaledBitmap(icon, 150, 150, true);
// icon.recycle();
// msg.thumbData = BitmapUtils.bitmapToByteArray(thumbBmp, true);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("miniProgram");
req.message = msg;
req.scene = WXSceneSession;
api.sendReq(req);
}
参考:微信开发平台
二:module.exports 模块化基础
作者:山水之间,来自原文地址
文件 目录如上图:
看到网上写的模块化都比较复杂,写个入门版的 好让大家理解理解
//common.js
var studentList = [
{
name: "xiaoming",
age: "22",
hobby: "sleep"
},
{
name: "xiaohong",
age: "22",
hobby: {
one: "eat",
two: "eatfood"
}
}
]
//模块化
module.exports = {
studentList: studentList
}
//index.js
var common = require("../aa/common.js")
//获取应用实例
var app = getApp()
Page({
data: {
},
onLoad: function () {
this.setData({
studentList:common.studentList
});
}
})
//index.html
<block wx:for="{{studentList}}" wx:for-item="item" wx:for-index="idx">
<view>
{{item.name}}
</view>
</block>
因为取的是name,所以最后输出的是xiaoming 和xiaohong。