Skip to content

Commit

Permalink
2020年2月4日19点48分
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang authored and Yang committed Feb 4, 2020
1 parent 8030e53 commit f507baa
Show file tree
Hide file tree
Showing 52 changed files with 1,026 additions and 422 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.9.13.ALL</version>
</dependency>

</dependencies>

Expand Down
67 changes: 67 additions & 0 deletions src/main/java/com/jryyy/forum/config/AlipayConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.jryyy.forum.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.FileWriter;
import java.io.IOException;

/**
* @author OU
*/

@Data
@Component
@ConfigurationProperties(prefix = "alipay")
public class AlipayConfiguration {



/**
* 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号
*/
private String appID;

/**
* 商户私钥,您的PKCS8格式RSA2私钥
*/
private String merchantPrivateKey;

/**
* 支付宝公钥
*/
private String alipayPublicKey;

/**
* 签名方式
*/
private String signType="RSA2";

/**
* 网关
*/
private String gatewayUrl="https://openapi.alipay.com/gateway.do";

/**
* 编码
*/
private String charset= "utf-8";

/**
* 异步通知地址
*/
private String notifyUrl="";

/**
* 类型
*/
private String format="json";

/**
* 商户号
*/
private String sysServiceProviderId="1234";


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jryyy.forum.config;

import com.jryyy.forum.constant.Constants;
import com.jryyy.forum.constant.KayAndUrl;
import com.jryyy.forum.constant.KayOrUrl;
import com.jryyy.forum.model.User;
import com.jryyy.forum.utils.security.TokenUtils;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -91,8 +91,8 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
try {
User user = tokenUtils.decodeJwtToken(token);
log.info("login:-----------"+user.getId());
redisTemplate.opsForHash().put(KayAndUrl.ONLINE_USER_LIST_KEY,accessor.getSessionId(),user.getId());
redisTemplate.opsForHash().put(KayAndUrl.ONLINE_USER_LIST_KEY, KayAndUrl.userKey(user.getId()),accessor.getSessionId());
redisTemplate.opsForHash().put(KayOrUrl.ONLINE_USER_LIST_KEY,accessor.getSessionId(),user.getId());
redisTemplate.opsForHash().put(KayOrUrl.ONLINE_USER_LIST_KEY, KayOrUrl.userKey(user.getId()),accessor.getSessionId());
} catch (Exception e) {
e.printStackTrace();
return message;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/jryyy/forum/constant/Constants.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.jryyy.forum.constant;


/**
* @author JrYYY
* 普通(通用)常量定义
*/
public class Constants {



public static final String USER_TOKEN_STRING = "Authorization";

public static final int MAXIMUM_NUMBER_ATTEMPTS = 6;

public static final String DEFAULT = "0";

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author OU
*/
public class KayAndUrl {
public class KayOrUrl {

public static final String unchecked_messages_key = "unchecked_messages_list";

Expand Down Expand Up @@ -51,4 +51,6 @@ public static String lockKey(Integer key){
public static String userAvatarUrl(Integer userId){return String.format("/user/%d/avatar/",userId);}

public static String userBgImgUrl(Integer userId){return String.format("/user/%d/bgImg/",userId);}

public static String zoneImageUrl(Integer userId){return String.format("zone/image/%d/",userId);}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Response getGroup(@PathVariable Integer userId) throws Exception {

@UserLoginToken
@DeleteMapping("/member/admin/{userId}")
@GroupPermissions(notAllowed = GroupRoleCode.MEMBER)
@GroupPermissions(notAllowed =GroupRoleCode.MEMBER)
public Response kickUser(@PathVariable Integer userId, @RequestParam Integer groupId, @RequestParam Integer memberId) throws Exception {
return groupService.kickOutGroup(groupId, memberId);
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/jryyy/forum/controller/SecurityController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jryyy.forum.controller;

import com.jryyy.forum.constant.GlobalStatus;
import com.jryyy.forum.constant.KayAndUrl;
import com.jryyy.forum.constant.KayOrUrl;
import com.jryyy.forum.constant.Template;
import com.jryyy.forum.utils.security.UserRoleCode;
import com.jryyy.forum.exception.GlobalException;
Expand Down Expand Up @@ -103,8 +103,8 @@ public Response verification(@RequestParam String email) throws Exception {
public Response putJwt(@RequestParam String token) throws Exception {
User user = tokenUtils.decodeJwtToken(token);
Response response = new Response<>(SecurityResponse.builder()
.token(tokenUtils.createJwtToken(user))
.role(user.getRole()).userId(user.getId()).build());
.token(tokenUtils.createJwtToken(user)).role(user.getRole())
.userId(user.getId()).build());
log.info(user.toString() + "---更新token");
return response;
}
Expand Down Expand Up @@ -144,10 +144,9 @@ public Response changePassword(@Valid @ModelAttribute ForgotUsernamePasswordRequ
public Response passwordCode(@RequestParam String email)throws Exception{
Response response = userService.verifyUser(email);
if (!(Boolean) response.getData()) {
throw new GlobalException(GlobalStatus.userDoesNotExist);
}
throw new GlobalException(GlobalStatus.userDoesNotExist); }
String content = String.format(Template.MODIFY_PASSWORD_VERIFICATION_TEMPLATE,
captchaUtils.generateDigitalVerificationCode(KayAndUrl.modifyPasswordCodeKey(email)));
captchaUtils.generateDigitalVerificationCode(KayOrUrl.modifyPasswordCodeKey(email)));
emailUtils.sendSimpleMail(email,"忘记密码验证码",content);
return new Response<>(true);
}
Expand All @@ -162,10 +161,9 @@ public Response passwordCode(@RequestParam String email)throws Exception{
public Response generateVerificationCode(@RequestParam String email) throws Exception {
Response response = userService.verifyUser(email);
if ((Boolean) response.getData()) {
throw new GlobalException(GlobalStatus.userAlreadyExists);
}
throw new GlobalException(GlobalStatus.userAlreadyExists); }
String content = String.format(Template.REGISTRATION_VERIFICATION_TEMPLATE,
captchaUtils.generateDigitalVerificationCode(KayAndUrl.registrationCodeKey(email)));
captchaUtils.generateDigitalVerificationCode(KayOrUrl.registrationCodeKey(email)));
emailUtils.sendSimpleMail(email,"注册验证码",content);
return new Response<>(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public Response updateUserAvatar(@PathVariable Integer userId,@ModelAttribute @R
return userInfoService.updateAvatar(userId,image);
}

@UserLoginToken
@DeleteMapping("/avatar/{userId}")
public Response initializeAvatar(@PathVariable Integer userId)throws Exception{
return userInfoService.initializeImage(userId);
}

@UserLoginToken
@PutMapping("/background/{userId}")
public Response updateUserBgImg(@PathVariable Integer userId,@ModelAttribute @RequestParam MultipartFile image)throws Exception{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jryyy.forum.controller;

import com.jryyy.forum.constant.KayAndUrl;
import com.jryyy.forum.constant.KayOrUrl;
import com.jryyy.forum.model.Message;
import com.jryyy.forum.model.Response;
import com.jryyy.forum.service.WebsocketService;
Expand Down Expand Up @@ -63,14 +63,14 @@ public Response groupChatQueryHistory(@PathVariable Integer userId, @RequestPara
@GetMapping("/group/offlineMessage/{userId}")
public Response groupChatOfflineHistory(@PathVariable Integer userId)throws Exception{
return websocketService.userOfflineMessage
(KayAndUrl.USER_GROUP_CHAT_OFFLINE_RECORD_KEY,userId);
(KayOrUrl.USER_GROUP_CHAT_OFFLINE_RECORD_KEY,userId);
}

@UserLoginToken
@GetMapping("/single/offlineMessage/{userId}")
public Response singleChatOfflineHistory(@PathVariable Integer userId)throws Exception{
return websocketService.userOfflineMessage(
KayAndUrl.USER_SINGLE_CHAT_OFFLINE_RECORD_KEY,userId);
KayOrUrl.USER_SINGLE_CHAT_OFFLINE_RECORD_KEY,userId);
}

@UserLoginToken
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/jryyy/forum/controller/ZoneController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.jryyy.forum.controller;

import com.jryyy.forum.model.Response;
import com.jryyy.forum.model.request.GetZoneRequest;
import com.jryyy.forum.model.request.ZoneRequest;
import com.jryyy.forum.service.ZoneService;
import com.jryyy.forum.utils.security.UserLoginToken;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.sql.ResultSet;

/**
* @author OU
*/
@RestController
@RequestMapping("/zone")
public class ZoneController {

private final ZoneService zoneService;

public ZoneController(ZoneService zoneService) {
this.zoneService = zoneService;
}

/**
* 写入空间
* @param request {@link ZoneRequest}
* @return {@link Response}
* @throws Exception
*/
@PostMapping("/{userId}")
@UserLoginToken
public Response insertZone(@PathVariable Integer userId,@ModelAttribute @Valid ZoneRequest request)throws Exception{
request.setUserId(userId);
return zoneService.insertZone(request);
}


/**
* 读取用户空间
* @param userId 用户id
* @param request {@link GetZoneRequest}
* @return {@link com.jryyy.forum.model.response.ZoneResponse}
* @throws Exception
*/
@UserLoginToken
@GetMapping("/{userId}")
public Response getUserZone(@PathVariable Integer userId,@ModelAttribute @Valid GetZoneRequest request)throws Exception{
return zoneService.getZone(userId,request);
}

/**
* 删除空间
* @param userId 用户id
* @param zoneId 空间id
* @return {@link Response}
* @throws Exception
*/
@DeleteMapping("/{userId}")
public Response deleteZone(@PathVariable Integer userId,@RequestParam Integer zoneId)throws Exception{
return zoneService.deleteZone(userId,zoneId);
}

/**
* 空间评论
* @param zoneId 空间id
* @return {@link Response }
* @throws Exception
*/
@GetMapping("/comment")
public Response findZoneComment(@RequestParam Integer zoneId, @RequestParam Integer curPage,
@RequestParam Integer pageSize)throws Exception{
return zoneService.findZoneComment(zoneId,curPage,pageSize);
}

@GetMapping("/reply")
public Response findZoneComment(@RequestParam Integer id)throws Exception{
return zoneService.findReply(id);
}

/**
*
* @param userId 用户id
* @param id 空间id
* @param comment 消息
* @return {@link Response}
* @throws Exception
*/
@UserLoginToken
@PostMapping("/comment/{userId}")
public Response comment(@PathVariable Integer userId, @RequestParam Integer id,@RequestParam String comment,Integer pId)throws Exception{
return zoneService.comment(userId,id,comment,pId);
}


/**
* 点赞
* @param userId 用户id
* @param zoneId 空间id
* @return {@link Response}
* @throws Exception
*/
@UserLoginToken
@PutMapping("/like/{userId}")
public Response like(@PathVariable Integer userId,@RequestParam Integer zoneId)throws Exception{
return zoneService.like(userId, zoneId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jryyy.forum.controller.webSocket;


import com.jryyy.forum.constant.KayAndUrl;
import com.jryyy.forum.constant.KayOrUrl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
Expand Down Expand Up @@ -38,8 +38,8 @@ public WebSocketDisconnectHandler(SimpMessagingTemplate messagingTemplate, Redis
public void onApplicationEvent(SessionDisconnectEvent sessionDisconnectEvent) {
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(sessionDisconnectEvent.getMessage());
log.info("logout:---------"+accessor.getSessionId());
String userId =(String) redisTemplate.opsForHash().get(KayAndUrl.ONLINE_USER_LIST_KEY,accessor.getSessionId());
redisTemplate.opsForHash().delete(KayAndUrl.ONLINE_USER_LIST_KEY,accessor.getSessionId());
redisTemplate.opsForHash().delete(KayAndUrl.ONLINE_USER_LIST_KEY, KayAndUrl.userKey(userId));
String userId =(String) redisTemplate.opsForHash().get(KayOrUrl.ONLINE_USER_LIST_KEY,accessor.getSessionId());
redisTemplate.opsForHash().delete(KayOrUrl.ONLINE_USER_LIST_KEY,accessor.getSessionId());
redisTemplate.opsForHash().delete(KayOrUrl.ONLINE_USER_LIST_KEY, KayOrUrl.userKey(userId));
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/jryyy/forum/dao/FavoritesMapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jryyy.forum.dao;

import com.jryyy.forum.model.response.FavoritesResponse;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
Expand All @@ -10,10 +9,6 @@

@Mapper
public interface FavoritesMapper {
@Select("select A.id,A.zoneId,C.username,B.createDate,B.msg " +
"from favorites A join user_zone B on A.zoneId = B.id " +
"join userinfo C on A.userId = C.userId Where A.userId = #{userId}")
List<FavoritesResponse> findByUserId(int userId) throws Exception;

@Insert("insert into favorites(userId,zoneId) values (#{userId},#{zoneId})")
void insertFavorites(int userId, int zoneId) throws Exception;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jryyy/forum/dao/FollowMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface FollowMapper {
* @return {@link FollowResponse}
* @throws Exception
*/
@Select("select A.id,A.friendId userId,B.username,B.avatar,B.bio,A.createDate date " +
@Select("select A.id,A.friendId userId,B.username,B.avatar,B.bio,A.createDate addDate,B.recentLoginDate " +
"from follow A join user_info B " +
"on A.friendId = B.userId " +
"where A.userId = #{userId}")
Expand All @@ -53,7 +53,7 @@ public interface FollowMapper {
* @return {@link FollowResponse}
* @throws Exception
*/
@Select("select A.id,A.userId,B.username,B.avatar,B.bio,A.createDate date " +
@Select("select A.id,A.userId,B.username,B.avatar,B.bio,A.createDate addDate,B.recentLoginDate " +
"from follow A join user_info B " +
"on A.userId = B.userId " +
"where A.friendId = #{friendId}")
Expand Down
Loading

0 comments on commit f507baa

Please sign in to comment.