Coder Social home page Coder Social 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.9</version>
</dependency>
  • 如何创建smsClient对象

    通过builder模式,为同一个账号创建唯一一个实例对象,不能重复创建。 smsClient对象创建后会自行管理多个tcp连接,如果重复创建Client对象,就会造成总连接数超过最大值。

  • 如何发送短信?

    参考test包里的测试用例 :

		String uri = "cmpp://127.0.0.1:17890?username=test01&password=1qaz2wsx&version=32&spcode=10086&msgsrc=test01&serviceid=000000&window=32&maxchannel=1";

		//通过builder创建一个Client对象,同一个通道账号只用保持一个smsClient实例。可以使用Spring注册为单例Bean。或者单例模式
		SmsClientBuilder builder = new SmsClientBuilder();
//		EndpointEntity client =  builder.createEndpointEntity(uri);
		final SmsClient smsClient = builder.uri(uri) // 保持空闲连接,以便能接收上行或者状态报告消息
				.receiver(new MessageReceiver() {
					public void receive(BaseMessage message) {
//						System.out.println(message.toString());
					}
				}).build();
				
		
		Future future = null;
		
		//发送5000条短信
		for (int i = 0; i < 1; i++) {
			 future = executor.submit(new Runnable() {

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

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

  • 如何接收短信?

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

    SGIP协议是特例,因为该协议要求开启一个Server端口,网关作为客户端连上来推送上行短信和状态报告。

  • 使用 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代理

SGIP回收状态报告和用户回复

  • 为什么smsClient不提供sgip协议的接收上行消息、状态报告能力

    smsClient是一个tcp客户端,它需要主动去连接服务端的tcp端口。而sgip协议要求接收上行回复短信时,SP要启动一个tcp服务,等待来自运营商短信网关的连接请求(此时运营商是tcp客户端)。 一般系统部署时,作为客户端可能会部署多个进程节点,类似HTTP请求,可以从多个节点分别发起请求。

    但sgip的上行短信接收服务作为一个tcp服务端只能有一个,集成在client端很别扭。 替代方式为:根据系统架构特点,设计接收上行消息的tcp服务如何部署,比如可以独立一个节点,也可以与Http的web服务一起部署。 SgipServer的开发方式可以参考smsServer

sms-client's People

Contributors

lihuanghe avatar

Watchers

 avatar

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.