Giter Site home page Giter Site logo

sms-client's Introduction

技术问题请加QQ群

qq 20180420170449

群名称:cmppGate短信
群 号:770738500

一个基于SMSGate框架 的纯发送短信客户端库,使用简单

How To Use

<dependency>
  <groupId>com.chinamobile.cmos</groupId>
  <artifactId>sms-client</artifactId>
  <version>0.0.3</version>
</dependency>
  • 如何发送短信?

    参考test包里的测试用例 :

		CMPPClientEndpointEntity client = new CMPPClientEndpointEntity();
		client.setId("client");
		// client.setLocalhost("127.0.0.1");
		// client.setLocalport(65521);
		client.setHost("127.0.0.1");   //服务器IP
		client.setPort(37890);        //端口
		client.setChartset(Charset.forName("utf-8"));
		client.setGroupName("test");
		client.setUserName("901783");  //企业代码
		client.setPassword("ICP001");  //密码
//	client.setProxy("http://username:password@ipaddress:port");  //http代理
//	client.setProxy("socks4://username:password@ipaddress:port");  //socks4代理
//	client.setProxy("socks5://username:password@ipaddress:port");  //socks5代理
		client.setMaxChannels((short) 2);  //最大连接数
		client.setVersion((short) 0x20);   //协议版本
		client.setWriteLimit(20);   //每个连接的最大发送速度,单位 拆分短信后 条/秒
		client.setReSendFailMsg(false);
		client.setSupportLongmsg(SupportLongMessage.BOTH);
		
		//SmsClientBuilder 适合和单例 ,一个通道账号只build一次
		SmsClientBuilder builder = new SmsClientBuilder();
		final SmsClient smsClient = builder.entity(client)
				.keepAllIdleConnection()  //保持空闲连接,以便能接收上行或者状态报告消息
				.window(32)             //设置发送窗口
				.receiver(new MessageReceiver() {

			public void receive(BaseMessage message) {
				logger.info("receive : {}",message.toString());
			}}).build();
		Future future = null;
		
		//发送5000条短信
		for (int i = 0; i < 5000; i++) {
			 future = executor.submit(new Runnable() {

				public void run() {
					//new 一个短信 Request对象
					CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
					msg.setDestterminalId(String.valueOf(System.nanoTime()));
					msg.setSrcId(String.valueOf(System.nanoTime()));
					msg.setLinkID("0000");
					msg.setMsgContent("老师好,接工信部投诉");
					msg.setRegisteredDelivery((short) 1);
					msg.setServiceId("10086");
					CmppSubmitResponseMessage response;
					try {
					//调用send方法发送
						response = (CmppSubmitResponseMessage) smsClient.send(msg);
						
						//收到Response消息
					} catch (Exception e) {
						logger.info("send ", e);
					}
				}
				
			});
		}
  • 如何发送长短信?

    默认已经处理好长短信了,就像发送普通短信一样。

  • 如何接收短信?

    参考test包里的测试用例 : 创建 Builder的时候注册 MessageReceiver

  • 使用 http 或者 socks 代理

    SmsGate支持HTTP、SOCKS代理以方便在使用代理访问服务器的情况。代理设置方式:

	// 无username 和 password 可写为  http://ipaddress:port
	client.setProxy("http://username:password@ipaddress:port");  //http代理
	client.setProxy("socks4://username:password@ipaddress:port");  //socks4代理
	client.setProxy("socks5://username:password@ipaddress:port");  //socks5代理

TODO

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.