“djh”
2025-03-25 a06aacdfa9fdc493eedfb5f5784853b1d8386165
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
74
75
76
77
78
79
80
81
package com.gkhy.sign.utils;
 
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import com.ruoyi.common.utils.http.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
 
import java.util.HashMap;
import java.util.Map;
 
public class SendMessageUtil {
 
    private static final Logger log = LoggerFactory.getLogger(SendMessageUtil.class);
 
    @Value("${safecheckqiniuymes.accesskey}")
    private String accesskey;
 
    @Value("${safecheckqiniuymes.secretkey}")
    private String secretkey;
 
    @Value("${safecheckqiniuymes.templateid}")
    private String templateid;
 
    public Response sendCheckMessage(String[] phone, Map<String,String> map){
 
        Auth auth = Auth.create(accesskey, secretkey);
        SmsManager smsManager = new SmsManager(auth);
 
        try {
           Response response =  smsManager.sendMessage(templateid, phone, map);
           return response;
        } catch (QiniuException e) {
            throw new RuntimeException(e);
        }
    }
 
    public void sendMessage(){
        String host = "https://kzsms.market.alicloudapi.com";
        String path = "/api/sms/send";
        String method = "POST";
        String appcode = "你自己的AppCode";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求,定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("templateId", "KZvoQcsO1HS23nYL8");
        bodys.put("mobile", "19548157345");
        bodys.put("value", "联系客服申请签名和模版");
 
 
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
//             */
//            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
//            System.out.println(response.toString());
//            HttpUtils.sendPost()
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 
 
}