jasmin基础

介绍

技术 特性 适用场景 说明
jasmin SMS gateway - 官网
- Getting started
- Doc
- Github

运维

安装

前提条件

  • RabbitMQ
  • Redis
  • python-dev(Ubuntu中的包名)
  • libffi-dev(Ubuntu中的包名)
  • libssl-dev(Ubuntu中的包名)
  • python-twisted(Ubuntu中的包名)
  • Python2.7(不能是Python3)

CentOS

1
2
3
4
5
6
7
8
9
10
11
12
13
$ yum -y install Python-devel libffi libffi-devel openssl-devel
$ yum -y install epel-release
$ yum install python-pip -y
$ pip install --upgrade pip
$ wget https://files.pythonhosted.org/packages/22/c2/5a30a4ad78af4d3e5df1701ec6a0dd59e1b0213dc2323dbf61b3af342ad5/Twisted-19.10.0-cp27-cp27mu-manylinux1_x86_64.whl
$ pip install Twisted-19.10.0-cp27-cp27mu-manylinux1_x86_64.whl

$ yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

$ wget -qO - http://bit.ly/jasmin-rpm-repo | sudo bash
$ yum install python-jasmin -y
$ systemctl enable jasmind
$ systemctl start jasmind

Ubuntu

1
2
3
4
$ wget -qO - http://bit.ly/jasmin-deb-repo | sudo bash
$ apt-get install python-jasmin
$ systemctl enable jasmind
$ systemctl start jasmind

Docker

1
2
3
4
$ docker pull jookies/jasmin
$ docker run -d -p 1401:1401 -p 2775:2775 -p 8990:8990 --name jasmin_01 jookies/jasmin:latest
$ docker stop jasmin_01
$ docker start jasmin_01

配置

配置CLI

配置项 默认值 说明
bind 127.0.0.1 jCli will only bind to this specified address.
port 8990 The binding TCP port.
authentication True If set to False, anonymous user can connect to jCli and admin user account is no more needed
admin_username jcliadmin The admin username
admin_password jclipwd The admin MD5 crypted password
log_* Python’s logging module configuration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ vim /etc/jasmin/jasmin.cfg
[jcli]
bind = 127.0.0.1
port = 8990
authentication = True
admin_username = jcliadmin
# MD5 password digest hex encoded
admin_password = 79e9b0aa3f3e7c53e916f7ac47439bcb

log_level = INFO
log_file = /var/log/jasmin/jcli.log
log_format = %(asctime)s %(levelname)-8s %(process)d %(message)s
log_date_format = %Y-%m-%d %H:%M:%S

$ lsof -i:8990
$ telnet 127.0.0.1 8990

配置 HTTP API

1
2
3
4
5
6
7
# RESTful API 默认端口 1401

# 启动
$ systemctl start jasmin-restapi

# Ping
$ curl -X GET http://127.0.0.1:1401/ping

配置 SMPP API

配置项 默认值 说明
id smpps_01 The SMPP Server id, used to identify the instance in case you use multiple servers per Jasmin process.
bind 0.0.0.0 The SMPP Server API listener will only bind to this specified address, given 0.0.0.0 the listener will bind on all interfaces.
port 2775 The binding TCP port.
sessionInitTimerSecs 30 Protocol tuning parameter: timeout for a bind request.
enquireLinkTimerSecs 30 Protocol tuning parameter: timeout for an enquire_link request.
inactivityTimerSecs 300 Protocol tuning parameter: inactivity timeout.
responseTimerSecs 60 Protocol tuning parameter: global request timeout.
pduReadTimerSecs 30 Protocol tuning parameter: binary pdu ready timeout.
log_* Python’s logging module configuration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ vim /etc/jasmin/jasmin.cfg
[smpp-server]
id = "smpps_01"
bind = 0.0.0.0
port = 2775

sessionInitTimerSecs = 30
enquireLinkTimerSecs = 30
inactivityTimerSecs = 300
responseTimerSecs = 60
pduReadTimerSecs = 30

log_level = INFO
log_file = /var/log/jasmin/default-smpps_01.log
log_format = %(asctime)s %(levelname)-8s %(process)d %(message)s
log_date_format = %Y-%m-%d %H:%M:%S

CLI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 查看连接
$ smppccm --list

# Adding smpp connection
$ smppccm -a
> cid DEMO_CONNECTOR
> host 127.0.0.1
> port 2775
> username smppclient1
> password password
> submit_throughput 110
> ok

# Starting the connector
$ smppccm -1 DEMO_CONNECTOR

# Configure simple route
$ mtrouter -a
> type defaultroute
> connector smppc(DEMO_CONNECTOR)
> rate 0.00
> ok

# Create a group
$ group -a
> gid foogroup
> ok

# Create a user
$ user -a
> username foo
> password bar
> gid foogroup
> uid foo
> ok

# Send SMS
$ curl http://127.0.0.1:1401/send?username=foo&password=bar&to=06222172&content=hello

排错

查看日志

路径 说明
/var/log/jasmin/redis-client.log
/var/log/jasmin/jcli.log
/var/log/jasmin/amqp-client.log
/var/log/jasmin/interceptor.log -

初始化脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# coding=utf-8

from twisted.internet import reactor, defer

from jasmin.routing.Filters import UserFilter
from jasmin.routing.Routes import StaticMTRoute, Route, MTRoute, SmppClientConnector
from jasmin.managers.proxies import SMPPClientManagerPBProxy
from jasmin.routing.proxies import RouterPBProxy
from jasmin.routing.jasminApi import User, Group
from jasmin.protocols.smpp.configs import SMPPClientConfig
# from jasmin.protocols.cli.smppccm import JCliSMPPClientConfig as SmppClientConnector

# smpp vendor config
s_ip = '127.0.0.1'
s_port = 8889
s_user = 'user2'
s_pwd = 'pass2'

@defer.inlineCallbacks
def runScenario():
proxy_smpp = SMPPClientManagerPBProxy()
yield proxy_smpp.connect('127.0.0.1', 8989, 'cmadmin', 'cmpwd')

# create & start smpp vendor
# submit_sm_throughput一定要设置,不然会很慢
c1 = {'id':s_user, 'host':s_ip, 'port': s_port, 'username':s_user, 'password':s_pwd, 'reconnectOnConnectionFailure':True,'submit_sm_throughput':200}
config1 = SMPPClientConfig(**c1)
yield proxy_smpp.add(config1)
yield proxy_smpp.start(s_user)

pr = RouterPBProxy()
yield pr.connect('127.0.0.1', 8988, 'radmin', 'rpwd')

# create group & user
g1 = Group(s_user)
u1 = User(uid = s_user, group = g1, username = s_user, password = s_pwd)
yield pr.group_add(g1)
yield pr.user_add(u1)

# create filter
f1 = UserFilter(u1)

# create router
con1 = SmppClientConnector(s_user)
r = StaticMTRoute([f1], con1, 0.0)
yield pr.mtroute_add(r, 2)

print 'create success!!!!'

reactor.stop()

runScenario()
reactor.run()

参考

坚持原创技术分享,您的支持将鼓励我继续创作!
0%