更新企微退出

master
wujingtao 2 years ago
parent d45792761d
commit c0ed8ce5b1

@ -254,6 +254,23 @@ public enum ResultCode implements IResultCode {
*
*/
WE_CHAT_COLLECTION_EMPTY(1004,"添加微信集合不能为空!"),
/**
* 线
*/
FAILED_STATUS_INFO(1005,"获取在线状态信息失败"),
/**
*
*/
REQUEST_PARAMETER_ERROR(1007,"请求参数错误"),
/**
* 退
*/
LOGOUT_SUCCESS(1008,"退出成功"),
/**
* 退
*/
LOGOUT_ERROR(1007,"退出失败"),
;
/**
*

@ -26,7 +26,7 @@ public class FileUploadController {
@Resource
private FileUploadService fileUploadService;
@ApiOperation("文件上传")
@ApiOperation("文件上传 type 0-手机号 1-微信号")
@PostMapping("upload")
public Result<Object> fileUpload(@RequestParam("files") MultipartFile[] files, Integer type) {
fileUploadService.fileUpload(files, type);

@ -10,7 +10,6 @@ import com.baiye.entity.query.SourceRecordQuery;
import com.baiye.service.SourceService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

@ -7,6 +7,7 @@ import com.baiye.core.base.api.ResultCode;
import com.baiye.entity.dto.WeChatAddBulkFriendDTO;
import com.baiye.entity.dto.WeChatAddFriendDTO;
import com.baiye.entity.dto.WeChatFriendInfoDTO;
import com.baiye.entity.dto.WeChatLogoutDTO;
import com.baiye.service.WeChatUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -78,4 +79,11 @@ public class WechatController {
return weChatUserService.addBulkFriend(bulkFriendDTO);
}
@Log("退出登录")
@ApiOperation("批量退出")
@PostMapping("/batchLogout")
public Result<Object> bulkAddFriend
(@RequestBody WeChatLogoutDTO weChatLogoutDTO) {
return weChatUserService.batchLogout(weChatLogoutDTO);
}
}

@ -13,9 +13,9 @@ spring:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/by_cdp?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull
url: jdbc:mysql://8.130.96.163:3306/db_wechat?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull
username: root
password: 12345678
password: y7z7noq2
# 初始连接数
initial-size: 5
# 最小连接数

@ -0,0 +1,21 @@
package com.baiye.dao;
import com.baiye.entity.WeChatUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @author wjt
* @date 2022/07/14
*/
@Mapper
public interface WeChatUserMapper extends BaseMapper<WeChatUser> {
/**
* id
* @param wxId
* @return
*/
WeChatUser findByWxId(@Param("wxid") String wxId);
}

@ -1,6 +1,6 @@
package com.baiye.dao;
import com.baiye.entity.WechatSource;
import com.baiye.entity.WeChatSource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -12,7 +12,7 @@ import java.util.List;
* @date 2022/07/12
*/
@Mapper
public interface WechatSourceMapper extends BaseMapper<WechatSource> {
public interface WechatSourceMapper extends BaseMapper<WeChatSource> {
/**
*
*

@ -28,7 +28,7 @@ public class Source extends BaseEntity implements Serializable {
@ApiModelProperty(value = "号码")
private String nid;
@ApiModelProperty(value = "类型 0-微信号 1-号码")
@ApiModelProperty(value = "类型 0-手机号 1-微信号")
private Integer type;
@ApiModelProperty(value = "上传记录id")
private Long recordId;

@ -21,7 +21,7 @@ public class SourceUploadRecord extends BaseEntity implements Serializable {
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@ApiModelProperty(value = "类型 0-微信号1-号码")
@ApiModelProperty(value = "类型 0-手机号1-微信号")
private Integer type;
@ApiModelProperty(value = "分配状态 0-未分配 1-已分配")

@ -1,6 +1,5 @@
package com.baiye.entity;
import com.baiye.core.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
@ -14,7 +13,7 @@ import java.io.Serializable;
*/
@Data
@TableName("tb_wechat_source")
public class WechatSource implements Serializable {
public class WeChatSource implements Serializable {
private static final long serialVersionUID = 1364334049883636489L;
@TableId(value = "id")

@ -0,0 +1,54 @@
package com.baiye.entity;
import com.baiye.core.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.util.Date;
/**
* @author wjt
* @date 2022/07/14
*/
@Data
@TableName("tb_wechat_user")
public class WeChatUser extends BaseEntity implements Serializable {
private static final long serialVersionUID = -4755997517585953316L;
@TableId(value = "id")
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@Column(name = "login_type")
@ApiModelProperty(value = "登录类型")
private Integer loginType;
@Column(name = "nickname")
@ApiModelProperty(value = "昵称")
private String nickname;
@Column(name = "login_date")
@ApiModelProperty(value = "登录时间")
private Date loginDate;
@Column(name = "small_head_img_url")
@ApiModelProperty(value = "头像")
private String smallHeadImgUrl;
@Column(name = "wx_id")
@ApiModelProperty(value = "微信号")
private String wxId;
@Column(name = "token")
@ApiModelProperty(value = "token")
private String token;
@Column(name = "random_id")
@ApiModelProperty(value = "随机id")
private String randomId;
}

@ -33,7 +33,7 @@ public class WeChatAddBulkFriendDTO {
private String appKey;
@NonNull
@ApiModelProperty(value = "appKey")
@ApiModelProperty(value = "appSecret")
private String appSecret;

@ -0,0 +1,28 @@
package com.baiye.entity.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NonNull;
/**
* @author Enzo
* @date : 2022/7/8
*/
@Data
public class WeChatLogoutDTO {
@ApiModelProperty(value = "批量退出微信号 以 分隔")
private String wxIds;
@ApiModelProperty(value = "如果wxIds时是否选择退出全部")
private Boolean ifNullLogoutAll;
@NonNull
@ApiModelProperty(value = "appKey")
private String appKey;
@NonNull
@ApiModelProperty(value = "appKey")
private String appSecret;
}

@ -6,6 +6,7 @@ import com.baiye.core.constant.WeChatResponse;
import com.baiye.entity.dto.WeChatAddBulkFriendDTO;
import com.baiye.entity.dto.WeChatAddFriendDTO;
import com.baiye.entity.dto.WeChatFriendInfoDTO;
import com.baiye.entity.dto.WeChatLogoutDTO;
import java.util.List;
@ -69,4 +70,11 @@ public interface WeChatUserService {
* @return
*/
Result<Object> friendInfo(WeChatFriendInfoDTO weChatFriendInfoDTO);
/**
* 退
* @param weChatLogoutDTO
* @return
*/
Result<Object> batchLogout(WeChatLogoutDTO weChatLogoutDTO);
}

@ -46,7 +46,7 @@ public class SourceServiceImpl implements SourceService {
for (String path : filePaths) {
File file = FileUtil.file(path);
ExcelReader reader = ExcelUtil.getReader(file, 0);
if (type == 0) {
if (type == 1) {
reader.addHeaderAlias("微信号", "vId");
} else {
reader.addHeaderAlias("手机号", "nid");
@ -86,7 +86,6 @@ public class SourceServiceImpl implements SourceService {
Long vId = map.keySet().iterator().next();
List<Long> sourceList = map.get(vId);
wechatSourceMapper.insertWechatSource(vId, sourceList);
//todo 加粉
}
}
}

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
@ -15,9 +16,11 @@ import com.baiye.core.util.DesUtil;
import com.baiye.dao.AppUserMapper;
import com.baiye.dao.QrCodeRecordMapper;
import com.baiye.dao.WeChatCallbackLogMapper;
import com.baiye.dao.WeChatUserMapper;
import com.baiye.entity.AppUser;
import com.baiye.entity.QrCodeRecord;
import com.baiye.entity.WeChatCallbackLog;
import com.baiye.entity.WeChatUser;
import com.baiye.entity.dto.*;
import com.baiye.exception.global.BadRequestException;
import com.baiye.properties.WeChatProperties;
@ -55,6 +58,7 @@ public class WeChatUserServiceImpl implements WeChatUserService {
private final WeChatCallbackLogMapper weChatCallbackLogMapper;
private final WeChatUserMapper weChatUserMapper;
@Override
public Result<String> getQrCode(String wechatId, String uuid, String appKey, String appSecret) {
@ -83,7 +87,7 @@ public class WeChatUserServiceImpl implements WeChatUserService {
qrCodeRecordMapper.insert(qrCodeRecord);
return Result.success(msg);
}
throw new BadRequestException(ResultCode.QR_CODE_GENERATION_FAILED.getMsg());
return Result.fail(ResultCode.QR_CODE_GENERATION_FAILED.getMsg());
}
@ -101,7 +105,7 @@ public class WeChatUserServiceImpl implements WeChatUserService {
}
return Result.fail(ResultCode.FAILED_ADD_FRIEND.getMsg());
}
return Result.fail();
return Result.fail(ResultCode.FAILED_ADD_FRIEND.getMsg());
}
/**
@ -145,7 +149,6 @@ public class WeChatUserServiceImpl implements WeChatUserService {
// 处理登录请求
if (weChatResponse.getStatus() == HttpStatus.HTTP_CREATED
|| weChatResponse.getStatus() == GETSTATIC2_QUICK) {
WeChatCallbackLog callbackLog = new WeChatCallbackLog();
WeChatUserLoginDTO userLoginDTO = weChatResponse.getStatus() == HttpStatus.HTTP_CREATED ?
JSONUtil.toBean(JSONUtil.toJsonStr(weChatResponse.getData()),
WeChatUserLoginSuccessDTO.class)
@ -156,21 +159,23 @@ public class WeChatUserServiceImpl implements WeChatUserService {
cusQrUuId = cusQrUuId.substring(INFORMATION, cusQrUuId.indexOf(StrPool.COLON)).trim();
userLoginDTO.setCusQrUuId(cusQrUuId);
}
map.put("msg", weChatResponse.getMsg());
map.put("data", userLoginDTO);
map.put("status", weChatResponse.getStatus());
// 插入用户
if (weChatResponse.getStatus() == HttpStatus.HTTP_CREATED) {
WeChatUser byUserId = weChatUserMapper.findByWxId(userLoginDTO.getWxid());
saveOrUpdateWeChatUser(userLoginDTO, byUserId);
}
// 插入日志
callbackLog.setCusQrUuId(cusQrUuId);
callbackLog.setCreateTime(DateUtil.date());
callbackLog.setStatus(weChatResponse.getStatus());
callbackLog.setCallStr(JSONUtil.toJsonStr(weChatResponse));
weChatCallbackLogMapper.insert(callbackLog);
log.info("============= the response as {} ==========", JSONUtil.toJsonStr(weChatResponse));
saveResponseLog(weChatResponse, cusQrUuId);
List<QrCodeRecord> byUuid = qrCodeRecordMapper.findByUuid(cusQrUuId);
if (CollUtil.isNotEmpty(byUuid) && StringUtils.isNotBlank(byUuid.get(0).getAppKey())) {
String appKey = byUuid.get(0).getAppKey();
if (StringUtils.isNotBlank(appKey)) {
AppUser byAppKey = appUserMapper.findByAppKey(appKey.trim());
map.put("data", userLoginDTO);
map.put("msg", weChatResponse.getMsg());
map.put("status", weChatResponse.getStatus());
// 发送请求
HttpUtil.post(byAppKey.getCallbackUrl(), JSONUtil.toJsonStr(map));
log.info("============= the send callback success uuid as {} date as {} ============", cusQrUuId, DateUtil.date());
}
@ -201,7 +206,7 @@ public class WeChatUserServiceImpl implements WeChatUserService {
return Result.data(weChatResponse.getData());
}
return Result.fail
(ResultCode.FAILED_FRIEND_INFO.getMsg());
(ResultCode.FAILED_STATUS_INFO.getMsg());
}
@ -217,9 +222,69 @@ public class WeChatUserServiceImpl implements WeChatUserService {
if (friendsInfo.contains(ResultCode.SUCCESS.getMsg())) {
WeChatResponse weChatResponse =
JSONUtil.toBean(friendsInfo, WeChatResponse.class);
return Result.data(weChatResponse.getData());
if (weChatResponse.getStatus() == HttpStatus.HTTP_OK) {
return Result.data(weChatResponse.getData());
}
return Result.fail
(StringUtils.isNotBlank(weChatResponse.getMsg()) ?
weChatResponse.getMsg() : ResultCode.FAILED_FRIEND_INFO.getMsg());
}
return Result.fail
(ResultCode.FAILED_FRIEND_INFO.getMsg());
}
private void saveResponseLog(WeChatResponse weChatResponse, String cusQrUuId) {
WeChatCallbackLog callbackLog = new WeChatCallbackLog();
callbackLog.setCusQrUuId(cusQrUuId);
callbackLog.setCreateTime(DateUtil.date());
callbackLog.setStatus(weChatResponse.getStatus());
callbackLog.setCallStr(JSONUtil.toJsonStr(weChatResponse));
weChatCallbackLogMapper.insert(callbackLog);
}
private void saveOrUpdateWeChatUser(WeChatUserLoginDTO userLoginDTO, WeChatUser byUserId) {
if (ObjectUtil.isNull(byUserId)) {
byUserId = new WeChatUser();
}
if (userLoginDTO instanceof WeChatUserLoginSuccessDTO) {
WeChatUserLoginSuccessDTO successDTO = (WeChatUserLoginSuccessDTO) userLoginDTO;
byUserId.setLoginDate(DateUtil.date());
byUserId.setRandomId(successDTO.getRandomid());
byUserId.setToken(successDTO.getToken());
byUserId.setWxId(successDTO.getWxid());
byUserId.setLoginType(successDTO.getLoginType());
byUserId.setNickname(successDTO.getNickname());
weChatUserMapper.insert(byUserId);
}
}
@Override
public Result<Object> batchLogout(WeChatLogoutDTO weChatLogoutDTO) {
if (StringUtils.isBlank(weChatLogoutDTO.getWxIds())
&& weChatLogoutDTO.getIfNullLogoutAll() == null) {
return Result.fail
(ResultCode.REQUEST_PARAMETER_ERROR.getMsg());
}
Map<String, Object> map = Maps.newHashMap();
map.put("wxIds", weChatLogoutDTO.getWxIds());
if (weChatLogoutDTO.getIfNullLogoutAll() != null) {
map.remove("wxIds");
map.put("ifNullLogoutAll", weChatLogoutDTO.getIfNullLogoutAll());
}
// 发送请求
String logoutInfo = HttpUtil.post
(weChatProperties.getGatewayHost().
concat(WeChatRequestConstants.WE_CHAT_LOGOUT), map);
if (logoutInfo.contains(ResultCode.SUCCESS.getMsg())) {
WeChatResponse weChatResponse =
JSONUtil.toBean(logoutInfo, WeChatResponse.class);
if (weChatResponse.getStatus() == HttpStatus.HTTP_OK) {
return Result.success(ResultCode.LOGOUT_SUCCESS.getMsg());
}
return Result.fail
(StringUtils.isNotBlank(weChatResponse.getMsg()) ?
weChatResponse.getMsg() : ResultCode.LOGOUT_ERROR.getMsg());
}
return Result.fail(ResultCode.LOGOUT_ERROR.getMsg());
}
}

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.baiye.dao.WeChatUserMapper">
<resultMap id="WeChatUserMap" type="com.baiye.entity.WeChatUser">
<id column="id" property="id"/>
</resultMap>
<select id="findByWxId" resultType="com.baiye.entity.WeChatUser">
select * from tb_wechat_user
<where>
<if test="wxid!=null ">
and wx_id = #{wxid}
</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save