### JAVA示例代码
```
package com.ksxing;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
/**
* Created by examstar on 2018/8/1.
*/
public class KSXJWTUtil {
/**
* 客户唯一标识符,由考试星提供,需替换成自己的appId
*/
private static final int appId = 123456;
/**
* 用于加密jwt,由考试星提供,需替换成自己的appKey
*/
private static final String appKey = "debae3071b7d48818fe51a1fbc1b1113";
/**
* 生成jwtInfo
*
* @param actionId
* @return
*/
private static String getJWTInfo(String actionId) {
String jwtInfo = null;
try {
jwtInfo = Jwts.builder()
.setHeaderParam("alg", "HS256")
.setHeaderParam("typ", "JWT")
.claim("exp", System.currentTimeMillis() + 1000 * 10)
.claim("action_id", actionId)
.signWith(
SignatureAlgorithm.HS256,
appKey.getBytes(StandardCharsets.UTF_8.toString())
)
.compact();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return jwtInfo;
}
/**
* 获取post请求地址
*
* @param actionId
* @return
*/
public static String getPostUrl(String actionId) {
/**
* 考试星域名
*/
String domainUrl = "https://api.kaoshixing.com";
String postUrl = String.format("%s/api/company/data/%d/?jwt=%s", domainUrl, appId, getJWTInfo(actionId));
return postUrl;
}
}
```
```
package com.ksxing;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.nio.charset.StandardCharsets;
/**
* Created by examstar on 2018/8/1.
*/
public class KSXPostUtil {
public static String sendPost(String url, String body) {
String responseContent = null;
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json");
httpPost.setEntity(new StringEntity(body, StandardCharsets.UTF_8.toString()));
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8.toString());
response.close();
httpClient.close();
} catch (Exception e) {
e.printStackTrace();
}
return responseContent;
}
}
```
###
```
package com.ksxing;
import net.sf.json.JSONObject;
/**
* Created by examstar on 2018/8/1.
*/
public class KSXPostUtilTest {
public static void main(String[] args) {
String postUrl = KSXJWTUtil.getPostUrl("201");
JSONObject json = new JSONObject();
json.put("user_id", "ksx001");
json.put("user_name", "考试星测试");
json.put("role", "staff");
json.put("department", "总部");
System.out.println(KSXPostUtil.sendPost(postUrl, json.toString()));
}
}
```
- 常见问题
- 如何发布一场考试?
- 如何创建一个课程?
- 如何发布一场直播?
- 如何发布一场每日学练计划?
- 如何创建一个自定义任务?
- 如何在考试星系统中调用摄像头
- 如何开通专属微信小程序?
- 如何规范考生答题前人脸识别核验?
- 【会否培训平台】功能概述
- 第一部分 后台管理端使用文档
- 第一章 首页
- 第二章 考试
- 防作弊功能介绍
- 分题流水判卷功能讲解
- 监考视频下载工具
- 第三章 学习项目(原任务流程)
- 第四章 课程
- 第五章 直播
- 第六章 每日学练
- 第七章 线下培训(仅支持移动端)
- 第八章 报名
- 第九章 问卷
- 第十章 证书
- 第十一章 数据中心
- 第十二章 资源管理
- 第十三章 学员管理
- 第十四章 公告管理
- 第十五章 店铺管理
- 第十六章 系统设置
- 第二部分 学员端产品使用文档
- 第一章 学员注册与登录
- 第二章 学员学习中心——PC端
- 第三章 学员学习中心——H5端
- 第三部分:开发者文档
- 考试星登录接口文档
- 考试星数据接口文档
- 考试星对外推送接口文档
- 示例代码
- SHA256加密示例(java)
- 上传人脸照片
- 第四部分:推送平台设置文档
- 微信公众号消息推送配置文档
- 《考试星在线考试系统》白皮书