Procházet zdrojové kódy

适配微信调整后的用户信息接口

Joe před 4 roky
rodič
revize
e926ef62f0
2 změnil soubory, kde provedl 42 přidání a 8 odebrání
  1. 40 7
      pages/order/create.js
  2. 2 1
      pages/order/create.wxml

+ 40 - 7
pages/order/create.js

@@ -56,7 +56,6 @@ Page({
    */
   onLoad: function (options) {
     this.init()
-
     var userInfoValue = wx.getStorageSync('userInfo')
     try {
       if (userInfoValue) {
@@ -106,7 +105,6 @@ Page({
     }).then(res => { // handle success 
       // console.log(res.data);
       // res.data.length
-      console.log(res)
       if (res.retCode == 0) {
         var gasArr = [];
         for (let i = 0; i < res.data.length; i++) {
@@ -439,18 +437,37 @@ Page({
 
   getUserInfo: function (e) {
     let that = this;
+    wx.getUserProfile({
+      lang: "zh_CN",
+      desc: "测试一下",
+      success(res) {
+        app.globalData.userInfo = res.userInfo;
+        wx.setStorage({
+          data: res.userInfo,
+          key: 'userInfo',
+        })
+        that.showDialogPhone(); //调用一键获取手机号弹窗
+        that.setData({
+          userInfo: res.userInfo,
+          hasUserInfo: true
+        })
+      },
+
+      fail(err) {
+        wx.showToast({
+          title: '您拒绝了授权',
+          icon: 'error',
+          duration: 2000
+        })
+      }
+    })
 
     // 获取用户信息
     wx.getSetting({
       success(res) {
-        console.log(res)
-        // console.log("res", res)
         if (res.authSetting['scope.userInfo']) {
-          // console.log("已授权=====")
-          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
           wx.getUserInfo({
             success(res) {
-              // console.log("获取用户信息成功", res.userInfo);
               app.globalData.userInfo = res.userInfo;
               wx.setStorage({
                 data: res.userInfo,
@@ -606,5 +623,21 @@ Page({
         }
       })
     }
+  },
+  test() {
+    wx.login({
+      success(res) {
+        console.log(res)
+      }
+    })
+    console.log(111111)
+    wx.getUserProfile({
+      lang: "zh_CN",
+      desc: "测试一下",
+      success(res) {
+        console.log(res)
+      }
+    })
   }
+
 })

+ 2 - 1
pages/order/create.wxml

@@ -1,5 +1,6 @@
 <!--pages/createorder/index.wxml-->
 <view>
+  <button bindtap="test">点击</button>
   <swiper indicator-dots="{{true}}" indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#ffffff" autoplay
     circular interval="4000" class="my-swipe" centeredSlides="true" autoHeight="true">
     <block wx:for="{{images}}" wx:key="index">
@@ -74,7 +75,7 @@
     </view>
     <view>请先授权</view>
     <view>请先授权获取昵称等信息后再进行此操作</view>
-    <button open-type="getUserInfo" bindgetuserinfo="getUserInfo">授权获取用户信息</button>
+    <button bindtap="getUserInfo">授权获取用户信息</button>
   </view>
 </view>