查看接口说明
http://sms.webchinese.com.cn/api.shtml
短信接口说明的页面截图如下:
注册账号
注册成功的页面如下:
image.png
设置短信内容的签名
比如:将短信签名设置为yzc
image.png
查取短信接口密钥
image.png设计Java程序
短信发送客户端的代码如下:
package day02;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
public class SendMessageTest {
public static void main(String[] args)throws Exception
{
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://utf8.sms.webchinese.cn");
StringEntity entity = null;
HttpResponse httpResponse = null;
Header[] headers = null;
try {
entity = new StringEntity("Uid=yangzc&Key=d41d8cd98f00b204e980&smsMob=18621726379&smsText=晚上8点,老地方见!","utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(entity);
//发送该请求
httpResponse = httpClient.execute(httpPost);
headers = httpResponse.getAllHeaders();
for(Header h:headers){
System.out.println(h.toString());
}
System.out.println(EntityUtils.toString(httpResponse.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
httpClient.close();
}
}
截图如下:
image.png
运行结果
截图如下:
image.png image.png image.png
网友评论