tj
6 天以前 b428226d0cf78bbb843fa17bffb1e338230fae6c
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
package com.mzl.flower.service.impl.sms;
 
import com.mzl.flower.config.sms.TosSmsProperties;
import com.mzl.flower.service.sms.TosSmsService;
import com.volcengine.model.request.SmsSendRequest;
import com.volcengine.model.response.SmsSendResponse;
import com.volcengine.service.sms.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.Map;
 
@Service
public class TosSmsServiceImpl implements TosSmsService {
 
    @Autowired
    private TosSmsProperties tosSmsProperties;
 
    @Autowired
    @Qualifier("volcSmsService")
    private SmsService smsService;
 
    @Override
    public SmsSendResponse sendSms(SmsSendRequest request) {
        SmsSendResponse response = null;
        try {
            response = smsService.sendV2(request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return response;
    }
 
    @Override
    public SmsSendResponse sendSms(String phonenum, Map<String, String> params) {
        SmsSendRequest req = new SmsSendRequest();
        req.setPhoneNumbers(phonenum);
        req.setSmsAccount(tosSmsProperties.getSmsAccount());
        req.setTemplateId(tosSmsProperties.getTemplateId());
        req.setSign(tosSmsProperties.getSign());
        req.setTemplateParamByMap(params);
        try {
            SmsSendResponse smsSendResponse = smsService.sendV2(req);
            return smsSendResponse;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    @Override
    public SmsSendResponse sendSms(String phonenum, Map<String, String> params, String smsAccount, String templateId, String sign) {
        SmsSendRequest req = new SmsSendRequest();
        req.setPhoneNumbers(phonenum);
        req.setSmsAccount(smsAccount);
        req.setTemplateId(templateId);
        req.setSign(sign);
        req.setTemplateParamByMap(params);
        try {
            SmsSendResponse smsSendResponse = smsService.sendV2(req);
            return smsSendResponse;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}