Browse Source

定义响应码

luqingbin 3 years ago
parent
commit
7ae26433d5

+ 0 - 26
src/main/java/com/github/yxyl120/opensdk/Utils/HttpUtils.java

@@ -1,9 +1,5 @@
 package com.github.yxyl120.opensdk.Utils;
 package com.github.yxyl120.opensdk.Utils;
 
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.yxyl120.opensdk.domain.RequestParameter;
-import com.github.yxyl120.opensdk.domain.order.OrderInfo;
 import com.github.yxyl120.opensdk.YxException;
 import com.github.yxyl120.opensdk.YxException;
 
 
 import java.io.*;
 import java.io.*;
@@ -15,20 +11,6 @@ public class HttpUtils {
 
 
     private static final Charset CHARSET = Charset.forName("UTF-8");
     private static final Charset CHARSET = Charset.forName("UTF-8");
 
 
-    /**
-     * 推送订单到一线平台
-     *
-     * @param api       接口
-     * @param parameter 接口参数
-     * @return 推送结果
-     * @throws YxException
-     */
-    public static String pushOrder(String api, RequestParameter<OrderInfo> parameter) throws YxException {
-        ParameterCheckUtils.checkParameters(parameter);
-        String sign = SignUtils.sign(parameter);
-        parameter.setSig(sign);
-        return post(api, toJson(parameter));
-    }
 
 
     /**
     /**
      * 请求一线api专用post请求
      * 请求一线api专用post请求
@@ -74,14 +56,6 @@ public class HttpUtils {
         return result.toString();
         return result.toString();
     }
     }
 
 
-    private static String toJson(Object object) {
-        ObjectMapper mapper = new ObjectMapper();
-        try {
-            return mapper.writeValueAsString(object);
-        } catch (JsonProcessingException e) {
-            return "";
-        }
-    }
 
 
     private static void close(Closeable closeable) {
     private static void close(Closeable closeable) {
         try {
         try {

+ 36 - 0
src/main/java/com/github/yxyl120/opensdk/YxClient.java

@@ -0,0 +1,36 @@
+package com.github.yxyl120.opensdk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.yxyl120.opensdk.Utils.HttpUtils;
+import com.github.yxyl120.opensdk.Utils.ParameterCheckUtils;
+import com.github.yxyl120.opensdk.Utils.SignUtils;
+import com.github.yxyl120.opensdk.domain.RequestParameter;
+import com.github.yxyl120.opensdk.domain.order.OrderInfo;
+
+public class YxClient {
+
+    /**
+     * 推送订单到一线平台
+     *
+     * @param api       接口
+     * @param parameter 接口参数
+     * @return 推送结果
+     * @throws YxException
+     */
+    public static String pushOrder(String api, RequestParameter<OrderInfo> parameter) throws YxException {
+        ParameterCheckUtils.checkParameters(parameter);
+        String sign = SignUtils.sign(parameter);
+        parameter.setSig(sign);
+        return HttpUtils.post(api, toJson(parameter));
+    }
+
+    private static String toJson(Object object) {
+        ObjectMapper mapper = new ObjectMapper();
+        try {
+            return mapper.writeValueAsString(object);
+        } catch (JsonProcessingException e) {
+            return "";
+        }
+    }
+}

+ 35 - 0
src/main/java/com/github/yxyl120/opensdk/enums/ResponseCode.java

@@ -0,0 +1,35 @@
+package com.github.yxyl120.opensdk.enums;
+
+/**
+ * 一线服务器返回的响应码与说明
+ */
+public enum ResponseCode {
+
+    SUCCESS(200, "请求成功"),
+
+    InvalidAppId(201, "appId非法"),
+    InvalidSecret(201, "密钥非法"),
+    SignatureExpire(301, "签名过期。Timestamp 和服务器时间相差不得超过五分钟,请检查本地时间是否和标准时间同步"),
+    SignatureFailure(302, "签名错误。签名计算错误,请对照调用方式中的签名方法文档检查签名计算过程"),
+    MissingParameter(501, "缺少参数"),
+    InvalidParameter(502, "参数错误(包括参数格式、类型等错误)"),
+    InvalidParameterValue(503, "参数取值错误"),
+    ServiceError(400, "服务器内部错误");
+
+    private int code;
+
+    private String desc;
+
+    ResponseCode(int code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+}