Ejemplo n.º 1
0
    def do_saveUpFile(self,data,userID):

        url = "http://" + mod_config.getConfig("INTERFACE", "IP")+":"+mod_config.getConfig("INTERFACE", "PORT")
        uptype = data["upType"]
        updata = data["file"][0]
        #上传接口数据
        if uptype == "1001":

            savefile =  sys.path[0] + "/Data/InterFace.txt"
            if  os.path.exists(savefile):
                os.remove(savefile)
            f = open(savefile, 'w')
            f.write(updata)
            f.close()

            sqlhandle = PymysqlHandle()
            sqlhandle.insterInterfaceData(savefile)
            returnDic = {"infoCode":0}
            returnDic['result'] = "scresss"
        #上传用户头像
        elif (uptype == "1002"):
            saveStr = "/Data/image/"+str(userID)+"head.png"
            savefile =  sys.path[0] + saveStr
            if  os.path.exists(savefile):
                os.remove(savefile)
            f = open(savefile, 'w')
            f.write(updata)
            f.close()

            url = url + saveStr
            headImage = {"headImage":url}
            sqlhandle = PymysqlHandle()
            sqlhandle.replaceUserInfo(headImage,userID)
            return headImage

        else:

            raise CustomError(-20006)

        return returnDic;
Ejemplo n.º 2
0
    def do_wxLogin(self, data, userID):

        if "js_code" not in data.keys():
            raise CustomError(-20005, "js_code")
        if "nickName" not in data.keys():
            raise CustomError(-20005, "nickName")

        parm = {
            'appid': 'wx2d3eaf4304b22f25',
            'secret': '456d14753450c85718b290fa187bc369',
            'js_code': data["js_code"],
            'grant_type': 'authorization_code'
        }
        r = requests.post('https://api.weixin.qq.com/sns/jscode2session', parm)
        if r.status_code == 200:
            wxresult = PythonString.jsonPase(r.text)
            if 'errcode' not in wxresult.keys():

                pymysqlHandle = PymysqlHandle()
                result = pymysqlHandle.selectUserInfoBykey(
                    "wxOpenid", wxresult["openid"])
                data = {
                    'wxOpenid': wxresult['openid'],
                    'userName': data["nickName"],
                    'userID': result["userID"],
                    'headImage': data["headImg"]
                }
                if result == None:
                    pymysqlHandle.insetUser(data)
                    result = pymysqlHandle.selectUserInfoBykey(
                        "wxOpenid", wxresult["openid"])
                else:
                    pymysqlHandle.replaceUserInfo(data, result["userID"])

                userID = result["userID"]
                '''创建section'''

                section = pymysqlHandle.getSection(result["userID"])

                if section != None:
                    nowtime = time.time()
                    if nowtime - section["createtime"] > 24 * 3600:
                        pymysqlHandle.deleteSection(result["userID"])
                        section = None

                if section == None:
                    '''创建section'''
                    salt = ''.join(
                        random.sample(string.ascii_letters + string.digits,
                                      32))
                    createtime = time.time()
                    userID = result["userID"]

                    data = {
                        'userID': userID,
                        'validityPeriod': 24,
                        'createtime': createtime,
                        'session': salt,
                    }
                    pymysqlHandle.insterSection(data)
                    result["session"] = salt
                    return result

            else:
                raise CustomError(-30002)
        else:
            raise CustomError(-30001)
Ejemplo n.º 3
0
    def do_replaceUserData(self, data, userID):

        sqlhandle = PymysqlHandle()

        sqlhandle.replaceUserInfo(data, userID)