[fix]优化pom和登录
This commit is contained in:
parent
5eec4e9255
commit
96b611f014
7
pom.xml
7
pom.xml
@ -60,6 +60,7 @@
|
||||
<!-- 打包默认跳过测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<knife4j.version>3.03</knife4j.version>
|
||||
<okhttp.version>4.12.0</okhttp.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
@ -422,7 +423,11 @@
|
||||
<artifactId>ruoyi-auth</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-mongo</artifactId>
|
||||
|
@ -67,11 +67,11 @@ public class CaptchaController {
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||
map.put("code", code);
|
||||
SmsBlend smsBlend = SmsFactory.getSmsBlend("config2");
|
||||
// SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
||||
// if (!smsResponse.isSuccess()) {
|
||||
// log.error("验证码短信发送异常 => {}", smsResponse);
|
||||
// return R.fail(smsResponse.getData().toString());
|
||||
// }
|
||||
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
||||
if (!smsResponse.isSuccess()) {
|
||||
log.error("验证码短信发送异常 => {}", smsResponse);
|
||||
return R.fail(smsResponse.getData().toString());
|
||||
}
|
||||
return R.ok(code);
|
||||
}
|
||||
|
||||
|
@ -56,4 +56,6 @@ public class LoginVo {
|
||||
*/
|
||||
private String userSig;
|
||||
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
|
@ -100,6 +100,7 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setUserId(loginUser.getUserId());
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
|
@ -72,14 +72,6 @@
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-web</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.dromara</groupId>-->
|
||||
<!-- <artifactId>ruoyi-member</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
@ -105,7 +97,14 @@
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-json</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -20,14 +20,7 @@ public interface ITencentIMService {
|
||||
*/
|
||||
boolean sendMessageToTencentIM(String fromUserId, String toUserId, String content);
|
||||
|
||||
/**
|
||||
* 创建腾讯IM账号
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户签名
|
||||
*/
|
||||
String createTencentIMAccount(String userId);
|
||||
|
||||
|
||||
/**
|
||||
* 推送消息给全体用户
|
||||
*
|
||||
@ -38,7 +31,7 @@ public interface ITencentIMService {
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean pushToAll(String title, String desc, boolean offlinePush, String ext);
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户属性推送消息
|
||||
*
|
||||
@ -50,7 +43,7 @@ public interface ITencentIMService {
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean pushByAttributes(String title, String desc, Map<String, Object> attributes, boolean offlinePush, String ext);
|
||||
|
||||
|
||||
/**
|
||||
* 根据标签推送消息
|
||||
*
|
||||
@ -62,7 +55,7 @@ public interface ITencentIMService {
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean pushByTags(String title, String desc, List<String> tags, boolean offlinePush, String ext);
|
||||
|
||||
|
||||
/**
|
||||
* 推送消息给指定用户
|
||||
*
|
||||
@ -74,13 +67,13 @@ public interface ITencentIMService {
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean pushToUsers(String title, String desc, List<String> userIds, boolean offlinePush, String ext);
|
||||
|
||||
|
||||
/**
|
||||
* 处理消息变量替换
|
||||
*
|
||||
*
|
||||
* @param content 原始内容
|
||||
* @param variables 变量映射
|
||||
* @return 替换后的内容
|
||||
*/
|
||||
String processMessageVariables(String content, Map<String, String> variables);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package org.dromara.system.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.system.service.ITencentIMService;
|
||||
@ -29,7 +29,7 @@ import java.util.Base64;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("systemTencentIMService")
|
||||
public class TencentIMServiceImpl implements ITencentIMService {
|
||||
public class TencentIMServiceImpl implements ITencentIMService {
|
||||
|
||||
@Value("${tencent.im.sdk-app-id}")
|
||||
private long sdkAppId;
|
||||
@ -149,43 +149,6 @@ public class TencentIMServiceImpl implements ITencentIMService {
|
||||
return generateUserSig(adminAccount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTencentIMAccount(String userId) {
|
||||
try {
|
||||
String userSig = generateAdminUserSig();
|
||||
String random = String.valueOf(System.currentTimeMillis());
|
||||
|
||||
// 构建API请求URL
|
||||
String url = String.format(
|
||||
"https://console.tim.qq.com/v4/im_open_login_svc/account_import" +
|
||||
"?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json",
|
||||
sdkAppId,
|
||||
adminAccount,
|
||||
userSig,
|
||||
random);
|
||||
|
||||
// 构建请求体
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("UserID", userId);
|
||||
requestBody.put("Nick", userId);
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
// 发送请求
|
||||
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
|
||||
|
||||
log.info("创建腾讯IM账号结果: {}", response.getBody());
|
||||
|
||||
// 生成并返回用户签名
|
||||
return generateUserSig(userId);
|
||||
} catch (Exception e) {
|
||||
log.error("创建腾讯IM账号异常: {}", userId, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendMessageToTencentIM(String fromUserId, String toUserId, String content) {
|
||||
@ -230,8 +193,8 @@ public class TencentIMServiceImpl implements ITencentIMService {
|
||||
log.info("发送消息到腾讯IM结果: {}", response.getBody());
|
||||
|
||||
// 解析响应判断是否成功
|
||||
JSONObject responseJson = JSONObject.parseObject(response.getBody());
|
||||
return "OK".equals(responseJson.getString("ActionStatus"));
|
||||
JSONObject responseJson = new JSONObject(response);
|
||||
return "OK".equals(responseJson.getStr("ActionStatus"));
|
||||
} catch (Exception e) {
|
||||
log.error("发送消息到腾讯IM异常", e);
|
||||
return false;
|
||||
@ -295,8 +258,8 @@ public class TencentIMServiceImpl implements ITencentIMService {
|
||||
log.info("全员推送消息结果: {}", response.getBody());
|
||||
|
||||
// 解析响应判断是否成功
|
||||
JSONObject responseJson = JSONObject.parseObject(response.getBody());
|
||||
return "OK".equals(responseJson.getString("ActionStatus"));
|
||||
JSONObject responseJson = new JSONObject(response);
|
||||
return "OK".equals(responseJson.getStr("ActionStatus"));
|
||||
} catch (Exception e) {
|
||||
log.error("全员推送消息异常", e);
|
||||
return false;
|
||||
@ -362,8 +325,8 @@ public class TencentIMServiceImpl implements ITencentIMService {
|
||||
log.info("属性推送消息结果: {}", response.getBody());
|
||||
|
||||
// 解析响应判断是否成功
|
||||
JSONObject responseJson = JSONObject.parseObject(response.getBody());
|
||||
return "OK".equals(responseJson.getString("ActionStatus"));
|
||||
JSONObject responseJson = new JSONObject(response.getBody());
|
||||
return "OK".equals(responseJson.getStr("ActionStatus"));
|
||||
} catch (Exception e) {
|
||||
log.error("属性推送消息异常", e);
|
||||
return false;
|
||||
@ -428,8 +391,8 @@ public class TencentIMServiceImpl implements ITencentIMService {
|
||||
log.info("标签推送消息结果: {}", response.getBody());
|
||||
|
||||
// 解析响应判断是否成功
|
||||
JSONObject responseJson = JSONObject.parseObject(response.getBody());
|
||||
return "OK".equals(responseJson.getString("ActionStatus"));
|
||||
JSONObject responseJson = new JSONObject(response.getBody());
|
||||
return "OK".equals(responseJson.getStr("ActionStatus"));
|
||||
} catch (Exception e) {
|
||||
log.error("标签推送消息异常", e);
|
||||
return false;
|
||||
@ -494,8 +457,8 @@ public class TencentIMServiceImpl implements ITencentIMService {
|
||||
log.info("指定用户推送消息结果: {}", response.getBody());
|
||||
|
||||
// 解析响应判断是否成功
|
||||
JSONObject responseJson = JSONObject.parseObject(response.getBody());
|
||||
return "OK".equals(responseJson.getString("ActionStatus"));
|
||||
JSONObject responseJson = new JSONObject(response.getBody());
|
||||
return "OK".equals(responseJson.getStr("ActionStatus"));
|
||||
} catch (Exception e) {
|
||||
log.error("指定用户推送消息异常", e);
|
||||
return false;
|
||||
|
@ -20,8 +20,6 @@
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-doc</artifactId>
|
||||
@ -102,24 +100,16 @@
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.dromara</groupId>-->
|
||||
<!-- <artifactId>ruoyi-order</artifactId>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.dromara</groupId>-->
|
||||
<!-- <artifactId>ruoyi-goods</artifactId>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.dromara</groupId>-->
|
||||
<!-- <artifactId>ruoyi-content</artifactId>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.22</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -23,12 +23,14 @@ public class MemberAccount extends BaseAudit {
|
||||
|
||||
|
||||
@Excel(name = "ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description ="MEMBER_ID")
|
||||
private Long memberId;
|
||||
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.wzj.soopin.member.service;
|
||||
|
||||
|
||||
import com.wzj.soopin.member.domain.po.Member;
|
||||
|
||||
/**km//,
|
||||
* 腾讯IM服务
|
||||
* @author wqx
|
||||
*/
|
||||
public interface ITencentIMServicce {
|
||||
String createTencentIMAccount(String userId);
|
||||
String createTencentIMAccount(Member member);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import org.dromara.common.log.event.LogininforEvent;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.web.config.properties.CaptchaProperties;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 注册校验方法
|
||||
@ -33,9 +34,11 @@ public class MemberRegisterService {
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final ITencentIMServicce tencentIMServicce;
|
||||
|
||||
private final String avatarUrl="http://122.152.205.72:88/group1/M00/00/05/CpoxxF6ZUySASMbOAABBAXhjY0Y649.png";
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Member register(RegisterBody registerBody) {
|
||||
String tenantId = registerBody.getTenantId();
|
||||
String username = registerBody.getUsername();
|
||||
@ -51,26 +54,26 @@ public class MemberRegisterService {
|
||||
}
|
||||
Member member = Member.builder().phoneEncrypted(phoneNumber)
|
||||
.userName(username==null?phoneNumber:username)
|
||||
.nickname(username)
|
||||
.avatar(avatarUrl)
|
||||
.nickname("新用户"+phoneNumber.substring(phoneNumber.length()-4,phoneNumber.length()))
|
||||
.password(BCrypt.hashpw(password==null?"123456":password)).build();
|
||||
|
||||
boolean exist = memberService.exists(new LambdaQueryWrapper<Member>()
|
||||
.eq(Member::getPhoneEncrypted, phoneNumber));
|
||||
if (exist) {
|
||||
|
||||
|
||||
|
||||
throw new UserException("user.register.save.error", username);
|
||||
}
|
||||
|
||||
// 生成 UserSig
|
||||
String userSig = tencentIMServicce.createTencentIMAccount(phoneNumber);
|
||||
member.setUserSig(userSig);
|
||||
|
||||
//先保存用户,然后用户ID生成IM账号
|
||||
boolean regFlag = memberService.save(member);
|
||||
if (!regFlag) {
|
||||
throw new UserException("user.register.error");
|
||||
}
|
||||
// 生成 UserSig
|
||||
String userSig = tencentIMServicce.createTencentIMAccount(member);
|
||||
member.setUserSig(userSig);
|
||||
|
||||
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
||||
return member;
|
||||
|
||||
|
@ -67,7 +67,6 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper,Member> implemen
|
||||
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.MEMBER, key = "#id")
|
||||
public boolean save(Member entity) {
|
||||
super.save(entity);
|
||||
|
||||
|
@ -1,10 +1,18 @@
|
||||
package com.wzj.soopin.member.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.wzj.soopin.member.domain.po.Member;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import com.wzj.soopin.member.service.ITencentIMServicce;
|
||||
import com.wzj.soopin.member.util.GenerateTestUserSig;
|
||||
import com.wzj.soopin.member.util.TLSSigAPIv2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -20,17 +28,20 @@ public class TencentIMServiceImpl implements ITencentIMServicce {
|
||||
* 创建腾讯云IM账号
|
||||
*/
|
||||
@Override
|
||||
public String createTencentIMAccount(String userId) {
|
||||
public String createTencentIMAccount(Member member) {
|
||||
|
||||
String phone=member.getPhoneHidden();
|
||||
try {
|
||||
|
||||
String userSig=generateUserSig(userId);
|
||||
String userSig=generateUserSig("administrator");
|
||||
String random = String.valueOf(System.currentTimeMillis());
|
||||
|
||||
|
||||
// 构建请求体
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.put("UserID", userId);
|
||||
requestBody.put("Nick", userId);
|
||||
requestBody.put("FaceUrl", "http://www.qq.com");
|
||||
requestBody.put("UserID", member.getId()+"");
|
||||
requestBody.put("Nick", member.getNickname());
|
||||
requestBody.put("FaceUrl", member.getAvatar());
|
||||
|
||||
// 构建URL - 使用管理员账号(administrator)而不是用户ID来生成签名
|
||||
String urlString = String.format(
|
||||
@ -40,44 +51,43 @@ public class TencentIMServiceImpl implements ITencentIMServicce {
|
||||
"administrator", // 使用管理员账号
|
||||
userSig, // 使用管理员的UserSig
|
||||
random);
|
||||
return userSig;
|
||||
// return userSig;
|
||||
|
||||
// // 创建HTTP客户端
|
||||
// OkHttpClient client = new OkHttpClient.Builder()
|
||||
// .connectTimeout(10, TimeUnit.SECONDS)
|
||||
// .writeTimeout(10, TimeUnit.SECONDS)
|
||||
// .readTimeout(10, TimeUnit.SECONDS)
|
||||
// .build();
|
||||
//
|
||||
// // 发送请求
|
||||
// Request request = new Request.Builder()
|
||||
// .url(urlString)
|
||||
// .post(RequestBody.create(MediaType.get("application/json; charset=utf-8"),
|
||||
// requestBody.toString()))
|
||||
// .build();
|
||||
//
|
||||
// try (Response response = client.newCall(request).execute()) {
|
||||
// if (!response.isSuccessful()) {
|
||||
// log.error("创建IM账号失败: {}, 状态码: {}", userId, response.code());
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// String responseBody = response.body().string();
|
||||
// JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
// int errorCode = jsonResponse.getInt("ErrorCode");
|
||||
//
|
||||
// if (errorCode == 0) {
|
||||
// log.info("创建IM账号成功: {}", userId);
|
||||
// return userSig;
|
||||
// } else {
|
||||
// log.error("创建IM账号失败: {}, 错误码: {}, 错误信息: {}",
|
||||
// userId, errorCode, jsonResponse.optString("ErrorInfo"));
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// 创建HTTP客户端
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.writeTimeout(15, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
// 发送请求
|
||||
Request request = new Request.Builder()
|
||||
.url(urlString)
|
||||
.post(RequestBody.create(MediaType.get("application/json; charset=utf-8"),
|
||||
requestBody.toString()))
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
log.error("创建IM账号失败: {}, 状态码: {}",phone , response.code());
|
||||
throw new ServiceException(String.format("创建IM账号异常: %s", phone));
|
||||
}
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
int errorCode = jsonResponse.getInt("ErrorCode");
|
||||
|
||||
if (errorCode == 0) {
|
||||
log.info("创建IM账号成功: {}", phone);
|
||||
return userSig;
|
||||
} else {
|
||||
log.error("创建IM账号失败: {}, 错误码: {}, 错误信息: {}",
|
||||
phone, errorCode, jsonResponse.get("ErrorInfo"));
|
||||
throw new ServiceException(String.format("创建IM账号异常: %s", phone));
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("创建IM账号异常: {}", userId, e);
|
||||
return null;
|
||||
throw new ServiceException(String.format("创建IM账号异常: %s", phone));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user