NoLoginController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package com.fdkankan.fusion.controller;
  2. import cn.hutool.captcha.CaptchaUtil;
  3. import cn.hutool.captcha.CircleCaptcha;
  4. import cn.hutool.captcha.LineCaptcha;
  5. import cn.hutool.captcha.ShearCaptcha;
  6. import cn.hutool.captcha.generator.CodeGenerator;
  7. import cn.hutool.captcha.generator.MathGenerator;
  8. import cn.hutool.captcha.generator.RandomGenerator;
  9. import cn.hutool.crypto.digest.MD5;
  10. import cn.hutool.http.ContentType;
  11. import com.alibaba.fastjson.JSONObject;
  12. import com.fdkankan.fusion.common.ResultCode;
  13. import com.fdkankan.fusion.common.ResultData;
  14. import com.fdkankan.fusion.common.util.MD5Checksum;
  15. import com.fdkankan.fusion.common.util.ProvinceUtils;
  16. import com.fdkankan.fusion.common.util.RedisKeyUtil;
  17. import com.fdkankan.fusion.exception.BusinessException;
  18. import com.fdkankan.fusion.httpClient.client.OtherClient;
  19. import com.fdkankan.fusion.request.ForwardParam;
  20. import com.fdkankan.fusion.response.UserAddRequest;
  21. import com.fdkankan.fusion.service.ITmUserService;
  22. import com.fdkankan.redis.util.RedisUtil;
  23. import jdk.nashorn.internal.runtime.regexp.joni.Config;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.apache.commons.compress.utils.OsgiUtils;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.apache.http.HttpHeaders;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
  30. import org.springframework.web.bind.annotation.*;
  31. import javax.servlet.http.HttpServletRequest;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.awt.image.BufferedImage;
  34. import java.io.IOException;
  35. import java.nio.charset.StandardCharsets;
  36. import java.security.Security;
  37. import java.util.Properties;
  38. @RestController
  39. @RequestMapping("/notAuth")
  40. @Slf4j
  41. public class NoLoginController {
  42. @Autowired
  43. RedisUtil redisUtil;
  44. @Autowired
  45. ITmUserService tmUserService;
  46. @Autowired
  47. OtherClient otherClient;
  48. @GetMapping("/getLoginAuthCode")
  49. public void getLoginCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
  50. response.setHeader("Cache-Control", "no-store, no-cache");
  51. response.setContentType("image/jpeg");
  52. String id ;
  53. try {
  54. LineCaptcha lineCaptcha = new LineCaptcha(200, 100);
  55. RandomGenerator mathGenerator = new RandomGenerator("1234567890",4);
  56. lineCaptcha.setGenerator(mathGenerator);
  57. //id = request.getSession().getId();
  58. id = lineCaptcha.getCode();
  59. // redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5);
  60. lineCaptcha.write(response.getOutputStream());
  61. response.getOutputStream().close();
  62. } catch (Exception e){
  63. log.info("生成登录验证码错误:",e);
  64. }
  65. }
  66. @PostMapping("/changePassword")
  67. public ResultData changePassword(@RequestBody UserAddRequest param){
  68. tmUserService.changePassword(param);
  69. return ResultData.ok();
  70. }
  71. @GetMapping("/getMsgAuthCode")
  72. public ResultData getMsgAuthCode(@RequestParam(name = "phoneNum") String phoneNum) {
  73. return ResultData.ok( tmUserService.getMsgAuthCode(phoneNum));
  74. }
  75. @PostMapping("getMapByAddress")
  76. public ResultData getMapByAddress(@RequestBody JSONObject jsonObject){
  77. if(jsonObject.getString("address") == null || StringUtils.isBlank(jsonObject.getString("address"))){
  78. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  79. }
  80. return ResultData.ok(ProvinceUtils.getRestMapByAddress(jsonObject.getString("address")));
  81. }
  82. @PostMapping("/forwardReq")
  83. public ResultData forwardReq(@RequestBody ForwardParam param){
  84. if(StringUtils.isBlank(param.getMethod()) || StringUtils.isBlank(param.getUrl())){
  85. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  86. }
  87. log.info("forwardReq:{}",param);
  88. if("GET".equalsIgnoreCase(param.getMethod())){
  89. return ResultData.ok(otherClient.get(param.getUrl()));
  90. }
  91. return ResultData.ok(otherClient.postJson(param.getUrl(),param.getJsonParam()));
  92. }
  93. }