Browse Source

修改post多图及图文上传

kth_win_android 2 years ago
parent
commit
9a2a93a981

+ 22 - 6
app/build.gradle

@@ -13,16 +13,32 @@ android {
 
         multiDexEnabled true
     }
-    buildTypes {
+    signingConfigs {
+        release {
+            storeFile file("kth_android_key.jks")
+            storePassword "jxkthfinger"
+            keyAlias "jxkth"
+            keyPassword "jxkthfinger"
+        }
+
         debug {
-//            buildConfigField "boolean", "LOG_DEBUG", "true"
-            minifyEnabled false
-            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+            storeFile file("kth_android_key.jks")
+            storePassword "jxkthfinger"
+            keyAlias "jxkth"
+            keyPassword "jxkthfinger"
         }
+    }
+
+    buildTypes {
         release {
-//            buildConfigField "boolean", "LOG_DEBUG", "false"
             minifyEnabled false
-            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+            signingConfig signingConfigs.release
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), project.file('proguard-rules.pro')
+        }
+        debug {
+            debuggable true
+            minifyEnabled false
+            signingConfig signingConfigs.debug
         }
     }
 

+ 32 - 0
app/src/main/java/com/mylove/okhttp/MD5Utils.java

@@ -51,7 +51,39 @@ public class MD5Utils {
         return result;
     }
 
+    public static String mapSort(Map<String, Object> map){
+        String result = "";
+        try {
+            List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(map.entrySet());
+            // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序)
+            Collections.sort(infoIds, new Comparator<Map.Entry<String, Object>>() {
+                public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
+                    return (o1.getKey()).toString().compareTo(o2.getKey().toString());
+                }
+            });
+            // 构造签名键值对的格式
+            StringBuilder sb = new StringBuilder();
+            for (Map.Entry<String, Object> item : infoIds) {
+                if (item.getKey() != null || item.getKey() != "") {
+                    String key = item.getKey().toString();
+                    String val = item.getValue().toString();
+                    if (!(val == "" || val == null)) {
+                        sb.append(key + "=" + val + "&");
+                    }
+                }
+            }
+            sb.deleteCharAt(sb.length()-1);
+            result = sb.toString();
+            Jlog.d(result);
+        } catch (Exception e) {
+            return result;
+        }
+        Jlog.d(result);
+        return result;
+    }
+
     public static String MD5Encode(String origin) {
+        Jlog.d(origin);
         String resultString = "";
         try {
             resultString = new String(origin.getBytes(Charset.forName("UTF-8")));

+ 173 - 70
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -2,10 +2,13 @@ package com.mylove.okhttp;
 
 import android.Manifest;
 import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.os.Environment;
 import android.util.Base64;
 import android.view.View;
+import android.widget.ImageView;
 
 import androidx.annotation.Nullable;
 import androidx.appcompat.app.AppCompatActivity;
@@ -23,6 +26,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.security.MessageDigest;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -40,79 +44,127 @@ public class MainActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
 //        setContentView(R.layout.notification_contentview);
         setContentView(R.layout.activity_main);
+//        Jlog.d(MD5Utils.MD5Encode("123456"));
+//        Jlog.d(encrypt("123456" + null));
+//        Jlog.d(encrypt("123456"));
+//        Jlog.d(getMd5_16("123456"));
+//        Jlog.d(encrypt32("123456"));
+//        Jlog.d(encryption("123456"));
+//
+//        Jlog.d(string2MD5("123456"));
+        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() {
                             @Override
                             public void onSuccess() {
-//                                Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
-//                                startActivity(intent);
-                                upload();
+                                Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
+                                startActivity(intent);
+//                                upload2();
                             }
                         });
             }
         });
-//        OkHttpUtil.getInstance(this).url("http://apitest.yanyi.online/app/update").getText(null).async(new OnOkHttpListener<Object>() {
-//            @Override
-//            public void onCompleted() {
-//
-//            }
-//
-//            @Override
-//            public void onSuccess(Object message) {
-//                Jlog.d(message);
-//            }
-//
-//            @Override
-//            public void onFailure(Throwable t) {
-//
-//            }
-//        });
+    }
 
-//        init();
-//        PermissionHelper.getInstance(this).hasPermission(0x11, new PermissionCallBack() {
-//            @Override
-//            public void onPermissionSuccess(int permissionCode) {
-//                downloadAPK();
-//            }
-//
-//            @Override
-//            public void onPermissionFailure(FailureMsg failureMsg) {
-//
-//            }
-//
-//            @Override
-//            public void onPermissionComplete(int permissionCode) {
-//
-//            }
-//        }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
-//        permissionHelper = new PermissionHelper(this, strings);
-//        permissionHelper.hasPermission(new PermissionHelper.OnPermissionListener() {
-//            @Override
-//            public void onAllPermissionSuccess() {
-////                init();
-//                downloadAPK();
-//            }
-//
-//            @Override
-//            public void onAllPermissionFailure() {
-//
-//            }
-//        });
-//        String str = "<html></html>";
-//        try {
-////            JSONObject jsonObject = new JSONObject(str);
-//            JsonElement jsonParser = JsonParser.parseString(str);
-//            Jlog.v(jsonParser.isJsonArray());
-//            Jlog.v(jsonParser.isJsonObject());
-//            Jlog.v(jsonParser.isJsonPrimitive());
-//            Jlog.v(jsonParser.isJsonNull());
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
+    public String encryption(String plainText) {
+        String md5 = new String();
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            md.update(plainText.getBytes());
+            byte b[] = md.digest();
+
+            int i;
+
+            StringBuffer buf = new StringBuffer("");
+            for (int offset = 0; offset < b.length; offset++) {
+                i = b[offset];
+                if (i < 0)
+                    i += 256;
+                if (i < 16)
+                    buf.append("0");
+                buf.append(Integer.toHexString(i));
+            }
+
+            md5 = buf.toString();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return md5;
+    }
+
+    private static String getMd5_16(String string) {
+        return encrypt32(string).substring(8, 24);
+    }
+
+    public static String encrypt32(String encryptStr) {
+        MessageDigest md5;
+        try {
+            md5 = MessageDigest.getInstance("MD5");
+            byte[] md5Bytes = md5.digest(encryptStr.getBytes());
+            StringBuffer hexValue = new StringBuffer();
+            for (int i = 0; i < md5Bytes.length; i++) {
+                int val = ((int) md5Bytes[i]) & 0xff;
+                if (val < 16)
+                    hexValue.append("0");
+                hexValue.append(Integer.toHexString(val));
+            }
+            encryptStr = hexValue.toString();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return encryptStr;
+    }
+
+    public static String md532(String source) {
+        char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+        try {
+            byte[] strTemp = source.getBytes("UTF-8");
+
+            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
+            mdTemp.update(strTemp);
+            byte[] md = mdTemp.digest();
+            int j = md.length;
+            char[] str = new char[j * 2];
+            int k = 0;
+            for (int i = 0; i < j; i++) {
+                byte b = md[i];
+
+                str[(k++)] = hexDigits[(b >> 4 & 0xF)];
+                str[(k++)] = hexDigits[(b & 0xF)];
+            }
+            return new String(str);
+        } catch (Exception e) {
+        }
+        return null;
+    }
+
+    private static final String slat = "&%5123***&&%%$$#@";
+
+    public static String encrypt(String dataStr) {
+        try {
+            dataStr = dataStr + slat;
+            MessageDigest m = MessageDigest.getInstance("MD5");
+            m.update(dataStr.getBytes("UTF8"));
+            byte s[] = m.digest();
+            String result = "";
+            for (int i = 0; i < s.length; i++) {
+                result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
+            }
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return "";
     }
 
     public void onClick(View view) {
@@ -125,25 +177,68 @@ public class MainActivity extends AppCompatActivity {
         });
     }
 
+    private void upload2() {
+        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/WeiXin/mmexport1679542887693.jpg";
+        File file = new File(path);
+        ImageView img = findViewById(R.id.img);
+        Bitmap bitmap = BitmapFactory.decodeFile(path);
+        img.setImageBitmap(bitmap);
+
+
+        String timestamp = System.currentTimeMillis() + "";
+        Map<String, Object> oMap = new HashMap<>();
+        oMap.put("yxdm", "123456");
+        oMap.put("sfzh", "139925199810233546");
+        String sign = MD5Utils.MD5Encode("8523697410hijklm" + sign2(oMap) + timestamp);
+//        String sign = MD5Utils.MD5Encode("8523697410hijklm" + MD5Utils.mapSort(oMap) + timestamp);
+        Jlog.d(sign);
+        oMap.put("sign", sign);
+        oMap.put("timestamp", timestamp);
+        oMap.put("file", file);
+        for (Map.Entry<String, Object> entry : oMap.entrySet()) {
+            if (entry.getValue() instanceof File) {
+                Jlog.d(entry.getKey() + "=" + ((File) entry.getValue()).getName());
+            } else {
+                Jlog.d(entry.getKey() + "=" + entry.getValue());
+            }
+        }
+        OkHttpUtil.getInstance(this).url("https://mp.idimage.com.cn/expo-bossapi/studentInfo/upload").postFileText(oMap).async(new OnOkHttpListener<Object>() {
+            @Override
+            public void onCompleted() {
+
+            }
+
+            @Override
+            public void onSuccess(Object message) {
+
+            }
+
+            @Override
+            public void onFailure(Throwable t) {
+
+            }
+        });
+    }
+
     private void upload() {
         String path = Environment.getExternalStorageDirectory() + "/DCIM/camera/IMG_20190620_082204.jpg";
         String path1 = Environment.getExternalStorageDirectory() + "/tencent/micromsg/weixin/mmexport1528644702092.jpg";
         File file = new File(path);
         File file1 = new File(path1);
-        Map<Object, Object> oMap = new HashMap<>();
-        oMap.put("sn", "2023022100001_孟*杰_0034");
+        Map<String, Object> oMap = new HashMap<>();
+        oMap.put("sn", "2023022100001");
         oMap.put("device_no", "123456");
         oMap.put("appid", "37bU34uZPTUjzGZTsZ8eSh");
         oMap.put("timestamp", System.currentTimeMillis() / 1000 + "");
         oMap.put("sign", sign(oMap));
         oMap.put("origin_image", fileToBase64(file));
         oMap.put("photo_image", fileToBase64(file1));
-        for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
-            if (entry.getValue().toString().length() <= 10) {
+        for (Map.Entry<String, Object> entry : oMap.entrySet()) {
+            if (entry.getValue().toString().length() <= 100) {
                 Jlog.d(entry.getKey() + "=" + entry.getValue());
 
             } else {
-                Jlog.d(entry.getKey() + "=" + (entry.getValue().toString().substring(0, 20)));
+                Jlog.d(entry.getKey() + "=" + (entry.getValue().toString().substring(0, 100)));
             }
         }
         OkHttpUtil.getInstance(this).url("https://opend.icaiji.com.cn/wxapp/v6/photo").postText(null, oMap).async(new OnOkHttpListener<Object>() {
@@ -164,15 +259,23 @@ public class MainActivity extends AppCompatActivity {
         });
     }
 
-    private String sign(Map<Object, Object> oMap) {
+    private String sign(Map<String, Object> oMap) {
         Map<String, String> map = new HashMap<>();
-        for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
-            map.put(entry.getKey().toString(), entry.getValue().toString());
+        for (Map.Entry<String, Object> entry : oMap.entrySet()) {
+            map.put(entry.getKey(), entry.getValue().toString());
         }
         map.put("secret", "3sx9NNhVGEEEouhoenA5aJ");
         return MD5Utils.getSignToken(map);
     }
 
+    private String sign2(Map<String, Object> oMap) {
+        Map<String, String> map = new HashMap<>();
+        for (Map.Entry<String, Object> entry : oMap.entrySet()) {
+            map.put(entry.getKey().toString(), entry.getValue().toString());
+        }
+        return MD5Utils.getSignToken(map);
+    }
+
     private String fileToBase64(File file) {
         String base64 = null;
         InputStream in = null;
@@ -197,13 +300,13 @@ public class MainActivity extends AppCompatActivity {
 
     private void init() {
         String url = "http://test.zhcjrwang.com/api/Test/Index";
-        Map<Object, Object> headerMap = new HashMap<>();
+        Map<String, Object> headerMap = new HashMap<>();
         headerMap.put("app_key", "XiangKeLai");
         String timeStamp = DateUtil.timeStamp();
         headerMap.put("timestamp", timeStamp);
         headerMap.put("sign", ("XiangKeLai1" + timeStamp).toUpperCase());
         Jlog.v(headerMap);
-        Map<Object, Object> bodyMap = new HashMap<>();
+        Map<String, Object> bodyMap = new HashMap<>();
         bodyMap.put("data", "+fAFfMCGsMZqeS+gyrZm1A==");
         Jlog.v(bodyMap);
         OkHttpUtil.getInstance(this).url(url, true).postText(headerMap, bodyMap).async(new OnOkHttpListener<Object>() {

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

@@ -11,4 +11,8 @@
         android:onClick="onClick"
         android:text="下载" />
 
+    <ImageView
+        android:id="@+id/img"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
 </LinearLayout>

+ 88 - 34
okhttplib/src/main/java/com/benyanyi/okhttp/type/HttpRequest.java

@@ -28,9 +28,9 @@ import okhttp3.RequestBody;
  */
 public class HttpRequest implements RequestType {
 
-    private Context context;
-    private boolean isCache;
-    private String url;
+    private final Context context;
+    private final boolean isCache;
+    private final String url;
     private String mCacheName;
     private Request request;
 
@@ -42,12 +42,12 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig getText(Map<Object, Object> map) {
+    public RequestConfig getText(Map<String, Object> map) {
         StringBuilder str = new StringBuilder(url);
         if (FormatUtil.isMapNotEmpty(map)) {
-            mCacheName = mCacheName + map.toString();
+            mCacheName = mCacheName + map;
             str.append("?");
-            for (Map.Entry<Object, Object> entry : map.entrySet()) {
+            for (Map.Entry<String, Object> entry : map.entrySet()) {
                 str.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
             }
             str = new StringBuilder(str.substring(0, str.length() - 1));
@@ -61,19 +61,19 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postText(Map<Object, Object> headerMap, Map<Object, Object> bodyMap) {
+    public RequestConfig postText(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
         FormBody.Builder builder = new FormBody.Builder();
         if (FormatUtil.isMapNotEmpty(bodyMap)) {
-            mCacheName = mCacheName + bodyMap.toString();
-            for (Map.Entry<Object, Object> entry : bodyMap.entrySet()) {
-                builder.add(entry.getKey().toString(), entry.getValue().toString());
+            mCacheName = mCacheName + bodyMap;
+            for (Map.Entry<String, Object> entry : bodyMap.entrySet()) {
+                builder.add(entry.getKey(), entry.getValue().toString());
             }
         }
         FormBody build = builder.build();
         Request.Builder builder1 = new Request.Builder();
         if (FormatUtil.isMapNotEmpty(headerMap)) {
-            for (Map.Entry<Object, Object> entry : headerMap.entrySet()) {
-                builder1.addHeader(entry.getKey().toString(), entry.getValue().toString());
+            for (Map.Entry<String, Object> entry : headerMap.entrySet()) {
+                builder1.addHeader(entry.getKey(), entry.getValue().toString());
             }
         }
         request = builder1.url(url)
@@ -83,11 +83,63 @@ public class HttpRequest implements RequestType {
     }
 
     @Override
-    public RequestConfig postJson(Map<Object, Object> map) {
+    public RequestConfig postFileText(Map<String, Object> bodyMap) {
+        MultipartBody.Builder builder = new MultipartBody.Builder()
+                .setType(MultipartBody.FORM);
+        if (FormatUtil.isMapNotEmpty(bodyMap)) {
+            for (Map.Entry<String, Object> entry : bodyMap.entrySet()) {
+                if (entry.getValue() instanceof File) {
+                    File file = new File(entry.getValue().toString());
+                    RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
+                    builder.addFormDataPart(entry.getKey(), file.getName(), requestBody);
+                } else {
+                    builder.addFormDataPart(entry.getKey(), entry.getValue().toString());
+                }
+            }
+        }
+        MultipartBody multipartBody = builder.build();
+        request = new Request.Builder()
+                .url(url)
+                .post(multipartBody)
+                .build();
+        return send(true);
+    }
+
+    @Override
+    public RequestConfig postFileText(Map<String, Object> headerMap, Map<String, Object> bodyMap) {
+        MultipartBody.Builder builder = new MultipartBody.Builder()
+                .setType(MultipartBody.FORM);
+        if (FormatUtil.isMapNotEmpty(bodyMap)) {
+            for (Map.Entry<String, Object> entry : bodyMap.entrySet()) {
+                if (entry.getValue() instanceof File) {
+                    File file = new File(entry.getValue().toString());
+                    RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
+                    builder.addFormDataPart(entry.getKey(), file.getName(), requestBody);
+                } else {
+                    builder.addFormDataPart(entry.getKey(), entry.getValue().toString());
+                }
+            }
+        }
+        MultipartBody multipartBody = builder.build();
+        Request.Builder headerBuilder = new 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()
+                .url(url)
+                .post(multipartBody)
+                .build();
+        return send(true);
+    }
+
+    @Override
+    public RequestConfig postJson(Map<String, Object> map) {
         MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
         if (FormatUtil.isMapNotEmpty(map)) {
-            mCacheName = mCacheName + map.toString();
-            RequestBody requestBody = RequestBody.create(mediaType, new Gson().toJson(map));
+            mCacheName = mCacheName + map;
+            RequestBody requestBody = RequestBody.create(new Gson().toJson(map), mediaType);
             request = new Request.Builder()
                     .url(url)
                     .addHeader("content-type", "application/json")
@@ -107,7 +159,7 @@ public class HttpRequest implements RequestType {
         MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
         if (FormatUtil.isNotEmpty(string)) {
             mCacheName = mCacheName + string;
-            RequestBody requestBody = RequestBody.create(mediaType, string);
+            RequestBody requestBody = RequestBody.create(string, mediaType);
             request = new Request.Builder()
                     .url(url)
                     .addHeader("content-type", "application/json")
@@ -133,24 +185,20 @@ public class HttpRequest implements RequestType {
         }
         request = new Request.Builder()
                 .url(url)
-                .post(RequestBody.create(mediaType, str))
+                .post(RequestBody.create(str, mediaType))
                 .build();
         return send();
     }
 
     @Override
-    public RequestConfig file(Map<Object, Object> map) {
+    public RequestConfig file(Map<String, Object> map) {
         MultipartBody.Builder builder = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM);
         if (FormatUtil.isMapNotEmpty(map)) {
-            for (Map.Entry<Object, Object> entry : map.entrySet()) {
+            for (Map.Entry<String, Object> entry : map.entrySet()) {
                 File file = new File(entry.getValue().toString());
-//                int indexOf = entry.getValue().toString().indexOf("/");
-//                RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
                 RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
-//                String fileName = entry.getKey().toString().substring(indexOf + 1);
-                String fileName = entry.getKey().toString();
-                builder.addFormDataPart(entry.getKey().toString(), fileName, requestBody);
+                builder.addFormDataPart(entry.getKey(), file.getName(), requestBody);
             }
         }
         MultipartBody multipartBody = builder.build();
@@ -166,13 +214,16 @@ public class HttpRequest implements RequestType {
         MultipartBody.Builder builder = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM);
         if (filePaths != null && filePaths.length > 0) {
-            for (String str : filePaths) {
-                File file = new File(str);
-//                int indexOf = entry.getValue().toString().indexOf("/");
-//                RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
+            if (filePaths.length == 1) {
+                File file = new File(filePaths[0]);
                 RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
-//                String fileName = entry.getKey().toString().substring(indexOf + 1);
                 builder.addFormDataPart("file", file.getName(), requestBody);
+            } else {
+                for (int i = 0; i < filePaths.length; i++) {
+                    File file = new File(filePaths[i]);
+                    RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
+                    builder.addFormDataPart("file" + i, file.getName(), requestBody);
+                }
             }
         }
         MultipartBody multipartBody = builder.build();
@@ -188,13 +239,16 @@ public class HttpRequest implements RequestType {
         MultipartBody.Builder builder = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM);
         if (filePaths != null && filePaths.size() > 0) {
-            for (String str : filePaths) {
-                File file = new File(str);
-//                int indexOf = entry.getValue().toString().indexOf("/");
-//                RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
+            if (filePaths.size() == 1) {
+                File file = new File(filePaths.get(0));
                 RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
-//                String fileName = entry.getKey().toString().substring(indexOf + 1);
                 builder.addFormDataPart("file", file.getName(), requestBody);
+            } else {
+                for (int i = 0; i < filePaths.size(); i++) {
+                    File file = new File(filePaths.get(i));
+                    RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
+                    builder.addFormDataPart("file" + i, file.getName(), requestBody);
+                }
             }
         }
         MultipartBody multipartBody = builder.build();

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

@@ -14,17 +14,21 @@ import java.util.Map;
  */
 public interface RequestType {
 
-    RequestConfig getText(Map<Object, Object> map);
+    RequestConfig getText(Map<String, Object> map);
 
-    RequestConfig postText(Map<Object, Object> headerMap, Map<Object, Object> bodyMap);
+    RequestConfig postText(Map<String, Object> headerMap, Map<String, Object> bodyMap);
 
-    RequestConfig postJson(Map<Object, Object> map);
+    RequestConfig postFileText(Map<String, Object> bodyMap);
+
+    RequestConfig postFileText(Map<String, Object> headerMap, Map<String, Object> bodyMap);
+
+    RequestConfig postJson(Map<String, Object> map);
 
     RequestConfig postJson(String string);
 
     RequestConfig xml(String xml);
 
-    RequestConfig file(Map<Object, Object> map);
+    RequestConfig file(Map<String, Object> map);
 
     RequestConfig file(String... filePaths);