微信小程序 获取用户openid并给webview传值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信小程序 获取用户openid并给webview传值相关的知识,希望对你有一定的参考价值。

现在能得到用户的信息了,但是没有用户的id,下载了个微信web开发者工具,创建小程序项目,通过webview加载远程的页面,一切都跑通了。
1、请问如何获取用户的openid呢,userinfo.nickname是可以显示出来名称的
2、如何将值传给webview页面呢?
参考内容
userInfo.nickName
。。。
<web-view src="https://domain.com/test.php?name=userInfo.nickName"></web-view>
这样传值不行呀,页面得到的值为空
。。。
Page(
data:
motoo:'hello world'

...
onLoad:functon()
if(this.data.caIuse)
app.userInfoReadyCallback = res =>...
)

对小程序工具不熟悉,望大神讲解一下。

参考技术A 解决了吗?同求......本回答被提问者采纳

如何获取微信小程序用户openid

参考技术A onLaunch: function()
var that = this
var user=wx.getStorageSync('user') || ;
var userInfo=wx.getStorageSync('userInfo') || ; //查看缓存是否有**值
if((!user.openid || (user.expires_in || Date.now()) < (Date.now() + 600))&&(!userInfo.nickName))
wx.login(
success: function(res)
if (res.code)
//发起网络请求获取openid
// console.log(res.code)
wx.request(
url: 'https://api.weixin.qq.com/sns/jscode2session?appId=你的appid&secret=你的secret&js_code='+res.code+'&grant_type=authorization_code',
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: , // 设置请求的 header
success: function(res)
var obj=;
obj.openid=res.data.openid;
obj.expires_in=Date.now()+res.data.expires_in;
// console.log(obj);
wx.setStorageSync('openid', obj);//存储openid

);
//获取用户资料
wx.getUserInfo(
success: function (res)
// console.log("111")
var users=;
users.avatarUrl=res.userInfo.avatarUrl;
users.nickName=res.userInfo.nickName;
console.log(users);
wx.setStorageSync('userInfo', users);//存储用户信息

)
else
console.log('获取用户登录态失败!' + res.errMsg)


)

以上是关于微信小程序 获取用户openid并给webview传值的主要内容,如果未能解决你的问题,请参考以下文章

微信小程序如何开发,怎么获取openID和用户信息

微信小程序,weixin,怎么获取用户的Openid

微信小程序怎么获取openid

微信小程序怎么获取openid

uniapp在微信小程序获取用户信息和openId

微信小程序获取用户openId、手机号