package zs.payment.resp; import com.alibaba.fastjson.annotation.JSONField; import java.util.HashMap; import java.util.Map; /** * 统一响应封装 */ public class Result { @JSONField(name = "body") private Map body; private Result(Map body) { this.body = body; } public static Result success() { Map body = new HashMap<>(); body.put("CODE", 200); body.put("MSG", "SUCCESS"); return new Result(body); } // public static Result success(String token) { // Map body = new HashMap<>(); // body.put("CODE", 200); // body.put("MSG", "SUCCESS"); // body.put("token", token); // return new Result(body); // } public static Result success(Object data) { Map body = new HashMap<>(); body.put("CODE", 200); body.put("MSG", "SUCCESS"); body.put("data", data); return new Result(body); } public static Result fail(String msg) { Map body = new HashMap<>(); body.put("CODE", 500); body.put("MSG", msg); return new Result(body); } public Map getBody() { return body; } public boolean isSuccess() { return Integer.valueOf(200).equals(body.get("CODE")); } }