示例#1
0
        start_response('200 OK', [('Content-type', 'charset=utf-8')])
        return open('./sms.html')
    # Check whether the parameters are legal.
    if 'from' not in url_para or 'pswd' not in url_para or 'msg' not in url_para:
        status = '200 OK'
        response_headers = [('Content-type', 'application/json;charset=utf-8')]
        start_response(status, response_headers)
        return [json.dumps({"sendCode": -1, "info": u"参数错误!"})]
    # If receiver's mobile phone number is not set, send to the sender as default.
    if 'to' not in url_para or url_para['to'] == '':
        url_para['to'] = url_para['from']
    else:
        url_para['to'] = url_para['to'].split(',')

    config = ConfigParser.ConfigParser()
    try:
        config.read('./sms/config.ini')
        msg_cls_type = config.get('Message', 'class type')
    except Exception, error:
        print(error)
        print('Use short fetion message as default message sender class.')
        msg_cls_type = 'Short Fetion'

    sms_sender = MessageFactory.create_message(msg_cls_type, url_para['from'], url_para['pswd'])

    status = '200 OK'
    response_headers = [('Content-type', 'application/json;charset=utf-8')]
    start_response(status, response_headers)

    return [json.dumps(sms_sender.send(url_para['msg'], url_para['to']))]
示例#2
0
文件: run.py 项目: ripples-alive/SMS
#!/usr/bin/env python
# encoding:utf-8
__author__ = 'Jayvic'
__date__ = '14-7-22'

import ConfigParser
import getpass

from message_factory import MessageFactory


config = ConfigParser.ConfigParser()
config.read('config.ini')
msg_cls_type = config.get('Message', 'class type')

from_tel = raw_input('Your mobile number: ')
password = getpass.getpass('Your password: '******'Send to: ')
    msg = raw_input('Content: ')
    if (to_tel == '') or (to_tel == from_tel):
        sms_sender.send_to_self(msg)
    else:
        sms_sender.send(msg, to_tel.split(','))