附代码:
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad(){
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
wx.showShareMenu({
withShareTicket: true
})
console.log('test');
wx.getShareInfo({
success: function(tmp){
var encryptedData = tmp.encryptedData;
var iv = tmp.iv;
console.log("tmp", tmp);
console.log("success", encryptedData);
},
fail: (tmp) => {
console.log("tmp", tmp.getShareInfo);
console.log('fail', tmp)
},
})
wx.getGroupEnterInfo({
success: (result) => {
console.log('success', result)
},
fail: (result) => {
console.log('fail', result)
},
})
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
},
onShareAppMessage: function() {
console.log("分享")
// if (ops.from === 'button') {
// // 来自页面内转发按钮
// console.log(ops.target)
// }
return {
title: '弹出分享时显示的分享标题',
desc: '分享页面的内容',
path: '/pages/index/index' // 路径,传递参数到指定页面。
}
},
})
在 App.onLaunch 里读 shareTicket