修改/编写记录(线上文档目前不做更新,一切以本文档提供字段为准)
Ps:1,查询接口返回total是条件下总数据,必须配合page_no和page_size来分页取数据;
2,新增接口中数量以及金额字段类型建议传字符串类型;
3,由于客户本地开发环境的不同,提供的任何代码实例仅供参考;
云ERP API调用接口方法详解请看以下连接:
云ERP接口规范说明
1)接口协议:json 报文 (UTF-8 编码)
2)接口方式:http post 方式
> 格式:{"appkey":"xxx","sessionkey":"xxx","method":"xxx","args1":"xxx","args2":"xxx","args3":"xxx",...,"sign":"xxx"}
> appkey、sessionkey、method、sign均为系统级参数,args1、args2、args3等均为应用级参数,参数名称以各接口真实情况为准
> appkey、sessionkey、secret可在ERP“控制面板-应用授权-云ERP授权”页面中获取,sign为数据签名,无法直接获取
3)接口地址:需根据客户所在环境选择调用地址
C-erp登陆地址 | 对应api地址 |
www.guanyierp.com | http://api.guanyierp.com/rest/erp_open |
v2.guanyierp.com | http://v2.api.guanyierp.com/rest/erp_open |
demo.guanyierp.com | http://api.demo.guanyierp.com/rest/erp_open |
erp.edgj.net | http://open.edgj.net/rest/erp_open |
签名详情(sign)
首先将请求参数拼接成标准的 json 格式字符串(此时应不包含sign字段及其内容。建议:先将字符串转为 json 对象,再由对象转为字符串,以此得到格式化后的标准形式),接着在字符串的首尾加上用户的secret(可在ERP的“控制面板-应用授权-云ERP授权”页面中获取),最后对其进行MD5(32位大写)加密,得到最终的签名
系统级请求参数
字段名 | 参数类型 | 字段解释 |
appkey | String | Appkey |
sessionkey | String | Sessionkey |
method | String | 请求的接口方法名 |
sign | String | 数据签名 |
系统级返回参数
字段名 | 参数值 | 字段解释 |
success | true/false | 响应成功/响应失败 |
errorCode | (成功时为空) | 错误代码 |
subErrorCode | (成功时为空) | 子错误代码 |
errorDesc | (成功时为空) | 错误描述 |
subErrorDesc | (成功时为空) | 子错误描述 |
requestMethod | gy.erp.stock.get | 请求接口方法 |
附录1:签名方法(java)
// 得到sign的字符串 public static String sign(String str, String secret) { logger.info("source: " + str); logger.info("secret: " + secret); StringBuilder enValue = new StringBuilder(); enValue.append(secret); enValue.append(str.toString()); enValue.append(secret); logger.info("append secret: " + enValue.toString()); logger.info("sign: " + encryptByMD5(enValue.toString())); return encryptByMD5(enValue.toString()); } // MD5 private static String encryptByMD5(String data) { StringBuilder sign = new StringBuilder(); try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bytes = md.digest(data.getBytes("UTF-8")); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); } sign.append(hex.toUpperCase()); }
} catch (Exception e) { e.printStackTrace(); } return sign.toString(); } |
附录2:请求方法(java)
public static void sendPost(String url, String data) { logger.info("url: " + url); logger.info("request: " + data); try { CloseableHttpClient httpclient = null; CloseableHttpResponse httpresponse = null; try { httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost(url); StringEntity stringentity = new StringEntity( data, ContentType.create("text/json", "UTF-8")); httppost.setEntity(stringentity); httpresponse = httpclient.execute(httppost); String response = EntityUtils .toString(httpresponse.getEntity()); logger.info("response: " + response); } finally { if (httpclient != null) { httpclient.close(); } if (httpresponse != null) { httpresponse.close(); } } } catch (Exception e) { e.printStackTrace(); } } |
Php实例代码:http://www.dooccn.com/php/#id/783cb41b15a69d924b09a8981747c4aa