Commit a4716146 by giaogiao

判断两个客户端是否存在会话;

parent 2433ceee
......@@ -14,7 +14,7 @@ import java.net.URL;
public class FirebaseTest {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 1; i++) {
extracted();
}
}
......@@ -26,7 +26,8 @@ public class FirebaseTest {
System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyPort", "7891");
String to = "ck_oO93kR42WlkmzBVjzcA:APA91bGTcXlFq9_AOvGOJSIB4Z38EOqhP3_6HQ18_XIn3othxSWTeRr_IaQn-75AB9FvD5CiTig03Y56VtZDEEihismai0OOMPyxB7R4ajaFrQszEQRbCBw3iUgaAyjK7e1RFeq22tRC";
// String to = "ck_oO93kR42WlkmzBVjzcA:APA91bGTcXlFq9_AOvGOJSIB4Z38EOqhP3_6HQ18_XIn3othxSWTeRr_IaQn-75AB9FvD5CiTig03Y56VtZDEEihismai0OOMPyxB7R4ajaFrQszEQRbCBw3iUgaAyjK7e1RFeq22tRC";
String to = "eLOQs869208Wq5_tQINUgl:APA91bEsiSt8_RBJYQ2bLDHJF4nuE6XS6bP-kdEAt463SpW2i0Q5wUcmma3ylszr698MUIkjkwV507EV7ao347pl0XwHTDgDM1kIL4WYfX28OznML2lefnYS7oMmlt5_uqvwDO1GWone";
String key = "AAAA7PNYwIg:APA91bG2PZlTpC9sxqeIxtKDJJGzGZlh1ca13_bR4c5qkv9pEvRxcDfgO8VQqV2g-7cCTZz3oDtpWAgcQ5TyMKGdlD7Zp3bEmFkpNYDJAIcshSbyW-BtjCbknT2R5px5THmEJrlTJuDi";
String jsonStr = null;
......
......@@ -41,16 +41,19 @@ public class ImApplicationTest {
}
private void addDb( int i) {
// 生成AppKey
String appKey = RSAGenerator.getAppKey(); //定义变量接收
// 生成appSecret
String appSecret = RSAGenerator.getAppSecret(appKey);
ImApplication imApplication = new ImApplication();
imApplication.setCreateTime(new Date());
imApplication.setUpdateTime(new Date());
imApplication.setId(new Snowflake(1L,1L).nextId());
imApplication.setId(new Snowflake(1L, 1L).nextId());
imApplication.setAppKey(appKey);
imApplication.setAppSecret(appSecret);
imApplication.setAppName("test"+i);
imApplication.setAppName("test" + i);
imApplicationService.save(imApplication);
}
......
......@@ -5,6 +5,7 @@ import com.wecloud.im.param.ImApplicationPageParam;
import com.wecloud.im.param.ImApplicationQueryVo;
import com.wecloud.im.param.add.ImApplicationAdd;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.tillo.app_ws.utils.RSAGenerator;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
......@@ -56,6 +57,15 @@ public class ImApplicationController extends BaseController {
ImApplication imApplication = new ImApplication();
BeanUtils.copyProperties(imApplicationAdd, imApplication);
// 生成AppKey
String appKey = RSAGenerator.getAppKey(); //定义变量接收
// 生成appSecret
String appSecret = RSAGenerator.getAppSecret(appKey);
imApplication.setAppKey(appKey);
imApplication.setAppSecret(appSecret);
boolean flag = imApplicationService.saveImApplication(imApplication);
return ApiResult.result(flag);
}
......
......@@ -41,7 +41,7 @@ public class ImMessageController extends BaseController {
* 修改消息体
*/
@PostMapping("/updateMsgById")
@ApiOperation(value = "修改消息体")
@ApiOperation(value = "修改消息体", notes = "只能修改客户端自己发送的消息")
public ApiResult<Boolean> updateMsgById(@RequestBody ImMsgUpdate imMsgUpdate) throws Exception {
return imMessageService.updateMsgById(imMsgUpdate);
}
......
......@@ -56,5 +56,12 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
*/
List<ImConversation> getMyImConversationList(@Param("clientId") Long clientId);
/**
* 判断两个客户端是否存在会话
*
* @param clientId1
* @param clientId2
* @return
*/
Integer getRepetitionConversation(@Param("clientId1") Long clientId1, @Param("clientId2") Long clientId2);
}
......@@ -37,11 +37,11 @@ public class ImApplicationAdd extends BaseEntity {
@ApiModelProperty("修改时间")
private Date updateTime;
@ApiModelProperty("key")
private String appKey;
@ApiModelProperty("密钥")
private String appSecret;
// @ApiModelProperty("key")
// private String appKey;
//
// @ApiModelProperty("密钥")
// private String appSecret;
@ApiModelProperty("app名称")
private String appName;
......
......@@ -30,6 +30,12 @@ public interface ImConversationService extends BaseService<ImConversation> {
boolean saveImConversation(ImConversation imConversation) throws Exception;
/**
* 创建会话
*
* @param imConversationCreate
* @return
*/
ApiResult<ImConversationCreateVo> createImConversation(ImConversationCreate imConversationCreate);
/**
......@@ -86,4 +92,14 @@ public interface ImConversationService extends BaseService<ImConversation> {
List<ImConversation> getMyImConversationList() throws Exception;
/**
* 判断两个客户端是否存在会话
*
* @param clientId1
* @param clientId2
* @return
*/
Integer getRepetitionConversation(Long clientId1, Long clientId2);
}
......@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient;
import com.wecloud.im.entity.ImConversation;
import com.wecloud.im.entity.ImConversationMembers;
......@@ -22,14 +21,13 @@ import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.vo.ImConversationCreateVo;
import com.wecloud.im.vo.MyConversationListVo;
import com.wecloud.im.vo.OfflineMsgDto;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -76,23 +74,25 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
public ApiResult<ImConversationCreateVo> createImConversation(ImConversationCreate imConversationCreate) {
JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
ImClient client = imClientService.getClient();
// 判断是否已经存在会话
// 两个用户如果已经创建过会话,不能重复创建会话
if (imConversationCreate.getClientIds().size() == 1) {
ImClient client2 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, client.getFkAppid())
.eq(ImClient::getClientId, imConversationCreate.getClientIds().get(0)));
Integer repetitionConversation = getRepetitionConversation(client.getId(), client2.getId());
if (repetitionConversation != 0) {
log.debug("repetitionConversation != 0");
return ApiResult.result(ApiCode.REPETITION_CONVERSATION, null);
}
}
// 会话id
Long imConversationId = SnowflakeUtil.getId();
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getOne(
new QueryWrapper<ImApplication>().lambda().eq(ImApplication::getAppKey, jwtToken.getAppKey())
);
Long fkAppid = imApplication.getId();
ImClient client = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, fkAppid)
.eq(ImClient::getClientId, jwtToken.getClientId()));
Long creator = client.getId();
// 创建会话
......@@ -100,7 +100,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imConversation.setId(imConversationId);
imConversation.setCreateTime(new Date());
imConversation.setLastMessage(null);
imConversation.setFkAppid(fkAppid);
imConversation.setFkAppid(client.getFkAppid());
imConversation.setCreator(creator);
imConversation.setName(imConversationCreate.getName());
......@@ -120,7 +120,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
ImConversationMembers imConversationMembers = new ImConversationMembers();
imConversationMembers.setId(imConversationMembersId);
imConversationMembers.setCreateTime(new Date());
imConversationMembers.setFkAppid(fkAppid);
imConversationMembers.setFkAppid(client.getFkAppid());
imConversationMembers.setFkConversationId(imConversationId);
imConversationMembers.setFkClientId(creator);
imConversationMembersService.save(imConversationMembers);
......@@ -128,13 +128,13 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 将他人添加到会话
for (String id : imConversationCreate.getClientIds()) {
ImClient client2 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, fkAppid)
.eq(ImClient::getFkAppid, client.getFkAppid())
.eq(ImClient::getClientId, id));
Long imConversationMembersId2 = SnowflakeUtil.getId();
ImConversationMembers imConversationMembers2 = new ImConversationMembers();
imConversationMembers2.setId(imConversationMembersId2);
imConversationMembers2.setCreateTime(new Date());
imConversationMembers2.setFkAppid(fkAppid);
imConversationMembers2.setFkAppid(client.getFkAppid());
imConversationMembers2.setFkConversationId(imConversationId);
imConversationMembers2.setFkClientId(client2.getId());
imConversationMembersService.save(imConversationMembers2);
......@@ -205,4 +205,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
return imConversationMapper.getMyImConversationList(client.getId());
}
@Override
public Integer getRepetitionConversation(Long clientId1, Long clientId2) {
return imConversationMapper.getRepetitionConversation(clientId1, clientId2);
}
}
......@@ -52,10 +52,17 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
@Override
public ApiResult<Boolean> updateMsgById(ImMsgUpdate imMsgUpdate) {
// ImClient client = imClientService.getClient();
ImClient client = imClientService.getClient();
ImMessage messageById = this.getById(imMsgUpdate.getId());
// 判断该消息是否是该客户端发送
if (!messageById.getSender().equals(client.getId())) {
return ApiResult.fail();
}
ImMessage imMessage = new ImMessage();
imMessage.setId(imMessage.getId());
imMessage.setId(imMsgUpdate.getId());
JsonMapper jsonMapper = new JsonMapper();
......
......@@ -53,5 +53,23 @@
ON imConversation.id = imConversationMembers.fk_conversation_id
WHERE imConversationMembers.fk_client_id = #{clientId}
</select>
<select id="getRepetitionConversation" resultType="java.lang.Integer">
-- 查询是否有重复会话
SELECT COUNT(id)
FROM (
SELECT im_conversation_members.*,
(SELECT COUNT(im2.id)
FROM im_conversation_members AS im2
WHERE im2.fk_conversation_id = im_conversation_members.fk_conversation_id) AS members_count
FROM im_conversation_members
INNER JOIN (SELECT *
FROM im_conversation_members
WHERE im_conversation_members.fk_client_id = #{clientId2}) AS im_conversation_members2
ON im_conversation_members.fk_conversation_id =
im_conversation_members2.fk_conversation_id
WHERE im_conversation_members.fk_client_id = #{clientId1}
) AS r1
WHERE members_count = 2
</select>
</mapper>
......@@ -83,3 +83,4 @@ api.response.code.user.USER_WECHAT_CODE=微信code错误
api.response.code.user.SMS_CODE_ERROR_NEW=新手机号验证码错误
api.response.code.user.UPDATA_PHONE_USE=绑定手机已经被使用
api.response.code.user.PHONE_IS_ME=手机号不能为自己
api.response.code.REPETITION_CONVERSATION=已有会话,不能重复创建会话
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
server_name wstest.im199.com;
ssl_certificate ssl/_.im199.com.crt;
ssl_certificate_key ssl/_.im199.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /api {
proxy_pass http://localhost:8082/api/;
}
location /ws {
proxy_pass http://localhost:8899/ws; # ws结尾不带"/",实际请求服务器时不会去掉"/ws"
proxy_set_header Upgrade $http_upgrade; # 升级协议头
proxy_set_header Connection upgrade; # 升级长连接协议头
}
location / {
root html;
index index.html index.htm;
}
}
}
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name ws.im199.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
server_name ws.im199.com;
ssl_certificate ssl/_.im199.com.crt;
ssl_certificate_key ssl/_.im199.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /api {
proxy_pass http://localhost:8082/api/;
}
location /ws {
proxy_pass http://localhost:8899/ws; # ws结尾不带"/",实际请求服务器时不会去掉"/ws"
proxy_set_header Upgrade $http_upgrade; # 升级协议头
proxy_set_header Connection upgrade; # 升级长连接协议头
}
location / {
root html;
index index.html index.htm;
}
}
}
......@@ -98,52 +98,16 @@ public enum ApiCode {
* JWT Token解析异常
**/
JWTDECODE_EXCEPTION(5107, "api.response.code.JWTDECODE_EXCEPTION"),
/**
* 默认的异常处理
*/
HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION(5108, "api.response.code.HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION"),
/**
* 账号或密码错误
*/
PWD_OR_USERNAME_ERROR(6001, "api.response.code.user.PWD_OR_USERNAME_ERROR"),
/**
* 旧手机号验证码错误
*/
SMS_CODE_ERROR(6005, "api.response.code.user.SMS_CODE_ERROR"),
/**
* 注册时验证码错误
*/
SMS_CODE_REGIST_ERROR(6007, "api.response.code.user.SMS_CODE_REGIST_ERROR"),
/**
* 新手机号验证码错误
*/
SMS_CODE_ERROR_NEW(6002, "api.response.code.user.SMS_CODE_ERROR_NEW"),
/**
* 用户不存在
*/
USER_NOT_FOUND(6003, "api.response.code.user.USER_NOT_FOUND"),
/**
* 微信code错误
*/
USER_WECHAT_CODE(6004, "api.response.code.user.USER_WECHAT_CODE"),
/**
* 绑定手机已经被使用
*/
UPDATA_PHONE_USE(6006, "api.response.code.user.UPDATA_PHONE_USE"),
/**
* 手机号不能为自己
* 已有会话,不能重复创建会话
*/
PHONE_IS_ME(6009, "api.response.code.user.PHONE_IS_ME"),
REPETITION_CONVERSATION(6010, "api.response.code.REPETITION_CONVERSATION"),
;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment