zhangf
2024-08-08 71706ced3375f4c18148516d0477d8fd645de2ee
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
package com.gkhy.huataiFourierSpecialGasMonitor.utils;
 
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
 
import java.util.Map;
 
@Component
public class SendMessageUtil {
 
    private static final Logger log = LoggerFactory.getLogger(SendMessageUtil.class);
 
    @Value("${qiniuymes.accesskey}")
    private String accesskey;
 
    @Value("${qiniuymes.secretkey}")
    private String secretkey;
 
    @Value("${qiniuymes.templateid}")
    private String templateid;
 
    /**
     * 发送短信提示
     */
    @Async("SocketTaskExecutor")
    public Boolean sendMessageCheck(String[] phone, Map<String, String> map){
        Auth auth = Auth.create(accesskey, secretkey);
        SmsManager smsManager = new SmsManager(auth);
        try {
            Response resp = smsManager.sendMessage(templateid, phone , map);
            if(resp.statusCode == 200){
                return true;
            }else {
                log.info("短信发送状态码非200:【"+resp.statusCode+"】");
                return false;
            }
        } catch (QiniuException e) {
            log.info("发生短信异常 =======================" ,e);
        }
        return false;
    }
}