bayi 1 year ago
parent
commit
0d50798994
4 changed files with 51 additions and 25 deletions
  1. 45 19
      app.js
  2. 1 1
      app.miniapp.json
  3. 2 2
      project.miniapp.json
  4. 3 3
      utils/request.js

+ 45 - 19
app.js

@@ -14,7 +14,9 @@ import {
 let storeBindings
 App({
     async onLaunch() {
+        // #if MP
         this.updateApplet()
+        // #endif
         this.checkIsIos()
         this.getNavbarInfo()
         await loginLog()
@@ -60,30 +62,54 @@ App({
                 getApp().callBack();
             }
         } else {
-            wx.getMiniProgramCode({
+            this.getWXCode().then(async res => {
+                if (res.code) {
+                    // 获取openid
+                    let data = {
+                        code: res.code,
+                        userChannelCode
+                    }
+                    if (shareUid != 'undefined' && shareUid) {
+                        data.shareUid = shareUid
+                    }
+                    let userRes = await userLogin(data)
+                    this.setUser(userRes.data)
+                    wx.setStorageSync('uid', userRes.data.uid)
+                    wx.setStorageSync('user', userRes.data)
+                    this.globalData.userInfo = userRes.data
+                    this.deviceLogin()
+                    if (getApp().callBack) {
+                        getApp().callBack(userRes);
+                    }
+                }
+            })
+        }
+    },
+    getWXCode() {
+        return new Promise((reslove, reject) => {
+            // #if MP
+            wx.login({
                 success: async (res) => {
                     if (res.code) {
-                        // 获取openid
-                        let data = {
-                            code: res.code,
-                            userChannelCode
-                        }
-                        if (shareUid != 'undefined' && shareUid) {
-                            data.shareUid = shareUid
-                        }
-                        let userRes = await userLogin(data)
-                        this.setUser(userRes.data)
-                        wx.setStorageSync('uid', userRes.data.uid)
-                        wx.setStorageSync('user', userRes.data)
-                        this.globalData.userInfo = userRes.data
-                        this.deviceLogin()
-                        if (getApp().callBack) {
-                            getApp().callBack(userRes);
-                        }
+                        reslove(res)
+                    } else {
+                        reject(res.errMsg)
                     }
                 }
             })
-        }
+            // #elif ANDROID
+            wx.getMiniProgramCode({
+                success(res) {
+                    if (res.code) {
+                        reslove(res)
+                    } else {
+                        console.log('获取小程序 code 失败!' + res.errMsg)
+                        reject(res.errMsg)
+                    }
+                }
+            })
+            // #endif
+        })
     },
     checkIsIos: function () {
         wx.getSystemInfo({

+ 1 - 1
app.miniapp.json

@@ -4,7 +4,7 @@
     },
     "identityServiceConfig":
     {
-        "authorizeMiniprogramType": 1,
+        "authorizeMiniprogramType": 2,
         "miniprogramLoginPath": "/pages/donutLogin/index"
     }
 }

+ 2 - 2
project.miniapp.json

@@ -3,14 +3,14 @@
   "name": "朗读小咖秀",
   "version": "0.0.1",
   "mini-android": {
-    "sdkVersion": "1.0.21",
+    "sdkVersion": "1.1.2",
     "toolkitVersion": "0.10.0",
     "useExtendedSdk": {
       "media": true,
       "bluetooth": false,
       "network": true,
       "scanner": false,
-      "xweb": false
+      "xweb": true
     },
     "icons": {
       "hdpi": "",

+ 3 - 3
utils/request.js

@@ -6,13 +6,13 @@ const {
         envVersion
     }
 } = wx.getAccountInfoSync();
-if (envVersion == 'develop') {
+/* if (envVersion == 'develop') {
     baseUrl = 'https://reader-api.efunbox.cn/wx'
     oldUrl = 'https://reader-api.efunbox.cn'
-} else {
+} else { */
     baseUrl = 'https://reader-api.ai160.com/wx'
     oldUrl = 'https://reader-api.ai160.com'
-}
+// }
 
 function request(url, method, data, oldBaseUrl = false, intercept = true) {