SMS短信通API下行接口参数
为什么80%的码农都做不了架构师?>>>
JAVA发送手机短信方法: (1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册. https://my.oschina.net/lmoon/blog/1477175 (2)使用短信mao的方式进行短信的发送,这种方式应该是比较常用,前提是需要购买硬件设备. (3)使用中国网建提供的SMS短信平台. 一、使用中国网建提供的API给手机发送短信为了使用中国网建给对方手机发送短信,需要以下几步操作: 1.登录中国网建,地址为:http://sms.webchinese.cn/ 2.注册,注册后你就会有用户名和密码,密码会自动发到你的手机里 3.获取网管接口密码,至于如何获得网关接口密码,我是这样偶尔获得的(网管接口密码并不是注册时发送到手机里的登录密码)。在该网站里尝试发一条短信,发短信时会有相应的提示,在发送的过程中会出现你的网关接口密码。 注意:你要保存好你的网关接口秘密,因为每次当你使用代码发送信息时都需要这个网关接口密码。 以下代码及所使用的jar可以从http://sms.webchinese.cn/直接获得。 GBK编码发送接口地址:
多个手机号请用半角,隔开
| ||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||
| JAVA调用 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");//在头文件中设置转码post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");NameValuePair[] data ={ new NameValuePair("Uid", "本站用户名"),new NameValuePair("Key", "接口安全秘钥"),new NameValuePair("smsMob","手机号码"),new NameValuePair("smsText","验证码: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); //打印返回消息状态post.releaseConnection();}} jar包下载 网管选择:默认网关、106网管(带签名)和广告网管。 使用事项: (1)给陌生人发广告短信,请您切换到广告网关发送,如发现用106网关发送立即封号; 演示程序下载 | ||||||||||||||||||||||||||||||||||||
二、使用短信mao的方式进行短信的发送此方式前提是需要购买硬件设备 | ||||||||||||||||||||||||||||||||||||
| 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名称,串口号,破特率,连接设备名称,设备型号,sms pin)SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 9600, "wavecom", "1234");gateway.setInbound(true); // 设置网关可以写入信息gateway.setOutbound(true); // 设置网关可以读取信息gateway.setSimPin("1234"); // 设置SIM PINgateway.setOutboundNotification(outboundNotification); // 设置入信回调实现srv.addGateway(gateway);// 发信服务中添加设定的网关 srv.startService(); // 初始化所有的网关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.// 手机号码,和短信内容msg = new OutboundMessage("15972900071", "今天星期三,2013-07-31,特别的日子!");msg.setEncoding(MessageEncodings.ENCUCS2);// 这句话是发中文短信必须的 srv.sendMessage(msg); //执行发送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();}}}
|
转载于:https://my.oschina.net/lmoon/blog/1477142
总结
以上是生活随笔为你收集整理的SMS短信通API下行接口参数的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 40.4. SOCKS
- 下一篇: 循环程序设计实验