Ejemplo n.º 1
0
def main():
    appId = 'wx4f4bc4dec97d474b'
    sessionKey = 'tiihtNczf5v6AKRyjwEUhQ=='
    encryptedData = 'CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew=='
    iv = 'r7BXXKkLb8qrSNn05n0qiA=='

    pc = WXBizDataCrypt(appId, sessionKey)

    print pc.decryptData(encryptedData, iv)
Ejemplo n.º 2
0
def main():
    appId = 'wx4f4bc4dec97d474b'
    sessionKey = 'tiihtNczf5v6AKRyjwEUhQ=='
    encryptedData = 'CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew=='
    iv = 'r7BXXKkLb8qrSNn05n0qiA=='

    pc = WXBizDataCrypt(appId, sessionKey)

    print(pc.decrypt(encryptedData, iv))
Ejemplo n.º 3
0
def main():
    appId = 'wxa2b78eac0a7c7627'
    sessionKey = '2dHE45EXC+B+9EkaS4Hi2g=='
    encryptedData = "69F+aqB6rlJDrifc4zLgbuS1X1kK9+iOdmayvYNtDtfDhfF9w0nmvlYEKR3V05JCKCAuZvIS3TIk+wo1VsNI8t3Lm45kz+fle/rvGyzw/d+gnFuds6gzyfzHj1et15ZzJ4d8OIVYH7lTEGYgkjlzG/qAXcygTEhzinmD2aG5MMr0AjImwj1KT8J45wdSxl8geONtITeCoHTnkm+nPBCN/QcAvj6m0ic+QSlpc4F9CkZz0N1IWaqn1mX13UWud5+khWLSrafrqlW9m40HJjPOsJNTbrlcD03Nf17DRMoROZrpCCym7cf7K3kEb6LH02AlhtxDH8Ob4OBgyaHj+YSiZ0d5bJ0hF5E5/zh6S1jczKCDs+TLKby4ZLb0g2zme+lPzcrQD65MRGQIXOtvS0rpHyEqngC1oIN8cW4IRDqSkXQwkCZcK1TN106IWAeEQJmgAtsBeUOu5ub7T2rZDc4a2thEF2hnatJQnYpXeCNOznS3CVgNYPJPMb/7cGOIpODQj1wCGVv8ColmO+CBrx7qtA=="
    iv = "RJYTtXu+0c1OXeYUD1Zapg=="

    pc = WXBizDataCrypt(appId, sessionKey)

    print pc.decrypt(encryptedData, iv)
Ejemplo n.º 4
0
 def decryptData(self):
     res = ''
     try:
         pc = WXBizDataCrypt(appid, self.session_key)
         res = pc.decrypt(self.res_info['encryptedData'],
                          self.res_info['iv'])
     except Exception as err:
         print('error1.................')
         print(err)
     return res
Ejemplo n.º 5
0
def main():
    # appId = 'wx4f4bc4dec97d474b'
    # sessionKey = 'tiihtNczf5v6AKRyjwEUhQ=='
    # encryptedData = 'CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew=='
    # iv = 'r7BXXKkLb8qrSNn05n0qiA=='

    appId = 'wx4f4bc4dec97d474b'
    sessionKey = 'YnZqdUaHpcDpNVBez+0L2Q=='
    encryptedData = '1Pg4InKuPnWNzy/WisTHTkZjNvtuY3w/JtGm6u49iPPoNV9vsr4KHkmlYLOLiqMxYAyvKhEVekDL79LUJXasF175c91tlbKK8uZ5XViOYZdHMYA2zcc0rZVRSiWAcsy+qYaNDdYG9qg78/Qc79ur+4XbPjEaFxzwcNSl7EDaBnPvPgPBvV83L6KUsCsbjhbjavgU6vBuw5EwwjQwk9OEIQ=='
    iv = '2uWUk/RZ0EbK54sNSIXmiw=='

    pc = WXBizDataCrypt(appId, sessionKey)

    print(pc.decrypt(encryptedData, iv))
Ejemplo n.º 6
0
def setphone():
    res = json.loads(request.data)
    logging.debug(res)
    logging.debug('============u:'+res['uid'])
    uinfo_s=redisobj.get('u:' + res['uid'])
    uinfo=json.loads(uinfo_s)
    logging.debug(uinfo)

    pc = WXBizDataCrypt(appId, uinfo['session_key'])

    phoneinfo=pc.decrypt(res['encryptedData'], res['iv'])
    logging.debug(phoneinfo)
    logging.debug(phoneinfo['purePhoneNumber'])

    redisobj.set('ph:' + phoneinfo['purePhoneNumber']+':uid',res['uid'])

    return 'success'
Ejemplo n.º 7
0
    def real_GET(self, request):
        nickName = request.args.get('nickName')[0]
        rundata = request.args.get('rundata')[0]
        code = request.args.get('sessionKey')[0]

        iv = request.args.get('iv')[0]
        logging.info('iv=%s' % iv)
        url = 'https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=ddf03c948cfe2610dd8d1ae125b212ea&' \
              'js_code=%s&grant_type=authorization_code' % (appId, code)
        res = requests.get(url)
        content = json.loads(res.content)
        sessionKey = content['session_key']
        pc = WXBizDataCrypt(appId, sessionKey)
        data = pc.decrypt(rundata, iv)
        for item in data:
            timestamp = timestamp_to_date(item['timestamp'])
            step = item['step']
            logging.info("%s   %s " % (timestamp, step))
        logging.info("nickname %s" % nickName)
        logging.info(nickName)
        return "success"
Ejemplo n.º 8
0
def testst():

    ll = []
    data = request.json
    appid = 'wx996ee0fd19218c1b'
    secret = '776589b2c28a20bfdcd180dc64fea01e'
    code = data['code']
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4033.400 QQBrowser/9.6.12624.400'
    }
    url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code'
    jsonn = requests.post(url, headers=headers).json()
    appId = 'wx996ee0fd19218c1b'
    sessionKey = jsonn['session_key']
    encryptedData = data['encryptedData']
    iv = data['iv']
    pc = WXBizDataCrypt(appId, sessionKey)
    print pc.decrypt(encryptedData, iv)
    ll = pc.decrypt(encryptedData, iv)
    encoded_json = json.dumps(ll, ensure_ascii=False)
    return encoded_json
Ejemplo n.º 9
0
    def real_POST(self, request):
        nickName = request.args.get('nickName')[0]
        rundata = request.args.get('rundata')[0]
        code = request.args.get('code')[0]
        avatarUrl = request.args.get('avatarUrl')[0]
        logging.info(avatarUrl)
        iv = request.args.get('iv')[0]
        logging.info('iv=%s' % iv)
        url = 'https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=ddf03c948cfe2610dd8d1ae125b212ea&' \
              'js_code=%s&grant_type=authorization_code' % (appId, code)
        res = requests.get(url)
        logging.info(res.content)
        content = json.loads(res.content)
        sessionKey = content['session_key']
        openid = content['openid']
        logging.info(sessionKey)
        pc = WXBizDataCrypt(appId, sessionKey)
        logging.info("rundata = %s" % rundata)
        data = pc.decrypt(rundata, iv)
        for item in data:
            timestamp = timestamp_to_date(item['timestamp'])
            step = item['step']
            logging.info("%s   %s " % (timestamp, step))
            run_day = get_day(item['timestamp'])
            logging.info(
                "insert into rundata(openid,step,runday,nickname) value"
                " ('%s',%s,'%s','%s') on DUPLICATE key update step=%s  , avatarUrl='%s'"
                % (openid, step, run_day, nickName, step, avatarUrl))
            MysqlDB.insert(
                "insert into rundata(openid,step,runday,nickname) value"
                " ('%s',%s,'%s','%s') on DUPLICATE key update step=%s  , avatarUrl='%s'"
                % (openid, step, run_day, nickName, step, avatarUrl))

        logging.info("nickname = %s" % nickName)
        resp = {'openid': openid, 'code': 0}
        return resp
Ejemplo n.º 10
0
def login():
    global currentId
    # print "------------------"
    # print request.json

    encryptedData = request.json['encryptedData']
    iv = request.json['iv']
    code = request.json['code']

    #step1:code -> sessionKey
    keyURL = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + appSecret + '&js_code=' + code + '&grant_type=authorization_code'
    r = requests.post(keyURL)
    sessionKey = r.json()["session_key"]

    pc = WXBizDataCrypt(appId, sessionKey)
    info = pc.decrypt(encryptedData, iv)
    openId = info['openId']
    gender = info['gender']
    nickname = info['nickName']
    avatarUrl = info['avatarUrl']
    print " login OK----------------"
    print threading.current_thread().getName
    print openId, nickname
    currentId = openId
    # print currentId
    users = User.query.filter_by(id=openId).first()
    if users:
        users.nickname = nickname
        users.avatarUrl = avatarUrl
        # user=users(nickname=nickname,avatarUrl=avatarUrl)
        db.session.add(users)
        db.session.commit()
        userInfo = {
            "id": users.id,
            "nickname": users.nickname,
            "state": users.state,
            "gender": users.gender,
            "avatarUrl": users.avatarUrl,
            "tel": users.tel,
            "latitude": users.latitude,
            "longitude": users.longitude
        }
        return json.dumps(userInfo)
    else:
        user = User(id=openId,
                    gender=gender,
                    nickname=nickname,
                    avatarUrl=avatarUrl)
        db.session.add(user)
        db.session.commit()
        userInfo = {
            "id": users.id,
            "nickname": users.nickname,
            "state": users.state,
            "gender": users.gender,
            "avatarUrl": users.avatarUrl,
            "tel": users.tel,
            "latitude": users.latitude,
            "longitude": users.longitude
        }
        return json.dumps(userInfo)
Ejemplo n.º 11
0
def decrypt(encryptedData, iv, session_key):
    appId = 'wx2bd3ca4f04e83411'

    pc = WXBizDataCrypt(appId, session_key)

    print pc.decryptData(encryptedData, iv)
Ejemplo n.º 12
0
    def post(self):
        args = parser.parse_args()

        APP_ID = current_app.config.get('APP_ID')
        session_key = args.get('session_key', None)
        encrypted_data = args.get('encrypted_data', None)
        iv = args.get('iv', None)
        openId_string = args.get('openId', None)

        if APP_ID and session_key and encrypted_data and iv and openId_string:
            crypt = WXBizDataCrypt(APP_ID, session_key)
            try:
                user_info = crypt.decrypt(encrypted_data, iv)
            except ValueError as e:
                return api_abort(400, e.args[0], binded=False, login=False)

            try:
                # XXX: openId由 Code2sessionAPI 获取。
                # openId = user_info.get('openId', None)
                # name = user_info.get('nickName', None)
                openId = unicode(openId_string, 'utf-8')
            except (UnicodeEncodeError, ValueError, TypeError) as e:
                return api_abort(400, e.args[0], binded=False, login=False)

            if openId:
                worker = Worker.query.filter_by(openId=openId).first()
                if worker and worker.name and worker.number:
                    # XXX: 用户如果绑定时已经修改过名称,则使用后台记录的名称,
                    # 而非解析出来的名称。
                    user_info.update(nickName=worker.name,
                                     number=worker.number,
                                     authority=worker.authority,
                                     belongto_team=str(worker.belongto_team),
                                     team_id=worker.team_id,
                                     login=True,
                                     binded=True)
                # elif worker:
                #     user_info.update(nickName=worker.name,
                #                      authority=worker.authority,
                #                      binded=False,
                #                      login=True)
                # XXX: 没有 openId 对应的记录则 SQLALchemy返回 None。
                elif worker is None:
                    # # XXX: 尝试使用用户名去查找记录,可能管理员预先在后台录入用户的名字和工号。
                    # # 这时需要更新用户的 openId。
                    # worker = Worker.query.filter_by(name=name).all()
                    # # XXX: 如果有重名的用户则不写入 openId。
                    # if len(worker) > 1:
                    #     user_info.update(binded=False, login=True)
                    # elif len(worker) == 1:
                    #     try:
                    #         worker[0].openId = openId
                    #         db.session.commit()
                    #         user_info.update(binded=False,
                    #                          login=True,
                    #                          authority=worker[0].authority)
                    #     except IntegrityError as e:
                    #         db.session.rollback()
                    #         api_abort(400,
                    #                   e.args[0],
                    #                   binded=False,
                    #                   login=True,
                    #                   authority=worker.authority)
                    # elif len(worker) == 0:
                    #     new_worker = Worker(name=name,
                    #                         number=None,
                    #                         openId=openId,
                    #                         major=None,
                    #                         post=None,
                    #                         authority=u'普通用户',
                    #                         belongto_department=None,
                    #                         belongto_workshop=None,
                    #                         belongto_team=None)
                    #     try:
                    #         db.session.add(new_worker)
                    #         db.session.commit()
                    #         user_info.update(binded=False,
                    #                          login=True,
                    #                          authority=u'普通用户')
                    #     except IntegrityError as e:
                    #         db.session.rollback()
                    #         api_abort(400, e.args[0], binded=False, login=True)
                    user_info.update(login=True, binded=False)
                return jsonify(user_info)
Ejemplo n.º 13
0
def get_user_info(encryptedData, iv, session_key):
    pc = WXBizDataCrypt(WXAPP_ID, session_key)
    return pc.decrypt(encryptedData, iv)