admin
2019-03-13 33b4ed2bbf28ec16b66e552680f56a691a4e908d
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
package com.yeshi.fanli.controller.client;
 
import java.io.PrintWriter;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.exception.SMSException;
import com.yeshi.fanli.service.inter.user.SMSService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
import org.yeshi.utils.JsonUtil;
 
@Controller
@RequestMapping("api/v1/sms")
public class SMSController {
 
    @Resource
    private SMSService smsService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private UserInfoService userInfoService;
 
    // 发送短信
 
    @RequestMapping(value = "sendSMS", method = RequestMethod.POST)
    public void sendMSM(AcceptData acceptData, String phone, Long uid, Integer type, PrintWriter out) {
        sendMSM(acceptData, phone, uid, type, StringUtil.Md5(phone + "-" + "-" + uid + "-" + type), out);
    }
 
    @RequestSerializableByKey(key = "key")
    public void sendMSM(AcceptData acceptData, String phone, Long uid, Integer type, String key, PrintWriter out) {
        try {
            if (phone.contains("**") && uid != null && uid > 0) {
                UserInfo userInfo = userInfoService.getUserById(uid);
                if (userInfo == null) {
                    out.print(JsonUtil.loadFalseResult(2, "用户不存在"));
                    return;
                } else if (StringUtil.isNullOrEmpty(userInfo.getPhone())) {
                    out.print(JsonUtil.loadFalseResult(3, "尚未绑定电话号码"));
                    return;
                }
                phone = userInfo.getPhone();
            }
 
            if (!StringUtil.isMobile(phone)) {
                out.print(JsonUtil.loadFalseResult(4, "电话号码格式不正确"));
                return;
            }
            String msg = smsService.sendLoginVCode(phone);
 
            out.print(JsonUtil.loadTrueResult("发送成功"));
        } catch (SMSException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
}