| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaSecCheckService; |
| | | import com.netflix.discovery.converters.Auto; |
| | | import com.panzhihua.applets.config.WxMaConfiguration; |
| | | import com.panzhihua.common.constants.FtpConstants; |
| | | import com.panzhihua.common.constants.UserConstants; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.area.AreaInfoVo; |
| | | import com.panzhihua.common.model.vos.user.UserPhoneVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | 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 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.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | |
| | | public class CommonApi { |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | // FTP 登录用户名 |
| | | @Value("${ftp.username}") |
| | | private String userName; |
| | | // FTP 登录密码 |
| | | @Value("${ftp.password}") |
| | | private String password; |
| | | // FTP 服务器地址IP地址 |
| | | @Value("${ftp.host}") |
| | | private String host; |
| | | // FTP 端口 |
| | | @Value("${ftp.port}") |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private String url; |
| | | |
| | | @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) { |
| | | @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(); |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + UUID.randomUUID().toString().replace("-", "") + ".jpg"; |
| | | File file1 = new File(fileName); |
| | | |
| | | String name = file.getOriginalFilename(); |
| | | name= UUID.randomUUID().toString().replaceAll("-","")+".jpg"; |
| | | name = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg"; |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(); |
| | | 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 (WxErrorException e) { |
| | | log.error("微信审核图片出错【{}】", e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is); |
| | | sftp.logout(); |
| | | return R.ok(FtpConstants.HTTP_URL+"/idcard/" + name); |
| | | return R.ok(url + "/idcard/" + name); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | |
| | | //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); |