package com.fdkankan.fusion.controller; import cn.hutool.captcha.CaptchaUtil; import cn.hutool.captcha.CircleCaptcha; import cn.hutool.captcha.LineCaptcha; import cn.hutool.captcha.ShearCaptcha; import cn.hutool.captcha.generator.CodeGenerator; import cn.hutool.captcha.generator.MathGenerator; import cn.hutool.captcha.generator.RandomGenerator; import cn.hutool.crypto.digest.MD5; import cn.hutool.http.ContentType; import com.alibaba.fastjson.JSONObject; import com.fdkankan.fusion.common.ResultCode; import com.fdkankan.fusion.common.ResultData; import com.fdkankan.fusion.common.util.MD5Checksum; import com.fdkankan.fusion.common.util.ProvinceUtils; import com.fdkankan.fusion.common.util.RedisKeyUtil; import com.fdkankan.fusion.exception.BusinessException; import com.fdkankan.fusion.httpClient.client.OtherClient; import com.fdkankan.fusion.request.ForwardParam; import com.fdkankan.fusion.response.UserAddRequest; import com.fdkankan.fusion.service.ITmUserService; import com.fdkankan.redis.util.RedisUtil; import jdk.nashorn.internal.runtime.regexp.joni.Config; import lombok.extern.slf4j.Slf4j; import org.apache.commons.compress.utils.OsgiUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHeaders; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.kafka.KafkaProperties; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.Security; import java.util.Properties; @RestController @RequestMapping("/notAuth") @Slf4j public class NoLoginController { @Autowired RedisUtil redisUtil; @Autowired ITmUserService tmUserService; @Autowired OtherClient otherClient; @GetMapping("/getLoginAuthCode") public void getLoginCode(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader("Cache-Control", "no-store, no-cache"); response.setContentType("image/jpeg"); String id ; try { LineCaptcha lineCaptcha = new LineCaptcha(200, 100); RandomGenerator mathGenerator = new RandomGenerator("1234567890",4); lineCaptcha.setGenerator(mathGenerator); //id = request.getSession().getId(); id = lineCaptcha.getCode(); // redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5); lineCaptcha.write(response.getOutputStream()); response.getOutputStream().close(); } catch (Exception e){ log.info("生成登录验证码错误:",e); } } @PostMapping("/changePassword") public ResultData changePassword(@RequestBody UserAddRequest param){ tmUserService.changePassword(param); return ResultData.ok(); } @GetMapping("/getMsgAuthCode") public ResultData getMsgAuthCode(@RequestParam(name = "phoneNum") String phoneNum) { return ResultData.ok( tmUserService.getMsgAuthCode(phoneNum)); } @PostMapping("getMapByAddress") public ResultData getMapByAddress(@RequestBody JSONObject jsonObject){ if(jsonObject.getString("address") == null || StringUtils.isBlank(jsonObject.getString("address"))){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } return ResultData.ok(ProvinceUtils.getRestMapByAddress(jsonObject.getString("address"))); } @PostMapping("/forwardReq") public ResultData forwardReq(@RequestBody ForwardParam param){ if(StringUtils.isBlank(param.getMethod()) || StringUtils.isBlank(param.getUrl())){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } log.info("forwardReq:{}",param); if("GET".equalsIgnoreCase(param.getMethod())){ return ResultData.ok(otherClient.get(param.getUrl())); } return ResultData.ok(otherClient.postJson(param.getUrl(),param.getJsonParam())); } }