Browse Source

提交2.0.9测试版本1

kth_win_android 2 years ago
parent
commit
43c65da91e

+ 45 - 0
app/src/main/java/com/mylove/okhttp/AESUtils.java

@@ -0,0 +1,45 @@
+package com.mylove.okhttp;
+
+
+import android.util.Base64;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * @author DELL
+ * @date 2023/4/25 14:49
+ * @user yangjiewei
+ * @email ben@yanyi.red
+ * @overview
+ */
+public class AESUtils {
+    private static final String ALGORITHM = "AES";
+    private static final String KEY = "EBC57497DC9AE3FD19FE8D11F92F77E0"; // 16字节的密钥
+
+    public static String encrypt(String value) {
+        try {
+            SecretKeySpec keySpec = new SecretKeySpec(KEY.getBytes(), ALGORITHM);
+            Cipher cipher = Cipher.getInstance(ALGORITHM);
+            cipher.init(Cipher.ENCRYPT_MODE, keySpec);
+            byte[] encryptedValue = cipher.doFinal(value.getBytes());
+            return new String(Base64.encode(encryptedValue, Base64.DEFAULT));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return value;
+    }
+
+    public static String decrypt(String encryptedValue) {
+        try {
+            SecretKeySpec keySpec = new SecretKeySpec(KEY.getBytes(), ALGORITHM);
+            Cipher cipher = Cipher.getInstance(ALGORITHM);
+            cipher.init(Cipher.DECRYPT_MODE, keySpec);
+            byte[] decryptedValue = cipher.doFinal(Base64.decode(encryptedValue, Base64.DEFAULT));
+            return new String(decryptedValue);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return encryptedValue;
+    }
+}

+ 62 - 10
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -1,6 +1,5 @@
 package com.mylove.okhttp;
 
-import android.Manifest;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -21,6 +20,7 @@ import com.benyanyi.okhttp.listener.OnOkHttpListener;
 import com.benyanyi.permissionlib.PermissionHelper;
 import com.benyanyi.permissionlib.callback.PermissionCallBack;
 import com.benyanyi.permissionlib.type.PermissionType;
+import com.google.gson.Gson;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -52,22 +52,74 @@ public class MainActivity extends AppCompatActivity {
 //        Jlog.d(encryption("123456"));
 //
 //        Jlog.d(string2MD5("123456"));
-        Map<String, Object> map = new HashMap<>();
+        final Map<String, Object> map = new HashMap<>();
         Jlog.d(MD5Utils.MD5Encode("8523697410hijklm" + MD5Utils.mapSort(map) + "1679铆风58611478"));
 
 
         findViewById(R.id.but).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                PermissionHelper.destroy();
-                PermissionHelper.with(MainActivity.this)
-                        .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
-                        .request(new PermissionCallBack() {
+//                PermissionHelper.destroy();
+//                PermissionHelper.with(MainActivity.this)
+//                        .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
+//                        .request(new PermissionCallBack() {
+//                            @Override
+//                            public void onSuccess() {
+////                                Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
+////                                startActivity(intent);
+//                                upload();
+//                            }
+//                        });
+                Map<String, Object> oMap = new HashMap<>();
+                oMap.put("deptId", null);
+                oMap.put("ids", null);
+                String json = new Gson().toJson(oMap);
+                Map<String, Object> map = new HashMap<>();
+                map.put("dataObject", AESUtils.encrypt(json));
+                OkHttpUtil.getInstance().url("http://192.168.0.173:8877/intelligentCustomerService/wxapi/wxAppointmeController/getAppointPhoto")
+                        .postJson(null, map)
+                        .async(Result.class, new OnOkHttpListener<Result>() {
                             @Override
-                            public void onSuccess() {
-//                                Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
-//                                startActivity(intent);
-                                upload();
+                            public void onCompleted() {
+
+                            }
+
+                            @Override
+                            public void onSuccess(Result message) {
+                                Jlog.d(AESUtils.decrypt(message.getStateValue()));
+                            }
+
+                            @Override
+                            public void onFailure(Throwable t) {
+
+                            }
+                        });
+            }
+        });
+        findViewById(R.id.but2).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                Map<String, Object> oMap = new HashMap<>();
+                oMap.put("idCardNum", "362204199212245730");
+                String json = new Gson().toJson(oMap);
+                Map<String, Object> map = new HashMap<>();
+                map.put("dataObject", AESUtils.encrypt(json));
+                OkHttpUtil.getInstance().url("http://192.168.0.173:8877/intelligentCustomerService/wxapi/wxAppointmeController/getDetailsByCardNum")
+                        .postJson(null, map)
+                        .async(Result.class, new OnOkHttpListener<Result>() {
+                            @Override
+                            public void onCompleted() {
+
+                            }
+
+                            @Override
+                            public void onSuccess(Result message) {
+                                Jlog.d(AESUtils.decrypt(message.getStateValue()));
+                            }
+
+                            @Override
+                            public void onFailure(Throwable t) {
+
                             }
                         });
             }

+ 66 - 0
app/src/main/java/com/mylove/okhttp/Result.java

@@ -0,0 +1,66 @@
+package com.mylove.okhttp;
+
+/**
+ * @author DELL
+ * @date 2023/4/26 16:01
+ * @user yangjiewei
+ * @email ben@yanyi.red
+ * @overview
+ */
+public class Result {
+
+    private String stateMsg;
+    private Object validationResults;
+    private Integer stateType;
+    private String stateValue;
+    private Object secret;
+    private Object url;
+
+    public String getStateMsg() {
+        return stateMsg;
+    }
+
+    public void setStateMsg(String stateMsg) {
+        this.stateMsg = stateMsg;
+    }
+
+    public Object getValidationResults() {
+        return validationResults;
+    }
+
+    public void setValidationResults(Object validationResults) {
+        this.validationResults = validationResults;
+    }
+
+    public Integer getStateType() {
+        return stateType;
+    }
+
+    public void setStateType(Integer stateType) {
+        this.stateType = stateType;
+    }
+
+    public String getStateValue() {
+        return stateValue;
+    }
+
+    public void setStateValue(String stateValue) {
+        this.stateValue = stateValue;
+    }
+
+    public Object getSecret() {
+        return secret;
+    }
+
+    public void setSecret(Object secret) {
+        this.secret = secret;
+    }
+
+    public Object getUrl() {
+        return url;
+    }
+
+    public void setUrl(Object url) {
+        this.url = url;
+    }
+}

+ 7 - 0
app/src/main/res/layout/activity_main.xml

@@ -11,6 +11,13 @@
         android:onClick="onClick"
         android:text="下载" />
 
+    <Button
+        android:id="@+id/but2"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:onClick="onClick"
+        android:text="请求" />
+
     <ImageView
         android:id="@+id/img"
         android:layout_width="wrap_content"

+ 4 - 5
okhttplib/src/main/java/com/benyanyi/okhttp/call/HttpCall.java

@@ -9,7 +9,6 @@ import java.util.List;
 
 import okhttp3.Call;
 import okhttp3.OkHttpClient;
-import okhttp3.Request;
 
 /**
  * @author YanYi
@@ -17,7 +16,7 @@ import okhttp3.Request;
  * @email ben@yanyi.red
  * @overview 数据请求
  */
-public class HttpCall implements RequestConfig {
+public class HttpCall implements Request {
 
     private CallBuilder builder;
 
@@ -64,7 +63,7 @@ public class HttpCall implements RequestConfig {
 
         private Context context;
         private String mCacheUrl;
-        private Request request;
+        private okhttp3.Request request;
         private OkHttpClient httpClient;
         private boolean isCache;//是否需要缓存
 
@@ -78,7 +77,7 @@ public class HttpCall implements RequestConfig {
             return this;
         }
 
-        public Builder setRequest(Request request) {
+        public Builder setRequest(okhttp3.Request request) {
             this.request = request;
             return this;
         }
@@ -93,7 +92,7 @@ public class HttpCall implements RequestConfig {
             return this;
         }
 
-        public RequestConfig builder() {
+        public Request builder() {
             return new HttpCall(this);
         }
     }

+ 1 - 1
okhttplib/src/main/java/com/benyanyi/okhttp/call/RequestConfig.java → okhttplib/src/main/java/com/benyanyi/okhttp/call/Request.java

@@ -11,7 +11,7 @@ import java.util.List;
  * @email ben@yanyi.red
  * @overview
  */
-public interface RequestConfig {
+public interface Request {
 
     void async(OnOkHttpListener<Object> onOkHttpListener);
 

+ 24 - 25
okhttplib/src/main/java/com/benyanyi/okhttp/config/HttpRequest.java

@@ -3,9 +3,9 @@ package com.benyanyi.okhttp.config;
 import android.content.Context;
 
 import com.benyanyi.okhttp.call.HttpCall;
-import com.benyanyi.okhttp.call.RequestConfig;
+import com.benyanyi.okhttp.call.Request;
 import com.benyanyi.okhttp.download.DownloadCall;
-import com.benyanyi.okhttp.download.DownloadConfig;
+import com.benyanyi.okhttp.download.DownloadRequest;
 import com.benyanyi.okhttp.type.RequestType;
 import com.benyanyi.okhttp.util.FormatUtil;
 import com.benyanyi.okhttp.util.OkHttpLog;
@@ -17,7 +17,6 @@ import java.util.Map;
 import okhttp3.FormBody;
 import okhttp3.MediaType;
 import okhttp3.MultipartBody;
-import okhttp3.Request;
 import okhttp3.RequestBody;
 
 /**
@@ -32,7 +31,7 @@ public class HttpRequest implements RequestType {
     private final boolean isCache;
     private final String url;
     private String mCacheName;
-    private Request request;
+    private okhttp3.Request request;
 
     public HttpRequest(Context context, String url, boolean isCache) {
         this.context = context;
@@ -42,7 +41,7 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig getText(Map<String, Object> map) {
+    public Request getText(Map<String, Object> map) {
         StringBuilder str = new StringBuilder(url);
         if (FormatUtil.isMapNotEmpty(map)) {
             mCacheName = mCacheName + map;
@@ -53,7 +52,7 @@ public class HttpRequest implements RequestType {
             str = new StringBuilder(str.substring(0, str.length() - 1));
         }
         OkHttpLog.d(str);
-        request = new Request.Builder()
+        request = new okhttp3.Request.Builder()
                 .url(str.toString())
                 .get()
                 .build();
@@ -61,7 +60,7 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postText(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
+    public Request postText(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
         FormBody.Builder builder = new FormBody.Builder();
         if (FormatUtil.isMapNotEmpty(bodyMap)) {
             mCacheName = mCacheName + bodyMap;
@@ -70,7 +69,7 @@ public class HttpRequest implements RequestType {
             }
         }
         FormBody build = builder.build();
-        Request.Builder builder1 = new Request.Builder();
+        okhttp3.Request.Builder builder1 = new okhttp3.Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
             for (Map.Entry<String, Object> entry : headerMap.entrySet()) {
                 builder1.addHeader(entry.getKey(), entry.getValue().toString());
@@ -83,7 +82,7 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postTextEncoded(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
+    public Request postTextEncoded(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
         FormBody.Builder builder = new FormBody.Builder();
         if (FormatUtil.isMapNotEmpty(bodyMap)) {
             mCacheName = mCacheName + bodyMap;
@@ -92,7 +91,7 @@ public class HttpRequest implements RequestType {
             }
         }
         FormBody build = builder.build();
-        Request.Builder builder1 = new Request.Builder();
+        okhttp3.Request.Builder builder1 = new okhttp3.Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
             for (Map.Entry<String, Object> entry : headerMap.entrySet()) {
                 builder1.addHeader(entry.getKey(), entry.getValue().toString());
@@ -105,7 +104,7 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postMultipart(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
+    public Request postMultipart(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
         MultipartBody.Builder builder = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM);
         if (FormatUtil.isMapNotEmpty(bodyMap)) {
@@ -126,13 +125,13 @@ public class HttpRequest implements RequestType {
             }
         }
         MultipartBody multipartBody = builder.build();
-        Request.Builder headerBuilder = new Request.Builder();
+        okhttp3.Request.Builder headerBuilder = new okhttp3.Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
             for (Map.Entry<String, Object> entry : headerMap.entrySet()) {
                 headerBuilder.addHeader(entry.getKey(), entry.getValue().toString());
             }
         }
-        request = new Request.Builder()
+        request = new okhttp3.Request.Builder()
                 .url(url)
                 .post(multipartBody)
                 .build();
@@ -140,9 +139,9 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postJson(Map<String, String> headerMap, Map<String, Object> map) {
+    public Request postJson(Map<String, String> headerMap, Map<String, Object> map) {
         MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
-        Request.Builder builder = new Request.Builder();
+        okhttp3.Request.Builder builder = new okhttp3.Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
             for (Map.Entry<String, String> entry : headerMap.entrySet()) {
                 builder.addHeader(entry.getKey(), entry.getValue());
@@ -165,9 +164,9 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postJson(Map<String, String> headerMap, String jsonBody) {
+    public Request postJson(Map<String, String> headerMap, String jsonBody) {
         MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
-        Request.Builder builder = new Request.Builder();
+        okhttp3.Request.Builder builder = new okhttp3.Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
             for (Map.Entry<String, String> entry : headerMap.entrySet()) {
                 builder.addHeader(entry.getKey(), entry.getValue());
@@ -190,7 +189,7 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig xml(Map<String, String> headerMap, String xmlBody) {
+    public Request xml(Map<String, String> headerMap, String xmlBody) {
         String str = xmlBody;
         MediaType mediaType = MediaType.parse("text/xml; charset=UTF-8");
         if (FormatUtil.isNotEmpty(str)) {
@@ -198,7 +197,7 @@ public class HttpRequest implements RequestType {
         } else {
             str = "";
         }
-        Request.Builder builder = new Request.Builder();
+        okhttp3.Request.Builder builder = new okhttp3.Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
             for (Map.Entry<String, String> entry : headerMap.entrySet()) {
                 builder.addHeader(entry.getKey(), entry.getValue());
@@ -212,30 +211,30 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public DownloadConfig download() {
+    public DownloadRequest download() {
         return new DownloadCall.Builder().setContext(context).setUrl(url).setCover(false).setSuffix("").builder();
     }
 
     @Override
-    public DownloadConfig download(boolean isCover) {
+    public DownloadRequest download(boolean isCover) {
         return new DownloadCall.Builder().setContext(context).setUrl(url).setCover(isCover).setSuffix("").builder();
     }
 
     @Override
-    public DownloadConfig download(String suffix) {
+    public DownloadRequest download(String suffix) {
         return new DownloadCall.Builder().setContext(context).setUrl(url).setCover(false).setSuffix(suffix).builder();
     }
 
     @Override
-    public DownloadConfig download(boolean isCover, String suffix) {
+    public DownloadRequest download(boolean isCover, String suffix) {
         return new DownloadCall.Builder().setContext(context).setUrl(url).setCover(isCover).setSuffix(suffix).builder();
     }
 
-    private RequestConfig send() {
+    private Request send() {
         return send(false);
     }
 
-    private RequestConfig send(boolean isFile) {
+    private Request send(boolean isFile) {
         return new HttpCall.Builder()
                 .setCache(isCache)
                 .setCacheUrl(mCacheName)

+ 2 - 2
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadCall.java

@@ -10,7 +10,7 @@ import com.benyanyi.okhttp.listener.OnDownLoadObserver;
  * @email ben@yanyi.red
  * @overview
  */
-public class DownloadCall implements DownloadConfig {
+public class DownloadCall implements DownloadRequest {
 
     private Context mContext;
     private String url;
@@ -81,7 +81,7 @@ public class DownloadCall implements DownloadConfig {
             return this;
         }
 
-        public DownloadConfig builder() {
+        public DownloadRequest builder() {
             return new DownloadCall(this);
         }
 

+ 1 - 1
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadConfig.java → okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadRequest.java

@@ -8,7 +8,7 @@ import com.benyanyi.okhttp.listener.OnDownLoadObserver;
  * @email ben@yanyi.red
  * @overview
  */
-public interface DownloadConfig {
+public interface DownloadRequest {
 
     void start();
 

+ 13 - 13
okhttplib/src/main/java/com/benyanyi/okhttp/type/RequestType.java

@@ -1,7 +1,7 @@
 package com.benyanyi.okhttp.type;
 
-import com.benyanyi.okhttp.call.RequestConfig;
-import com.benyanyi.okhttp.download.DownloadConfig;
+import com.benyanyi.okhttp.call.Request;
+import com.benyanyi.okhttp.download.DownloadRequest;
 
 import java.util.Map;
 
@@ -18,7 +18,7 @@ public interface RequestType {
      *
      * @param map 请求文本
      */
-    RequestConfig getText(Map<String, Object> map);
+    Request getText(Map<String, Object> map);
 
     /**
      * post文本请求
@@ -27,7 +27,7 @@ public interface RequestType {
      * @param headerMap 请求头
      * @param bodyMap   请求体
      */
-    RequestConfig postText(Map<String, Object> headerMap, Map<String, Object> bodyMap);
+    Request postText(Map<String, Object> headerMap, Map<String, Object> bodyMap);
 
     /**
      * post文本请求
@@ -36,7 +36,7 @@ public interface RequestType {
      * @param headerMap 请求头
      * @param bodyMap   请求体
      */
-    RequestConfig postTextEncoded(Map<String, Object> headerMap, Map<String, Object> bodyMap);
+    Request postTextEncoded(Map<String, Object> headerMap, Map<String, Object> bodyMap);
 
     /**
      * post多图文上传
@@ -44,7 +44,7 @@ public interface RequestType {
      * @param headerMap 请求头
      * @param bodyMap   请求体
      */
-    RequestConfig postMultipart(Map<String, Object> headerMap, Map<String, Object> bodyMap);
+    Request postMultipart(Map<String, Object> headerMap, Map<String, Object> bodyMap);
 
     /**
      * post json字符上传
@@ -52,7 +52,7 @@ public interface RequestType {
      * @param headerMap 请求头
      * @param map       需要拼接成json的键值对
      */
-    RequestConfig postJson(Map<String, String> headerMap, Map<String, Object> map);
+    Request postJson(Map<String, String> headerMap, Map<String, Object> map);
 
     /**
      * post json字符上传
@@ -60,7 +60,7 @@ public interface RequestType {
      * @param headerMap 请求头
      * @param jsonBody  请求体
      */
-    RequestConfig postJson(Map<String, String> headerMap, String jsonBody);
+    Request postJson(Map<String, String> headerMap, String jsonBody);
 
     /**
      * post xml字符上传
@@ -68,26 +68,26 @@ public interface RequestType {
      * @param headerMap 请求头
      * @param xmlBody   请求体
      */
-    RequestConfig xml(Map<String, String> headerMap, String xmlBody);
+    Request xml(Map<String, String> headerMap, String xmlBody);
 
     /**
      * 文件下载
      */
-    DownloadConfig download();
+    DownloadRequest download();
 
     /**
      * 文件下载
      *
      * @param isCover 是否覆盖之前的文件
      */
-    DownloadConfig download(boolean isCover);
+    DownloadRequest download(boolean isCover);
 
     /**
      * 文件下载
      *
      * @param suffix 文件名后缀
      */
-    DownloadConfig download(String suffix);
+    DownloadRequest download(String suffix);
 
     /**
      * 文件下载
@@ -95,6 +95,6 @@ public interface RequestType {
      * @param isCover 是否覆盖之前的文件
      * @param suffix  文件名后缀
      */
-    DownloadConfig download(boolean isCover, String suffix);
+    DownloadRequest download(boolean isCover, String suffix);
 
 }