这是一个神奇的网站,哦不,神奇的云函数,它只有三行代码:(真的只有三行哦)
云函数:login
index.js:
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event) => { return { ...event, ...cloud.getWXContext() } }
神奇功能之五:获取群id:
将小程序分享到某群里,可获得该群的群id,
page.js:
onShareAppMessage: function () {
wx.showShareMenu({
withShareTicket: true
})
let path = '/pages/xxx/xxx'
let title = 'title'
let imageUrl = `http://xxx.com/100.jpg`
return {title,imageUrl,path}
},
app.js:
onLaunch: function (options) {
options.shareTicket && this.getOpenGId(options.shareTicket)
},
getOpenGId: function (shareTicket) {
wx.getShareInfo({
shareTicket,
success: function (res) {
wx.cloud.callFunction({
name: 'login',
data: { weRunData: wx.cloud.CloudID(res.cloudID) },
success: res=> {
console.log(res.result.weRunData.data.openGId);
}
})
}
})
},
需要说明一下的是:从群里点击分享卡片进入小程序,必须是重启的小程序,不能是已经打开的小程序,否则得不到shareTicket。
其他功能:
神奇功能之一:获取openid:
https://developers.weixin.qq.com/community/develop/article/doc/00080c6e3746d8a940f9b43e55fc13
神奇功能之二:不用授权获取unionid:
https://developers.weixin.qq.com/community/develop/article/doc/000a0c6b580338e947f9db0c65b813
神奇功能之三:100%成功获取unionid:
https://developers.weixin.qq.com/community/develop/article/doc/00066a967c4e384949f93fe1151413
神奇功能之四:获取电话号码:
https://developers.weixin.qq.com/community/develop/article/doc/0006a8ec7ac860c94bf90a34f5d813
在编辑器上获取到群id之后,如何在真实微信群里测试呢