| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaSecCheckService; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.panzhihua.applets.config.MinioUtil; |
| | | import com.panzhihua.applets.config.WxMaConfiguration; |
| | | import com.panzhihua.applets.umf.UmfPayUtil; |
| | | import com.panzhihua.applets.unionpay.*; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.constants.FtpConstants; |
| | | import com.panzhihua.common.constants.UserConstants; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.dtos.bracelet.BraceletEarlyWarningDO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.Base64File; |
| | | import com.panzhihua.common.model.vos.community.WeatherVO; |
| | | import com.panzhihua.common.model.vos.user.UserPhoneVO; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | import com.panzhihua.common.service.bracelet.CommunityBraceletService; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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 javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Base64; |
| | | import java.util.UUID; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | import static com.panzhihua.common.utlis.FileTypeUploadUtils.assertAllowed; |
| | | import static com.panzhihua.common.utlis.PayUtil.makeUUID; |
| | | |
| | | /** |
| | | * @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 登录用户名 |
| | |
| | | @Value("${ftp.port}") |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private int url; |
| | | private String url; |
| | | @Value("${minio.url}") |
| | | private String minUrl; |
| | | @Resource |
| | | private WxMaConfiguration wxMaConfiguration; |
| | | @Resource |
| | | private CommunityService communityService; |
| | | |
| | | @ApiOperation(value = "上传照片") |
| | | @PostMapping(value = "uploadimage",consumes = "multipart/*",headers = "content-type=multipart/form-date") |
| | | public R uploadImage(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | @Resource |
| | | private CommunityBraceletService communityBraceletService; |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | @Resource |
| | | private UmfPayUtil umfPayUtil; |
| | | |
| | | 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(this.getAppId()).getSecCheckService(); |
| | | String property = System.getProperty("user.dir"); |
| | | |
| | | String fileExtension = ".jpg"; |
| | | |
| | | String originName = file.getOriginalFilename(); |
| | | AtomicBoolean isVideo = new AtomicBoolean(false); |
| | | videoExtensionAllow.forEach(ext -> { |
| | | String originNameLowerCase = originName.toLowerCase(); |
| | | if (originNameLowerCase.endsWith("." + ext)) { |
| | | isVideo.set(true); |
| | | } |
| | | }); |
| | | if (isVideo.get()) { |
| | | fileExtension = ".mp4"; |
| | | } |
| | | |
| | | String fileName = property + File.separator + UUID.randomUUID().toString().replace("-", "") + fileExtension; |
| | | File file1 = new File(fileName); |
| | | |
| | | String name = file.getOriginalFilename(); |
| | | name= UUID.randomUUID().toString().replaceAll("-","")+".jpg"; |
| | | name = UUID.randomUUID().toString().replaceAll("-", "") + fileExtension; |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName,password,host,port); |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | InputStream is = file.getInputStream(); |
| | | file.transferTo(file1); |
| | | try { |
| | | // boolean b = wxMaSecCheckService.checkImage(file1); |
| | | boolean delete = file1.delete(); |
| | | log.info("临时文件删除【{}】", delete); |
| | | // if (!b) { |
| | | // return R.fail("图片内容违规"); |
| | | // } |
| | | } catch (Exception e) { |
| | | log.error("微信审核图片出错【{}】", e.getMessage()); |
| | | return R.fail("图片上传失败"); |
| | | // e.printStackTrace(); |
| | | } |
| | | sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is); |
| | | sftp.logout(); |
| | | return R.ok(url+"/idcard/" + name); |
| | | return R.ok(url + "/idcard/" + name); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | 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 = "/uploadImagesInputStream") |
| | | public R uploadImagesInputStream(@RequestBody Base64File file, HttpServletRequest request) { |
| | | if(StringUtils.isEmpty(file.getFile())){ |
| | | return R.fail("文件不能为Null"); |
| | | } |
| | | try { |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg"; |
| | | InputStream is = minioUtil.base64StrToInputStream(file.getFile().replace("data:image/png;base64,","").replace("data:image/jpg;base64,","").replace("data:image/jpeg;base64,","")); |
| | | String imageUrl = minioUtil.uploadInputStream(is, 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 { |
| | | assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String uuid=UUID.randomUUID().toString().replaceAll("-", ""); |
| | | String name = uuid + "."+ extension; |
| | | String fileName = minioUtil.uploadRetFileName(file, name); |
| | | Thumbnails.of(file.getInputStream()).scale(0.5).outputQuality(0.71).outputFormat("jpg").toFile(uuid+"_compress"); |
| | | File file1=new File(uuid+"_compress.jpg"); |
| | | String imageUrl = minioUtil.uploadFile(file1, uuid+"_compress.jpg"); |
| | | //上传完压缩图后把原图清理,防止文件服务器资源爆满 |
| | | minioUtil.removeMinio(fileName); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "发送验证码") |
| | |
| | | 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); |
| | | valueOperations.set(UserConstants.PHONE_PUT + newPhone, nextInt + "", 3, TimeUnit.MINUTES); |
| | | return R.ok(nextInt); |
| | | } |
| | | |
| | | 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 = "获取天气", response = WeatherVO.class) |
| | | @GetMapping(value = "/getWeather/noToken") |
| | | 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); |
| | | return R.ok(JSON.parseObject(result)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取安全知识培训跳转url") |
| | | @GetMapping(value = "getSafety") |
| | | public R getSafety() |
| | | { |
| | | return R.ok("https://pzh.axhpx.com/Wechat/"); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("uu洗车下单接口") |
| | | @GetMapping("/uuPay") |
| | | public R uuPay(@RequestParam("orderid") String orderid,@RequestParam("openid")String openid,@RequestParam("amount")String amount){ |
| | | Map map=umfPayUtil.pay(orderid, DateUtils.getCurrentDateString(),openid,amount); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @ApiOperation("无水洗车下单接口") |
| | | @GetMapping("/wsPay") |
| | | public R wsPay(@RequestParam("orderid") String orderid,@RequestParam("openid")String openid,@RequestParam("amount")String amount){ |
| | | Map map=umfPayUtil.pay2(orderid, DateUtils.getCurrentDateString(),openid,amount); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation("uu洗车银联下单接口") |
| | | @GetMapping("/uuUnionpayPay") |
| | | public R uuUnionpayPay(@RequestParam("amount")String amount, |
| | | @RequestParam("productId")String productId, |
| | | @RequestParam("openId")String openId){ |
| | | |
| | | LocalDateTime time=DateUtils.getCurrentDate(); |
| | | String merOrderId= UnionpayContent.TOP4+time.format(DateUtils.format_ymdhms_yyyyMMddmmHHssSSS)+makeUUID(7); |
| | | String map= UnifiedOrder.sendOrder(amount,"uu洗车下单",productId,openId,time,merOrderId); |
| | | communityService.add(productId,merOrderId,amount); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @ApiOperation("无水洗车银联下单接口") |
| | | @GetMapping("/wsUnionpayPay") |
| | | public R wsUnionpayPay(@RequestParam("amount")String amount, |
| | | @RequestParam("productId")String productId, |
| | | @RequestParam("openId")String openId){ |
| | | LocalDateTime time=DateUtils.getCurrentDate(); |
| | | String merOrderId= UnionpayContent.TOP4+time.format(DateUtils.format_ymdhms_yyyyMMddmmHHssSSS)+makeUUID(7); |
| | | String map= UnifiedOrder.sendOrder(amount,"无水洗车下单",productId,openId,time,merOrderId); |
| | | communityService.add(productId,merOrderId,amount); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @ApiOperation("uu洗车银联退款接口") |
| | | @GetMapping("/uuUnionpayRefund") |
| | | public R uuUnionpayRefundPay(@RequestParam("refundAmount")String refundAmount, |
| | | @RequestParam("refundOrderId")String refundOrderId){ |
| | | String map= Refund.sendOrder(refundAmount,refundOrderId); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @ApiOperation("无水洗车银联退款接口") |
| | | @GetMapping("/wsUnionpayRefund") |
| | | public R wsUnionpayRefundPay(@RequestParam("refundAmount")String refundAmount, |
| | | @RequestParam("refundOrderId")String refundOrderId){ |
| | | String map= Refund.sendOrder(refundAmount,refundOrderId); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("银联支付查询接口") |
| | | @GetMapping("/unionpayQuery") |
| | | public R unionpayRefundPay(@RequestParam("merOrderId")String merOrderId){ |
| | | String map= Query.query(merOrderId); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @ApiOperation("银联退款查询接口") |
| | | @GetMapping("/unionpayRefundQuery") |
| | | public R unionpayRefundQuery(@RequestParam("merOrderId")String merOrderId){ |
| | | String map= RefundQuery.refundQuery(merOrderId); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取预警数据 |
| | | * @param communityId |
| | | * @return |
| | | */ |
| | | @ApiOperation("微信手环人员处理工单列表") |
| | | @GetMapping("bracelet/getEarlyWarningList") |
| | | public R getList(@RequestParam("pageNum") Integer pageNum, |
| | | @RequestParam("pageSize") Integer pageSize, |
| | | @RequestParam("communityId") String communityId, |
| | | @RequestParam("disposeUserId") String disposeUserId, |
| | | @RequestParam("type") String type) |
| | | { |
| | | return communityBraceletService.getList(pageNum,pageSize,communityId,"",disposeUserId,type,"",""); |
| | | } |
| | | |
| | | /** |
| | | * 微信处理接口 |
| | | * @param braceletEarlyWarningDO |
| | | * @return |
| | | */ |
| | | @PostMapping("bracelet/WXdispose") |
| | | public R WXdispose(@RequestBody BraceletEarlyWarningDO braceletEarlyWarningDO) |
| | | { |
| | | if(StringUtils.isEmpty(braceletEarlyWarningDO.getDisposeText())) |
| | | { |
| | | return R.fail("处理内容不能为空"); |
| | | } |
| | | braceletEarlyWarningDO.setDisposeType("2"); |
| | | return communityBraceletService.WXdispose(braceletEarlyWarningDO); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |