全程云>开发者平台> 接口开发示例

接口开发示例

  • 获取令牌(token):

    http://[customer-site]/WebApi/Handler/1.0/Sys/Token/Get.ashx

    请求示例(C#):

    string url = "http://[customer-site]/WebApi/Handler/1.0/Sys/Token/Get.ashx";

    string data = "format=json&org_id=xxx&login_name=xxx&password=xxx&is_encrypt=xxx&app_id=xxx";

    string result = RequestApi(url, data);

    /// <summary>

    /// 发送HTTP请求

    /// </summary>

    /// <param name="url">请求的URL</param>

    /// <param name="data">请求的参数</param>

    /// <returns>请求结果</returns>

    public static string RequestApi(string url, string data)

    {

    WebClient wc = new WebClient();

    wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

    wc.Encoding = Encoding.UTF8;

    string result = wc.UploadString(url, data);

    return result;

    }

    返回结果:

    {"value":"99413ec3-a3df-4a9e-a160-7479a5593116"}

    参数说明:

    customer-site:替换成WebApi部署站点

    format:可选,返回数据格式,默认为json

    org_id:组织机构id

    login_name:登录帐号

    password:登录密码

    is_encrypt:是否加密(默认false:不加密,true:加密)

    app_id:应用id 由全程软件授权后提供

    以上为get方式调用接口,post方式只需按post方式构造请求数据即可

  • 获取当前用户信息:

    http://[customer-site]/WebApi/Handler/1.0/IBP/User/GetCurrentUser.ashx

    请求示例(C#):

    string url = "http://[customer-site]/WebApi/Handler/1.0/IBP/User/GetCurrentUser.ashx";

    string data = "token=99413ec3-a3df-4a9e-a160-7479a5593116&format=json";

    string result = RequestApi(url, data);

    /// <summary>

    /// 发送HTTP请求

    /// </summary>

    /// <param name="url">请求的URL</param>

    /// <param name="data">请求的参数</param>

    /// <returns>请求结果</returns>

    public static string RequestApi(string url, string data)

    {

    WebClient wc = new WebClient();

    wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

    wc.Encoding = Encoding.UTF8;

    string result = wc.UploadString(url, data);

    return result;

    }

    返回结果:

    {"value":{

    "PK_ID": 127,

    "sLoginName": "zxg-test",

    "sPassWord": "6E-CE-4F-D5-1B-C1-13-94-26-92-63-7D-9D-4B-86-0E",

    "sName": "zxg-test",

    "sNameEn": "",

    "iSex": 1,

    "dCreatedDate": "2013-08-10 13:33:37",

    "iUserType": 0,

    "iLock": 0,

    "iSuspend": 0,

    "iIsDel": 0,

    "uKey": "",

    "TrueDate": "1900-01-01 00:00:00",

    "sEmp_ID": "101",

    "NetSize": 0,

    "MailSize": 0,

    "iAuthLogin": 0,

    "sWorkNo": null,

    "iIsRole": 1

    }

    }

    参数说明:

    customer-site:替换成WebApi部署站点

    format:可选,返回数据格式,默认为json

    token:接口调用令牌,除了login不需要token,其他所有接口调用都必须包含此项

    以上为get方式调用接口,post方式只需按post方式构造请求数据即可

  • 获取令牌(token):

    http://[customer-site]/WebApi/Handler/1.0/Sys/Token/Get.ashx

    请求示例(Java):

    String  url = "http://[customer-site]/WebApi/Handler/1.0/Sys/Token/Get.ashx";

    String  data = "format=json&org_id=xxx&login_name=xxx&password=xxx&is_encrypt=xxx&app_id=xxx";

    String  result = RequestApi(url, data);

    /**

    * @param url

    *            :请求接口

    * @param data

    *            :参数

    * @return 返回结果

    */

    public static String request(String url, String data) {

    BufferedReader reader = null;

    String result = null;

    StringBuffer sbf = new StringBuffer();

    url = url + "?" + data;

    try {

    URL url = new URL(url);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setRequestMethod("GET");

    connection.connect();

    InputStream is = connection.getInputStream();

    reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

    String strRead = null;

    while ((strRead = reader.readLine()) != null) {

    sbf.append(strRead);

    sbf.append("\r\n");

    }

    reader.close();

    result = sbf.toString();

    } catch (Exception e) {

    e.printStackTrace();

    }

    return result;

    }

    返回结果:

    {"value":"99413ec3-a3df-4a9e-a160-7479a5593116"}

    参数说明:

    customer-site:替换成WebApi部署站点

    format:可选,返回数据格式,默认为json

    org_id:组织机构id

    login_name:登录帐号

    password:登录密码

    is_encrypt:是否加密(默认false:不加密,true:加密)

    app_id:应用id 又全程软件授权后提供

    以上为get方式调用接口,post方式只需按post方式构造请求数据即可

  • 获取当前用户信息:

    http://[customer-site]/WebApi/Handler/1.0/IBP/User/GetCurrentUser.ashx

    请求示例(Java):

    String url = "http://[customer-site]/WebApi/Handler/1.0/IBP/User/GetCurrentUser.ashx";

    String data = "token=99413ec3-a3df-4a9e-a160-7479a5593116&format=json";

    String result = RequestApi(url, data);

    /**

    * @param url

    *            :请求接口

    * @param data

    *            :参数

    * @return 返回结果

    */

    public static String request(String url, String data) {

    BufferedReader reader = null;

    String result = null;

    StringBuffer sbf = new StringBuffer();

    url = url + "?" + data;

    try {

    URL url = new URL(url);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setRequestMethod("GET");

    connection.connect();

    InputStream is = connection.getInputStream();

    reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

    String strRead = null;

    while ((strRead = reader.readLine()) != null) {

    sbf.append(strRead);

    sbf.append("\r\n");

    }

    reader.close();

    result = sbf.toString();

    } catch (Exception e) {

    e.printStackTrace();

    }

    return result;

    }

    返回结果:

    {"value":{

    "PK_ID": 127,

    "sLoginName": "zxg-test",

    "sPassWord": "6E-CE-4F-D5-1B-C1-13-94-26-92-63-7D-9D-4B-86-0E",

    "sName": "zxg-test",

    "sNameEn": "",

    "iSex": 1,

    "dCreatedDate": "2013-08-10 13:33:37",

    "iUserType": 0,

    "iLock": 0,

    "iSuspend": 0,

    "iIsDel": 0,

    "uKey": "",

    "TrueDate": "1900-01-01 00:00:00",

    "sEmp_ID": "101",

    "NetSize": 0,

    "MailSize": 0,

    "iAuthLogin": 0,

    "sWorkNo": null,

    "iIsRole": 1

    }

    }

    参数说明:

    customer-site:替换成WebApi部署站点

    format:可选,返回数据格式,默认为json

    token:接口调用令牌,除了login不需要token,其他所有接口调用都必须包含此项

    以上为get方式调用接口,post方式只需按post方式构造请求数据即可