Browse Source

feature:增加小程序的qq,xmly的授权功能

zeng.chen 9 hours ago
parent
commit
3c71936944
6 changed files with 168 additions and 35 deletions
  1. 6 3
      app.js
  2. 2 1
      app.json
  3. 129 22
      pages/pageB/deviceWake/deviceWake.js
  4. 21 2
      pages/pageB/deviceWake/deviceWake.wxml
  5. 8 7
      utils/requestUtil.js
  6. 2 0
      utils/routePath.js

+ 6 - 3
app.js

@@ -15,8 +15,8 @@ const iosHost = 'wxs://mqtt.test.radio1964.com:8884';
 const androidHost = 'wxs://mqtt.test.radio1964.com:8884'
 App({
   globalData: {
-    isRelease: true,
-    is_debug: 2, // 1 测试环境 // 2正式环境
+    isRelease: false, //改这个改环境
+    is_debug: 1, //这个没有用, 1 测试环境 // 2正式环境
     baseUrl: env.prod.baseUrl,
 
     userInfo: null,
@@ -35,6 +35,7 @@ App({
     oneInitBluetooth: true,
     webSkipUrl: "",
 
+    // 蓝牙用到了,wifi没用到
     mDeviceList: [],
     // 当前设备
     // device: {},
@@ -116,7 +117,7 @@ App({
     update.update();
   },
 
-  onHide: function () {},
+  onHide: function () { },
 
   ///连接设备
   connect() {
@@ -280,6 +281,8 @@ App({
         "type": type,
         "DstDeviceName": DstDeviceName,
         "SrcDeviceName": SrcDeviceName,
+        "is_debug": that.globalData.is_debug,
+        "version": 3,
       };
       if (option.other) {
         data.other = option.other;

+ 2 - 1
app.json

@@ -18,7 +18,8 @@
         "deviceConnect1/deviceConnect1",
         "deviceConnect2/deviceConnect2",
         "deviceConnect3/deviceConnect3",
-        "deviceConnect4/deviceConnect4"
+        "deviceConnect4/deviceConnect4",
+        "authWeb/authWeb"
       ]
     },
     {

+ 129 - 22
pages/pageB/deviceWake/deviceWake.js

@@ -9,6 +9,7 @@ const {
 import lexin_util from '../../../utils/lexin/util.js';
 import routePath from '../../../utils/routePath.js';
 import routeUtil from '../../../utils/routeUtil.js';
+import { autoAuth, unbind, EnumPlatformId } from '../../../utils/auth/auth_util.js';
 
 Page({
   data: {
@@ -24,21 +25,21 @@ Page({
     alarm_id_1: {}, // 唤醒
     timeindex: 1,
     timeArray: [{
-        id: 600,
-        name: '10分钟'
-      },
-      {
-        id: 1800,
-        name: '30分钟'
-      },
-      {
-        id: 3600,
-        name: '60分钟'
-      },
-      {
-        id: 5400,
-        name: '90分钟'
-      }
+      id: 600,
+      name: '10分钟'
+    },
+    {
+      id: 1800,
+      name: '30分钟'
+    },
+    {
+      id: 3600,
+      name: '60分钟'
+    },
+    {
+      id: 5400,
+      name: '90分钟'
+    }
     ],
     clientType: "",
     time0: '00:00:00',
@@ -58,13 +59,16 @@ Page({
       twoButText: "好的",
       footTop: 10,
     },
-    twoButCallback: () => {},
+    twoButCallback: () => { },
     toast_visible: false,
     // 后续新加需求
     deviceOther: null,
     updataDeviceInfo: false,
     repeatIndex: 0,
     deviceId: "",
+    isQQAuth: false,
+    isAuthXmly: false,
+    qqAuthInfo: {},
   },
 
   onLoad(options) {
@@ -93,6 +97,11 @@ Page({
       DstDeviceName: deviceMac
     });
 
+    app.PubMsg({
+      type: "start_dm_auth",
+      DstDeviceName: deviceMac
+    });
+
     // 赋值按钮回调
     that.setData({
       twoButCallback: () => {
@@ -105,11 +114,11 @@ Page({
 
   onShow(options) {
     var that = this;
-    var deviceMac = that.data.deviceMac;
-    app.PubMsg({
-      type: "get_dev_info",
-      DstDeviceName: deviceMac,
-    });
+    // var deviceMac = that.data.deviceMac;
+    // app.PubMsg({
+    //   type: "get_dev_info",
+    //   DstDeviceName: deviceMac,
+    // });
   },
 
   mqttCallback(type, option) {
@@ -136,6 +145,7 @@ Page({
       case "message":
         // 设备信息
         if (payloads.type === "get_dev_info") {
+          console.log("设备信息get_dev_info:", payloads);
           that.setData({
             deviceOther: payloads.other,
             updataDeviceInfo: true,
@@ -223,8 +233,19 @@ Page({
               }
             })
           }
+        } else if (payloads.type === "start_dm_auth") {
+          //	{
+          // 		"dsn":	"431589788221452",
+          // 		"authReqInfo":	{
+          // 			"codeChallenge":	"YzJkMmU5NGU2Y2NlZjM1ODAwMDIzNjJjYmZmY2Y5OTJhY2Q0MmU1N2FiYzBkYWYyMzVmMDJlYzMxMTZiMjc1Mw==",
+          // 			"sessionId":	"1646821421"
+          // 		}
+          // 	}
+          console.log("设备信息start_dm_auth:", payloads);
+          that.data.qqAuthInfo = payloads.other;
+
         }
-        default:
+      default:
     }
   },
 
@@ -473,6 +494,92 @@ Page({
       })
     })
   },
+  goQQAuth() {
+    var that = this;
+    if (that.data.isQQAuth) {
+      wx.showModal({
+        title: '解除授权',
+        content: '确定要解除QQ音乐授权吗?',
+        success(res) {
+          if (res.confirm) {
+            that.setData({
+              isQQAuth: false
+            });
+          }
+        }
+      });
+    } else {
+
+      autoAuth(EnumPlatformId.QQ, that.getDeivce()).then((res) => {
+        console.log("isQQAuth", res);
+        if (res) {
+          that.setData({
+            isAuthXmly: true
+          });
+        } else if (res === false) {
+          wx.showToast({
+            title: '授权失败,请稍后再试',
+            icon: 'none'
+          });
+        } else {
+          // null的不处理
+        }
+      }).catch((error) => {
+        console.error('Error during authorization:', error);
+        wx.showToast({
+          title: '授权失败,请稍后再试',
+          icon: 'none'
+        });
+      });
+    }
+  },
+  goXmlyAuth() {
+    var that = this;
+    console.log("goXmlyAuth", that.data.isAuthXmly)
+    if (that.data.isAuthXmly) {
+      wx.showModal({
+        title: '解除授权',
+        content: '确定要解除喜马拉雅授权吗?',
+        success(res) {
+          if (res.confirm) {
+            unbind(EnumPlatformId.XMLY, that.getDeivce()).then((res) => {
+              that.setData({
+                isAuthXmly: res
+              });
+            });
+          }
+        }
+      })
+    } else {
+      // routeUtil.jump(routePath.xmlyAuth);
+      autoAuth(EnumPlatformId.XMLY, that.getDeivce()).then((res) => {
+        console.log("isAuthXmly", res);
+
+        if (res) {
+          that.setData({
+            isAuthXmly: true
+          });
+        } else if (res === false) {
+          wx.showToast({
+            title: '授权失败,请稍后再试',
+            icon: 'none'
+          });
+        } else {
+          // null的不处理
+        }
+      }).catch((error) => {
+        console.error('Error during authorization:', error);
+        wx.showToast({
+          title: '授权失败,请稍后再试',
+          icon: 'none'
+        });
+      });
+    }
+  },
+  getDeivce() {
+    var that = this;
+    return { "clientType": that.data.clientType, "deviceMac": that.data.deviceMac, "deviceId": that.data.deviceId, "dsn": that.data.qqAuthInfo.dsn };
+  },
 
   /** 
    * 时间戳转化为年 月 日 时 分 秒 

+ 21 - 2
pages/pageB/deviceWake/deviceWake.wxml

@@ -1,6 +1,5 @@
 <view class="deviceWake">
-  <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{nvabarData}}'>
-  </nav-bar>
+  <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{nvabarData}}'></nav-bar>
   <view class="content">
     <view class="tip">
       <image src="./../../../img/gt.png" mode="heightFix"></image>
@@ -73,6 +72,26 @@
         </view>
       </view> -->
     </view>
+    <view class="waskList">
+      <view class="swicth">
+        <image src="./../../../img/wk2.png" mode="heightFix"></image>
+        <text>授权设置</text>
+      </view>
+      <view class="page__bd" style="opacity: {{isQQAuth ? 1 : 0.4}};" bindtap="goQQAuth">
+        <text>QQ音乐授权</text>
+        <view class="choice">
+          <text>{{isQQAuth?"已授权" : "去授权"}}</text>
+          <image src="./../../../img/b.png" mode="heightFix"></image>
+        </view>
+      </view>
+      <view class="page__bd" style="opacity: {{isAuthXmly ? 1 : 0.4}};" bindtap="goXmlyAuth">
+        <text>喜马拉雅授权</text>
+        <view class="choice">
+          <text>{{isAuthXmly?"已授权" : "去授权"}}</text>
+          <image src="./../../../img/b.png" mode="heightFix"></image>
+        </view>
+      </view>
+    </view>
   </view>
   <Toast visible="{{toast_visible}}" toast-data='{{toastData}}' twoButCallback="{{twoButCallback}}"></Toast>
 </view>

+ 8 - 7
utils/requestUtil.js

@@ -77,17 +77,18 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
       title: '加载中',
     });
   }
-  console.log("请求参数:", fullurl, data)
+  var headerMap = Object.assign({
+    "content-type": "application/x-www-form-urlencoded",
+    "appid": "wx08f94a3e90881910",
+    "Authorization": isToken ? Authorization : undefined
+  }, header)
+  console.log("请求参数:", fullurl, headerMap)
   return new Promise((resolve, reject) => {
     wx.request({
       url: fullurl,
       method,
       data,
-      header: Object.assign({
-        "content-type": "application/x-www-form-urlencoded",
-        "appid": "wx08f94a3e90881910",
-        "Authorization": isToken ? Authorization : undefined
-      }, header),
+      header: headerMap,
       success(res) {
         console.log("接口:", fullurl, res)
         if (res.statusCode !== 200) {
@@ -130,7 +131,7 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
           msg: JSON.stringify(err)
         })
       },
-      complete() {}
+      complete() { }
     })
   })
 }

+ 2 - 0
utils/routePath.js

@@ -19,6 +19,7 @@ const deviceConnect1 = "../../pageB/deviceConnect1/deviceConnect1";
 const deviceConnect2 = "../../pageB/deviceConnect2/deviceConnect2";
 const deviceConnect3 = "../../pageB/deviceConnect3/deviceConnect3";
 const deviceConnect4 = "../../pageB/deviceConnect4/deviceConnect4";
+const authWeb = "../../pageB/authWeb/authWeb";
 
 /// C
 const about = "../../pageC/about/about";
@@ -62,6 +63,7 @@ module.exports = {
   deviceConnect2: deviceConnect2,
   deviceConnect3: deviceConnect3,
   deviceConnect4: deviceConnect4,
+  authWeb: authWeb,
   /// C
   about: about,
   aboutIndex: aboutIndex,