1.api接口说明

  • api接口采用jwt规范。Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场景。JWT调用示例代码


2.api参数配置

  • appId : 客户唯一标识符,由考试星提供,例如:14343。
  • appKey : 用于加密/解密jwt,由考试星提供,例如:xf5ha3h67h4Ger34wh35p345h4。
  • 获取方式:【管理员后台:系统设置->更多设置->开发者信息管理】


3.考试星提供api统一接口地址


4.客户提供api统一接口地址


5.生成加密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;
}


6.action_id参数解释


action_id调用方请求行为类型10000客户查询考生考试结果信息10001考试星回传考生考试结果信息。


7.查询考生考试结果信息


action_id = 10000

请求地址:https://api.kaoshixing.com/api/company/data/:appId?jwt=:jwtInfo

请求方式:POST


请求参数:

参数名称是否必填类型参数描述
userIdString考生唯一标识
examIdint考试id
commitTimeStartString起始交卷时间
commitTimeEndString最晚交卷时间
pageint页数,每页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
}


8.同步考生的考试结果(客户提供)


action_id = 10001


时序图:


请求地址(仅作示例):https://www.example.com/api/company/data/:appId?jwt=:jwtInfo

请求方式:POST


请求参数:


参数编号参数名称类型参数描述
1jwtString包含action_id的加密字符串
2paramsJSONObject包含考生的考试信息


参数示例:

{
    "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"
    }
}


参数说明:


返回数据:

{
    "success":true,
    "code":10000,
    "desc":"成功",
    "bizContent":null
}