企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 1.api接口说明 * api接口采用jwt规范。Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场景。[JWT调用示例代码](https://www.kancloud.cn/exam-star/ksxhelp_1/1797394) ### 2.api参数配置 * appId : 客户唯一标识符,由考试星提供,例如:14343。 * appKey : 用于加密/解密jwt,由考试星提供,例如:xf5ha3h67h4Ger34wh35p345h4。 获取方式:【管理员后台:系统设置->更多设置->开发者信息管理】 ### 3.1考试星提供api统一接口地址 * 地址: https://api.kaoshixing.com/api/company/data/:appId?jwt=:jwtInfo * 请求方式:post * jwtInfo:jwt_info是根据jwt规范,用appKey将过期时间、action_id加密,生成的加密字符串 ### 3.2客户提供api统一接口地址 * 地址(仅作示例):https://www.example.com/api/company/data/:appId?jwt=:jwtInfo * 请求方式:post * jwtInfo:jwt_info是根据jwt规范,用appKey将过期时间、action_id加密,生成的加密字符串 ### 4.生成加密jwtInfo和解密(java示例) (1).安装依赖 ``` <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.7.0</version> </dependency> ​ ``` (2).生成加密字符串 ``` import io.jsonwebtoken.Jwts; String appKey = “xf5ha3h67h4Ger34wh35p345h4” String jwtInfo = Jwts.builder() .claim("exp", System. currentTimeMillis() + 1000*10) .claim("action_id", "201") .signWith(SignatureAlgorithm.HS256,appKey.getBytes("UTF-8")).compact(); ​ ``` (3).加密参数解释 ``` appKey:加密的私钥,由考试星提供。 exp:过期时间。 action_id:请求行为类型。 ``` (4).解密方法示例 ``` import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.Jwts; ​ public Boolean decodeJwt(String jwtInfo, String appKey) { try { Claims claims; claims = Jwts.parser().setSigningKey(appKey.getBytes("UTF-8")).parseClaimsJws(jwtInfo).getBody(); String actionId = null == claims.get("action_id") || "".equals(claims.get("action_id")) ? "" : claims.get("action_id").toString(); /** * 处理action_id */ } catch (ExpiredJwtException e) { LOGGER.info("decodeJwt解密失败!"); return false; } catch (Exception e) { LOGGER.info("decodeJwt解密失败!"); return false; } return true; } ``` ### 5.action_id参数解释 | **action_id** | **调用方** | **请求行为类型** | |:----|:----|:----| | 10000 | 客户 | 查询考生考试结果信息 | | 10001 | 考试星 | 回传考生考试结果信息 | ### 6.查询考生考试结果信息 action_id = 10000 请求地址:https://api.kaoshixing.com/api/company/data/:appId?jwt=:jwtInfo 请求方式:POST 请求参数: | **参数编号** | **参数名称** | 是否必填 | **类型** | **参数描述** | | ------------ | --------------- | -------- | -------- | -------------------- | | 1 | userId | 是 | String | 考生唯一标识(账号) | | 2 | examId | 否 | int | 考试id | | 3 | commitTimeStart | 否 | String | 起始交卷时间 | | 4 | commitTimeEnd | 否 | String | 最晚交卷时间 | | 5 | page | 是 | int | 页数,每页5条数据 | 参数示例: ``` { "userId":"zhangsan", "examId":47167, "commitTimeStart":"2021-06-01 08:00:00", "commitTimeEnd":"2021-06-30 20:00:00", "page":1 } ``` 正常返回: ``` { "success":true, "code":10000, "desc":"成功", "englishDesc":"Success", "bizContent":{ "total":2, "current":1, "rowCount":5, "rows":[ { "userId":"zhangsan", "examId":47167, "examName":"期末考试", "examStartTime":"2021-06-02 14:18:00", "examEndTime":"2021-06-30 14:18:00", "examTime":60, "startTime":"2021-06-03 11:44:37", "commitTime":"2021-06-03 11:44:44", "score":"0.0", "isPass":0, "times":2, "examResultsId":40561249, "examStyleName":"考试分类", "examStyleId":20046 }, { "userId":"zhangsan", "examId":47167, "examName":"期末考试", "examStartTime":"2021-06-02 14:18:00", "examEndTime":"2021-06-30 14:18:00", "examTime":60, "startTime":"2021-06-02 14:19:17", "commitTime":null, "score":"0.0", "isPass":0, "times":1, "examResultsId":40561220, "examStyleName":"考试分类", "examStyleId":20046 } ] } } ``` 参数说明: | **参数** | **类型** | **说明** | |:----|:----|:----| | userId | String | 客户内部考生id | | examId | int | 考试id | | examName | String | 考试名称 | | examStartTime | String | 考试开始时间 | | examEndTime | String | 考试结束时间 | | examTime | int | 考试时长(分钟) | | startTime | String | 考生开考时间 | | commitTime | String | 考生交卷时间 | | score | double | 考试分数 | | isPass | int | 是否及格(1及格,0不及格) | | times | int | 考试次数 | | examResultsId | int | 考试结果id | | examStyleName | String | 考试分类名 | | examStyleId | int | 考试分类id | 错误返回: ``` {    "success":false,    "code":31014,    "desc":"用户不存在",    "englishDesc":"user not existed",    "bizContent":null } ``` ### 7.同步考生的考试结果(客户提供) action_id = 10001 时序图: ![](https://img.kancloud.cn/f1/2c/f12c041f70f013ad9b8ed06beea5bd20_1320x1122.jpg) 请求地址(仅作示例):https://www.example.com/api/company/data/:appId?jwt=:jwtInfo 请求方式:POST 请求参数: | **参数编号** | **参数名称** | **类型** | **参数描述** | |:----|:----|:----|:----| | 1 | jwt | String | 包含action_id的加密字符串 | | 2 | params | JSONObject | 包含考生的考试信息 | 参数示例: ``` {    "jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo1LCJleHAiOjE0OTc5NTMxODguNjg0MTIxLCJhY3Rpb25faWQiOiIyMDEifQ.I3j56t_tVMX1GgH62dy-rIktqFRienFZTJ7VKgc6lPs",    "params":{        "commitTime":"2018-10-30 20:00:00",        "examEndTime":"2018-10-31 18:00:00",        "examId":15960,        "examName":"测试考试",        "examStartTime":"2018-10-30 18:00:00",        "examTime":60,        "isPass":1,        "score":100,        "startTime":"2018-10-30 19:00:00",        "times":1,        "userId":"779821sfsf"   } } ​ ``` 参数说明: | **参数** | **类型** | **说明** | |:----|:----|:----| | userId | String | 客户内部考生id | | examId | int | 考试id | | examName | String | 考试名称 | | examStartTime | String | 考试开始时间 | | examEndTime | String | 考试结束时间 | | examTime | int | 考试时长(分钟) | | startTime | String | 考生开考时间 | | commitTime | String | 考生交卷时间 | | score | double | 考试分数 | | isPass | int | 是否及格(1及格,0不及格) | | times | int | 考试次数 | | examResultsId | int | 考试结果id | | examStyleName | String | 考试分类名 | | examStyleId | int | 考试分类id | 返回数据: ``` {    "success":true,    "code":10000,    "desc":"成功",    "bizContent":null } ```