Created
May 18, 2017 10:09
-
-
Save bramblex/06c6d6a6cbf2c3716e5a26ea9a9471c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const request = require('request-promise-native').defaults({ | |
json: true, | |
headers: { | |
'systemVersionCode': '19', | |
'source': '4', | |
'SYSCODE': '20', | |
'versionCode': '32', | |
'deviceId': '865127010282718', | |
'phoneModel': 'Lenovo A850', | |
'User-Agent': 'Dalvik/1.6.0 (Linux; U; Android 4.4.2; Lenovo A850 Build/JDQ39)' | |
} | |
}) | |
class Door { | |
constructor() { | |
this.token = null | |
this.doors = null | |
this.communityId = null | |
} | |
async login(tel, password) { | |
const {data: {accessToken}} = await request.post({ | |
uri: 'http://www.uhomecp.com/uhomecp-sso/v2/userApp/info/login', | |
form: {password, tel}, | |
}) | |
this.token = accessToken | |
} | |
async getList() { | |
const {data} = await request.get({ | |
uri: 'http://www.uhomecp.com/uhomecp-app/door/myDoorList.json', | |
headers: { token: this.token }, | |
}) | |
this.doors = {} | |
for (let door of data) { | |
this.doors[door.doorId] = { | |
doorId: door.doorId, | |
name: door.name, | |
communityId: door.communityId, | |
doorIdStr: door.doorIdStr | |
} | |
} | |
} | |
async open (id) { | |
const door = this.doors[id] | |
const result = await request.post({ | |
uri: 'http://www.uhomecp.com/uhomecp-app/door/openDoor.json', | |
headers: { token: this.token }, | |
form: {doorIdStr: door.doorIdStr, communityId: door.communityId}, | |
}) | |
return result.code === '0' ? true : false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment