houjie 4 년 전
부모
커밋
3a50f099dc
10개의 변경된 파일1087개의 추가작업 그리고 926개의 파일을 삭제
  1. 8 2
      API/Constant.js
  2. 9 3
      API/ProtoConfig.js
  3. 1 1
      Lib/ProtoMap.js
  4. 13 2
      Lib/Request.js
  5. 6 5
      manifest.json
  6. 846 884
      package-lock.json
  7. 4 3
      package.json
  8. 32 17
      pages.json
  9. 140 0
      pages/login/login.vue
  10. 28 9
      proto/User.proto

+ 8 - 2
API/Constant.js

@@ -1,8 +1,14 @@
 
 // URL
 export let BASEURL = '';
+// if(process.env.NODE_ENV === 'development'){ // 开发环境
+//   BASEURL = 'https://test.ohplay.radio1964.net/ohplay/Web/HttpToTcp';
+// }else{ // 生产
+//   BASEURL = 'https://ohplay.radio1964.net/ohplay/Web/HttpToTcp';
+// };
+
 if(process.env.NODE_ENV === 'development'){ // 开发环境
-  BASEURL = 'https://test.ohplay.radio1964.net/Ohplay/Web/HttpToTcp';
+  BASEURL = 'https://test.ohplay.radio1964.net/';
 }else{ // 生产
-  BASEURL = 'https://ohplay.radio1964.net/Ohplay/Web/HttpToTcp';
+  BASEURL = 'https://ohplay.radio1964.net/';
 };

+ 9 - 3
API/ProtoConfig.js

@@ -2,9 +2,15 @@ import {
 	user
 } from './../proto/bundle.js';
 
+//不需要token的请求
+const NoTokenServants = [10003,10005]
+
 const ProtoConfig = {
-	1001: user.wx_mini_program_login_req, // 登录请求
-	1002: user.wx_mini_program_login_rsp, // 登录返回
+	10003: user.registerReq,//注册请求
+	10004: user.registerRsp,//注册返回
+	10005: user.loginReq, // 登录请求
+	10006: user.loginRsp, // 登录返回
+	
 };
 
-module.exports = ProtoConfig;
+module.exports = {ProtoConfig,NoTokenServants};

+ 1 - 1
Lib/ProtoMap.js

@@ -2,7 +2,7 @@ import {
 	common,
 } from './../proto/bundle';
 
-import ProtoConfig from './../API/ProtoConfig';
+import {ProtoConfig} from './../API/ProtoConfig';
 
 
 function getMsgWebsocket(version, server, servant, buffer) {

+ 13 - 2
Lib/Request.js

@@ -3,9 +3,15 @@ import {
 	requestEncode,
 	responseDecode
 } from "./ProtoMap";
+import {NoTokenServants} from './../API/ProtoConfig';
 
 import { BASEURL } from "../API/Constant";
 
+//这个path需要token
+const PATH = 'Ohplay/Web/HttpToTcp';
+//这个path不需要token
+const PATH1 = 'ohplay/Web/HttpToTcp';
+
 let token = "";
 
 // 登录
@@ -70,7 +76,7 @@ function getToken() {
 }
 
 // 获取token
-getToken();
+//getToken();
 // login();
 
 
@@ -83,7 +89,7 @@ const defaultHeader = {
 uni.addInterceptor('request', {
   invoke(args) {
     // request 触发前拼接 url 
-    args.url = BASEURL;
+    //args.url = BASEURL;
 		if(token) {
 			args.header.token = token;
 		};
@@ -105,8 +111,13 @@ uni.addInterceptor('request', {
  * @returns 
  */
 function request(data, type = "POST", header = defaultHeader) {
+	let url = BASEURL+PATH
+	if(NoTokenServants.indexOf(data.servant)>=0){
+		url = BASEURL+PATH1
+	}
 	return new Promise((resolve, reject) => {
 		uni.request({
+			url,
 			header: header,
 			method: type,
 			timeout: 15000,

+ 6 - 5
manifest.json

@@ -8,7 +8,7 @@
     /* 5+App特有相关 */
     "app-plus" : {
         "usingComponents" : true,
-		"nvueStyleCompiler" : "uni-app",
+        "nvueStyleCompiler" : "uni-app",
         "compilerVersion" : 3,
         "splashscreen" : {
             "alwaysShowBeforeRender" : true,
@@ -50,9 +50,10 @@
     "quickapp" : {},
     /* 小程序特有相关 */
     "mp-weixin" : {
-        "appid" : "",
+        "appid" : "wx08f94a3e90881910",
         "setting" : {
-            "urlCheck" : false
+            "urlCheck" : false,
+            "es6" : false
         },
         "usingComponents" : true
     },
@@ -65,7 +66,7 @@
     "mp-toutiao" : {
         "usingComponents" : true
     },
-    "uniStatistics": {  
-        "enable": false
+    "uniStatistics" : {
+        "enable" : false
     }
 }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 846 - 884
package-lock.json


+ 4 - 3
package.json

@@ -4,17 +4,18 @@
   "description": "",
   "main": "main.js",
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "proto": "pbjs -t static-module -w commonjs -o proto/bundle.js proto/*.proto"
   },
   "author": "",
   "license": "ISC",
   "dependencies": {
     "@dcloudio/uni-helper-json": "^1.0.13",
-    "ali-oss": "^6.15.2",
     "mqtt": "^4.1.0",
     "protobufjs": "^6.11.2"
   },
   "devDependencies": {
-    "@types/ali-oss": "^6.0.8"
+    "@types/html5plus": "^1.0.1",
+    "@types/uni-app": "^1.4.3"
   }
 }

+ 32 - 17
pages.json

@@ -11,6 +11,9 @@
 			"style": {
 				"navigationBarTitleText": "OhPlay"
 			}
+		},
+		{
+			"path": "pages/login/login"
 		}
 	],
 	"globalStyle": {
@@ -20,20 +23,32 @@
 		"backgroundColor": "#F8F8F8"
 	},
 	"tabBar": {
-    "color": "#7A7E83",
-    "selectedColor": "#3cc51f",
-    "borderStyle": "black",
-    "backgroundColor": "#ffffff",
-    "list": [{
-        "pagePath": "pages/index/index",
-        "iconPath": "static/image/iot.png",
-        "selectedIconPath": "static/image/iot_org.png",
-        "text": "首页"
-    }, {
-        "pagePath": "pages/mine/mine",
-        "iconPath": "static/image/mine.png",
-        "selectedIconPath": "static/image/mine_pressed.png",
-        "text": "我的"
-    }]
-}
-}
+		"color": "#7A7E83",
+		"selectedColor": "#3cc51f",
+		"borderStyle": "black",
+		"backgroundColor": "#ffffff",
+		"list": [
+			{
+				"pagePath": "pages/index/index",
+				"iconPath": "static/image/iot.png",
+				"selectedIconPath": "static/image/iot_org.png",
+				"text": "首页"
+			},
+			{
+				"pagePath": "pages/mine/mine",
+				"iconPath": "static/image/mine.png",
+				"selectedIconPath": "static/image/mine_pressed.png",
+				"text": "我的"
+			}
+		]
+	},
+	"condition": {
+		"current": 0,
+		"list": [
+			{
+				"name": "登录组件",
+				"path": "pages/login/login"
+			}
+		]
+	}
+}

+ 140 - 0
pages/login/login.vue

@@ -0,0 +1,140 @@
+<template>
+  <view class="login">
+    <button
+      type="default"
+      open-type="getPhoneNumber"
+      @getphonenumber="decryptPhoneNumber"
+      @click="login"
+    >
+      微信授权一键登录
+    </button>
+  </view>
+</template>
+
+<script>
+export default {
+  components: {},
+  data: () => ({
+    openid: null,
+    phoneInfo: null,
+  }),
+  computed: {},
+  methods: {
+    login() {
+      let that = this;
+      //获取openid
+      uni.login({
+        provider: "weixin",
+        success: function (loginRes) {
+          console.log(loginRes.authResult);
+          //调用登录接口
+          that
+            .$request({
+              server: 2,
+              servant: 10005,
+              data: {
+                code: loginRes.code,
+              },
+            })
+            .then((result) => {
+              console.log(result);
+              if (result.code === 0) {
+                that.openid = result.data.openid;
+                //获取token
+                that.getToken();
+              }
+            })
+            .catch((err) => {
+              console.log(err);
+            });
+        },
+        fail(err) {
+          console.log(err);
+        },
+      });
+    },
+    //获取手机号码
+    decryptPhoneNumber(e) {
+      console.log(e.detail);
+      if (e.detail.errMsg == "getPhoneNumber:ok") {
+        console.log(e.detail.iv);
+        console.log(e.detail.encryptedData);
+        this.phoneInfo = {
+          encryptedData: e.detail.encryptedData,
+          iv: e.detail.iv,
+        };
+        //获取token
+        this.getToken();
+      }
+    },
+    //获取uuid和token
+    getToken() {
+      console.log(this.openid);
+      console.log(this.phoneInfo);
+      if (this.openid && this.phoneInfo) {
+        console.log('getToken');
+        const platform = uni.getSystemInfoSync().platform;
+        let systemType;
+        switch (platform) {
+          case "ios":
+            systemType = 1;
+            break;
+          case "android":
+            systemType = 2;
+            break;
+          default:
+            systemType = 3;
+            break;
+        }
+        const openid = this.openid;
+        const iv = this.phoneInfo.iv;
+        const phone = this.phoneInfo.encryptedData;
+        //清除数据避免重复调用
+        this.openid = null;
+        this.phoneInfo = null;
+        this.$request({
+          server: 2,
+          servant: 10003,
+          data: {
+            type: 1,
+            openid,
+            phone,
+            systemType,
+            iv,
+          },
+        })
+          .then((result) => {
+            console.log(result);
+          })
+          .catch((err) => {
+            console.log(err);
+          });
+      }
+    },
+  },
+  watch: {},
+
+  // 页面周期函数--监听页面加载
+  onLoad() {},
+  // 页面周期函数--监听页面初次渲染完成
+  onReady() {},
+  // 页面周期函数--监听页面显示(not-nvue)
+  onShow() {},
+  // 页面周期函数--监听页面隐藏
+  onHide() {},
+  // 页面周期函数--监听页面卸载
+  onUnload() {},
+  // 页面处理函数--监听用户下拉动作
+  onPullDownRefresh() {
+    uni.stopPullDownRefresh();
+  },
+  // 页面处理函数--监听用户上拉触底
+  onReachBottom() {},
+  // 页面处理函数--监听页面滚动(not-nvue)
+  /* onPageScroll(event) {}, */
+  // 页面处理函数--用户点击右上角分享
+  /* onShareAppMessage(options) {}, */
+};
+</script>
+
+<style></style>

+ 28 - 9
proto/User.proto

@@ -4,19 +4,38 @@ package user;
 
 import "common";
 
-//登录请求
-message wx_mini_program_login_req {
-    string phone             = 1; //
-    string code              = 2;
-    string verifyCode    	 = 3; //
-    string nickname          = 4;
-    string headUrl          = 5;
-    uint32 systemType       = 6;
+
+//获取openid(10005/10006)
+message loginReq {
+    string code              = 1; //微信临时code
+}
+
+message loginRsp {
+    ErrorInfo errInfo   = 1; // 错误码信息
+    string openid        = 2; // 微信账号唯一标识openid
+}
+
+//枚举消息类型 
+enum EPhoneType {
+    phone  = 0;
+    local  = 1;//本机手机号
+    other  = 2;//
+}
+
+//注册or登录协议(10003/10004)
+message registerReq {
+    EPhoneType type          = 1;//暂时没啥用,默认为1
+    string openid            = 2; //微信账号唯一标识openid
+    string phone             = 3; //微信接口getPhoneNumber获取到的encryptedData
+    string verifyCode       = 4; //验证码,这里无用
+    uint32 systemType       = 5; //1:ios,2:android
+    string iv                = 6;//微信接口getPhoneNumber获取到的encryptedData
 }
 
-message wx_mini_program_login_rsp {
+message registerRsp {
     ErrorInfo errInfo   = 1; // 错误码信息
     string token         = 2; // 访问令牌
+    uint32 id           = 3;
 }