Browse Source

修改用户端传参

master
[yxf] 4 days ago
parent
commit
7e40037df3
  1. 2
      im-platform/src/main/java/com/bx/implatform/dto/LoginDTO.java
  2. 14
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  3. 58
      im-uniapp/pages/login/login.vue

2
im-platform/src/main/java/com/bx/implatform/dto/LoginDTO.java

@ -35,7 +35,7 @@ public class LoginDTO {
private String uniqueToken; private String uniqueToken;
@Schema(description = "客服ID") @Schema(description = "客服ID")
private String keFuId; private String customerId;
@Schema(description = "可切换客服账号") @Schema(description = "可切换客服账号")
private String switchableAccountIds; private String switchableAccountIds;

14
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -163,24 +163,24 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
*/ */
private Long getCustomerServiceId(LoginDTO dto) { private Long getCustomerServiceId(LoginDTO dto) {
// 1. 如果前端传了 kefuid,直接使用并验证该客服是否有效 // 1. 如果前端传了 kefuid,直接使用并验证该客服是否有效
if (StrUtil.isNotBlank(dto.getKeFuId())) { if (StrUtil.isNotBlank(dto.getCustomerId())) {
try { try {
Long kefuid = Long.parseLong(dto.getKeFuId()); Long customerId = Long.parseLong(dto.getCustomerId());
// 验证该客服是否存在且有效 // 验证该客服是否存在且有效
User customer = this.getById(kefuid); User customer = this.getById(customerId);
if (customer != null && customer.getIsCustomer() == 2) { if (customer != null && customer.getIsCustomer() == 2) {
// 验证该客服的uniqueToken是否与传入的匹配 // 验证该客服的uniqueToken是否与传入的匹配
if (dto.getUniqueToken().equals(customer.getUniqueToken())) { if (dto.getUniqueToken().equals(customer.getUniqueToken())) {
return kefuid; return customerId;
} else { } else {
log.warn("前端传入的客服ID {} 的uniqueToken与当前不匹配,将使用token查询", kefuid); log.warn("前端传入的客服ID {} 的uniqueToken与当前不匹配,将使用token查询", customerId);
} }
} else { } else {
log.warn("前端传入的客服ID {} 无效或不是客服,将使用token查询", kefuid); log.warn("前端传入的客服ID {} 无效或不是客服,将使用token查询", customerId);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
log.warn("前端传入的kefuid格式错误:{}", dto.getKeFuId()); log.warn("前端传入的kefuid格式错误:{}", dto.getCustomerId());
} }
} }
// 2. 通过uniqueToken查询客服 // 2. 通过uniqueToken查询客服

58
im-uniapp/pages/login/login.vue

@ -21,7 +21,7 @@ export default {
ip: '', ip: '',
sourceUrl: '', sourceUrl: '',
uniqueToken: '', uniqueToken: '',
kefuid: '' customerid: ''
} }
} }
}, },
@ -60,7 +60,7 @@ export default {
console.log("来源网址:", this.dataForm.sourceUrl); console.log("来源网址:", this.dataForm.sourceUrl);
}, },
// URLtokenkefuid // URLtokencustomerid
getTokenFromUrl() { getTokenFromUrl() {
// #ifdef H5 // #ifdef H5
const pages = getCurrentPages(); const pages = getCurrentPages();
@ -71,20 +71,20 @@ export default {
this.dataForm.uniqueToken = options.token; this.dataForm.uniqueToken = options.token;
} }
if (options.kefuid) { if (options.customerid) {
this.dataForm.kefuid = options.kefuid; this.dataForm.customerid = options.customerid;
} }
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token'); const token = urlParams.get('token');
const kefuid = urlParams.get('kefuid'); const customerid = urlParams.get('customerid');
if (token) { if (token) {
this.dataForm.uniqueToken = token; this.dataForm.uniqueToken = token;
} }
if (kefuid) { if (customerid) {
this.dataForm.kefuid = kefuid; this.dataForm.customerid = customerid;
} }
// #endif // #endif
@ -96,8 +96,8 @@ export default {
if (options.token) { if (options.token) {
this.dataForm.uniqueToken = options.token; this.dataForm.uniqueToken = options.token;
} }
if (options.kefuid) { if (options.customerid) {
this.dataForm.kefuid = options.kefuid; this.dataForm.customerid = options.customerid;
} }
// #endif // #endif
@ -110,8 +110,8 @@ export default {
this.dataForm.uniqueToken = options.token; this.dataForm.uniqueToken = options.token;
} }
console.log(options); console.log(options);
if (options.kefuid) { if (options.customerid) {
this.dataForm.kefuid = options.kefuid; this.dataForm.customerid = options.customerid;
} }
// #endif // #endif
}, },
@ -127,7 +127,6 @@ export default {
if (!this.dataForm.uniqueToken) { if (!this.dataForm.uniqueToken) {
console.log("未携带token,跳转到404页面"); console.log("未携带token,跳转到404页面");
// #ifdef H5 // #ifdef H5
// /h5/
window.location.href = '/h5/#/pages/login/404'; window.location.href = '/h5/#/pages/login/404';
// #endif // #endif
@ -153,7 +152,7 @@ export default {
ip: this.dataForm.ip, ip: this.dataForm.ip,
sourceUrl: this.dataForm.sourceUrl, sourceUrl: this.dataForm.sourceUrl,
uniqueToken: this.dataForm.uniqueToken, uniqueToken: this.dataForm.uniqueToken,
keFuId: this.dataForm.kefuid, // kefuid customerId: this.dataForm.customerid,
}; };
this.$http({ this.$http({
@ -179,9 +178,10 @@ export default {
} }
this.friendStore.addFriend(friend); this.friendStore.addFriend(friend);
// URL token this.clearUrlParams();
// #ifdef H5 // #ifdef H5
const cleanUrl = window.location.origin + '/h5/' + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; const cleanUrl = window.location.origin + '/h5/#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE';
window.location.href = cleanUrl; window.location.href = cleanUrl;
// #endif // #endif
@ -195,24 +195,28 @@ export default {
}).catch(err => { }).catch(err => {
console.log("自动登录失败", err); console.log("自动登录失败", err);
GLOBAL_AUTO_LOGIN_LOCK = false; GLOBAL_AUTO_LOGIN_LOCK = false;
this.clearUrlParams();
// token404
if (err && (err.code === 401 || err.statusCode === 401)) {
// #ifdef H5 // #ifdef H5
window.location.href = '/h5/pages/login/404'; window.location.href = '/h5/#/pages/login/404';
// #endif // #endif
// #ifndef H5 // #ifndef H5
uni.redirectTo({ uni.redirectTo({ url: '/pages/login/404' });
url: '/pages/login/404'
});
// #endif // #endif
}
}); });
}, },
clearUrlParams() {
// #ifdef H5
const url = new URL(window.location.href);
url.searchParams.delete('token');
url.searchParams.delete('customerid');
window.history.replaceState(null, '', url.pathname + url.search + url.hash);
// #endif
},
getIp() { getIp() {
// ip
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
url: 'https://api.ipify.org?format=json', url: 'https://api.ipify.org?format=json',
@ -235,16 +239,14 @@ export default {
}, },
onLoad(options) { onLoad(options) {
// onLoadoptionstoken
if (options.token) { if (options.token) {
this.dataForm.uniqueToken = options.token; this.dataForm.uniqueToken = options.token;
console.log("onLoad获取到token:", this.dataForm.uniqueToken); console.log("onLoad获取到token:", this.dataForm.uniqueToken);
} }
if (options.kefuid) { if (options.customerid) {
this.dataForm.kefuid = options.kefuid; this.dataForm.customerid = options.customerid;
console.log("onLoad获取到kefuid:", this.dataForm.kefuid); console.log("onLoad获取到customerid:", this.dataForm.customerid);
} }
//
setTimeout(() => { setTimeout(() => {
this.autoLogin(); this.autoLogin();
}, 50); }, 50);

Loading…
Cancel
Save