作者:金色閃光4,來自原文地址
-
private void sendMiniApps(String articlePk, String title, String content,
-
String url, Bitmap icon) {
-
-
WXMiniProgramObject miniProgram = new WXMiniProgramObject();
-
//低版本微信打開 URL
-
miniProgram.webpageUrl = url;
-
//跳轉(zhuǎn)的小程序的原始 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);
-
-
//使用此方法會(huì)出現(xiàn)無法分享的問題
-
// 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);
-
-
}
參考:微信開發(fā)平臺(tái)
二:module.exports 模塊化基礎(chǔ)
作者:山水之間,來自原文地址

文件 目錄如上圖:
看到網(wǎng)上寫的模塊化都比較復(fù)雜,寫個(gè)入門版的 好讓大家理解理解
//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")
-
//獲取應(yīng)用實(shí)例
-
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>
因?yàn)槿〉氖莕ame,所以最后輸出的是xiaoming 和xiaohong。
看完上面可以接著看: 跳坑《一百六十六》模塊化、組件化及封裝相關(guān)知識(shí)及組件
|