厦门阿里云代理商:安卓发送短信完整代码

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class AlibabaCloudSMS {

public static void main(String[] args) {
    String accessKeyId = "your_access_key_id";
    String accessKeySecret = "your_access_key_secret";
    String phoneNumbers = "your_phone_number";
    String signName = "your_sign_name";
    String templateCode = "your_template_code";
    String templateParam = "{"code":"123456"}";

    try {
        String url = "http://dysmsapi.aliyuncs.com/?Action=SendSms"
                + "&PhoneNumbers=" + URLEncoder.encode(phoneNumbers, "UTF-8")
                + "&SignName=" + URLEncoder.encode(signName, "UTF-8")
                + "&TemplateCode=" + URLEncoder.encode(templateCode, "UTF-8")
                + "&TemplateParam=" + URLEncoder.encode(templateParam, "UTF-8")
                + "&AccessKeyId=" + URLEncoder.encode(accessKeyId, "UTF-8")
                + "&SignatureMethod=HMAC-SHA1"
                + "&SignatureNonce=45e25e9b-0a6f-4e51-9c3a-731b488ec5fc"
                + "&SignatureVersion=1.0"
                + "&Timestamp=2018-12-05T23:56:34Z"
                + "&Signature=Signature";

        System.out.println("SMS URL: " + url);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

}

import java.io.*;
import java.net.*;
import java.util.*;

厦门阿里云代理商:安卓发送短信完整代码

public class SMSSender {


public static void main(String[] args) {
    String url = "http://api.k780.com:88";
    String appKey = "your_app_key";
    
    Map<String, String> params = new HashMap<>();
    params.put("app", "sms.send");
    params.put("tempid", "your_template_id");
    params.put("sign", "your_sign");
    params.put("appkey", appKey);
    params.put("mobile", "your_mobile_number");
    params.put("content", "your_message_content");
    
    try {
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(getParamsString(params));
        wr.flush();
        wr.close();
        
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        
        System.out.println(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private static String getParamsString(Map<String, String> params) throws UnsupportedEncodingException {
    StringBuilder result = new StringBuilder();
    
    for (Map.Entry<String, String> entry : params.entrySet()) {
        result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
        result.append("=");
        result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
        result.append("&");
    }
    
    String resultString = result.toString();
    return resultString.length() > 0 ? resultString.substring(0, resultString.length() - 1) : resultString;
}

}

发布者:luotuoemo,转转请注明出处:https://www.jintuiyun.com/156548.html

(0)
luotuoemo的头像luotuoemo
上一篇 2024年3月3日 03:00
下一篇 2024年3月3日 03:58

相关推荐

  • 阿里云轻量服务器怎么安装源码

    安装源码前需要安装以下环境: 安装 git:sudo apt install git 安装编译工具:sudo apt install build-essential 安装其他依赖库:sudo apt install libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libncurs…

    2023年8月20日
    1.2K00
  • 阿里云轻应用宝塔

    阿里云web应用防火墙网站暂时无法访问 你想问的是阿里云web应用防火墙网站暂时无法访问怎么办吗?这种情况的解决办法如下:1、找到阿里云web,在浏览器阿里云web中点击开始,找到控制面板,并在该页面中找到“Windws防火墙”,鼠标双击左键。2、进入“Windws防火墙”设置页面,点击“高级”,把“本地连接”和“宽带连接”前来自面的勾选去掉,还可360问答…

    2023年8月28日
    87600
  • 阿里云企业邮箱:如何管理企业邮箱登录设备?

    阿里云企业邮箱:如何管理企业邮箱登录设备 在现代企业中,电子邮件是最重要的沟通工具之一。阿里云企业邮箱作为国内领先的企业邮箱服务提供商,以其强大的功能和安全性赢得了众多企业用户的青睐。本文将详细介绍如何管理阿里云企业邮箱的登录设备,并探讨阿里云企业邮箱的优势。 阿里云企业邮箱的优势 安全性高:阿里云企业邮箱提供多重安全防护措施,包括反垃圾邮件、病毒防护、数据…

    2025年4月6日
    58200
  • 厦门阿里云代理商:asp.net网站背景颜色

    在ASP.NET网站中设置背景颜色可以通过以下几种方式实现: 在ASP.NET页面的代码中设置背景颜色:在ASP.NET页面的代码中找到<body>标签,然后在其中添加style属性,设置背景颜色,例如: <body style="background-color: #f2f2f2;"> 这里的#f2f2f2是十六…

    2024年2月10日
    62200
  • 金华阿里云代理商:阿里云堡垒自动化运维

    阿里云堡垒自动化运维是一种通过堡垒机实现对企业服务器、系统和应用的安全管控和自动化运维的解决方案。金华阿里云代理商可以帮助企业购买和配置阿里云堡垒机,提供技术支持和培训服务。 通过阿里云堡垒机,企业可以实现以下功能: 资源权限管理:通过阿里云堡垒机可以对企业服务器和系统的访问权限进行集中管理,管理员可以根据员工的职责和权限设置相应的访问权限,减少误操作和安全…

    2023年12月14日
    68400

发表回复

登录后才能评论

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:ixuntao@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
购买阿里云服务器请访问:https://www.4526.cn/