java短信接口 调用_带你了解短信接口的调用
查看接口說明
image.png
注冊賬號
注冊成功的頁面如下:
image.png
設置短信內容的簽名
比如:將短信簽名設置為yzc
image.png
查取短信接口密鑰
image.png
設計Java程序
短信發(fā)送客戶端的代碼如下:
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);
//發(fā)送該請求
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
總結
以上是生活随笔為你收集整理的java短信接口 调用_带你了解短信接口的调用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 豌豆粉的功效与作用、禁忌和食用方法
- 下一篇: java jdbc分页_使用JDBC进行