# 5.4学习笔记

微信分享功能:


``` javascript
wx.shareAppMessage({
title: "一起来挑战",
imageUrl: canvas.toTempFilePathSync({
destWidth: 500,
destHeight: 400
}),
query: "",
success: function (res) {
// 接口调用成功,并非是分享成功
console.log("成功发送消息===>", res, "<====");
if (res.shareTickets) {
clientEvent.dispatchEvent("hidePanel", "failPanel");
clientEvent.dispatchEvent("showPanel", "notNotPanel", false);
console.log("我被分享到群里了");
} else {
clientEvent.dispatchEvent("hidePanel", "failPanel");
clientEvent.dispatchEvent("showPanel", "failPanel", "需分享至微信群才能复活哦!");
console.log("res===>", res, "<====");
console.log("res.shareTickets===>", res.shareTickets, "<===");
}

// this.unschedule(this.setTime);
}.bind(this),
fail: function () {
console.log("发送失败");
}.bind(this),
complete: function () {
console.log("调用结束");
}.bind(this)
});
```

分享功能中的参数shareTickets,是微信群的唯一标识,可以根据这个值来判断玩家是分享到好友,还是分享到了群聊;shareTickets还可以使用在获取群排行的代码中;

**·注意:**
在使用shareTickets前,要将权限打开:

```
wx.showShareMenu({
withShareTicket: true
});
```

详情请访问微信官方文档:[微信小游戏开发文档](https://developers.weixin.qq.com/minigame/dev/index.html)