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

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

相关推荐

  • 阿里云服务器系统镜像和应用镜像

    阿里云linux服务器环境自己搭配还是买镜像? 阿里云服务器购买后拥有最高权限,即root账户,可以安装MySQL就有数据库了,不会安装环境的可以使用镜像安装。 求助,阿里云服务器可以自己配置系统镜像不 是可以的,这是基本的功能。。 阿里云windows server2016 net的镜像怎么配置 很简单.你需要先把新的云主机开通.把老的云主机上面的数据下载…

    2023年8月28日
    4800
  • 台州阿里云代理商:阿里云 托管代码

    台州阿里云代理商是指在台州地区代理阿里云服务的公司。他们可以提供阿里云的托管服务,帮助客户将他们的代码和数据存储在阿里云的服务器上,并提供运行和维护服务。通过台州阿里云代理商,客户可以高效地利用阿里云的优质资源,实现代码的托管和运行。如果您需要台州地区的阿里云代理商服务,可以联系当地的阿里云代理商进行咨询和合作。 作为台州地区的阿里云代理商,我们可以为您提供…

    2024年2月18日
    4400
  • 阿里云国际站:asp 正则表达式 域名

    To create a regular expression for validating domain names in ASP, which is often needed when working with Alibaba Cloud services, you can use the following pattern: /^((?!-))(xn--…

    2024年7月6日
    3700
  • 荣成阿里云企业邮箱代理商:阿里邮箱个人版怎么改邮箱名称

    荣成阿里云企业邮箱代理商:阿里邮箱个人版怎么改邮箱名称 阿里云企业邮箱作为一款知名的企业级邮箱服务,为用户提供稳定可靠的通信和协作平台。荣成阿里云企业邮箱代理商在销售阿里云企业邮箱的同时,也负责提供售后服务和解决方案支持。本文将介绍如何在阿里邮箱个人版中改邮箱名称,并着重讲述了阿里云企业邮箱和代理商的优势。 阿里邮箱个人版改邮箱名称 在阿里邮箱个人版中改邮箱…

    2024年2月9日
    4200
  • 宜宾阿里云代理商:android手机震动

    抱歉,您的问题不是很清楚。请问您是想咨询宜宾阿里云代理商与Android手机震动有关的问题吗?如果是的话,请提供更多的详细信息,我们会尽力帮助您解答。 对于Android手机,可以通过调用Vibrator(震动器)类来实现震动功能。具体步骤如下: 在AndroidManifest.xml文件中添加震动权限: <uses-permission andro…

    2024年1月18日
    9800

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:ixuntao@qq.com

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

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