JAVA小功能手机短信发送

JAVA小功能实现----手机短信发送 留个关注吧

1.首先要在手机短信发送的网址注册用户,获取配置手机短信发送网址链接

2.下载需要用的jia包,将这三个jar包复制到项目中去在这里插入图片描述
3.代码编写及配置
new NameValuePair(“Uid”, “hengqirong”)为自己的账户名
new NameValuePair(“Key”, “d41d8cd98f00b204e980”)为自己短信密钥
new NameValuePair(“smsMob”,phone)为要发送至短信的手机号
new NameValuePair(“smsText”,“尊敬的用户”+ Account+“您好,您图书馆账号刚刚修改后的密码为:”+Password)}为要发送的内容拼接JAVA小功能手机短信发送_第1张图片

package books.hqr.Filter;


import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

/***
 * 手机短信发送功能 更改密码发送短信
 * time: 2022年4月17日下午9:28:37
 * name:hengqirong
 */
public class SMSsending {
	public void SMS(String phone,String Account,String Password) throws Exception {

		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://gbk.api.smschinese.cn"); 

		post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
		NameValuePair[] data ={
                new NameValuePair("Uid", "hengqirong"),
				new NameValuePair("Key", "d41d8cd98f00b204e980"),
				new NameValuePair("smsMob",phone),
                new NameValuePair("smsText","尊敬的用户"+ Account+"您好,您图书馆账号刚刚修改后的密码为:"+Password)};
		post.setRequestBody(data);

		client.executeMethod(post);
		Header[] headers = post.getResponseHeaders();
		int statusCode = post.getStatusCode();
		System.out.println("statusCode:"+statusCode);
		for(Header h : headers)
		{
		System.out.println(h.toString());
		}
		String result = new String(post.getResponseBodyAsString().getBytes("gbk")); 
		System.out.println(result); //打印返回消息状态


		post.releaseConnection();

		}

}

4.短信接口配置如下JAVA小功能手机短信发送_第2张图片
5.如果报错了下面是原因JAVA小功能手机短信发送_第3张图片
6.最后创建main调用该类中的短信发送方法传入参数就可以实现

你可能感兴趣的:(java小功能实现,java,开发语言)