コード例 #1
0
ファイル: smpp_server.py プロジェクト: kashifpk/smpp5
    def db_storage(recipients, message, user_id, sender):
        """
        This method is responsible to store Sms and related fields provided by client in database
        """

        sms_ids = ''    # contains all message ids that are sended by client to recipient of same or different network.
        #smses_ids = ''  # contains only message ids that are sended by client to recipient of some other network.
        sender = sender.decode(encoding='ascii')
        recipients = recipients.decode(encoding='ascii').splitlines()
        selected_package = selected_packages(user_id)
        for recipient in recipients:
            processed_fields = process_outgoing_sms(sender, user_id, recipient)

        # storing vaues to database

            S = Sms()
            S.sms_type = 'outgoing'
            S.sms_from = processed_fields['sender_number']
            S.sms_to = recipient
            S.schedule_delivery_time = datetime.date.today()
            S.validity_period = datetime.date.today()+datetime.timedelta(days=1)
            S.msg = message
            S.timestamp = datetime.date.today()
            S.status = 'scheduled'
            S.msg_type = 'text'
            S.user_id = user_id
            S.package_name = selected_package['package_name']
            S.rates = selected_package['rates']
            S.target_network = processed_fields['target_network']  # process sms file would use it to send to respective network of which server is.
            S.client_type = 'smpp'
            DBSession.add(S)
            transaction.commit()
            sms = DBSession.query(Sms)[-1]  # to send id to the client for ancilliary operations and querying.
            sms_ids = sms_ids + str(sms.id) + '\n'
            if processed_fields['target_network'] != processed_fields['source_network']:  # if destination and source network is different 
                connect_info(recipient, message, processed_fields['target_network'], sms.id,
                             processed_fields['sender_number'])  # connect to the destination's smpp server.
                #smses_ids = smses_ids + str(s) + '\n'
        #updating_status(smses_ids)
        return(sms_ids)
コード例 #2
0
ファイル: database_test.py プロジェクト: kashifpk/smpp5
import datetime

if '__main__' == __name__:
    db.bind_session()
    d = datetime.date.today()-datetime.timedelta(days=4)
    S = Sms()
    S.sms_type = 'outgoing'
    S.sms_from = '+9233365195924'
    S.sms_to = '+923366767999'
    S.schedule_delivery_time = d   # give date 2nd december
    S.validity_period = d+datetime.timedelta(days=1)
    S.msg = "dont disturb.."
    S.timestamp = d
    S.status = 'delivered'
    S.msg_type = 'text'
    S.user_id = 'ASMA'
    S.package_name = 'dhamaka'
    S.rates = 0.0
    S.target_network = 'ufone'  # process sms file would use it to send to respective network of which server is.
    S.client_type = 'smpp'
    DBSession.add(S)
    #user = DBSession.query(User_Number).filter_by(user_id='ASMA').first()  # user refers to normal user
    #cell_number = user.cell_number
    #source_prefix = cell_number[0:6]
    #dest_prefix = '+92300'
    #source_network = DBSession.query(Prefix_Match).filter_by(prefix=source_prefix).first()  # t_user refers to network
    #dest_network = DBSession.query(Prefix_Match).filter_by(prefix=dest_prefix).first()  # t_user refers to network
    #print(source_network.network)
    #print(dest_network.network)
    transaction.commit()
    #data = b'\x00\x00\x00/\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01SMPP3TEST\x00secret08\x00' + \