最近又有游戏要对接网络游戏防沉迷实名认证系统接口,又又搞了我三天两夜才把接口对接完毕,确实难受的一批.其实之前对接过,无奈没有保留代码,导致痛苦的事情又经历一遍,这次总结经验,于是有了这篇文章.
首先记录下(备忘)官方网站地址:网络游戏防沉迷实名认证系统 (nppa.gov.cn)
接着上正戏,因为本人从事的是Java,所有只有Java的实现,不是同行可以先走一步了,本人得意声明:所有代码都是我自己写的,如有雷同不胜荣幸!
1.先看看我的代码目录结构
接着就是每一个类的内容展示(顺序从上至下):
2.接口回调的所有编码,我做成枚举类
package com.xxx.xxx.api.authentication.enumData;public enum AuthResponseCode {OK(0, "OK", "请求成功"),SYS_ERROR(1001, "SYS ERROR", "系统错误"),SYS_REQ_RESOURCE_NOT_EXIST(1002, "SYS REQ RESOURCE NOT EXIST", "接口请求的资源不存在"),SYS_REQ_METHOD_ERROR(1003, "SYS REQ METHOD ERROR", "接口请求方式错误"),SYS_REQ_HEADER_MISS_ERROR(1004, "SYS REQ HEADER MISS ERROR", "接口请求核心参数缺失"),SYS_REQ_IP_ERROR(1005, "SYS REQ IP ERROR", "接口请求IP地址非法"),SYS_REQ_BUSY_ERROR(1006, "SYS REQ BUSY ERROR", "接口请求超出流量限制"),SYS_REQ_EXPIRE_ERROR(1007, "SYS REQ EXPIRE ERROR", "接口请求过期"),SYS_REQ_PARTNER_ERROR(1008, "SYS REQ PARTNER ERROR", "接口请求方身份非法"),SYS_REQ_PARTNER_AUTH_DISABLE(1009, "SYS REQ PARTNER AUTH DISABLE", "接口请求方权限未启用"),SYS_REQ_AUTH_ERROR(1010, "SYS REQ AUTH ERROR", "接口请求方无该接口权限"),SYS_REQ_PARTNER_AUTH_ERROR(1011, "SYS REQ PARTNER AUTH ERROR", "接口请求方身份核验错误"),SYS_REQ_PARAM_CHECK_ERROR(1012, "SYS REQ PARAM CHECK ERROR", "接口请求报文核验失败");private final int code;private final String message;private final String description;AuthResponseCode(int code, String message, String description) {this.code = code;this.message = message;this.description = description;}public int getCode() {return code;}public String getMessage() {return message;}public String getDescription() {return description;}public static AuthResponseCode fromCode(int code) {for (AuthResponseCode responseCode : AuthResponseCode.values()) {if (responseCode.getCode() == code) {return responseCode;}}throw new IllegalArgumentException("Unknown error code: " + code);}
}
3.实体DO类
package com.xxx.xxx.api.authentication.vo;import lombok.Data;@Data
public class AuthResponse<T> {private Integer errcode;private String errmsg;private T data;}
package com.xxx.xxx.api.authentication.vo;public class AuthResponseData {private CheckQueryResult result;public CheckQueryResult getResult() {return result;}public void setResult(CheckQueryResult result) {this.result = result;}public static class CheckQueryResult {private int status;private String pi;public int getStatus() {return status;}public void setStatus(int status) {this.status = status;}public String getPi() {return pi;}public void setPi(String pi) {this.pi = pi;}}
}
package com.xxx.xxx.api.authentication.vo;import com.alibaba.fastjson.annotation.JSONType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;@Data
@No