Browse Source

openid 问题

roose 4 năm trước cách đây
mục cha
commit
82d57e4d02
5 tập tin đã thay đổi với 48 bổ sung39 xóa
  1. 29 23
      app.js
  2. 1 1
      pages/collectInfo/collectInfo.js
  3. 6 8
      pages/index/index.js
  4. 1 1
      pages/index/index.wxml
  5. 11 6
      pages/login/login.js

+ 29 - 23
app.js

@@ -74,39 +74,45 @@ App({
     console.log(msg)
   },
   getAuthKey: function () {
+    console.log("apppppppjsjsjsjsjjsjsj");
+    
     return new Promise(function (resolve, reject) {
       // 调用登录接口  
       wx.login({
         success: function (res) {
           if (res.code) {
-            console.log("appppppppppppppppppppppppppp用户的code:" + res.code);
-          
-            const appid = "wx1c015df104db7030"
-            const secret = "d1956c1b5d3601657c98b0dc80a006f7"
-            let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
+            // const appid = "wx1c015df104db7030"
+            // const secret = "d1956c1b5d3601657c98b0dc80a006f7"
+            // let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
             wx.request({
-              // 自行补上自己的 APPID 和 SECRET
-              url: url,
+              url: util.globalData.publicUrl + '/wx/getAppletOpenId',
+              method: "GET",
+              data: {
+                cid: 'applet',
+                code: res.code
+              },
               success: res => {
                 // 获取到用户的 openid
-                console.log("用户的openid:" + res.data.openid);
-                wx.setStorageSync('openId', res.data.openid)
-                wx.request({
-                  url: util.globalData.publicUrl + '/applet/isExist',
-                  method: "GET",
-                  data: {
-                    appletsId: wx.getStorageSync('openId')
-                  },
-                  success: (res) => {
-                    console.log('app登录是否绑定的',res);
-                    if (res.data.code == 0) {
-                      if (res.data.data) {
-                        wx.setStorageSync('user', 'user');
+                if (res.data.status == 200) {
+                  wx.setStorageSync('openId', res.data.data.openid)
+                  wx.request({
+                    url: util.globalData.publicUrl + '/applet/isExist',
+                    method: "GET",
+                    data: {
+                      appletsId: wx.getStorageSync('openId')
+                    },
+                    success: (res) => {
+                      console.log('app登录是否绑定的', res.data.code);
+                      if (res.data.code == 0) {
+                        if (res.data.data) {
+                          wx.setStorageSync('user', 'user');
+                        }
+                        resolve(res);
                       }
-                      resolve(res);
                     }
-                  }
-                })
+                  })
+                }
+
               }
             });
           } else {

+ 1 - 1
pages/collectInfo/collectInfo.js

@@ -757,7 +757,7 @@ Page({
                             if (e.data.words_result['公民身份号码'].words.substring(10, 12) < month || e.data.words_result['公民身份号码'].words.substring(10, 12) == month && e.data.words_result['公民身份号码'].words.substring(12, 14) <= day) {
                               age++;
                             }
-                            if (age >= 60) {
+                            if (age >=60) {
                               let idNumber = 'oldInfo[' + _this.data.activeIndex + '].idNumber'
                               let name = 'oldInfo[' + _this.data.activeIndex + '].name'
                               let nation = 'oldInfo[' + _this.data.activeIndex + '].nation'

+ 6 - 8
pages/index/index.js

@@ -144,7 +144,7 @@ Page({
 
   },
   depts() {
-    console.log(wx.getStorageSync('openId'));
+    console.log("1111111111111111111111111111");
     wx.request({
       url: app.globalData.publicUrl + '/applet/homeStatistics',
       method: "GET",
@@ -152,6 +152,8 @@ Page({
         appletsId: wx.getStorageSync('openId')
       },
       success: (res) => {
+        console.log("resrrrrrrrrrrrrrrrrrrrrrrr",res);
+        
         if (res.data.code == 0) {
           this.setData({
             number: res.data.data
@@ -161,8 +163,6 @@ Page({
     })
   },
   welcomeMessage() {
-    console.log("welcomeMessage");
-    console.log(wx.getStorageSync('openId'));
     this.setData({
       msgList: []
     })
@@ -196,7 +196,6 @@ Page({
         },
         success: (res) => {
           if (res.data.code == 0) {
-            console.log(res, "111111111111111");
             if (res.data.data.length == 0) {
               this.data.msgList.push({
                 title: '暂无通知'
@@ -223,20 +222,19 @@ Page({
   //   this.depts();
   // },
   onShow() {
-    console.log("onshowssshshshhshshshss");
     this.depts();
     this.welcomeMessage();
 
   },
   onLoad: function () {
-    console.log("主页onload");
+    console.log("主页load11111");
+    
     var that = this;
     const apps = getApp()
     apps.getAuthKey().then(function (res) {
       that.depts();
     })
-    console.log("主页onload22222222222222222");
-
+    console.log("主页load2222222222222222");
   }
 
 

+ 1 - 1
pages/index/index.wxml

@@ -21,7 +21,7 @@
 	</view>
 	<view class="shu-top2">
 		<view class="shu"></view>
-		<view class="top2">{{number.dept}}统计1</view>
+		<view class="top2">{{number.dept}}统计</view>
 	</view>
 	<view class="top3">
 		<view class="top3-box">

+ 11 - 6
pages/login/login.js

@@ -90,16 +90,21 @@ Page({
       success: res => {
         // 获取到用户的 code 之后:res.code
         console.log("用户的code:" + res.code);
-        const appid = "wx1c015df104db7030"
-        const secret = "d1956c1b5d3601657c98b0dc80a006f7"
-        let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
+        // const appid = "wx1c015df104db7030"
+        // const secret = "d1956c1b5d3601657c98b0dc80a006f7"
+        // let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
         wx.request({
           // 自行补上自己的 APPID 和 SECRET
-          url: url,
+          url: app.globalData.publicUrl + '/wx/getAppletOpenId',
+          method: "GET",
+          data: {
+            cid :'applet',
+            code :res.code
+          },
           success: res => {
             // 获取到用户的 openid
-            console.log("用户的openid:" + res.data.openid);
-            wx.setStorageSync('openId', res.data.openid)
+            console.log("用户的openid:" + res.data.data.openid);
+            wx.setStorageSync('openId', res.data.data.openid)
             wx.request({
               url: app.globalData.publicUrl + '/applet/isExist',
               method: "GET",