Permalink
Browse files

Updated README.md

  • Loading branch information...
1 parent 909c4cb commit c1065f9144541a12cfdef7bcbda3b9cc2f7f5f26 @junewu committed Dec 23, 2013
View
@@ -1 +1,3 @@
-## Nothing
+##some small tools are written by Aurora.
+
+###digit2word.py is a python script, which could convert digits to words from 0 to 999.
View
@@ -1,93 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-__author__ = 'Aurora Wu (wuxy91@gmail.com)'
-__copyright__ = "Copyright (c) 2013 aurorawu.com"
-
-
-import dbutils
-import balance
-import datetime
-import time
-import tool
-import config
-import ams
-import check
-import traceback
-
-
-class Account:
- """tool_dict contains a query connection of the database connection pool, and a update connection of
- the database connection pool"""
- def __init__(self, logger, tool_dict):
- self.logger = logger
- self.tool_dict = tool_dict
-
- def get_bind_relation(self, uid):#获得绑定关系
- dbHandler = dbutils.DBHandler(self.logger, self.tool_dict['read_conn'])
- try:
- sql = 'SELECT uid, caller FROM KC_DB.`T_ImsiBindAccount` WHERE uid = %s'
- rs = dbHandler.query_one(sql, [uid])
- return rs if rs else ['', '']
- except:
- self.logger.error(u'Account.get_bind_mobile() 查询异常:%s' % traceback.format_exc())
-
- def remove_bind_relation(self, uid):#删除绑定关系
- dbHandler = dbutils.DBHandler(self.logger, self.tool_dict['read_conn'])
- try:
- sql = "DELETE FROM KC_DB.`T_ImsiBindAccount` WHERE uid = %s" % uid
- return dbHandler.single_update(sql, [uid])
- except:
- self.logger.error(u'Account.remove_bind_relation() 执行异常:%s' % traceback.format_exc())
-
- def login(self, account, md5psw, version_no, os_type, ip='', bid='kc', pform='', psystem='', ptype='', cversion='',
- callback=None):#登录
- self.logger.info(u"收到登录请求:帐号/手机号码==%s,版本==%s,版本号==%s,产品==%s" % (account, os_type, version_no, bid))
- result = {}
- try:
- if not callback:
- callback = tool.return_values
- if not account or len(md5psw) != 32:
- result['result'], result['reason'] = "100004", u'账号密码验证失败'
- return callback(result)
- #检查是用手机号码还是帐号登录的
- login_type = 'mobile' if check.is_mobile(account) == 1 else 'kc'
- # phone = account if login_type == 'mobile' else ''
- # res = ams.login(login_type, account, md5psw, 'mobile', ip, bid, pform, psystem, ptype, cversion)
- job = self.tool_dict['queue'].enqueue(ams.login, login_type, account, md5psw, 'mobile', ip, bid, pform,
- psystem, ptype, cversion)
- #####################################################################################
- time.sleep(2)
- res = job.result
- if res['code'] == '2':
- self.logger.info(u"帐号不存在:%s" % account)
- result['result'], result['reason'] = "100008", u'帐号不存在'
- return callback(result)
- elif res['code'] == '10':
- self.logger.info(u"登录失败,账号密码错误:%s" % account)
- result['result'], result['reason'] = "100004", u'账号密码验证失败'
- return callback(result)
- elif res['code'] == '0':#登录成功
- uid, phone, password = ams.getInfo(login_type, account, bid)
- caller = self.get_bind_relation(account)[1]
- caller = phone if not caller else caller
- msg, uid_list, calltime = '', [], 0
- first_login = res.get('first', 0)
- if int(first_login) == 1 or uid in uid_list:
- msg = config.FirstLoginMsg % (datetime.date.today() + datetime.timedelta(days=7)).strftime("%Y-%m-%d")
- elif version_no >= '1.4.2':
- balance_info = balance.Balance(self.logger, self.tool_dict).get_balance_2(uid, bid)
- msg = config.NormalLoginMsg % balance_info
- calltime = balance_info['calltime']
- self.logger.info(u"登录成功:KC号==%s,手机==%s,版本==%s,版本号==%s" % (uid, phone, os_type, version_no))
- result = {'result': '0', 'mobile': phone, 'kcid': uid, 'caller': caller, 'msg': msg, 'first': first_login,
- 'calltime': str(calltime), 'reason': u'登录成功'}
- return callback(result)
- else:
- self.logger.warn(u"%s登录失败,AMS返回码:%s" % (account, res['code']))
- result['result'], result['reason'] = '999998', u'未知错误,错误码:%s' % res['code']
- return callback(result)
- except:
- result["result"], result["reason"] = "999999", u"服务器繁忙,请稍后再试"
- self.logger.error(u'Account.login() 发生错误:%s' % traceback.format_exc())
- finally:
- self.logger.info(u'登录结果:%s' % result)
View
195 ams.py
@@ -1,195 +0,0 @@
-#!/usr/local/bin/python
-#coding=utf-8
-import urllib2, httplib, urllib
-import logging, traceback, datetime, random
-import config, tool
-
-logger = tool.mylog(__name__)
-
-
-def rc4(data, key):
- x = 0
- box = range(256)
- for i in range(256):
- x = (x + box[i] + ord(key[i % len(key)])) % 256
- box[i], box[x] = box[x], box[i]
- x = 0
- y = 0
- out = []
- for char in data:
- x = (x + 1) % 256
- y = (y + box[x]) % 256
- box[x], box[y] = box[y], box[x]
- out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
- return ''.join(out)
-
-
-def hex2str(s):
- '''16进制转字符串'''
- if s[:2] == '0x' or s[:2] == '0X':
- s = s[2:]
- res = ""
- for i in range(0, len(s), 2):
- hex_dig = s[i:i + 2]
- res += (chr(int(hex_dig, base=16)))
- return res
-
-
-def str2hex(string):
- '''字符串转16进制'''
- res = ""
- for s in string:
- hex_dig = hex(ord(s))[2:]
- if len(hex_dig) == 1:
- hex_dig = "0" + hex_dig
- res += hex_dig
- return res
-
-
-def getAmsResp(amsFunc, params,timeout=10):
- try:
- #httpConn = httplib.HTTPConnection(AMS_HOST, AMS_PORT)
- #httpConn.request("POST", amsFunc, params + "&" + getAmsSign(),{"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
- #f = httpConn.getresponse()
- url = "http://" + config.AMS_HOST + ":" + str(config.AMS_PORT) + amsFunc + "?" + params + "&" + getAmsSign()
- res = tool.http_get(url,timeout)
- # f = urllib2.urlopen(url)
- # res = f.read()
- # f.close()
- logger.info(u"AMS URL:%s;结果:%s" % (url, res))
- return urlCode2Dict(res)
- except:
- logger.error("getAmsResp Fail: %s %s" % (url, traceback.format_exc()))
- return {"code": "9999"}
-
-
-def urlCode2Dict(result):
- '''ams返回url串转换成dict'''
- return dict(x.split('=') for x in result.split('&'))
-
-
-def getRand():
- n = datetime.datetime.now().strftime("%H%M%S")
- m = str(random.randint(1000, 9999))
- return n + m
-
-
-def getAmsSign():
- macdate = datetime.datetime.now().strftime("%Y%m%d")
- macrand = getRand()
- mac = tool.md5_password(config.LOCALHOST + macdate + macrand + config.MAC_KEY)
- mac_dict = {"macip": config.LOCALHOST, \
- "macdate": macdate, \
- "macrand": macrand, \
- "mac": mac}
- return urllib.urlencode(mac_dict)
-
-
-def info(accounttype, account, brandid='kc'):
- '''查询kc/手机/密码'''
- param = urllib.urlencode({"accounttype": accounttype, \
- "account": account, "bid": brandid})
- return getAmsResp("/ams2/info.act", param,timeout=40)
-
-
-def login(loginType, account, password, loginfrom, ip, brandid='kc', pform='', psystem='', ptype='', cversion=''):
- '''登录认证'''
- param = urllib.urlencode({"loginType": loginType, \
- "account": account, \
- "password": password, \
- "from": loginfrom, \
- "ip": ip, \
- "bid": brandid, \
- "pform": pform, \
- "psystem": psystem, \
- "ptype": ptype, \
- "cversion": cversion
- })
- return getAmsResp("/ams2/login.act", param,timeout=30)
-
-
-def choose(ip):
- '''选号'''
- return getAmsResp("/ams2/choose.act", "ip=%s" % ip)
-
-
-def kcreg(uid, password, random, invitedby, invitedflag, regfrom):
- '''注册'''
- return getAmsResp("/ams2/kcreg.act", "uid=%s&password=%s&random=%s&invitedby=%s&invitedflag=%s&from=%s" % uid,
- password, random, invitedby, invitedflag, regfrom)
-
-
-def automobilereg(number, invitedby, invitedflag, regfrom, ip, ext='', brandid='kc'):
- '''自动注册'''
- return getAmsResp("/ams2/automobilereg.act", "number=%s&invitedby=%s&invitedflag=%s&from=%s&ip=%s&ext=%s&bid=%s"
- % (number, invitedby, invitedflag, regfrom, ip, ext, brandid),timeout=40)
-
-
-def mobilereg(number, invitedby, invitedflag, regfrom, ip, ext='', brandid='kc'):
- '''短信注册'''
- return getAmsResp("/ams2/mobilereg.act", "number=%s&invitedby=%s&invitedflag=%s&from=%s&ip=%s&ext=%s&bid=%s"
- % (number, invitedby, invitedflag, regfrom, ip, ext, brandid),timeout=40)
-
-
-def unbind(number, uid, password):
- '''绑定请求'''
- return getAmsResp("/ams2/unbind.act", "number=%s&uid=%s&password=%s" % (number, uid, password),timeout=40)
-
-
-def bindapply(number, uid, password, brandid='kc'):
- '''绑定请求'''
- return getAmsResp("/ams2/bindapply.act", "number=%s&uid=%s&password=%s&bid=%s" %
- (number, uid, password, brandid),timeout=40)
-
-
-def bindsubmit(uid, number, verifyCode, brandid='kc'):
- '''提交绑定'''
- return getAmsResp("/ams2/bindsubmit.act", "number=%s&uid=%s&verifyCode=%s&bid=%s" %
- (number, uid, verifyCode, brandid),timeout=40)
-
-
-def delacctnotify(accounts):
- '''APS删除账户通知'''
- return getAmsResp("/ams2/delacctnotify.act", "from=APS&accounts=%s" % accounts)
-
-
-def changepwd(uid, oldpwd, newpwd):
- '''修改密码'''
- return getAmsResp("/ams2/changepassword.act", "uid=%s&oldpassword=%s&newpassword=%s" % (uid, oldpwd, newpwd))
-
-
-def check_pwd(type, account, md5pwd):
- if not account or account == 'null' or not account.isdigit():
- return {"result": 1}
- if len(str(account)) == 11 and str(account)[0] == '1':
- type = 'mobile'
- res = info(type, account)
- if 'code' in res and str(res['code']) == '0':
- pwd = res['password']
- phone = res['number']
- uid = res['uid']
- if tool.md5_password(rc4(hex2str(pwd), config.AMS_KEY)) == md5pwd:
- return {"result": 0, "kcid": uid, "phone": phone}
- else:
- return {"result": 2}
- return {"result": 1}
-
-
-def getInfo(account_type, account, brandid='kc'):
- kcid, mobile, password = '', '', ''
- if not account or account == 'null' or not str(account).isdigit():
- return kcid, mobile, password
- if len(str(account)) == 11 and str(account)[0] == '1':
- account_type = 'mobile'
- res = info(account_type, account, brandid)
- if 'code' in res and str(res['code']) == '0':
- kcid = res['uid']
- mobile = res['number']
- password = rc4(hex2str(res['password']), config.AMS_KEY)
- return kcid, mobile, password
-
-
-if __name__ == '__main__':
- #print automobilereg('13430789767', '9646', '1', 'mobile', '1.1.1.1')
- pass
-
Oops, something went wrong.

0 comments on commit c1065f9

Please sign in to comment.