123
This commit is contained in:
67
ruoyi-admin/src/main/java/com/ruoyi/op/ImOp.java
Normal file
67
ruoyi-admin/src/main/java/com/ruoyi/op/ImOp.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package com.ruoyi.op;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.ruoyi.cai.domain.User;
|
||||||
|
import com.ruoyi.cai.im.ImManager;
|
||||||
|
import com.ruoyi.cai.service.UserService;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.yunxin.client.ImUserClient;
|
||||||
|
import com.ruoyi.yunxin.req.CreateUserReq;
|
||||||
|
import com.ruoyi.yunxin.req.UpdateTokenReq;
|
||||||
|
import com.ruoyi.yunxin.resp.YxCommonR;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class ImOp {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImUserClient imUserClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImManager imManager;
|
||||||
|
|
||||||
|
public void refreshIm(){
|
||||||
|
List<User> list = userService.list();
|
||||||
|
for (User user : list) {
|
||||||
|
String imToken = IdUtil.simpleUUID();
|
||||||
|
userService.update(Wrappers.lambdaUpdate(User.class).eq(User::getId,user.getId()).set(User::getImToken, imToken));
|
||||||
|
this.register(user.getId(),user.getImToken(),user.getNickname());
|
||||||
|
imManager.updateImInfo(user.getId(),user.getAvatar(),user.getNickname(),user.getGender());
|
||||||
|
LoginHelper.logoutApp(user.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(Long userId,String token,String nickname){
|
||||||
|
CreateUserReq req = new CreateUserReq();
|
||||||
|
req.setAccid(userId+"");
|
||||||
|
req.setToken(token);
|
||||||
|
req.setName(nickname);
|
||||||
|
YxCommonR r = imUserClient.createUser(req);
|
||||||
|
if(!r.isSuccess()){
|
||||||
|
if(r.getCode() == 414){
|
||||||
|
UpdateTokenReq req1 = new UpdateTokenReq();
|
||||||
|
req1.setAccid(userId+"");
|
||||||
|
req1.setToken(token);
|
||||||
|
YxCommonR commonR = imUserClient.updateToken(req1);
|
||||||
|
if(!commonR.isSuccess()){
|
||||||
|
log.error("刷新云token失败,{}", JSON.toJSONString(commonR));
|
||||||
|
throw new ServiceException("注册失败,云信异常");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.error("创建云信账号失败,{}", JSON.toJSONString(r));
|
||||||
|
throw new ServiceException("注册失败,云信异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.ruoyi.web.controller.cai.admin.op;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.op.ImOp;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/cai/op/im")
|
||||||
|
@Slf4j
|
||||||
|
public class ImOpController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImOp imOp;
|
||||||
|
|
||||||
|
@GetMapping("/refreshIm")
|
||||||
|
public R<Void> list() {
|
||||||
|
imOp.refreshIm();
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ public class UserTest {
|
|||||||
public void refreshIm(){
|
public void refreshIm(){
|
||||||
List<User> list = userService.list();
|
List<User> list = userService.list();
|
||||||
for (User user : list) {
|
for (User user : list) {
|
||||||
// this.register(user.getId(),user.getImToken(),user.getNickname());
|
this.register(user.getId(),user.getImToken(),user.getNickname());
|
||||||
imManager.updateImInfo(user.getId(),user.getAvatar(),user.getNickname(),user.getGender());
|
imManager.updateImInfo(user.getId(),user.getAvatar(),user.getNickname(),user.getGender());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,12 @@ public class AddressUtils {
|
|||||||
}
|
}
|
||||||
// 内网不查询
|
// 内网不查询
|
||||||
ip = StringUtils.contains(ip, "0:0:0:0:0:0:0:1") ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
|
ip = StringUtils.contains(ip, "0:0:0:0:0:0:0:1") ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
|
||||||
if (NetUtil.isInnerIP(ip)) {
|
try {
|
||||||
return "内网IP";
|
if (NetUtil.isInnerIP(ip)) {
|
||||||
|
return "内网IP";
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
return RegionUtils.getCityInfo(ip);
|
return RegionUtils.getCityInfo(ip);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user