Line Notify API 串接实作(三)-查询状态及撤销使用者token

前情提要
Line Notify API 串接实作-前置作业
Line Notify API 串接实作(一)-取得access token
Line Notify API 串接实作(二)-推播讯息


Line Notify 提供了我们可以去查询使用者的token状态和撤销使用者的token功能,这些都可以帮助我们更方便的设置Notify设定。

查询使用者token状态

GET https://notify-api.line.me/api/status

请求参数-header
图一

回应参数-header
图二

回应参数-body
图三

postman
图四

checkTokenStatus方法

public static LineNotifyCheckResponse checkTokenStatus(String token) {HttpHeaders headers = new HttpHeaders();headers.setBearerAuth(token);HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(headers);ResponseEntity<LineNotifyCheckResponse> lineNotifyCheckResponse = restTemplate.exchange(LineNotifyUrl.TOKEN_STATUS_CHECK.getUrl(), LineNotifyUrl.TOKEN_STATUS_CHECK.getHttpMethod(), entity, LineNotifyCheckResponse.class);if(!lineNotifyCheckResponse.getStatusCode().equals(HttpStatus.OK)) {throw new LineNotifyUtilException(LineNotifyErrorEnum.TOKEN_STATUS_CHECK_ERROR.getError(),LineNotifyErrorEnum.TOKEN_STATUS_CHECK_ERROR.getMessage());}return lineNotifyCheckResponse.getBody();}

LineNotifyCheckResponse

@Datapublic class LineNotifyCheckResponse {private Integer status;private String message;private String targetType;private String target;}

撤销使用者token

POST https://notify-api.line.me/api/revoke

请求参数-header
图五

回应参数-header
图六

回应参数-body
图七

postman
图八

Line讯息弹出
图九

revoke方法

public static LineNotifyRevokeResponse revoke(String token) {HttpHeaders headers = new HttpHeaders();headers.setBearerAuth(token);HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(headers);ResponseEntity<LineNotifyRevokeResponse> lineNotifyRevokeResponse = restTemplate.exchange(LineNotifyUrl.TOKEN_REVOKE.getUrl(), LineNotifyUrl.TOKEN_REVOKE.getHttpMethod(), entity, LineNotifyRevokeResponse.class);if(!(lineNotifyRevokeResponse.getStatusCode().equals(HttpStatus.OK))&&   !(lineNotifyRevokeResponse.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) ) {throw new LineNotifyUtilException(LineNotifyErrorEnum.TOKEN_REVOKE_FAIL.getError(),LineNotifyErrorEnum.TOKEN_REVOKE_FAIL.getMessage());}return lineNotifyRevokeResponse.getBody();}

LineNotifyRevokeResponse物件

@Datapublic class LineNotifyRevokeResponse {private String status;private String message;}

好了,那我们Line Notify的讲解到此告一段落,之后有机会再来实作看看Line其他有趣的API

参考资料
Line Notify Document


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章