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

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

相关推荐

  • 阿里云邮箱怎么收邮件

    收阿里云邮箱邮件可以通过以下步骤进行: 打开阿里云邮箱登录页面,在浏览器中输入邮箱网址,如https://mail.aliyun.com。 输入正确的邮箱账号和密码,点击登录按钮。 登录成功后,进入邮箱主界面。会显示你的收件箱、草稿箱、已发送、垃圾箱等文件夹。 点击收件箱文件夹,即可查看收到的邮件。如果有新邮件,会显示未读邮件的数量。 点击邮件标题,即可打开…

    2023年9月9日
    70600
  • 阿里云服务器哪个地域比较好

    阿里云服务器的哪个地域比较好,主要取决于您的具体需求和使用场景。以下是一些常用的地域选择建议: 华北地域(北京、张家口、呼和浩特):适合北方用户、政府机构和大型企业,有较好的网络延迟和带宽性能。 华东地域(上海、杭州、苏州、合肥):适合东部地区用户,有良好的网络连接和大量的机房选择。 华南地域(深圳、广州、香港):适合华南地区用户,网络延迟较低,适合面向香港…

    2023年10月1日
    70500
  • 代理阿里物联网云平台二次开发

    物联网云平台开发要多少钱?贵不贵? 物联网云平台开发除了需要耗资外 还需要技术人才 特别是网络安全团队 云平台对于技术要求较高 且服务器租金贵 一个流量大点的云平台流量费也是不小的支出 阿里云物联网云平台对普通人有什么用?    阿里来自云物联网主要功能是将用户端的所有需要的信息互通互联,实现全方位的远程识别、读取和操控、互动。    应甲起者善再特个一用层…

    2023年8月28日
    80400
  • 阿里云企业邮箱:什么时候阿里云企业邮箱支持邮件分类?

    阿里云企业邮箱的邮件分类功能何时推出? 许多用户关心阿里云企业邮箱何时会推出邮件分类功能。虽然目前官方尚未公布具体时间表,但可以预见的是,基于阿里云强大的技术实力和对用户体验的重视,邮件分类功能很可能会在未来更新中与用户见面。 阿里云企业邮箱的优势一览 作为国内领先的企业邮箱服务提供商,阿里云企业邮箱拥有众多显著优势。首先,它依托阿里云强大的云计算基础设施,…

    2025年7月21日
    49800
  • 阿里云服务器ecs认证

    阿里云ECS(Elastic Compute Service)认证是指阿里云官方针对使用ECS服务器的用户进行的一种认证活动。通过ECS认证,用户可以获得阿里云官方的认可和推荐。 阿里云ECS认证的主要目的是验证用户在使用ECS服务器时的操作能力和技术水平。认证考试主要分为基础篇和专业篇两个级别。在考试中,考生需要回答一系列与ECS服务器相关的技术问题,并完…

    2023年9月16日
    75200

发表回复

登录后才能评论

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:ixuntao@qq.com

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

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