SMS短信通API下行接口参数
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
JAVA發(fā)送手機(jī)短信方法: (1)使用webservice接口發(fā)送手機(jī)短信,這個(gè)可以使用sina提供的webservice進(jìn)行發(fā)送,但是需要進(jìn)行注冊(cè).??https://my.oschina.net/lmoon/blog/1477175 ??????????????? (2)使用短信mao的方式進(jìn)行短信的發(fā)送,這種方式應(yīng)該是比較常用,前提是需要購(gòu)買(mǎi)硬件設(shè)備. (3)使用中國(guó)網(wǎng)建提供的SMS短信平臺(tái). 一、使用中國(guó)網(wǎng)建提供的API給手機(jī)發(fā)送短信為了使用中國(guó)網(wǎng)建給對(duì)方手機(jī)發(fā)送短信,需要以下幾步操作: 1.登錄中國(guó)網(wǎng)建,地址為:http://sms.webchinese.cn/ 2.注冊(cè),注冊(cè)后你就會(huì)有用戶名和密碼,密碼會(huì)自動(dòng)發(fā)到你的手機(jī)里 3.獲取網(wǎng)管接口密碼,至于如何獲得網(wǎng)關(guān)接口密碼,我是這樣偶爾獲得的(網(wǎng)管接口密碼并不是注冊(cè)時(shí)發(fā)送到手機(jī)里的登錄密碼)。在該網(wǎng)站里嘗試發(fā)一條短信,發(fā)短信時(shí)會(huì)有相應(yīng)的提示,在發(fā)送的過(guò)程中會(huì)出現(xiàn)你的網(wǎng)關(guān)接口密碼。 注意:你要保存好你的網(wǎng)關(guān)接口秘密,因?yàn)槊看萎?dāng)你使用代碼發(fā)送信息時(shí)都需要這個(gè)網(wǎng)關(guān)接口密碼。 以下代碼及所使用的jar可以從http://sms.webchinese.cn/直接獲得。 GBK編碼發(fā)送接口地址:
多個(gè)手機(jī)號(hào)請(qǐng)用半角,隔開(kāi)
| ||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||
| ? | ||||||||||||||||||||||||||||||||||||
| ? | ||||||||||||||||||||||||||||||||||||
| JAVA調(diào)用 import java.io.UnsupportedEncodingException;
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;public class SendMsg_webchinese {public static void main(String[] args)throws Exception{HttpClient client = new HttpClient();PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");//在頭文件中設(shè)置轉(zhuǎn)碼post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");NameValuePair[] data ={ new NameValuePair("Uid", "本站用戶名"),new NameValuePair("Key", "接口安全秘鑰"),new NameValuePair("smsMob","手機(jī)號(hào)碼"),new NameValuePair("smsText","驗(yàn)證碼:8888")};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); //打印返回消息狀態(tài)post.releaseConnection();}} jar包下載 網(wǎng)管選擇:默認(rèn)網(wǎng)關(guān)、106網(wǎng)管(帶簽名)和廣告網(wǎng)管。 使用事項(xiàng): (1)給陌生人發(fā)廣告短信,請(qǐng)您切換到廣告網(wǎng)關(guān)發(fā)送,如發(fā)現(xiàn)用106網(wǎng)關(guān)發(fā)送立即封號(hào); 演示程序下載 | ||||||||||||||||||||||||||||||||||||
| ? | ||||||||||||||||||||||||||||||||||||
二、使用短信mao的方式進(jìn)行短信的發(fā)送此方式前提是需要購(gòu)買(mǎi)硬件設(shè)備 | ||||||||||||||||||||||||||||||||||||
| import org.smslib.IOutboundMessageNotification;import org.smslib.Library;import org.smslib.OutboundMessage;import org.smslib.Service;import org.smslib.Message.MessageEncodings;import org.smslib.modem.SerialModemGateway; public class SendMessage {public void doIt() throws Exception {Service srv;OutboundMessage msg;OutboundNotification outboundNotification = new OutboundNotification();System.out.println("Example: Send message from a serial gsm modem.");System.out.println(Library.getLibraryDescription());System.out.println("Version: " + Library.getLibraryVersion());srv = new Service();//SerialModemGateway(com名稱(chēng),串口號(hào),破特率,連接設(shè)備名稱(chēng),設(shè)備型號(hào),sms pin)SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 9600, "wavecom", "1234");gateway.setInbound(true); // 設(shè)置網(wǎng)關(guān)可以寫(xiě)入信息gateway.setOutbound(true); // 設(shè)置網(wǎng)關(guān)可以讀取信息gateway.setSimPin("1234"); // 設(shè)置SIM PINgateway.setOutboundNotification(outboundNotification); // 設(shè)置入信回調(diào)實(shí)現(xiàn)srv.addGateway(gateway);// 發(fā)信服務(wù)中添加設(shè)定的網(wǎng)關(guān) srv.startService(); // 初始化所有的網(wǎng)關(guān)System.out.println("Modem Information:");System.out.println(" Manufacturer: " + gateway.getManufacturer());System.out.println(" Model: " + gateway.getModel());System.out.println(" Serial No: " + gateway.getSerialNo());System.out.println(" SIM IMSI: " + gateway.getImsi());System.out.println(" Signal Level: " + gateway.getSignalLevel() + "%");System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");System.out.println();// Send a message synchronously.// 手機(jī)號(hào)碼,和短信內(nèi)容msg = new OutboundMessage("15972900071", "今天星期三,2013-07-31,特別的日子!");msg.setEncoding(MessageEncodings.ENCUCS2);// 這句話是發(fā)中文短信必須的 srv.sendMessage(msg); //執(zhí)行發(fā)送System.out.println(msg);System.out.println("Now Sleeping - Hit <enter> to terminate.");System.in.read();srv.stopService();}public class OutboundNotification implements IOutboundMessageNotification {public void process(String gatewayId, OutboundMessage msg) {System.out.println("Outbound handler called from Gateway: " + gatewayId);System.out.println(msg);}}public static void main(String args[]) {SendMessage app = new SendMessage();try {app.doIt();} catch (Exception e) {e.printStackTrace();}}} ? |
轉(zhuǎn)載于:https://my.oschina.net/lmoon/blog/1477142
總結(jié)
以上是生活随笔為你收集整理的SMS短信通API下行接口参数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 40.4. SOCKS
- 下一篇: 循环程序设计实验