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

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

相关推荐

  • 河源阿里云企业邮箱代理商:阿里邮箱app怎么分组

    阿里邮箱APP分组 作为河源阿里云企业邮箱代理商,我们了解到阿里云企业邮箱是一款功能强大、安全可靠的企业邮件解决方案。在使用阿里云企业邮箱后,我们深切感受到了它的优势和便利。本文将重点介绍如何在阿里邮箱APP中进行分组操作。 阿里云企业邮箱的优势 阿里云企业邮箱相比其他企业邮箱提供商具有以下优势: 安全可靠:阿里云采用多层次的安全防护措施,保障企业邮箱数据的…

    2024年2月11日
    20100
  • 郑州阿里云代理商:安装虚拟机电脑很卡

    如果您在安装虚拟机时遇到了电脑卡顿的问题,可以尝试以下解决方法: 确保电脑的配置符合虚拟机的最低系统要求。虚拟机对电脑硬件配置有一定要求,如果您的电脑配置较低,可能会导致运行虚拟机时卡顿。可以查阅虚拟机的系统要求,并与您的电脑配置进行对比。 分配更多的系统资源给虚拟机。在使用虚拟机时,可以考虑增加虚拟机分配的内存、CPU 等资源,以提高虚拟机的运行效果。通过…

    2024年2月16日
    17900
  • 信阳阿里云企业邮箱代理商:阿里云邮箱怎么登录其它邮箱的东西

    如何登录其他邮箱 在使用阿里云企业邮箱时,我们有时候需要登录其他邮箱来查看邮件或进行邮件的操作。下面将介绍如何登录其他邮箱。 步骤一:打开邮箱登录页面 首先,在浏览器中输入相应邮箱服务商的网址,比如163、QQ邮箱等,找到登录入口。 步骤二:输入账号和密码 在登录页面输入您的邮箱账号和密码,然后点击登录按钮进入邮箱主页。 步骤三:进行邮件操作 登录成功后,您…

    2024年2月21日
    20000
  • 阿里云短信收不到验证码

    如果你在使用阿里云短信服务时无法收到验证码,请尝试以下解决办法: 检查手机号码是否正确输入:确保手机号码没有输入错误。 检查阿里云账号短信开通情况:确保已经在阿里云账号上开通了短信服务,并且已经购买了足够的短信配额。 检查短信模板和签名设置是否正确:确保使用的短信模板和签名是经过审核并正确配置的,否则阿里云短信服务将无法发送短信。 检查短信发送接口是否正常工…

    2023年9月11日
    17600
  • 阿里云ace云计算架构师月薪

    架构师月薪5万什么水平 高。架构师月薪5万元人民币是相当高的薪资水平,该水平的薪资通常也要空键求架构师承担较高的职责和复杂的项目或组织管理工作,需要承担更高的工作风险和压力,而且该薪资水平也受地理位置、公司规模、行业发展等多方面因素的影响。架构师,这个词源于建筑学,软件工程当中的架构师和建筑工源哗程当中建筑师有许多相通之处,都是负责“产品斗裂巧”宏观的架构设…

    2023年8月25日
    20300

发表回复

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

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:ixuntao@qq.com

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

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