فهرست منبع

调用注册和登录接口

limengbo 5 سال پیش
والد
کامیت
d80d3c3eee
6فایلهای تغییر یافته به همراه54 افزوده شده و 87 حذف شده
  1. 2 1
      app.json
  2. 13 13
      pages/index/index.js
  3. 16 2
      project.config.json
  4. 7 0
      sitemap.json
  5. 2 2
      utils/const.js
  6. 14 69
      utils/httpUtilNoLogin.js

+ 2 - 1
app.json

@@ -35,5 +35,6 @@
     "onReachBottomDistance": 50,
     "enablePullDownRefresh": true
   },
-  "debug": false
+  "debug": false,
+  "sitemapLocation": "sitemap.json"
 }

+ 13 - 13
pages/index/index.js

@@ -179,20 +179,20 @@ Page({
       title: '小学课文朗读配音'
     })
     // this.init();
-    getOpenidNoLogin((res) => {
+    if (wx.getStorageSync('uid')) {
       hotInit(this)
-    }, (error) => {
-      // console.log(error)
-
-      wx.setStorageSync('userSourseType', 'normal')
-      this.setData({
-        hide: !this.data.hide
-      })
-      return;
-    });
-    if (this.data.myIndex === 0) {
-      // 从修改信息页面退回
-      this.getUserWorksInfo(true);
+    } else {
+      getOpenidNoLogin((res) => {
+        hotInit(this)
+      }, (error) => {
+        // console.log(error)
+        wx.setStorageSync('userSourseType', 'normal')
+        return;
+      });
+      if (this.data.myIndex === 0) {
+        // 从修改信息页面退回
+        this.getUserWorksInfo(true);
+      }
     }
   },
   onHide: function() {

+ 16 - 2
project.config.json

@@ -8,16 +8,30 @@
 		"es6": true,
 		"postcss": true,
 		"minified": true,
-		"newFeature": true
+		"newFeature": true,
+		"coverView": true,
+		"autoAudits": true,
+		"showShadowRootInWxmlPanel": true,
+		"scopeDataCheck": false,
+		"checkInvalidKey": true,
+		"checkSiteMap": true,
+		"uploadWithSourceMap": true,
+		"babelSetting": {
+			"ignore": [],
+			"disablePlugins": [],
+			"outputPath": ""
+		}
 	},
 	"compileType": "miniprogram",
-	"libVersion": "2.3.2",
+	"libVersion": "2.10.1",
 	"appid": "wxdfa8a4f1623d28db",
 	"projectname": "%E5%B0%8F%E5%AD%A6%E8%AF%BE%E6%96%87%E6%9C%97%E8%AF%BB%E9%85%8D%E9%9F%B3",
 	"debugOptions": {
 		"hidedInDevtools": []
 	},
 	"isGameTourist": false,
+	"simulatorType": "wechat",
+	"simulatorPluginLibVersion": {},
 	"condition": {
 		"search": {
 			"current": -1,

+ 7 - 0
sitemap.json

@@ -0,0 +1,7 @@
+{
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
+  "rules": [{
+  "action": "allow",
+  "page": "*"
+  }]
+}

+ 2 - 2
utils/const.js

@@ -2,6 +2,6 @@
 module.exports = {
   productApi: 'https://reader.lingjiao.cn/readerProduct/',
   // productApi: 'https://readertest.lingjiao.cn/readerProduct/',
-  baseApi: 'https://reader.lingjiao.cn/readerBase/'
-  // baseApi: 'https://readertest.lingjiao.cn/readerBase/'
+  // baseApi: 'https://reader.lingjiao.cn/readerBase/'
+  baseApi: 'https://readertest.lingjiao.cn:442/readerBase/'
 }

+ 14 - 69
utils/httpUtilNoLogin.js

@@ -22,7 +22,7 @@ function wxLogin(successcallback, failcallback) {
         success: function (res) {
             if (res.code) {
                 // 获取openid
-                console.log('openId', res.code)
+                console.log('code', res.code)
                 let url = genAPIUrl('wx/user/openId')
                 let data = {
                     code: res.code
@@ -35,71 +35,6 @@ function wxLogin(successcallback, failcallback) {
     })
 }
 
-function userLoginRecord(uid) {
-    if (wx.getStorageSync('uid')) {
-        console.log('调用方法')
-        let url = genAPIUrl('wx/loginLog');
-        return request.getInstance().header({
-            uid: wx.getStorageSync('uid')
-        }).method('POST').url(url).send().success(() => {}).fail(() => {});
-    }
-
-}
-//登录
-function getLoginSchedule(sessionKey, openId, successcallback, failcallback) {
-    wx.getSetting({
-        success: function (res) {
-            // 已经授权,可以直接调用 getUserInfo 获取头像昵称
-            wx.getUserInfo({
-                withCredentials: true,
-                success: function (res) {
-                    let url = genAPIUrl('wx/user/loginRegist');
-                    let appLaunch = wx.getLaunchOptionsSync();
-                    let userSourseType = '';
-                    console.log(appLaunch.scene)
-                    switch (appLaunch.scene) {
-                        case 1020:
-                            userSourseType = 'profile';
-                            break;
-                        case 1058:
-                            userSourseType = 'article';
-                            break;
-                        default:
-                            userSourseType = wx.getStorageSync('userSourseType');
-                            break;
-                    }
-                    const userData = {
-                        encryptedData: res.encryptedData,
-                        sessionKey: sessionKey,
-                        iv: res.iv,
-                        sourceType: userSourseType
-                    }
-                    request.getInstance().url(url).header({
-                        "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
-                    }).data(userData).method('POST').send().success(res => {
-                        wx.hideToast()
-                        wx.showToast({
-                            title: '登录成功',
-                            icon: 'success',
-                            duration: 1500,
-                            mask: true
-                        })
-                        wx.setStorageSync('uid', res.data.data.data.uid)
-                        wx.setStorageSync('user', res.data.data.data)
-                        userLoginRecord()
-                        successcallback(res)
-
-                    });
-                },
-                fail: function (res) {
-                    failcallback(res)
-                }
-            })
-        }
-    })
-
-}
-
 // 获取原来的 openid 和 session_key
 function getOpenidNoLogin(successcallback, failcallback) {
     if (wx.getStorageSync('user')) {
@@ -116,9 +51,19 @@ function getOpenidNoLogin(successcallback, failcallback) {
         if (res.data.code == 200) {
             let sessionKey = res.data.data.session_key;
             let openId = res.data.data.openid;
-            successcallback()
-            wx.setStorageSync('uid', '111')
-            // getLoginSchedule(sessionKey, openId, successcallback, failcallback);
+            // successcallback()
+            // wx.setStorageSync('uid', '111')
+            let url = genAPIUrl('wx/user/register');
+            request.getInstance().method('POST').url(url).header({
+                'content-type': 'application/x-www-form-urlencoded'
+            }).data({
+                openId
+            }).send().success((res) => {
+                if (res.data.code === 200) {
+                    wx.setStorageSync('uid', res.data.data.uid)
+                    successcallback(res)
+                }
+            }).fail(() => {});
         }
 
     }, function (res) {