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 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 headers = new HashMap(); //最后在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 querys = new HashMap(); Map bodys = new HashMap(); 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(); } } }