使用第三方平台短信接口实现发送验证码

这篇博客展示了如何利用第三方平台的短信接口,通过Java的HTTP请求(GET和POST方式)实现短信验证码的发送。文章包含具体代码实现,包括账号密码的设置,以及发送、查询等功能。
摘要由CSDN通过智能技术生成
  还是第三方的小平台的demo简单,基本没有任何封装的东西,简单易懂好实现,基本就是填上账号就能用.
package com.test;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;


public class SendMessage {
	@SuppressWarnings({ "static-access", "static-access" })
	public static void main(String[] args) {
		try {

			SendMessage sm = new SendMessage();

			// Http Get请求
			//test.sendSMSGet("13439117920",
			//"Java Http GET 方式短信调试已经成功!!!!!【成都凌凯】", "");
			
			String code=random.getThree();
			// Http post 请求
			sm.sendSMSPost("手机号",
					"短信内容:"+code+ "有效时间为五分钟", "");
			
			
			String CorpID = "";// 账户名
			String Pwd = "";// 密码
			
			//回复信息查询
		//	test.getReplyMsg(CorpID, Pwd);
			//余额查询
			sm.getSelSum(CorpID, Pwd);
			//获取禁止号码
		//	test.getNotSend(CorpID, Pwd);
			
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

	}

	/**
	 * http get请求 发送方法 其他方法同理 返回值>0 提交成功
	 * 
	 * @param Mobile
	 *            手机号码
	 * @param Content
	 *            发送内容
	 * @param send_time
	 *            定时发送的时间;可以为空,为空时为及时发送
	 * @return 返回值
	 * @throws MalformedURLException
	 * @throws UnsupportedEncodingException
	 */
	public static int sendSMSGet(String Mobile, String Content, String send_time)
			throws MalformedURLException, UnsupportedEncodingException {
		URL url = null;
		String CorpID = "";// 账户名
		String Pwd = "";// 密码
		String send_content = URLEncoder.encode(
				Content.replaceAll("<br/>", " "), "GBK");// 发送内容
		url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID="
				
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值