Summary:

  • Login verification and obtain the system token

Version:

No. Editor Edit date Revision date
2.0.0 admin 2020-06-20 2020-06-20

Request URL:

Request mode:

  • POST

Request header:

Parameter Required field Data type Explanation
Content-Type Yes string application/json

Request parameter:

Parameter Required field Data type Explanation
FUserName Yes string System assigned user name
FPassword Yes string Password(MD5(32))

Python -Get MD5-32 password.
E.g. login account’s password is 123456

import hashlib
# python code

def md5sum(password):
        m = hashlib.md5()  
        m.update(password.encode("utf-8")) 
        return m.hexdigest()
print(md5sum('123456'))

#Get Resulst: 'e10adc3949ba59abbe56e057f20f883e'

Response example:

Correct response:

{
    "Result": 200,
    "Message":"success",
    "FObject": [{
        "FUserName": "admin",
        "FUserGUID": "63C399BD-2A0B-40E9-857D-6DEBF4908F92",
        "FTokenID": "DB7F20D9-84C3-44C3-B05A-06A9C392A189",
        "FExpireTime": "2020-07-30T08:00:00"
    }]
}

Error response:

{
    "Result": 103,
    "Message": "userName or password is error",
    "FObject": null
}

Return parameter description:

Parameter Data type Explanation
FUserName String System assigned user name
FUserGUID String User unique ID
FTokenID String token(All subsequent request interfaces need to use this as authentication)
FExpireTime DateTime Account expiration time(UTC)

Other result status description:

  • 106:Account expiration
  • 103:Wrong user name or password
  • 102:Request parameter error

Examples:

Java:

String result = "";
//Request url
String url = "http://cloud.assetscontrols.com:8092/OpenApi/login";
//Request parameters, JSON format parameters, it is recommended to pass in objects
String body = "{FUserName:\"admin\",FPassword:\"E10ADC3949BA59ABBE56E057F20F883E\"}";
URL realUrl = new URL(url);
// Set properties of general request
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "keep-Alive");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("method", "post");
conn.setDoOutput(true);
conn.setDoInput(true);
PrintWriter pw = new PrintWriter(conn.getOutputStream());
// Send request parameters
pw.print(body);
pw.flush();
BufferedReader bufReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = bufReader.readLine()) != null) {
     result += line;
 }
//JSON string is returned
return result;

C#(.NET):

//Request url
string url = "http://cloud.assetscontrols.com:8092/OpenApi/login";  
//Request parameters, JSON format parameters, it is recommended to pass in objects
string body = "{FUserName:\"admin\",FPassword:\"E10ADC3949BA59ABBE56E057F20F883E\"}"; 
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "post";
request.Accept = "*/*";
request.ContentType = "application/json";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
    //JSON string is returned
    return reader.ReadToEnd();
}

Python:

url = 'http://cloud.assetscontrols.com:8092/OpenApi/login'
      data = {
      'FUserName': 'admin',
      'FPassword': 'E10ADC3949BA59ABBE56E057F20F883E'
       }
      data = parse.urlencode(data).encode('utf-8')
      headers = {
       'User-Agent': r'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
                     r'Chrome/45.0.2454.85 Safari/537.36 115Browser/6.0.3',
       'Connection': 'keep-alive'
       }
      req = request.Request(url, headers=headers, data=data)  
      page = request.urlopen(req).read()
      page = page.decode('utf-8')
      return page;
文档更新时间: 2024-12-19 16:52   作者:admin