电脑能控制手机吗?可以同时控制多部手机吗?当然是可以的。通过手机多控软件就可以实现这个功能。Total Control作为安卓手机的多控系统,是我用过的各方面都很稳定不仅可以实现同时控制多到100部手机,还可以通过脚本实现各种功能的软件。识别颜色是其强大功能之一,本文我就说说如何用Total Control 提供的REST API 实现单点比较颜色,支持颜色范围,相似度比较颜色。
Total Control 提供的REST API:
请求参数:
请求示例:
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/colors/color?token=270eq7lXQK8bXYsJ&x=566&y=729&color=0xffffff&sim=0.3
响应示例:
{
"value":"",
"status":true
}
Python示例:
#!/user/bin/python
#-*- coding:utf-8 -*-
import base64
import requests
# The username and password are separated by a single : and sent on the wire base64 encoded
user_pass = 'sigma:3D391497'
encodeStr = base64.b64encode(user_pass.encode("UTF-8"))
# First step: Get the API token
LoginUrl = "http://localhost:8090/TotalControl/v1/login"
response = requests.get(LoginUrl, headers={'Authorization':encodeStr})
print("Get the token,Return value: ",response.json())
token = response.json()['value']['token']
print("The value of token is: ",token)
# Second step: Get the device id value of the master device
if token is not None:
GetDeviceUrl = "http://localhost:8090/TotalControl/v1/devices/main?token=" + token
response = requests.get(url=GetDeviceUrl)
print("Get the device id,Return value: ", response.json())
device = response.json()['id']
print("The value of device id is: ", device)
if device is not None:
# Third step: Execute this REST API
APIUrl = "http://localhost:8090/TotalControl/v1/devices/" + device + "/screen/colors/color"
data = {
"x": 566,
"y": 729,
"color": "0xffffff",
"sim": 0.9,
"token": token
}
response = requests.get(url=APIUrl, params=data)
ret = response.json()['status']
# Determine if this REST API is executed successfully
if ret is True:
print("Executed successfully,Return value: ", response.json())
elif response.status_code == 200 and ret is not True:
print("An error message is returned: ",response.json())
else:
print("This API failed to execute.")
else:
print("Failed to get device id.")
else:
print("Failed to get token.")
运行结果:
Get the token,Return value: {'status': True, 'value': {'token': 'lo7ssQ12KgkM6ik7'}}
The value of token is: lo7ssQ12KgkM6ik7
Get the device id,Return value: {'id': 'device@33254183'}
The value of device id is: device@33254183
Executed successfully,Return value: {'status': True, 'value': ''}
看起来复杂,其实确实有点复杂,不过别怕,Total Control就是考虑到很多脚本语言并不是特别容易掌握,所以才提供了Rest API,我们可以选择简单的脚本语言入手。Total Control会帮我做转换,速度官网下载走起!