huanghongfa
2020-12-20 def38240262b4403377d4c16beac3ea048f1e658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.panzhihua.applets.api;
 
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.user.UserPhoneVO;
import com.panzhihua.common.utlis.SFTPUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
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.InputStream;
import java.util.concurrent.TimeUnit;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 公共接口
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-12-10 15:41
 **/
@Slf4j
@RestController
@RequestMapping("/common/")
@Api(tags = {"公共接口"})
public class CommonApi {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
 
    @ApiOperation(value = "上传照片")
    @PostMapping(value = "uploadimage",consumes = "multipart/*",headers = "content-type=multipart/form-date")
    public R uploadImage(@RequestParam MultipartFile file, HttpServletRequest request) {
        String name = file.getOriginalFilename();
        try {
            SFTPUtil sftp = new SFTPUtil();
            sftp.login();
            InputStream is = file.getInputStream();
            sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is);
            sftp.logout();
            return R.ok(FtpConstants.HTTP_URL+"/idcard/" + name);
        } catch (Exception e) {
            log.error("上传照片失败【{}】", e.getMessage());
            return R.fail();
        }
 
    }
 
    @ApiOperation(value = "发送验证码")
    @PostMapping(value = "smscode")
    public R smscode(@RequestBody UserPhoneVO userPhoneVO) {
        String newPhone = userPhoneVO.getNewPhone();
        if (ObjectUtils.isEmpty(newPhone)) {
            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);
        return R.ok(nextInt);
    }
 
    public static void main(String[] args) {
        int nextInt = RandomUtils.nextInt(99999, 1000000);
        System.out.println(nextInt);
    }
}