123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <template>
- <view class="fui-wrap">
- <u-button
- text="默认按钮"
- size="normal"
- type="info"
- @click="click"
- ></u-button>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- }
- },
- onLoad() {
- // #ifdef MP-WEIXIN
- wx.login({
- success: function(res) {
- wx.request({
- url: "https://api.weixin.qq.com/sns/jscode2session",
- data: {
- appid: process.env.UNI_WX_APPID,
- secret: process.env.UNI_WX_AS,
- js_code: res.code,
- grant_type: "authorization_code",
- },
- success: function(response) {
- const openid = response.data.openid;
- console.log("获取到的code:", res.code, "获取到的openid:", openid);
- // 使用登录凭证获取用户信息
- uni.getUserInfo({
- provider: 'weixin',
- success: function (infoRes) {
- console.log(infoRes.userInfo); // 打印用户信息
- console.log('用户昵称为: ' + infoRes.userInfo.nickName); // 打印用户昵称
- // 在这里,你可以将用户的头像和昵称保存到本地或者发送到后端进行处理
- // infoRes.userInfo.avatarUrl是用户的头像链接
- // infoRes.userInfo.nickName是用户的昵称
- }
- });
- }
- })
- }
- })
- // #endif
- },
- methods: {
- getUserInfo() {
- uni.getUserProfile({
- desc: '获取用户信息',
- success: (res) => {
- console.log(res);
- }
- })
- },
- },
- onShareAppMessage() {
- return {
- title: 'First UI组件库'
- }
- }
- }
- </script>
- <style>
- .fui-banner__box {
- width: 100%;
- min-height: 538rpx;
- position: relative;
- background-color: #EDF9FF;
- }
- </style>
|