溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程

發(fā)布時(shí)間:2021-04-15 10:41:02 來源:億速云 閱讀:148 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關(guān)JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

想使代碼生效需要注冊:

http://sms.webchinese.cn/default.shtmlhttp://sms.webchinese.cn/default.shtml

在muven項(xiàng)目里面導(dǎo)入jar包

<dependencies>
  <dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.4</version>
  </dependency>
  <dependency>
    <groupId>commons-httpclient</groupId>
    <artifactId>commons-httpclient</artifactId>
    <version>3.1</version>
  </dependency>
  <dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
  </dependency>
  <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.1</version>
  </dependency>
  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.8</version>
  </dependency>
  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.8</version>
  </dependency>
</dependencies>

創(chuàng)建一個(gè)測試類:下面代碼粘貼上去用就行了

public static void main(String[] args) throws HttpException, IOException {
  // TODO Auto-generated method stub
  HttpClient client = new HttpClient();
  PostMethod post = new PostMethod("http://gbk.api.smschinese.cn/");
  post.addRequestHeader("Content-Type",
      "application/x-www-form-urlencoded;charset=gbk");// 在頭文件中設(shè)置轉(zhuǎn)碼
  NameValuePair[] data = { new NameValuePair("Uid", "****"), // 注冊的用戶名
      new NameValuePair("Key", "********"), // 這個(gè)key需要在里面獲取
      new NameValuePair("smsMob", "*********"), // 手機(jī)號碼
      new NameValuePair("smsText", "嘻嘻!猜猜我是誰?") };//設(shè)置短信內(nèi)容
  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();

}

JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程

輸出結(jié)果成功后是這個(gè)效果;這個(gè)值代表短信發(fā)送的數(shù)量如果下面的返回值不是1請參照以下圖片

JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程

可能需要的的問題:

JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程

當(dāng)然 返回值等于1的時(shí)候不代表你就能收到短信 只能說明你短信發(fā)送成功了想要短信成功的接收不需要進(jìn)去官網(wǎng)去申請短信接收接口

JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程

感謝各位的閱讀!關(guān)于“JAVA如何實(shí)現(xiàn)第三方短信發(fā)送過程”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI