更新时间:2025-11-13 GMT+08:00
WEB渠道接口鉴权方式
实现说明
调用WEB侧接口,请求中的Cookie需要携带ccmessaging-token,ccmessaging-token的值为集成页面的时候ccmessaging通过请求响应写到浏览器Cookie中的。校验token的方法如下:
/**
* 校验Token是否有效
*
* @param oldToken 座席或者客户端访问的token
* @return true:有效 false:无效
*/
@Override
public boolean isValid(String oldToken) throws Exception {
boolean isValidResult = false;
String cacheTokenValue = "";
if (!ChatStringUtils.isEmpty(oldToken)) { // 传入的token必须非空
String tokenCacheKey = null;
try {
String urlDecodeToken = URLDecoder.decode(oldToken, "UTF-8"); // 前台取得的是url编码后的string
String baseDecodeToken = new String(Base64.getDecoder().decode(urlDecodeToken), "UTF-8");
JSONObject userInfoObject = JSON.parseObject(baseDecodeToken);
String uid = String.valueOf(userInfoObject.get("tenantId")) + String.valueOf(
userInfoObject.get("channelId")) + String.valueOf(userInfoObject.get("userId"));
tokenCacheKey = cacheService.getChatCacheKey("TOKENKEY", uid);
cacheTokenValue = BaseUtil.decode(cacheService.getValue(tokenCacheKey));
} catch (Exception e) {
RedisCacheUtil.putRedisCache(Boolean.FALSE, e);
if (tokenCacheKey != null) {
cacheTokenValue = BaseUtil.decode(cacheService.getValue(tokenCacheKey));
}
log.error("Invalid AccessToken!Please check!", e);
}
if (!ChatStringUtils.isEmpty(cacheTokenValue) && cacheTokenValue.equals(
oldToken)) { // 請求傳入的token是否和redis取出的token一樣
isValidResult = true;
}
}
return isValidResult;
}
父主题: WEB渠道