uniapp 微信小程序授权页面并且获取当前微信小程序的logo
- 微信小程序授权页面 在uniapp中,可以使用uni.login()方法获取微信用户的code,然后通过wx.request()方法向服务器发送请求,获取微信用户的openid和session_key。具体操作步骤如下:
1)在uniapp的manifest.json文件中添加微信小程序的appid:
"mp-weixin": {
"appid": "your appid"
}
2)在uniapp的页面中调用uni.login()方法,获取微信用户的code:
uni.login({
provider: 'weixin',
success: function (res) {
if (res.code) {
// 发送请求,获取openid和session_key
wx.request({
url: 'your server url',
data: {
code: res.code
},
success: function (res) {
// 获取openid和session_key
var openid = res.data.openid;
var session_key = res.data.session_key;
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
3)在服务器端使用微信开发者工具提供的接口,获取openid和session_key。
- 获取当前微信小程序的logo 在uniapp中,可以使用uni.getSystemInfo()方法获取当前设备的信息,其中就包含了微信小程序的logo。具体操作步骤如下:
1)在uniapp的页面中调用uni.getSystemInfo()方法,获取当前设备的信息:
uni.getSystemInfo({
success: function (res) {
// 获取微信小程序的logo
var logoUrl = res.appLogo;
}
})
2)使用获取到的logoUrl即可显示微信小程序的logo
原文地址: https://www.cveoy.top/t/topic/fjsW 著作权归作者所有。请勿转载和采集!