| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaSecCheckService; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Arrays; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.panzhihua.applets.config.MinioUtil; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.lang3.RandomUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.panzhihua.applets.config.WxMaConfiguration; |
| | | import com.panzhihua.common.constants.Constants; |
| | |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.HttpUtils; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaSecCheckService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.RandomUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Arrays; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | /** |
| | | * @program: springcloud_k8s_panzhihuazhihuishequ |
| | |
| | | @RestController |
| | | @RequestMapping("/common/") |
| | | @Api(tags = {"公共接口"}) |
| | | public class CommonApi { |
| | | public class CommonApi extends BaseController { |
| | | /** |
| | | * 允许的图片文件后缀 |
| | | */ |
| | | private static List<String> fileExtensionAllow = Arrays.asList("gif", "jpg", "png", "jpeg"); |
| | | /** |
| | | * 允许的视频文件后缀 |
| | | */ |
| | | private static List<String> videoExtensionAllow = Arrays.asList("mp4", "mov"); |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | // FTP 登录用户名 |
| | |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private String url; |
| | | |
| | | /** |
| | | * 允许的图片文件后缀 |
| | | */ |
| | | private static List<String> fileExtensionAllow = Arrays.asList("gif", "jpg", "png", "jpeg"); |
| | | /** |
| | | * 允许的视频文件后缀 |
| | | */ |
| | | private static List<String> videoExtensionAllow = Arrays.asList("mp4", "mov"); |
| | | |
| | | @Value("${minio.url}") |
| | | private String minUrl; |
| | | @Resource |
| | | private WxMaConfiguration wxMaConfiguration; |
| | | @Resource |
| | | private CommunityService communityService; |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | public static void main(String[] args) { |
| | | // int nextInt = RandomUtils.nextInt(99999, 1000000); |
| | | // System.out.println(nextInt); |
| | | String basicStr = |
| | | "2092261934651932672" + ":" + "de1c0dbb-9197-4724-9cc2-aa94e30a072f" + ":" + System.currentTimeMillis(); |
| | | String s = Base64.getEncoder().encodeToString(basicStr.getBytes()); |
| | | System.out.println(s); |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "上传照片/视频 (jpg/jpeg/png/mp4/mov)") |
| | | @PostMapping(value = "uploadimage", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImage(@RequestParam MultipartFile file, HttpServletRequest request) throws IOException { |
| | | // 微信图片内容校验 |
| | | WxMaSecCheckService wxMaSecCheckService = wxMaConfiguration.getMaService().getSecCheckService(); |
| | | // 微信图片内容校验 |
| | | WxMaSecCheckService wxMaSecCheckService = wxMaConfiguration.getMaService(this.getAppId()).getSecCheckService(); |
| | | String property = System.getProperty("user.dir"); |
| | | |
| | | String fileExtension = ".jpg"; |
| | | |
| | | String originName = file.getOriginalFilename(); |
| | | AtomicBoolean isVideo = new AtomicBoolean(false); |
| | | videoExtensionAllow.forEach(ext ->{ |
| | | videoExtensionAllow.forEach(ext -> { |
| | | String originNameLowerCase = originName.toLowerCase(); |
| | | if(originNameLowerCase.endsWith("." +ext)){ |
| | | if (originNameLowerCase.endsWith("." + ext)) { |
| | | isVideo.set(true); |
| | | } |
| | | }); |
| | | if(isVideo.get()){ |
| | | if (isVideo.get()) { |
| | | fileExtension = ".mp4"; |
| | | } |
| | | |
| | | |
| | | String fileName = property + File.separator + UUID.randomUUID().toString().replace("-", "") + fileExtension; |
| | | File file1 = new File(fileName); |
| | |
| | | InputStream is = file.getInputStream(); |
| | | file.transferTo(file1); |
| | | try { |
| | | // boolean b = wxMaSecCheckService.checkImage(file1); |
| | | // boolean b = wxMaSecCheckService.checkImage(file1); |
| | | boolean delete = file1.delete(); |
| | | log.info("临时文件删除【{}】", delete); |
| | | // if (!b) { |
| | | // return R.fail("图片内容违规"); |
| | | // } |
| | | // if (!b) { |
| | | // return R.fail("图片内容违规"); |
| | | // } |
| | | } catch (Exception e) { |
| | | log.error("微信审核图片出错【{}】", e.getMessage()); |
| | | return R.fail("图片上传失败"); |
| | | // e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is); |
| | | sftp.logout(); |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片压缩接口") |
| | | @PostMapping(value = "/uploadimagescompress", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImagesComPress(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String uuid=UUID.randomUUID().toString().replaceAll("-", ""); |
| | | String name = uuid + "."+ extension; |
| | | minioUtil.upload(file, name); |
| | | Thumbnails.of(file.getInputStream()).scale(1).outputQuality(0.01).outputFormat("jpg").toFile(uuid+"compress"); |
| | | File file1=new File(uuid+"compress.jpg"); |
| | | String imageUrl = minioUtil.uploadFile(file1, uuid+"compress.jpg"); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "发送验证码") |
| | | @PostMapping(value = "smscode") |
| | | public R smscode(@RequestBody UserPhoneVO userPhoneVO) { |
| | |
| | | if (ObjectUtils.isEmpty(newPhone)) { |
| | | return R.fail("新手机号不能为空"); |
| | | } |
| | | //todo 发送验证码接第三方 |
| | | // todo 发送验证码接第三方 |
| | | int nextInt = RandomUtils.nextInt(99999, 1000000); |
| | | ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue(); |
| | | valueOperations.set(UserConstants.PHONE_PUT + newPhone, nextInt + "", 3, TimeUnit.MINUTES); |
| | | return R.ok(nextInt); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取天气",response = WeatherVO.class) |
| | | @ApiOperation(value = "获取天气", response = WeatherVO.class) |
| | | @GetMapping(value = "/getWeather/noToken") |
| | | public R getWeather(){ |
| | | //获取请求url |
| | | public R getWeather() { |
| | | // 获取请求url |
| | | String url = Constants.G_D_WEATHER_URL; |
| | | //获取请求参数 |
| | | // 获取请求参数 |
| | | String param = "key=" + Constants.G_D_WEATHER_KEY + "&city=510400"; |
| | | String result = HttpUtils.sendGet(url,param); |
| | | String result = HttpUtils.sendGet(url, param); |
| | | return R.ok(JSON.parseObject(result)); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // int nextInt = RandomUtils.nextInt(99999, 1000000); |
| | | // System.out.println(nextInt); |
| | | String basicStr = "2092261934651932672" + ":" + "de1c0dbb-9197-4724-9cc2-aa94e30a072f" + ":" + System.currentTimeMillis(); |
| | | String s = Base64.getEncoder().encodeToString(basicStr.getBytes()); |
| | | System.out.println(s); |
| | | |
| | | } |
| | | } |