一、服務端配置文件:application.yml
```
config:
#應用id
appId:
#應用密鑰
appSecret:
#服務地址
server-url: https://open.digitalcitizen.com.cn:7280/idauth
```
二、接口代碼
接口controller類:com.nlp.ctids.controller.ValidateIdentityController
接口方法:com.nlp.ctids.controller.ValidateIdentityController#apply
```
@RequestMapping("/{method}/{authMode}")
@ResponseBody
public String apply(@PathVariable String method, @PathVariable String authMode, @RequestBody String jsonData, HttpServletRequest request) {
String accessToken = tokenService.getAccessToken();
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", accessToken);
headers.put("appId", config.appId);
String post = HttpUtil.post(config.serverUrl + "/validateIdentity/" + method + "/" + authMode, jsonData, headers);
return post;
}
```
三、獲取token方法代碼
方法類:com.nlp.ctids.service.TokenService
```
public CommonResponse getAccessToken(String appId, String appSecret) {
CommonResponse commonResponse = tokenMap.get(appId + appSecret);
try {
if (commonResponse != null) {
Map<String, Object> data = (Map<String, Object>) commonResponse.getData();
Long expireTime = (Long) data.get("expireTime");
if (expireTime == null || expireTime < System.currentTimeMillis()) {
commonResponse = null;
}
}
} catch (Exception e) {
commonResponse = null;
}
if (commonResponse != null) {
return commonResponse;
}
Map<String, String> data = new HashMap<>();
data.put("appId", appId);
data.put("appSecret", appSecret);
String response = HttpUtil.post(config.serverUrl + "/auth/getCode", JSON.toJSONString(data), null);
commonResponse = JSON.parseObject(response, CommonResponse.class);
if ("0".equals(commonResponse.getCode())) {
tokenMap.put(appId + appSecret, commonResponse);
}
return commonResponse;
}
```
- CTID身份認證服務能力接入文檔
- 身份認證服務介紹
- 身份認證能力介紹
- 名詞解釋
- 產品定價
- 計費說明
- 接入集成介紹
- API接口列表
- 鑒權接口
- 身份認證接口
- 集成示例
- 集成示例總圖
- 客戶端加密方式接入示例
- 安卓客戶端示例
- IOS客戶端示例
- Java服務端示例
- PHP服務端示例
- 服務端加密接入方式示例
- Java服務端加密示例
- PHP服務端加密示例
- 管理系統介紹
- 登錄
- 機構應用信息
- 身份驗證日志
- 常見問題
- 客戶端加密接入方式FAQ
- Android端FAQ
- IOS端FAQ
- JAVA服務端FAQ
- PHP服務端FAQ
- 服務端加密接入方式FAQ
- JAVA服務端加密FAQ
- PHP服務端加密FAQ
- 平臺FAQ
- 服務端常見異常
- 資料下載
- 客戶端加密接入方式DEMO源碼
- 服務端加密接入方式DEMO源碼