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