Python smpplib截断smpp凭据

问题描述 投票:0回答:1

我正在使用Python SMPP lib发送短信。当我尝试使用更长的凭据连接到SmppServer时,用户名和密码将被截断并且授权失败。

验证失败的情况: - 用户名/密码长度超过16个字符

传递案例: - 用户名/密码不超过16个字符

因此,由于上述观察,我确信SMMPP网关没有问题。我尝试通信的网关接受任意长度的用户名/密码。

以下是我的代码,它将smpplib包装到自定义类中:

import smpplib
import smpplib.gsm

from smpplib.client import Client


class SmppClientConfig(object, ):

    def __init__(self, host, port, username, password, source, target, on_delivered_cb, on_sent_cb):
        self.HOST = host
        self.PORT = port
        self.USERNAME = username
        self.PASSWORD = password
        self.SOURCE = source
        self.TARGET = target
        self.ON_RECEIVED_CALLBACK = on_sent_cb
        self.ON_DELIVERED_CALLBACK = on_delivered_cb


class SmppSenderClient(object):

    def __init__(self, config: SmppClientConfig):
        print('Creating SMPP client config with host: ' + config.HOST + ' port: ' + str(config.PORT))

        self._config = config
        self._client = Client(config.HOST, config.PORT)
        self._on_delivered_callback = config.ON_DELIVERED_CALLBACK
        self._on_received_callback = config.ON_RECEIVED_CALLBACK

        self._init_client()

    def _init_client(self):
        print('Initializing SmppSender client with username: ' + self._config.USERNAME)

        self._register_events()
        self._client.connect()
        self._client.bind_transmitter(system_id=self._config.USERNAME, password=self._config.PASSWORD)

    def _register_events(self):
        print('Registering Smpp events')
        self._client.set_message_sent_handler(self._config.ON_DELIVERED_CALLBACK)
        self._client.set_message_received_handler(self._config.ON_RECEIVED_CALLBACK)

    def send_message(self, message: str):
        print('Sending SMS message to target: ' + self._config.TARGET)
        parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message)

        for part in parts:
            self._client.send_message(
                source_addr_ton=smpplib.consts.SMPP_TON_INTL,
                source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                source_addr=self._config.SOURCE,

                dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
                dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                destination_addr=self._config.TARGET,
                short_message=part,

                data_coding=encoding_flag,
                esm_class=msg_type_flag,
                registered_delivery=True,
            )

我不确定这是图书馆的预期行为还是限制。我试过找到这个lib的文档,但除了this之外找不到任何东西。

如果您遇到类似的问题,请告知是否存在任何可能的问题,或者这是否是SMPP协议中的预期行为(这种情况非常不可能)。

更新:我在源代码中发现了限制:

class BindTransmitter(Command):
    """Bind as a transmitter command"""

    params = {
        'system_id': Param(type=str, max=16),
        'password': Param(type=str, max=9),
        'system_type': Param(type=str, max=13),
        'interface_version': Param(type=int, size=1),
        'addr_ton': Param(type=int, size=1),
        'addr_npi': Param(type=int, size=1),
        'address_range': Param(type=str, max=41),
    }

    # Order is important, but params dictionary is unordered
    params_order = (
        'system_id', 'password', 'system_type',
        'interface_version', 'addr_ton', 'addr_npi', 'address_range',
    )

    def __init__(self, command, **kwargs):
        super(BindTransmitter, self).__init__(command, need_sequence=False, **kwargs)

        self._set_vars(**(dict.fromkeys(self.params)))
        self.interface_version = consts.SMPP_VERSION_34

正如你所看到的那样,qazxsw poi构造函数(qazxsw poi)将qazxsw poi截断为最大长度16和BindTransmitter为9.不确定为什么这样做是这样的。

python-3.x smpp
1个回答
0
投票

我检查了官方的SMPP协议规范。根据规范,__init__应该是最大16和system_id应该是9连接类型:passsword

以下是此规范的屏幕截图:system_id

如果有人有兴趣,这是规格的password

总而言之,规范的库实现是正确的。

© www.soinside.com 2019 - 2024. All rights reserved.