Skip to content

Commit

Permalink
新增一个房价查询协议解析
Browse files Browse the repository at this point in the history
  • Loading branch information
wkunzhi committed Feb 22, 2020
1 parent 5ca5fe8 commit 7e8a8bc
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 其他实战/【房价】房价获取/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 概述
这不是一个完整的项目,是测试demo,可以获取区域内在售房产单套价格



**代码只是测试了一个最新销售小区中的一栋楼的在售楼房价格**

如果需要更完整的,就联系作者
Binary file not shown.
123 changes: 123 additions & 0 deletions 其他实战/【房价】房价获取/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- encoding: utf-8 -*-
# Auth: Zok Email: [email protected]
# Date: 2020/2/21

import requests
import json
import os
import sys
from urllib import parse

sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))

from util import *


class Fun:
"""
So 层
IV: jhf5632s
Key:hjkiuy6754edxc32890tfhjkw23xdea
"""

def __init__(self):
self.session = requests.session()

def get_list(self):
"""
获取楼盘列表
作为演示只获取第一页,中的第一个地产
"""
get_list_url = 'https://mobileapi.funi.com/m/community/search.json?page=1&pageSize=20&lng=106.593157&lat=29.541358&cityId=1'
response = self.session.get(get_list_url)
return json.loads(response.text)

def get_building(self, _id):
"""
获取楼栋表
"""
house_id = _id
key = '81$$@$$80$$@$$40$$@$$0$$@$$69$$@$$68$$@$$11$$@$$' + house_id + '$$@$$59$$@$$10$$@$$39$$@$$78$$@$$79$$@$$79$$@$$35$$@$$29$$@$$83$$@$$57$$@$$79$$@$$24$$@$$7$$@$$62$$@$$7$$@$$37$$@$$5$$@$$73$$@$$49$$@$$16$$@$$79$$@$$45$$@$$5'
key = des3_encrypt(key)
key = parse.quote(key)
url = 'https://mobileapi.funi.com/m/community/building211.json?key={key}'.format(key=key)
response = self.session.get(url)
print('楼栋数据', response.text)
return json.loads(response.text)

def one_fun(self, infos, _id):
"""
通过获取到的楼栋表,取每栋的可售房信息
测试,只取了前三个
:return:
"""
# 组合楼栋串 这里只取前三栋,作为测试
buildingIdArray = ','.join([item.get('id') for item in infos.get('data')][:3])
url = 'https://mobileapi.funi.com/m/community/buildingAmount.json'
data = {
'tal_id': '867686021859176', # ? 固定
'cityId': '1', # 成都,测试这里固定先
'communityId': _id, # 14944 = 蓝光观岭国际社区9期
'buildingIdArray': buildingIdArray,
'tal': 'ANDROID',
}
response = self.session.post(url, data=data)
print('楼栋数据', response.text)
return json.loads(response.text)

def getHousePrice(self, buildingId, _id):
"""
获取房价单间
这里测试,只取获取到得建筑得第一栋
:return:
"""

bId = buildingId
houseId = _id
unitId = '1'
key = '59$$@$$34$$@$$7$$@$$' + houseId + '$$@$$' + bId + '$$@$$87$$@$$30$$@$$18$$@$$8$$@$$' + unitId + '$$@$$82$$@$$14$$@$$53$$@$$51$$@$$51$$@$$70$$@$$50$$@$$3$$@$$57$$@$$72$$@$$39$$@$$95$$@$$4$$@$$43$$@$$37$$@$$94$$@$$35$$@$$38$$@$$79$$@$$96$$@$$'
key = make_str(key) # 这里需要重新处理
key = des3_encrypt(key)
key = parse.quote(key)
url = 'https://mobileapi.funi.com/m/community/house211.json?key={key}'.format(key=key)
response = self.session.get(url)
print('房价返回数据', response.text)
return json.loads(response.text)

def parse_data(self, items):
"""
这里只解析,在售状态得!!
:param items:
:return:
"""
for item in items.get('data'):
house_list = item.get('houseList')
for house in house_list:
if decrypt_str(house.get('status')) == "已售": continue
print('****每户分割线****')
print('楼层:', decrypt_str(house.get('floor')))
print('套内:', decrypt_str(house.get('roomNo')))
print('建面:', decrypt_str(house.get('totalArea')))
print('区域:', decrypt_str(house.get('area')))
print('状态:', decrypt_str(house.get('status')))
if house.get('listWaterPrice'):
print('【价格】:', decrypt_str(house.get('listWaterPrice')))
# 这里其实还有更多字段,后面有空再研究

def start(self):
infos = self.get_list()

# 只取一个小区测试
_id = infos.get('data')[0].get('id')
data = self.get_building(_id)
buildings = self.one_fun(data, _id)

# 只取一栋楼测试
buildingId = buildings.get('data')[0].get('buildingId')
datas = self.getHousePrice(buildingId, _id)
self.parse_data(datas)


if __name__ == '__main__':
fun = Fun()
fun.start()
84 changes: 84 additions & 0 deletions 其他实战/【房价】房价获取/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- encoding: utf-8 -*-
# Auth: Zok Email: [email protected]
# Date: 2020/2/21


from pyDes import *
import base64

KEY = b'hjkiuy6754edxc32890tfhjkw23xdea'[:24] # 密钥只需要24位
IV = b'jhf5632s'


def des3_encrypt(s):
"""
3DES 加密
:param s: 原始字符串
:return: 加密后字符串,16进制
"""
k = triple_des(KEY, CBC, IV, pad=None, padmode=PAD_PKCS5)
en = k.encrypt(s, padmode=PAD_PKCS5)
return base64.b64encode(en).decode('utf-8')


def des3_decrypt(s):
"""
3DES 解密
:param s: 加密字符串
:return: 明文
"""
_str = base64.b64decode(s)
k = triple_des(KEY, CBC, IV, pad=None, padmode=PAD_PKCS5)
en = k.decrypt(_str, padmode=PAD_PKCS5).decode('utf-8')
return en


def decrypt_str(s):
info = des3_decrypt(s) # 获得 解密后得 base64
content = info[:-6]
hIndex = base64.b64decode(info[-6:].replace("==", "")).decode().split("_")
content2 = content[int(hIndex[0]):]
txt = base64.b64decode(
content2[: len(content2)-int(hIndex[1])][::-1]
).decode('utf-8').replace("##", "").replace("{@mk7}", "")
return txt


def make_str(enB):
"""
复写字符串算法
根据传入文档,转换ascii并计算和
并复写算法
for (byte item : enB.getBytes("UTF-8")) {
sumResult = Long.valueOf(sumResult.longValue() + ((long) item));
}
"""
count = 0
for i in enB:
count += ord(i)
# print('合', count) # 每个字符的 Ascii 码的总和
p = count % len(enB)
n = 1
# print('position', p)
while p + n < len(enB) and p - n >= 0:
enB = rep(
rep(enB, p + n, enB[p - n]),
p - n,
enB[p + n]
)
n += 1
return enB


def rep(source, index, rep_str):
"""
复写的java层字符转换方法
:return:
"""
str1 = source[0: index]
return str1 + rep_str + source[index + 1:]


if __name__ == '__main__':
decrypt_str("AaDaKV8GxE77rIScVyq7E0rebiFQjhrkq8PUcmR8A22NHhAW58pQkQ==")

0 comments on commit 7e8a8bc

Please sign in to comment.