本文整理汇总了Python中helpers.smshelper.SMSHelper.send_to_terminal方法的典型用法代码示例。如果您正苦于以下问题:Python SMSHelper.send_to_terminal方法的具体用法?Python SMSHelper.send_to_terminal怎么用?Python SMSHelper.send_to_terminal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.smshelper.SMSHelper
的用法示例。
在下文中一共展示了SMSHelper.send_to_terminal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def get(self):
status = ErrorCode.SUCCESS
try:
tid = self.get_argument('tid',None)
# check tid whether exist in request and update current_user
self.check_tid(tid)
terminal = self.db.get("SELECT id FROM T_TERMINAL_INFO"
" WHERE tid = %s"
" AND service_status = %s",
self.current_user.tid,
UWEB.SERVICE_STATUS.ON)
if terminal:
lq_sms_key = get_lq_sms_key(self.current_user.tid)
sms = SMSCode.SMS_LQ % SMS.LQ.WEB
biz_type = QueryHelper.get_biz_type_by_tmobile(self.current_user.sim, self.db)
if biz_type != UWEB.BIZ_TYPE.YDWS:
pass
else:
SMSHelper.send_to_terminal(self.current_user.sim, sms)
self.redis.setvalue(lq_sms_key, True, SMS.LQ_INTERVAL)
lq_interval_key = get_lq_interval_key(self.current_user.tid)
self.redis.setvalue(lq_interval_key, int(time.time()), (SMS.LQ.WEB*60 - 160))
logging.info("[UWEB] wake up, send %s to Sim: %s", sms, self.current_user.sim)
else:
status = ErrorCode.LOGIN_AGAIN
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] uid: %s wake up tid: %s failed. Exception: %s",
self.current_user.uid, self.current_user.tid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例2: send_domain_sms
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def send_domain_sms(db, redis, tid, mobile, domain):
"""Send domain sms to terminal..
"""
sms_domain = SMSCode.SMS_DOMAIN % domain
SMSHelper.send_to_terminal(mobile, sms_domain)
self.db.execute("UPDATE T_TERMINAL_INFO SET domain = %s"
" WHERE tid = %s",
domain_ip, tid)
logging.info("[PUBLIC] Send domain sms: %s to mobile: %s",
sms_domain, mobile)
示例3: kqly
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def kqly(db, redis, tids):
"""Start bluetooth.
"""
for tid in tids:
terminal = QueryHelper.get_terminal_by_tid(tid, db)
kqly_key = get_kqly_key(tid)
kqly_value = redis.getvalue(kqly_key)
if not kqly_value:
interval = 30 # in minute
sms = SMSCode.SMS_KQLY % interval
SMSHelper.send_to_terminal(terminal.mobile, sms)
redis.setvalue(kqly_key, True, SMS.KQLY_SMS_INTERVAL)
示例4: send
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def send(content, mobile):
logging.info("Send %s to %s", content, mobile)
#NOTE: send encrypt sms to mobile
response = SMSHelper.send_to_terminal(mobile, content)
#NOTE: send general sms to mobile
#response = SMSHelper.send(mobile, content)
logging.info("Response: %s", response)
示例5: send_cq_sms
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def send_cq_sms(db, redis, tid, mobile):
"""Send cq sms to terminal..
"""
sms_cq = SMSCode.SMS_CQ
if len(mobile) != 11:
logging.info("[PUBLIC] Mobile is valid, ignore it. mobile: %s", mobile)
return
biz_type = QueryHelper.get_biz_type_by_tmobile(mobile, db)
if biz_type != UWEB.BIZ_TYPE.YDWS:
logging.info(
"[PUBLIC] Biz_type is no need cq, ignore it. mobile: %s, biz_type: %s", mobile, biz_type)
return
SMSHelper.send_to_terminal(mobile, sms_cq)
logging.info("[PUBLIC] Send cq sms to terminal. mobile: %s", mobile)
示例6: send_lq_sms
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def send_lq_sms(self, sim, tid, interval):
"""Send LQ Message to terminal.
lq_sms_key: when send lq sms to terminal, keep it in redis
for 3 minutes. in 3 minutes, do not send lq sms twice.
lq_interval_key: when send lq sms to terminal, keep it in redis
for interval. in the period of interval, terminal is been awaken.
when the period of interval is past, lq_sms should be send again
"""
lq_sms_key = get_lq_sms_key(tid)
lq_interval_key = get_lq_interval_key(tid)
self.redis.setvalue(lq_interval_key, int(time.time()), (interval * 60 - 160))
if not self.redis.getvalue(lq_sms_key):
sms = SMSCode.SMS_LQ % interval
biz_type = QueryHelper.get_biz_type_by_tmobile(sim, self.db)
if biz_type != UWEB.BIZ_TYPE.YDWS:
pass
else:
SMSHelper.send_to_terminal(sim, sms)
logging.info("[UWEB] send %s to Sim: %s", sms, sim)
self.redis.setvalue(lq_sms_key, True, SMS.LQ_INTERVAL)
示例7: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
"""Reregist a pair of umobile and tmobile.
Send sms to terminal.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
logging.info("[UWEB] Register request: %s", data)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
tmobile = data.tmobile
user = QueryHelper.get_user_by_tmobile(tmobile, self.db)
if user:
umobile = user.owner_mobile
terminal = QueryHelper.get_terminal_by_tmobile(
tmobile, self.db)
if int(terminal.biz_type) == UWEB.BIZ_TYPE.YDWS:
register_sms = SMSCode.SMS_REGISTER % (umobile, tmobile)
ret = SMSHelper.send_to_terminal(tmobile, register_sms)
else:
activation_code = QueryHelper.get_activation_code(self.db)
register_sms = SMSCode.SMS_REGISTER_YDWQ % (
ConfHelper.UWEB_CONF.url_out, activation_code)
ret = SMSHelper.send(tmobile, register_sms)
ret = DotDict(json_decode(ret))
if ret.status == ErrorCode.SUCCESS:
logging.info("[UWEB] Reregist successfully. umobile: %s, tmobile: %s .",
umobile, tmobile)
else:
status = ErrorCode.REGISTER_FAILED
logging.error("[UWEB] Reregister failed. umobile: %s, tmobile: %s. Message: %s",
umobile, tmobile, ErrorCode.ERROR_MESSAGE[status])
else:
logging.exception("[UWEB] Terminal has no user, ignore it. tmobile: %s. ",
tmobile)
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] Reregister failed. tmobile: %s , Exception: %s",
tmobile, e.args)
status = ErrorCode.REGISTER_FAILED
self.write_ret(status)
示例8: send_jb_sms
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def send_jb_sms(self, tmobile, umobile, tid):
"""
#NOTE: deprecated. It should never be invoked.
"""
unbind_sms = SMSCode.SMS_UNBIND
biz_type = QueryHelper.get_biz_type_by_tmobile(tmobile, self.db)
if biz_type != UWEB.BIZ_TYPE.YDWS:
ret = DotDict(status=ErrorCode.SUCCESS)
else:
ret = SMSHelper.send_to_terminal(tmobile, unbind_sms)
ret = json_decode(ret)
status = ret["status"]
if status == ErrorCode.SUCCESS:
self.db.execute(
"UPDATE T_TERMINAL_INFO" " SET service_status = %s" " WHERE mobile = %s",
UWEB.SERVICE_STATUS.TO_BE_UNBIND,
tmobile,
)
terminals = self.db.query(
"SELECT id FROM T_TERMINAL_INFO" " WHERE owner_mobile = %s" " AND service_status = %s",
umobile,
UWEB.SERVICE_STATUS.ON,
)
# clear user
if len(terminals) == 0:
self.db.execute("DELETE FROM T_USER" " WHERE mobile = %s", umobile)
lastinfo_key = get_lastinfo_key(umobile)
lastinfo_time_key = get_lastinfo_time_key(umobile)
ios_id_key = get_ios_id_key(umobile)
ios_badge_key = get_ios_badge_key(umobile)
keys = [lastinfo_key, lastinfo_time_key, ios_id_key, ios_badge_key]
self.redis.delete(*keys)
logging.info("[UWEB] Delete User: %s", umobile)
logging.info("[UWEB] umobile: %s, tid: %s, tmobile: %s SMS unbind successfully.", umobile, tid, tmobile)
else:
logging.error(
"[UWEB] umobile: %s, tid: %s, tmobile: %s SMS unbind failed. Message: %s",
umobile,
tid,
tmobile,
ErrorCode.ERROR_MESSAGE[status],
)
return status
示例9: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
status = ErrorCode.SUCCESS
try:
# {"tmobile":18810496308,"pmobile":18810496308}
data = DotDict(json_decode(self.request.body))
tmobile = data.tmobile
pmobile = data.pmobile
register_sms = SMSCode.SMS_REGISTER % (pmobile, tmobile)
ret = SMSHelper.send_to_terminal(tmobile, register_sms)
ret = DotDict(json_decode(ret))
if ret.status == ErrorCode.SUCCESS:
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET msgid = %s"
" WHERE mobile = %s",
ret['msgid'], tmobile)
self.write_ret(status)
else:
status = ErrorCode.FAILED
self.write_ret(status)
except Exception as e:
logging.exception("SMS register failed. Exception: %s", e.args)
status = ErrorCode.FAILED
self.write_ret(status)
示例10: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
"""Turn on tracing."""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid', None)
tids = data.get('tids', None)
flag = int(data.get('flag', 1))
# check tid whether exist in request and update current_user
self.check_tid(tid)
logging.info("[UWEB] track LQ request: %s, "
" uid: %s, tid: %s, tids: %s, flag: %s",
data, self.current_user.uid, tid, tids, flag)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
tids = str_to_list(tids)
tids = tids if tids else [self.current_user.tid, ]
tids = [str(tid) for tid in tids]
if int(flag) == 1:
for tid in tids:
# NOTE: just send lqgz temporary
terminal = QueryHelper.get_terminal_by_tid(tid, self.db)
lqgz_key = get_lqgz_key(tid)
lqgz_value = self.redis.getvalue(lqgz_key)
lqgz_interval_key = get_lqgz_interval_key(tid)
if not lqgz_value:
interval = 30 # in minute
biz_type = QueryHelper.get_biz_type_by_tmobile(
terminal.mobile, self.db)
if biz_type != UWEB.BIZ_TYPE.YDWS:
self.write_ret(status)
return
sms = SMSCode.SMS_LQGZ % interval
SMSHelper.send_to_terminal(terminal.mobile, sms)
self.redis.setvalue(
lqgz_key, True, SMS.LQGZ_SMS_INTERVAL)
self.redis.setvalue(
lqgz_interval_key, True, SMS.LQGZ_INTERVAL * 2)
# END
track_key = get_track_key(tid)
track = self.redis.get(track_key)
logging.info("[UWEB] Get track: %s from redis", track)
if track and int(track) == 1:
# turn on track already
logging.info(
"[UWEB] Terminal: %s turn on track already.", tid)
else:
self.db.execute("UPDATE T_TERMINAL_INFO SET track = %s"
" WHERE tid = %s",
flag, tid)
self.redis.setvalue(track_key, 1, UWEB.TRACK_INTERVAL)
sessionID_key = get_terminal_sessionID_key(tid)
self.redis.delete(sessionID_key)
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] uid: %s, tid: %s send lqgz failed. Exception: %s. ",
self.current_user.uid, self.current_user.tid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例11: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
try:
data = DotDict(json_decode(self.request.body))
gid = data.gid
mobiles = list(data.mobiles)
logging.info("[UWEB] batch jh: %s, corp_id: %s",
data, self.current_user.cid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. Exception: %s",
e.args)
self.write_ret(status)
return
try:
status = ErrorCode.SUCCESS
begintime = int(time.time())
now_ = datetime.datetime.now()
endtime = now_ + relativedelta(years=1)
endtime = int(time.mktime(endtime.timetuple()))
res = []
for item in mobiles:
tmobile = item['tmobile']
if item['umobile']:
umobile = item['umobile']
else:
corp = self.db.get(
"SELECT cid, mobile FROM T_CORP WHERE cid = %s", self.current_user.cid)
umobile = corp.mobile
biz_type = item['biz_type']
r = DotDict(tmobile=tmobile,
status=ErrorCode.SUCCESS)
# 1. add terminal
terminal = self.db.get("SELECT id, tid, service_status FROM T_TERMINAL_INFO WHERE mobile = %s",
tmobile)
if terminal:
if terminal.service_status == UWEB.SERVICE_STATUS.TO_BE_UNBIND:
delete_terminal(terminal.tid, self.db, self.redis)
else:
logging.error("[UWEB] mobile: %s already existed.", tmobile)
r['status'] = ErrorCode.TERMINAL_ORDERED
continue
terminal_info = dict(tid=tmobile,
group_id=gid,
tmobile=tmobile,
owner_mobile=umobile,
mannual_status=UWEB.DEFEND_STATUS.YES,
begintime=begintime,
endtime=4733481600,
offline_time=begintime,
login_permit=0,
biz_type=biz_type,
service_status=UWEB.SERVICE_STATUS.ON)
if int(biz_type) == UWEB.BIZ_TYPE.YDWS:
register_sms = SMSCode.SMS_REGISTER % (umobile, tmobile)
ret = SMSHelper.send_to_terminal(tmobile, register_sms)
else:
activation_code = QueryHelper.get_activation_code(self.db)
tid = get_tid_from_mobile_ydwq(tmobile)
terminal_info['tid'] = tid
terminal_info['activation_code'] = activation_code
terminal_info[
'service_status'] = UWEB.SERVICE_STATUS.TO_BE_ACTIVATED
register_sms = SMSCode.SMS_REGISTER_YDWQ % (
ConfHelper.UWEB_CONF.url_out, activation_code)
ret = SMSHelper.send(tmobile, register_sms)
add_terminal(terminal_info, self.db, self.redis)
# record the add action, enterprise
bind_info = dict(tid=terminal_info['tid'],
tmobile=tmobile,
umobile=umobile,
group_id=gid,
cid=self.current_user.cid,
add_time=int(time.time()))
record_add_action(bind_info, self.db)
ret = DotDict(json_decode(ret))
if ret.status == ErrorCode.SUCCESS:
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET msgid = %s"
" WHERE tid = %s",
ret['msgid'], terminal_info['tid'])
else:
r['status'] = ErrorCode.FAILED
# 2. add user
user_info = dict(umobile=umobile,
password='111111',
uname=umobile)
add_user(user_info, self.db, self.redis)
res.append(r)
self.write_ret(status,
dict_=DotDict(res=res))
except Exception as e:
#.........这里部分代码省略.........
示例12: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self, tmobile, pmobile, is_clear):
"""Delete a terminal.
@param: tmobile // terminal's mobile
@param: pmobile // owner_mobile
@param: is_clear: 清除// 1: 清除历史数据; 0: 不清楚历史数据
"""
status = ErrorCode.SUCCESS
try:
terminal = self.db.get("SELECT id, login, mobile, tid"
" FROM T_TERMINAL_INFO"
" WHERE mobile = %s",
tmobile)
tid = terminal.tid
#NOTE: record whether clear history in redis
key = get_del_data_key(tid)
self.redis.set(key, is_clear)
biz_type = QueryHelper.get_biz_type_by_tmobile(tmobile, self.db)
if int(biz_type) == UWEB.BIZ_TYPE.YDWS:
if terminal.login != GATEWAY.TERMINAL_LOGIN.ONLINE: # offline
if terminal.mobile == tid:
delete_terminal_new(tid, self.db, self.redis)
logging.info('[ADMIN] Delete terminal. umobile:%s, tid: %s, tmobile:%s.',
pmobile, tid, tmobile)
else:
delete_terminal_new(tid, self.db, self.redis)
unbind_sms = SMSCode.SMS_UNBIND
ret = SMSHelper.send_to_terminal(tmobile, unbind_sms)
ret = DotDict(json_decode(ret))
logging.info('[ADMIN] Send JB sms. umobile:%s, tid: %s, tmobile:%s.',
pmobile, tid, tmobile)
self.write_ret(status)
return
else:
delete_terminal_new(tid, self.db, self.redis)
self.write_ret(status)
return
# unbind terminal
seq = str(int(time.time()*1000))[-4:]
args = DotDict(seq=seq,
tid=terminal.tid)
response = GFSenderHelper.forward(GFSenderHelper.URLS.UNBIND, args)
response = json_decode(response)
if response['success'] == ErrorCode.SUCCESS:
logging.info("[ADMIN] Umobile: %s, tid: %s, tmobile:%s"
" GPRS unbind successfully",
pmobile, terminal.tid, tmobile)
else:
status = response['success']
# unbind failed. clear sessionID for relogin, then unbind it again
sessionID_key = get_terminal_sessionID_key(terminal.tid)
self.redis.delete(sessionID_key)
logging.error("[ADMIN] Umobile:%s, tid: %s, tmobile:%s"
" GPRS unbind failed, message: %s, send JB sms...",
pmobile, terminal.tid, tmobile,
ErrorCode.ERROR_MESSAGE[status])
unbind_sms = SMSCode.SMS_UNBIND
biz_type = QueryHelper.get_biz_type_by_tmobile(tmobile, self.db)
if biz_type != UWEB.BIZ_TYPE.YDWS:
ret = DotDict(status=ErrorCode.SUCCESS)
else:
ret = SMSHelper.send_to_terminal(tmobile, unbind_sms)
ret = DotDict(json_decode(ret))
status = ret.status
if ret.status == ErrorCode.SUCCESS:
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET service_status = %s"
" WHERE id = %s",
UWEB.SERVICE_STATUS.TO_BE_UNBIND,
terminal.id)
logging.info("[ADMIN] umobile: %s, tid: %s, tmobile: %s"
" SMS unbind successfully.",
pmobile, terminal.tid, tmobile)
else:
logging.error("[ADMIN] umobile: %s, tid: %s, tmobile: %s"
" SMS unbind failed. Message: %s",
pmobile, terminal.tid, tmobile,
ErrorCode.ERROR_MESSAGE[status])
except Exception as e:
status = ErrorCode.FAILED
logging.exception("[ADMIN] Delete service failed."
" tmobile: %s, owner mobile: %s, Exception: %s",
tmobile, pmobile, e.args)
self.write_ret(status)
示例13: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
"""Regist a pair of umobile and tmobile.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
logging.info("[UWEB] Register request: %s", data)
umobile = data.umobile
tmobile = data.tmobile
captcha = data.captcha
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. Exception: %s",
e.args)
self.write_ret(status)
return
try:
# check tmobile is whitelist or not
white_list = check_zs_phone(tmobile, self.db)
if not white_list:
logging.info("[UWEB] Mobile is not whitelist. tmobile: %s.", tmobile)
status = ErrorCode.MOBILE_NOT_ORDERED
message = ErrorCode.ERROR_MESSAGE[status] % tmobile
self.write_ret(status, message=message)
return
captcha_key = get_captcha_key(umobile)
captcha_old = self.redis.get(captcha_key)
if captcha_old:
if captcha == str(captcha_old):
terminal = QueryHelper.get_terminal_by_tmobile(
tmobile, self.db)
if terminal:
if terminal.service_status == UWEB.SERVICE_STATUS.TO_BE_UNBIND:
# delete to_be_unbind terminal!
delete_terminal(terminal.tid, self.db, self.redis)
else:
status = ErrorCode.TERMINAL_ORDERED
logging.info("[UWEB] Regist failed. umobile: %s, tmobile: %s Message: %s",
umobile, tmobile, ErrorCode.ERROR_MESSAGE[status])
self.write_ret(status)
return
register_sms = SMSCode.SMS_REGISTER % (umobile, tmobile)
ret = SMSHelper.send_to_terminal(tmobile, register_sms)
ret = DotDict(json_decode(ret))
if ret.status == ErrorCode.SUCCESS:
logging.info("[UWEB] Regist successfully. umobile: %s, tmobile: %s ",
umobile, tmobile)
self.redis.delete(captcha_key)
else:
status = ErrorCode.REGISTER_FAILED
logging.error("[UWEB] Regist failed. umobile: %s, tmobile: %s. Message: %s",
umobile, tmobile, ErrorCode.ERROR_MESSAGE[status])
else:
status = ErrorCode.WRONG_CAPTCHA
logging.error("[UWEB] Regist failed. umobile: %s, captcha: %s, captcha_old: %s, Message: %s",
umobile, captcha, captcha_old, ErrorCode.ERROR_MESSAGE[status])
else:
status = ErrorCode.NO_CAPTCHA
logging.error("[UWEB] Register failed. umobile: %s, captcha: %s, Message: %s",
umobile, captcha, ErrorCode.ERROR_MESSAGE[status])
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] Register failed. umobile: %s tmobile: %s , Exception: %s",
umobile, tmobile, e.args)
status = ErrorCode.REGISTER_FAILED
self.write_ret(status)
示例14: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
"""Create business for a couple of users.
"""
fields = DotDict(ecid="",
cnum="",
ctype="",
ccolor="",
cbrand="",
tmobile="",
begintime="",
endtime="",
uname="",
umobile="",
password="",
address="",
email="",
ecmobile="",
biz_type="")
for key in fields.iterkeys():
fields[key] = self.get_argument(key, '')
# if not check_sql_injection(fields[key]):
# logging.error("Create business condition contain SQL inject. %s : %s", key, fields[key])
# self.render('errors/error.html',
# message=ErrorCode.ERROR_MESSAGE[ErrorCode.CREATE_CONDITION_ILLEGAL])
# return
white_list = check_zs_phone(fields.tmobile, self.db)
if not white_list:
logging.error(
"Create business error, %s is not whitelist", fields.tmobile)
self.render('errors/error.html',
message=ErrorCode.ERROR_MESSAGE[ErrorCode.MOBILE_NOT_ORDERED])
return
try:
# 1: add user
user = self.db.get(
"SELECT id FROM T_USER WHERE mobile = %s", fields.umobile)
if not user:
self.db.execute("INSERT INTO T_USER(id, uid, password, name, mobile, address, email, remark)"
" VALUES(NULL, %s, password(%s), %s, %s, %s, %s, NULL)",
fields.umobile, '111111',
fields.uname, fields.umobile,
fields.address, fields.email)
self.db.execute("INSERT INTO T_SMS_OPTION(uid)"
" VALUES(%s)",
fields.umobile)
# 2: add terminal
group = self.db.get("SELECT id FROM T_GROUP"
" WHERE corp_id = %s AND type = 0 LIMIT 1",
fields.ecid)
if not group:
gid = self.db.execute("INSERT INTO T_GROUP(corp_id, name, type)"
" VALUES(%s, default, default)",
fields.ecid)
else:
gid = group.id
# record the add action, enterprise
bind_info = dict(tid=fields.tmobile,
tmobile=fields.tmobile,
umobile=fields.umobile,
group_id=gid,
cid=fields.ecmobile,
add_time=int(time.time()))
record_add_action(bind_info, self.db)
if not fields.umobile:
user_mobile = fields.ecmobile
else:
user_mobile = fields.umobile
# 3: send message to terminal
biz_type = int(fields.biz_type)
if biz_type == UWEB.BIZ_TYPE.YDWS:
self.db.execute("INSERT INTO T_TERMINAL_INFO(tid, group_id, mobile, owner_mobile,"
" begintime, endtime, offline_time, login_permit)"
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
fields.tmobile, gid,
fields.tmobile, user_mobile,
fields.begintime, 4733481600, fields.begintime, 0)
register_sms = SMSCode.SMS_REGISTER % (
fields.umobile, fields.tmobile)
ret = SMSHelper.send_to_terminal(fields.tmobile, register_sms)
self.db.execute("INSERT INTO T_CAR(tid, cnum, type, color, brand)"
" VALUES(%s, %s, %s, %s, %s)",
fields.tmobile, fields.cnum,
fields.ctype, fields.ccolor, fields.cbrand)
else:
tid = get_tid_from_mobile_ydwq(fields.tmobile)
activation_code = QueryHelper.get_activation_code(self.db)
self.db.execute("INSERT INTO T_TERMINAL_INFO(tid, group_id, mobile, owner_mobile,"
" begintime, endtime, offline_time, login_permit,"
" biz_type, activation_code, service_status)"
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
tid, gid,
fields.tmobile, user_mobile,
fields.begintime, 4733481600,
fields.begintime, 0, biz_type,
activation_code, UWEB.SERVICE_STATUS.TO_BE_ACTIVATED)
#.........这里部分代码省略.........
示例15: post
# 需要导入模块: from helpers.smshelper import SMSHelper [as 别名]
# 或者: from helpers.smshelper.SMSHelper import send_to_terminal [as 别名]
def post(self):
status = ErrorCode.SUCCESS
try:
data = json_decode(self.request.body)
logging.info("[LOG] message request: %s", data)
sms_type = data.get('sms_type')
tmobile = data.get('tmobile')
content = ''
if check_phone(tmobile) is None:
status = ErrorCode.ILLEGAL_MOBILE
self.write_ret(status)
else:
if sms_type == 'JH':
umobile = data.get('umobile')
if check_phone(umobile):
content = ':SIM' + ' ' + umobile + ':' + tmobile
SMSHelper.send_to_terminal(tmobile, content)
self.write_ret(status)
else:
status = ErrorCode.ILLEGAL_MOBILE
self.write_ret(status)
elif sms_type == 'JB':
content = ':' + sms_type
is_clear = data.get('is_clear')
ret = SMSHelper.send_to_terminal(tmobile, content)
ret = json_decode(ret)
terminal = self.acbdb.get("SELECT id, tid, owner_mobile, login"
" FROM T_TERMINAL_INFO"
" WHERE mobile = %s"
" AND service_status = 1",
tmobile)
if not terminal:
status = ErrorCode.TERMINAL_NOT_EXISTED
logging.error("The terminal with tmobile: %s does not exist!",
tmobile)
self.write_ret(status)
return
umobile = terminal.owner_mobile
if ret['status'] == 0:
self.acbdb.execute("UPDATE T_TERMINAL_INFO"
" SET service_status = 2"
" WHERE mobile = %s",
tmobile)
# terminals = self.acbdb.query("SELECT id FROM T_TERMINAL_INFO"
# " WHERE owner_mobile = %s"
# " AND service_status = 1",
# umobile)
# clear user
# if len(terminals) == 0:
# self.acbdb.execute("DELETE FROM T_USER"
# " WHERE mobile = %s",
# umobile)
if is_clear == 1:
clear_data(terminal['tid'], self.acbdb, self.redis)
self.write_ret(status)
elif sms_type == 'CQ':
content = ':' + sms_type
SMSHelper.send_to_terminal(tmobile, content)
self.write_ret(status)
elif sms_type == 'REBOOT':
content = ':' + sms_type
# SMSHelper.send_to_terminal(tmobile,content)
SMSHelper.send_update_to_terminal(tmobile, content)
self.write_ret(status)
elif sms_type == 'TEST':
content = u'尊敬的顾客,您好:这是一条测试短信,收到本条短信,说明短信提示服务正常,本短信不需要回复,如有问题,请和客服人员联系。感谢使用我们的产品,您的移动卫士。'
SMSHelper.send(tmobile, content)
self.write_ret(status)
elif sms_type == 'KQLY':
content = ':%s 30' % sms_type
SMSHelper.send_to_terminal(tmobile, content)
self.write_ret(status)
elif sms_type == 'LQGZ':
content = ':%s 30' % sms_type
SMSHelper.send_to_terminal(tmobile, content)
self.write_ret(status)
elif sms_type == 'DW':
content = ':' + sms_type
SMSHelper.send_to_terminal(tmobile, content)
self.write_ret(status)
elif sms_type == 'UPDATE':
content = ':' + sms_type
SMSHelper.send_update_to_terminal(tmobile, content)
self.write_ret(status)
elif sms_type == 'DEL':
terminal = self.acbdb.get(
'SELECT tid FROM T_TERMINAL_INFO WHERE mobile=%s', tmobile)
if terminal:
delete_terminal(
terminal.tid, self.acbdb, self.redis, del_user=False)
self.write_ret(status)
elif sms_type == 'DOMAIN':
ip = data.get('domain')
content = ':DOMAIN ' + ip
info = self.acbdb.get(
#.........这里部分代码省略.........