New file |
| | |
| | | package com.whyc.controller; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.util.ActionUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.SecureRandom; |
| | | |
| | | @RequestMapping("message") |
| | | @RestController |
| | | @Api(tags = "验证码") |
| | | public class MessageController { |
| | | |
| | | @ApiOperation("获取验证码") |
| | | @GetMapping("/getFontDynamicCode") |
| | | public Response getFontDynamicCode() throws NoSuchAlgorithmException { |
| | | StringBuilder sb = new StringBuilder(); |
| | | String originStr = "0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789"; |
| | | SecureRandom random; |
| | | random = SecureRandom.getInstance("SHA1PRNG"); |
| | | |
| | | for (int i = 0; i < 4; i++) { |
| | | sb.append(originStr.charAt(random.nextInt(originStr.length()))); |
| | | } |
| | | //内存Session中存储动态口令 |
| | | ActionUtil.getSession().setAttribute("fontDynamicCode", sb.toString()); |
| | | return new Response().set(1,sb.toString()); |
| | | } |
| | | |
| | | } |