前情提要
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