Przeglądaj źródła

还在使用本地签名

gcz 3 lat temu
rodzic
commit
601354ece6

+ 3 - 0
.env.development

@@ -4,6 +4,9 @@ NODE_ENV = development
 # 开发环境
 VUE_APP_BASE_API = '/company-api'
 
+# 开发环境公用接口
+VUE_APP_COMMON_API = '/common-api'
+
 
 # 路由懒加载
 VUE_CLI_BABEL_TRANSPILE_MODULES = true

+ 4 - 1
.env.production

@@ -2,4 +2,7 @@
 NODE_ENV = production
 
 # 生产环境
-VUE_APP_BASE_API = 'https://wx.hw.hongweisoft.com/veterans/company/'
+VUE_APP_BASE_API = 'https://wx.hw.hongweisoft.com/veterans/company/'
+
+# 生产环境公共接口
+VUE_APP_COMMON_API = 'https://wx.hw.hongweisoft.com/veterans/app/'

+ 47 - 4
public/debug/GenerateTestUserSig.js

@@ -1,4 +1,6 @@
 import * as LibGenerateTestUserSig from './lib-generate-test-usersig.min.js'
+import { getSignatureInfo } from "../../src/api";
+// import store from '@/store';
 
 /**
  * 腾讯云 SDKAppId,需要替换为您自己账号下的 SDKAppId。
@@ -6,7 +8,7 @@ import * as LibGenerateTestUserSig from './lib-generate-test-usersig.min.js'
  * 进入腾讯云实时音视频[控制台](https://console.cloud.tencent.com/rav ) 创建应用,即可看到 SDKAppId,
  * 它是腾讯云用于区分客户的唯一标识。
  */
-const SDKAPPID = 1400594521
+const SDKAPPID = 1400601414
 
 
 /**
@@ -15,7 +17,7 @@ const SDKAPPID = 1400594521
  * 时间单位:秒
  * 默认时间:7 x 24 x 60 x 60 = 604800 = 7 天
  */
-const EXPIRETIME = 604800
+const EXPIRETIME = 86400
 
 
 /**
@@ -28,7 +30,7 @@ const EXPIRETIME = 604800
  * 注意:该方案仅适用于调试Demo,正式上线前请将 UserSig 计算代码和密钥迁移到您的后台服务器上,以避免加密密钥泄露导致的流量盗用。
  * 文档:https://cloud.tencent.com/document/product/647/17275#Server
  */
-const SECRETKEY = 'd643bc248fd0c49a041ef7551962fe639abfbb9db660dd1c6d7e868f8193f704'
+const SECRETKEY = '6d065252f0779d8a4a45020630b3507ac1c8f946669fc240b9818ed243e40547'
 
 /*
  * Module:   GenerateTestUserSig
@@ -47,15 +49,56 @@ const SECRETKEY = 'd643bc248fd0c49a041ef7551962fe639abfbb9db660dd1c6d7e868f8193f
  *
  * Reference:https://cloud.tencent.com/document/product/647/17275#Server
  */
-export function genTestUserSig(userID) {
+export function  genTestUserSig(userID) {
   // console.log("LibGenerateTestUserSig",LibGenerateTestUserSig.default)
   // console.log("typeof LibGenerateTestUserSig",typeof LibGenerateTestUserSig.default)
   const generator = new LibGenerateTestUserSig.default(SDKAPPID, SECRETKEY, EXPIRETIME)
   const userSig = generator.genTestUserSig(userID)
 
+  // return {
+  //   sdkAppID: SDKAPPID,
+  //   userSig: userSig,
+  // }
+  
+
+
+//接口获取签名
+  let inviterId = sessionStorage.getItem('inviterId');
+  if(!userID){userID=inviterId}
+  console.log('inviterId',inviterId);
+  let type = null;
+  let from = sessionStorage.getItem('from');
+  console.log('from',from);
+  console.log('userID',userID);
+  // console.log('userSig',userSig);
+  if(from=='company'){
+    type = 3
+  }else if(from=='veterans'){
+    type = 1
+  }else if(from=='teacher'){
+    type = 2
+  }
+
+  let inviterInfo={};
+   getSignatureInfo({id:userID,type:type}).then(res=>{
+    console.log('getSignatureInfo',res.data);
+    inviterInfo = res.data.data;
+    inviterInfo.sdkAppID = SDKAPPID;
+    inviterInfo.userSig = res.data.data.signature;
+    sessionStorage.setItem('inviterInfo', JSON.stringify(inviterInfo));
+    console.log('inviterInfo',inviterInfo);
+    // return inviterInfo;
+  }).catch(err=>{
+    console.log('getSignatureInfo',err);
+  })
+
+  // return inviterInfo
+
   return {
     sdkAppID: SDKAPPID,
     userSig: userSig,
   }
+
+  
 }
 

+ 1 - 1
src/App.vue

@@ -55,7 +55,7 @@
       </svg>
       <div class="content-wrap">
         <div class="content">
-          提示:退役军人用"veteMemberId",企业使用企业ID登录。
+          <!-- 提示:退役军人用"veteMemberId",企业使用企业ID登录。 -->
         </div>
       </div>
     </div>

+ 13 - 0
src/api/index.js

@@ -3,6 +3,7 @@ import qs from 'qs';
 
 const API_DOMAIN = 'https://service-c2zjvuxa-1252463788.gz.apigw.tencentcs.com';
 let MY_API_DOMAIN = process.env.VUE_APP_BASE_API;
+let MY_COMMON_API = process.env.VUE_APP_COMMON_API;
 
 export async function getSmsVerifyCode(phoneNum) {
   let data = {
@@ -92,3 +93,15 @@ export function companyInfo(data) {
   return axios(params);
 }
 
+// 根据id获取签名信息
+export function getSignatureInfo(data) {
+  let params = {
+    method: 'get',
+    headers: { 'content-type': 'application/json' },
+    params: data,
+    url: `${MY_COMMON_API}im/getSignatureInfo`,
+  }
+  return axios(params);
+}
+
+

+ 4 - 1
src/components/home-page/index.vue

@@ -11,7 +11,7 @@
         "
         alt=""
       /> -->
-      {{ loginUserInfo && (loginUserInfo.name || loginUserInfo.userId) }}
+      {{ loginUserInfo && (sessionInviterInfo&&sessionInviterInfo.username || loginUserInfo.name || loginUserInfo.userId) }}
       欢迎您!
     </div>
     <div class="home-page-section-list">
@@ -47,6 +47,7 @@ export default {
     return {
       enableEditName: true,
       defaultAvatar: require("../../../static/images/avatar15.png"),
+      sessionInviterInfo:{},
     };
   },
   watch: {
@@ -60,6 +61,8 @@ export default {
     if (this.veteMemberId && this.isLogin) {
       this.goto("/video-call");
     }
+    let inviterInfo = JSON.parse(sessionStorage.getItem('inviterInfo'));
+    this.sessionInviterInfo = inviterInfo||{};
   },
   methods: {
     goto: function (path) {

+ 34 - 10
src/components/login/index.vue

@@ -13,6 +13,7 @@
 <script>
 import { genTestUserSig } from "../../../public/debug/GenerateTestUserSig";
 import { companyInfo, memberinfo } from "../../api";
+import { log, setUserLoginInfo } from "../../utils";
 
 export default {
   name: "Login",
@@ -41,10 +42,14 @@ export default {
         return;
       }
       //清掉登录状态才能重新登录
-      this.$store.commit("userLogoutSuccess");
+      this.logout();
 
-      let form = sessionStorage.getItem('from');
-       if(form=='company'){
+      let from = sessionStorage.getItem('from');
+      // let inviterInfo = JSON.parse(sessionStorage.getItem('inviterInfo'));
+      let inviterInfo = await genTestUserSig(this.UserID);
+      console.log('inviterInfo',inviterInfo);
+      console.log('login inviterInfo',inviterInfo);
+       if(from=='company'){
          companyInfo({ companyId: this.UserID })
         .then((res) => {
           if (res.data.code == "200") {
@@ -52,11 +57,11 @@ export default {
           } else {
             this.loginInfo = {};
           }
-          // console.log("this.loginInfo", this.loginInfo);
+          console.log("this.loginInfo", this.loginInfo);
 
           const userSig = genTestUserSig(this.UserID).userSig;
           const userId = this.UserID;
-          const name = this.loginInfo.userName;
+          const name = this.loginInfo?.userName||inviterInfo?.username;
           const loginsPortrait = this.loginInfo.logoFileList[0]?.filesUrl;
           this.$store.commit("userLoginSuccess");
           this.$store.commit("setLoginUserInfo", {
@@ -89,7 +94,7 @@ export default {
             userSig,
           });
         });
-       }else if(form=='veterans'){
+       }else if(from=='veterans'){
          memberinfo({ veteMemberId: this.UserID })
         .then((res) => {
           console.log('memberinfo',res);
@@ -137,12 +142,31 @@ export default {
         });
 
        }else{
-         this.$message("登录出错请联系管理员!");
-         console.log('1111 form',form);
-       }
+         const userSig = genTestUserSig(this.UserID).userSig;
+          const userId = this.UserID;
+          const loginsPortrait = `${location.origin}/#/static/images/avatar15.png`;
+          this.$store.commit("userLoginSuccess");
+          this.$store.commit("setLoginUserInfo", {
+            userId,
+            // loginsPortrait,
+            userSig,
+          });
 
-      
+          // 登录 trtcCalling
+          this.$trtcCalling.login({
+            userID: this.UserID,
+            userSig,
+          });
+       } 
     },
+    logout(){
+      this.$trtcCalling.logout();
+        this.$store.commit("userLogoutSuccess");
+        setUserLoginInfo({
+          token: "",
+          phoneNum: "",
+        });
+    }
   },
 };
 </script>

+ 4 - 1
src/components/video-call/index.vue

@@ -2,7 +2,7 @@
   <div class="video-call-section">
     <div class="video-call-section-header">
       <img class="portrait" :src="loginUserInfo.loginsPortrait||defaultAvatar" alt="" />
-      {{ loginUserInfo && (loginUserInfo.name || loginUserInfo.userId) }}
+      {{ loginUserInfo && (sessionInviterInfo&&sessionInviterInfo.username || loginUserInfo.name || loginUserInfo.userId) }}
       欢迎您!
     </div>
     <!-- <div class="video-call-section-title" v-if="!isShowVideoCall">视频通话</div> -->
@@ -91,6 +91,7 @@ export default {
       callFlag: false,
       cancelFlag: false,
       defaultAvatar: require("../../../static/images/avatar15.png"),
+      sessionInviterInfo:{},
     };
   },
   mounted() {
@@ -98,6 +99,8 @@ export default {
       this.startMeeting();
       this.updateUserId2Name(this.meetingUserIdList);
     }
+    let inviterInfo = JSON.parse(sessionStorage.getItem('inviterInfo'));
+    this.sessionInviterInfo = inviterInfo||{};
   },
   destroyed() {
     this.$store.commit("updateMuteVideoUserIdList", []);

+ 4 - 0
src/router/index.js

@@ -48,6 +48,10 @@ export function createRouter() {
       if (Object.prototype.hasOwnProperty.call(to.query, 'veteMemberId')) {
         store.commit("setVeteMemberId", to.query.veteMemberId);
       }
+      if (Object.prototype.hasOwnProperty.call(to.query, 'inviterId')) {
+        // store.commit("setInviterId", to.query.inviterId);
+        sessionStorage.setItem('inviterId',to.query.inviterId)
+      }
       if (to.path !== '/login') {
         if (from.path !== '/login') {
           next('/login?' + objToParam(to.query));

+ 5 - 0
src/store/index.js

@@ -15,9 +15,13 @@ function createStore() {
       meetingUserIdList: [],
       muteVideoUserIdList: [],
       muteAudioUserIdList: [],
+      inviterId:'',
       veteMemberId: '',
     },
     mutations: {
+      setInviterId(state, inviterId) {
+        state.inviterId = inviterId
+      },
       setVeteMemberId(state, veteMemberId) {
         state.veteMemberId = veteMemberId
       },
@@ -27,6 +31,7 @@ function createStore() {
       userLogoutSuccess(state) {
         state.isLogin = false;
         state.loginUserInfo = null;
+        sessionStorage.removeItem('inviterInfo');
       },
       setLoginUserInfo(state, payload) {
         const { userId, userSig, name, loginsPortrait } = payload;

+ 9 - 1
vue.config.js

@@ -10,7 +10,15 @@ module.exports = {
         pathRewrite: {
           ['^' + process.env.VUE_APP_BASE_API]: ''
         }
-      }
+      },
+      [process.env.VUE_APP_COMMON_API]: {
+        // target: `http://wx.hw.hongweisoft.com/veterans/company/`,
+        target: `https://wx.hw.hongweisoft.com/veterans/app/`,
+        changeOrigin: true,
+        pathRewrite: {
+          ['^' + process.env.VUE_APP_COMMON_API]: ''
+        }
+      },
     },
     disableHostCheck: true
   },