Browse Source

优化请求,将soap请求重新封装,将rxjava1.x变成成rxjava2.x

yanyi 6 years ago
parent
commit
dd0c94c786
39 changed files with 337 additions and 881 deletions
  1. 1 1
      .idea/gradle.xml
  2. 0 36
      .idea/inspectionProfiles/Project_Default.xml
  3. 4 19
      .idea/misc.xml
  4. 1 1
      .idea/modules.xml
  5. 2 3
      app/build.gradle
  6. 0 135
      app/src/main/java/com/mylove/okhttp/MainActivity.java
  7. 12 5
      build.gradle
  8. 0 19
      okhttp2/src/main/java/com/mylove/okhttp/Cache.java
  9. 0 29
      okhttp2/src/main/java/com/mylove/okhttp/DownloadBean.java
  10. 0 351
      okhttp2/src/main/java/com/mylove/okhttp/FormatUtil.java
  11. 0 37
      okhttp2/src/main/java/com/mylove/okhttp/ResultMsg.java
  12. 0 0
      okhttplib/.gitignore
  13. 80 0
      okhttplib/bintrayUpload.gradle
  14. 5 4
      okhttplib/build.gradle
  15. 0 0
      okhttplib/proguard-rules.pro
  16. 0 0
      okhttplib/src/androidTest/java/com/mylove/okhttp/ExampleInstrumentedTest.java
  17. 0 0
      okhttplib/src/main/AndroidManifest.xml
  18. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/AutoRequest.java
  19. 30 0
      okhttplib/src/main/java/com/mylove/okhttp/Cache.java
  20. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/CacheInterceptor.java
  21. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/CacheUtils.java
  22. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/CallType.java
  23. 33 30
      okhttplib/src/main/java/com/mylove/okhttp/DownloadObservable.java
  24. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/DownloadRequest.java
  25. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/FileUtil.java
  26. 37 0
      okhttplib/src/main/java/com/mylove/okhttp/FormatUtil.java
  27. 3 6
      okhttplib/src/main/java/com/mylove/okhttp/Internet.java
  28. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/InternetBean.java
  29. 11 32
      okhttplib/src/main/java/com/mylove/okhttp/InternetUtil.java
  30. 29 35
      okhttplib/src/main/java/com/mylove/okhttp/MD5keyUtil.java
  31. 61 98
      okhttplib/src/main/java/com/mylove/okhttp/ObservableRequest.java
  32. 22 0
      okhttplib/src/main/java/com/mylove/okhttp/OkHttpInfo.java
  33. 0 4
      okhttplib/src/main/java/com/mylove/okhttp/OkHttpUtil.java
  34. 0 3
      okhttplib/src/main/java/com/mylove/okhttp/RequestType.java
  35. 4 7
      okhttplib/src/main/java/com/mylove/okhttp/XMLRequest.java
  36. 1 4
      okhttplib/src/main/java/com/mylove/okhttp/onOkHttpListener.java
  37. 0 0
      okhttplib/src/main/res/values/strings.xml
  38. 0 0
      okhttplib/src/test/java/com/mylove/okhttp/ExampleUnitTest.java
  39. 1 1
      settings.gradle

+ 1 - 1
.idea/gradle.xml

@@ -9,7 +9,7 @@
           <set>
             <option value="$PROJECT_DIR$" />
             <option value="$PROJECT_DIR$/app" />
-            <option value="$PROJECT_DIR$/okhttp2" />
+            <option value="$PROJECT_DIR$/okhttplib" />
           </set>
         </option>
         <option name="resolveModulePerSourceSet" value="false" />

+ 0 - 36
.idea/inspectionProfiles/Project_Default.xml

@@ -1,36 +0,0 @@
-<component name="InspectionProjectProfileManager">
-  <profile version="1.0">
-    <option name="myName" value="Project Default" />
-    <inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
-      <option name="TOP_LEVEL_CLASS_OPTIONS">
-        <value>
-          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
-          <option name="REQUIRED_TAGS" value="" />
-        </value>
-      </option>
-      <option name="INNER_CLASS_OPTIONS">
-        <value>
-          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
-          <option name="REQUIRED_TAGS" value="" />
-        </value>
-      </option>
-      <option name="METHOD_OPTIONS">
-        <value>
-          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
-          <option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
-        </value>
-      </option>
-      <option name="FIELD_OPTIONS">
-        <value>
-          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
-          <option name="REQUIRED_TAGS" value="" />
-        </value>
-      </option>
-      <option name="IGNORE_DEPRECATED" value="false" />
-      <option name="IGNORE_JAVADOC_PERIOD" value="true" />
-      <option name="IGNORE_DUPLICATED_THROWS" value="false" />
-      <option name="IGNORE_POINT_TO_ITSELF" value="false" />
-      <option name="myAdditionalJavadocTags" value="date" />
-    </inspection_tool>
-  </profile>
-</component>

+ 4 - 19
.idea/misc.xml

@@ -5,11 +5,12 @@
     <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
     <option name="myNullables">
       <value>
-        <list size="4">
+        <list size="5">
           <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
           <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
-          <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
-          <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
+          <item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
+          <item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
+          <item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
         </list>
       </value>
     </option>
@@ -30,20 +31,4 @@
   <component name="ProjectType">
     <option name="id" value="Android" />
   </component>
-  <component name="masterDetails">
-    <states>
-      <state key="ProjectJDKs.UI">
-        <settings>
-          <last-edited>1.8</last-edited>
-          <splitter-proportions>
-            <option name="proportions">
-              <list>
-                <option value="0.2" />
-              </list>
-            </option>
-          </splitter-proportions>
-        </settings>
-      </state>
-    </states>
-  </component>
 </project>

+ 1 - 1
.idea/modules.xml

@@ -4,7 +4,7 @@
     <modules>
       <module fileurl="file://$PROJECT_DIR$/OkHttp.iml" filepath="$PROJECT_DIR$/OkHttp.iml" />
       <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
-      <module fileurl="file://$PROJECT_DIR$/okhttp2/okhttp2.iml" filepath="$PROJECT_DIR$/okhttp2/okhttp2.iml" />
+      <module fileurl="file://$PROJECT_DIR$/okhttplib/okhttplib.iml" filepath="$PROJECT_DIR$/okhttplib/okhttplib.iml" />
     </modules>
   </component>
 </project>

+ 2 - 3
app/build.gradle

@@ -30,7 +30,6 @@ dependencies {
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.1'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
-    compile project(':okhttp2')
-    implementation 'com.github.love-yanyi:Logger:1.0.1'
-    implementation 'com.didikee:permissionsHelper:0.1.8'
+    compile project(':okhttplib')
+    implementation 'com.yanyi.benyanyi:loglib:1.0.0'
 }

+ 0 - 135
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -1,16 +1,9 @@
 package com.mylove.okhttp;
 
-import android.content.Intent;
 import android.os.Bundle;
-import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 
-import com.mylove.loglib.JLog;
-
-import didikee.com.permissionshelper.PermissionsHelper;
-import didikee.com.permissionshelper.permission.DangerousPermissions;
-
 
 /**
  * @author myLove
@@ -21,12 +14,6 @@ import didikee.com.permissionshelper.permission.DangerousPermissions;
 
 public class MainActivity extends AppCompatActivity {
 
-    /**
-     * app所需要的全部危险权限
-     */
-    static final String[] PERMISSIONS = new String[]{DangerousPermissions.STORAGE};
-    private PermissionsHelper permissionsHelper;
-
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -35,132 +22,10 @@ public class MainActivity extends AppCompatActivity {
     }
 
     private void setPermissions() {
-        permissionsHelper = new PermissionsHelper(this, PERMISSIONS, true);
-        if (permissionsHelper.checkAllPermissions(PERMISSIONS)) {
-            permissionsHelper.onDestroy();
             data();
-        } else {
-            //申请权限
-            permissionsHelper.startRequestNeedPermissions();
-        }
-        permissionsHelper.setonAllNeedPermissionsGrantedListener(new PermissionsHelper.onAllNeedPermissionsGrantedListener() {
-            //全部许可了,已经获得了所有权限
-            @Override
-            public void onAllNeedPermissionsGranted() {
-                //做原先的业务代码
-                JLog.d();
-                data();
-            }
-
-            //被拒绝了,只要有一个权限被拒绝那么就会调用
-            @Override
-            public void onPermissionsDenied() {
-                //拒绝了,如何处理?(视情况而定)
-                JLog.d();
-                permissionsHelper.setParams(null);
-            }
-
-            //用户已经永久的拒绝了
-            @Override
-            public void hasLockForever() {
-                JLog.i("hasLockForever");
-                permissionsHelper.setParams(null);
-            }
-
-            //被拒绝后,在最后一次申请权限之前
-            @Override
-            public void onBeforeRequestFinalPermissions(PermissionsHelper helper) {
-                JLog.i();
-                helper.continueRequestPermissions();
-            }
-        });
     }
 
     private void data() {
-//        sendTest();
-        sendTest2();
-    }
-
-//    private void sendTest() {
-//        OkHttpUtil.getInstance(this).post("http://www.yanyi.red/api/AppMsg.php").async(null, new onOkHttpListener() {
-//            @Override
-//            public void onCompleted() {
-//
-//            }
-//
-//            @Override
-//            public void onSuccess(ResultMsg requestMsg) {
-//                JLog.v(requestMsg);
-//            }
-//
-//            @Override
-//            public void onFailure(Throwable t) {
-//
-//            }
-//        });
-//        OkHttpUtil.getInstance(this).post("http://www.yanyi.red/api/TestApi.php").async(null, new onOkHttpListener() {
-//            @Override
-//            public void onCompleted() {
-//                JLog.v();
-//            }
-//
-//            @Override
-//            public void onSuccess(ResultMsg resultMsg) {
-//                JLog.v(resultMsg);
-//            }
-//
-//            @Override
-//            public void onFailure(Throwable throwable) {
-//                throwable.printStackTrace();
-//            }
-//        });
-//    }
-
-    private void sendTest2() {
-        OkHttpUtil.getInstance(this).post("http://www.yanyi.red/api/AppMsg.php").async(null, new onOkHttpListener() {
-            @Override
-            public void onCompleted() {
-                JLog.v();
-            }
-
-            @Override
-            public void onSuccess(ResultMsg resultMsg) {
-                JLog.v(resultMsg);
-            }
-
-            @Override
-            public void onFailure(Throwable throwable) {
-                throwable.printStackTrace();
-            }
-        });
-        OkHttpUtil.getInstance(this).post("http://www.yanyi.red/api/TestApi.php").async(null, new onOkHttpListener() {
-            @Override
-            public void onCompleted() {
-                JLog.v();
-            }
-
-            @Override
-            public void onSuccess(ResultMsg resultMsg) {
-                JLog.v(resultMsg);
-            }
-
-            @Override
-            public void onFailure(Throwable throwable) {
-                throwable.printStackTrace();
-            }
-        });
     }
 
-    @Override
-    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
-                                           @NonNull int[] grantResults) {
-        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
-        permissionsHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
-    }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-        permissionsHelper.onActivityResult(requestCode, resultCode, data);
-    }
 }

+ 12 - 5
build.gradle

@@ -1,15 +1,15 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 
 buildscript {
-    
+
     repositories {
         google()
         jcenter()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.0.1'
-        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
-        
+        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
+        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
@@ -20,8 +20,15 @@ allprojects {
     repositories {
         google()
         jcenter()
-        maven {
-            url 'https://jitpack.io'
+        //解决中文乱码问题
+        tasks.withType(Javadoc) { //兼容中文
+            options.addStringOption('Xdoclint:none', '-quiet')
+            options.addStringOption('encoding', 'UTF-8')
+            options {
+                encoding "UTF-8"
+                charSet 'UTF-8'
+                links "http://docs.oracle.com/javase/7/docs/api"
+            }
         }
     }
 }

+ 0 - 19
okhttp2/src/main/java/com/mylove/okhttp/Cache.java

@@ -1,19 +0,0 @@
-package com.mylove.okhttp;
-
-import android.content.Context;
-
-/**
- * @author myLove
- * @time 2017/12/26 17:23
- * @e-mail love@yanyi.red
- * @overview
- */
-
-class Cache {
-    /**
-     * 设置缓存路径,以及缓存文件大小
-     */
-    static okhttp3.Cache privateCache(Context mContext) {
-        return new okhttp3.Cache(mContext.getCacheDir(), 1024 * 1024);
-    }
-}

+ 0 - 29
okhttp2/src/main/java/com/mylove/okhttp/DownloadBean.java

@@ -1,29 +0,0 @@
-package com.mylove.okhttp;
-
-/**
- * @author myLove
- * @time 2017/11/24 14:02
- * @e-mail mylove.520.y@gmail.com
- * @overview
- */
-
-class DownloadBean {
-    private String str;
-    private int progress;
-
-    public String getStr() {
-        return str;
-    }
-
-    public void setStr(String str) {
-        this.str = str;
-    }
-
-    public int getProgress() {
-        return progress;
-    }
-
-    public void setProgress(int progress) {
-        this.progress = progress;
-    }
-}

+ 0 - 351
okhttp2/src/main/java/com/mylove/okhttp/FormatUtil.java

@@ -1,351 +0,0 @@
-package com.mylove.okhttp;
-
-import android.content.Context;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * 字符串工具类
- */
- class FormatUtil {
-
-
-     static final String EMPTY = "";
-
-    /**
-     * 判断字符串是否为空
-     *
-     * @param str
-     * @return true 不为空, false 为空
-     */
-     static boolean isNotEmpty(String str) {
-        return str != null && !"null".equals(str) && str.trim().length() != 0;
-    }
-
-    /**
-     * 判断字符串是否为空
-     *
-     * @param str
-     * @return true 为空,false 不为空
-     */
-     static boolean isEmpty(String str) {
-        return str == null || "null".equals(str) || str.trim().length() == 0;
-    }
-
-     static final SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm", Locale.CHINA);
-
-     static String getCurrentTime() {
-        return dateformat.format(new Date());
-    }
-
-     static final SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
-
-     static String formatDateTime(long millseconds) {
-        return sdformat.format(new Date(millseconds));
-    }
-
-     static String getCurrentDateTime() {
-        return sdformat.format(new Date());
-    }
-
-    /**
-     * 判断集合是否为空
-     */
-     static <T> boolean isCollectionsNotEmpty(Collection<T> collection) {
-        return collection != null && collection.size() > 0;
-    }
-
-    /**
-     * 判断MAP是否为空
-     */
-     static <K, V> boolean isMapNotEmpty(Map<K, V> map) {
-        return map != null && map.size() > 0;
-    }
-
-    /**
-     * 判断List是否为空
-     */
-     static boolean isListEmpty(List<?> array) {
-        return array != null && array.size() == 0;
-    }
-
-    /**
-     * 判断JSON数组是否为空
-     */
-     static boolean isJSONArrayEmpty(JSONArray array) {
-        return array == null || array.length() == 0;
-    }
-
-     static boolean isObjectNotNull(Object object) {
-        if (object != null && object.getClass().isArray()) {
-            // 如果是数组类型
-            throw new UnsupportedOperationException("isObjectNotNull not supported operation :" + object);
-        }
-        return object != null;
-    }
-
-    /**
-     * 判断JSON数据不空为
-     */
-     static boolean isJSONArrayNotEmpty(JSONArray array) {
-        return array != null && array.length() > 0;
-    }
-
-    /**
-     * 判断JSON数组是否为空
-     */
-     static boolean isJSONObjectEmpty(JSONObject object) {
-        return object == null || object.length() == 0;
-    }
-
-    /**
-     * 判断JSON数据不空为
-     */
-     static boolean isJSONObjectNotEmpty(JSONObject object) {
-        return object != null && object.length() > 0;
-    }
-
-     static boolean isIntArrayNotEmpty(int[] array) {
-        return array != null && array.length > 0;
-    }
-
-    /**
-     * 判断List数据不空为
-     */
-     static boolean isListNotEmpty(List<?> array) {
-        return array != null && array.size() > 0;
-    }
-
-    /**
-     * 判断long数组不为空
-     *
-     * @param array
-     * @return
-     */
-     static boolean isLongArrayNotEmpty(long[] array) {
-        return array != null && array.length > 0;
-    }
-
-    /**
-     * 判断float数组不为空
-     *
-     * @param array
-     * @return
-     */
-     static boolean isFloatArrayNotEmpty(float[] array) {
-        return array != null && array.length > 0;
-    }
-
-    /**
-     * 判断double数组不为空
-     *
-     * @param array
-     * @return
-     */
-     static boolean isDoubleArrayNotEmpty(double[] array) {
-        return array != null && array.length > 0;
-    }
-
-    /**
-     * 该方法主要使用正则表达式来判断字符串中是否包含字母
-     *
-     * @param cardNum
-     * @return 返回是否包含
-     */
-     static boolean isJudge(String cardNum) {
-        String regex = ".*[a-zA-Z]+.*";
-        Matcher m = Pattern.compile(regex).matcher(cardNum);
-        return m.matches();
-    }
-
-     static boolean isNotBlank(String str) {
-        return (str != null) && (str.length() != 0);
-    }
-
-     static boolean isBlank(String str) {
-        return (str == null) || (str.length() == 0);
-    }
-
-     static boolean isNotTrimBlank(String str) {
-        return (str != null) && (str.trim().length() != 0);
-    }
-
-     static boolean isTrimBlank(String str) {
-        return (str == null) || (str.trim().length() == 0);
-    }
-
-    /**
-     * 判断是否是身份证
-     *
-     * @param idNo
-     * @return
-     */
-     static boolean isIdNo(String idNo) {
-//        if (isTrimBlank(idNo))
-//        {
-//            return false;
-//        }
-//        Pattern p = Pattern.compile("^([1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3})|([1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[X,x]))$");
-//        Matcher matcher = p.matcher(idNo);
-//        return matcher.find();
-        if (isTrimBlank(idNo)) {
-            return false;
-        }
-        Pattern p = Pattern.compile("^([1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3})|([1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[X,x]))$");
-        Matcher matcher = p.matcher(idNo);
-        return !matcher.find();
-    }
-
-    /**
-     * 判断是否为手机号
-     *
-     * @param mobiles
-     * @return
-     */
-     static boolean isNotMobileNO(String mobiles) {
-//        Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
-        Pattern p = Pattern.compile("^((1[358][0-9])|(14[57])|(17[0678]))\\d{8}$");
-        Matcher m = p.matcher(mobiles);
-        return !m.matches();
-    }
-
-    /**
-     * 判断是否为邮箱号
-     *
-     * @param email
-     * @return
-     */
-     static boolean isEmail(String email) {
-        if (isTrimBlank(email)) {
-            return false;
-        }
-        String str = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
-        Pattern p = Pattern.compile(str);
-        Matcher m = p.matcher(email);
-        return m.matches();
-    }
-
-    /**
-     * 在HTML特殊字符的处理
-     *
-     * @param source
-     * @return
-     */
-     static String htmlEscapeCharsToString(String source) {
-        return FormatUtil.isEmpty(source) ? source : source.replaceAll("&lt;", "<")
-                .replaceAll("&gt;", ">")
-                .replaceAll("&amp;", "&")
-                .replaceAll("&quot;", "\"")
-                .replaceAll("&copy;", "©")
-                .replaceAll("&yen;", "¥")
-                .replaceAll("&divide;", "÷")
-                .replaceAll("&times;", "×")
-                .replaceAll("&reg;", "®")
-                .replaceAll("&sect;", "§")
-                .replaceAll("&pound;", "£")
-                .replaceAll("&cent;", "¢");
-    }
-
-    /**
-     * 验证用户名是否合法
-     *
-     * @param id
-     * @return
-     */
-     static boolean isNotUserName(String id) {
-        if (isTrimBlank(id)) {
-            return false;
-        }
-        // 字母开头,由字母,数字和下划线组成的长度为2到16的字符串
-        Pattern p = Pattern.compile("^[a-zA-Z0-9_-]{2,16}$");
-        Matcher m = p.matcher(id);
-        return !m.find();
-    }
-
-     static boolean isNotPassWord(String password) {
-        if (isTrimBlank(password)) {
-            return false;
-        }
-        // 就是以大小写字母开头,由大小写字母,数字和下划线组成的长度为6到18的字符串
-        Pattern p = Pattern.compile("^[a-zA-Z0-9_]{6,18}$");
-        Matcher m = p.matcher(password);
-        return !m.find();
-    }
-
-    /**
-     * 判断银行卡号是否合法
-     *
-     * @param bankCard
-     * @return
-     */
-     static boolean isNotBank(String bankCard) {
-        if (isTrimBlank(bankCard)) {
-            return false;
-        }
-        // 一共16或19位,都是数字。
-        Pattern p = Pattern.compile("^\\d{16}$|^\\d{19}$");
-        Matcher m = p.matcher(bankCard);
-        return !m.find();
-    }
-
-    /**
-     * @param context
-     * @param resId
-     * @param str
-     * @return
-     */
-     static String isStringFormat(Context context, int resId, String str) {
-        return String.format(context.getResources().getString(resId), str);
-    }
-
-    /**
-     * 从Raw文件中读取
-     *
-     * @param context
-     * @param resId
-     * @return
-     */
-     static String getFromRaw(Context context, int resId) {
-        try {
-            InputStreamReader inputReader = new InputStreamReader(context.getResources().openRawResource(resId));
-            BufferedReader bufReader = new BufferedReader(inputReader);
-            String line = "";
-            StringBuilder Result = new StringBuilder();
-            while ((line = bufReader.readLine()) != null)
-                Result.append(line);
-            return Result.toString();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    // 直接从assets读取
-     static String getFromAssets(Context context, String fileName) {
-        try {
-            InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName));
-            BufferedReader bufReader = new BufferedReader(inputReader);
-            String line = "";
-            StringBuilder Result = new StringBuilder();
-            while ((line = bufReader.readLine()) != null) {
-                Result.append(line);
-            }
-            return Result.toString();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-}

+ 0 - 37
okhttp2/src/main/java/com/mylove/okhttp/ResultMsg.java

@@ -1,37 +0,0 @@
-package com.mylove.okhttp;
-
-/**
- * @author myLove
- * @time 2017/12/14 16:50
- * @e-mail mylove.520.y@gmail.com
- * @overview
- */
-
-public class ResultMsg {
-    private String code;
-    private String result;
-
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-
-    public String getResult() {
-        return result;
-    }
-
-    public void setResult(String result) {
-        this.result = result;
-    }
-
-    @Override
-    public String toString() {
-        return "ResultMsg{" +
-                "code='" + code + '\'' +
-                ", result='" + result + '\'' +
-                '}';
-    }
-}

+ 0 - 0
okhttp2/.gitignore → okhttplib/.gitignore


+ 80 - 0
okhttplib/bintrayUpload.gradle

@@ -0,0 +1,80 @@
+// 这里添加下面两行代码。
+apply plugin: 'com.github.dcendents.android-maven'
+apply plugin: 'com.jfrog.bintray'
+
+// 定义两个链接,下面会用到。
+def siteUrl = 'https://github.com/BenYanYi/OkHttp' // 项目主页。
+def gitUrl = 'https://github.com/BenYanYi/OkHttp.git' // Git仓库的url。
+
+group = "com.yanyi.benyanyi"// 唯一包名,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的com.ansen.http就是这里配置的。
+version = "1.0.1"//项目引用的版本号,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的1.0.1就是这里配置的。
+install {
+    repositories.mavenInstaller {
+        // This generates POM.xml with proper parameters
+        pom {
+            project {
+                packaging 'aar'
+                // Add your description here
+                name 'multi-format 1D/2D barcode image processing use zxing.'
+                url siteUrl
+                // Set your license
+                licenses {
+                    license {
+                        name 'The Apache Software License, Version 2.0'
+                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+                    }
+                }
+                developers {
+                    developer {
+                        id 'benyanyi'     //填写的一些基本信息
+                        name 'benyanyi'
+                        email 'git@yanyi.red'
+                    }
+                }
+                scm {
+                    connection gitUrl
+                    developerConnection gitUrl
+                    url siteUrl
+                }
+            }
+        }
+    }
+}
+task sourcesJar(type: Jar) {
+    from android.sourceSets.main.java.srcDirs
+    classifier = 'sources'
+}
+task javadoc(type: Javadoc) {
+    source = android.sourceSets.main.java.srcDirs
+    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+}
+task javadocJar(type: Jar, dependsOn: javadoc) {
+    classifier = 'javadoc'
+    from javadoc.destinationDir
+}
+artifacts {
+    archives javadocJar
+    archives sourcesJar
+}
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
+bintray {
+    user = properties.getProperty("bintray.user")
+    key = properties.getProperty("bintray.apikey")
+    configurations = ['archives']
+    pkg {
+        repo = "OkHttpLib"
+        name = "OkHttpLib"   //发布到JCenter上的项目名字
+        websiteUrl = siteUrl
+        vcsUrl = gitUrl
+        licenses = ["Apache-2.0"]
+        publish = true
+    }
+}
+javadoc { //jav doc采用utf-8编码否则会报“GBK的不可映射字符”错误
+    options{
+        encoding "UTF-8"
+        charSet 'UTF-8'
+    }
+}
+//gradlew bintrayUpload    terminal中输入

+ 5 - 4
okhttp2/build.gradle → okhttplib/build.gradle

@@ -1,6 +1,4 @@
 apply plugin: 'com.android.library'
-apply plugin: 'com.github.dcendents.android-maven'
-group = 'com.github.BenYanYi'
 
 android {
     compileSdkVersion 26
@@ -34,7 +32,10 @@ dependencies {
     androidTestImplementation 'com.android.support.test:runner:1.0.1'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
     compile 'com.squareup.okhttp3:okhttp:3.9.0'
+    //网络请求log 拦截器
+    compile 'com.squareup.okhttp3:logging-interceptor:3.9.0'
     compile 'com.squareup.okio:okio:1.13.0'
-    compile 'io.reactivex:rxjava:1.3.3'
-    compile 'io.reactivex:rxandroid:1.2.1'
+    compile 'io.reactivex.rxjava2:rxjava:2.1.4'
+    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
 }
+apply from: 'bintrayUpload.gradle'

+ 0 - 0
okhttp2/proguard-rules.pro → okhttplib/proguard-rules.pro


+ 0 - 0
okhttp2/src/androidTest/java/com/mylove/okhttp/ExampleInstrumentedTest.java → okhttplib/src/androidTest/java/com/mylove/okhttp/ExampleInstrumentedTest.java


+ 0 - 0
okhttp2/src/main/AndroidManifest.xml → okhttplib/src/main/AndroidManifest.xml


+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/AutoRequest.java → okhttplib/src/main/java/com/mylove/okhttp/AutoRequest.java

@@ -7,9 +7,6 @@ import java.util.Map;
 
 /**
  * @author myLove
- * @time 2017/11/15 14:17
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 public class AutoRequest {

+ 30 - 0
okhttplib/src/main/java/com/mylove/okhttp/Cache.java

@@ -0,0 +1,30 @@
+package com.mylove.okhttp;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import okhttp3.logging.HttpLoggingInterceptor;
+
+/**
+ * @author myLove
+ */
+
+class Cache {
+    /**
+     * 设置缓存路径,以及缓存文件大小
+     */
+    static okhttp3.Cache privateCache(Context mContext) {
+        return new okhttp3.Cache(mContext.getCacheDir(), 1024 * 1024);
+    }
+
+    static HttpLoggingInterceptor HTTP_LOGGING_INTERCEPTOR =
+            new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
+                @Override
+                public void log(@NonNull String message) {
+                    if (OkHttpInfo.isLOG) {
+                        Log.v(OkHttpInfo.TAG, message);
+                    }
+                }
+            }).setLevel(HttpLoggingInterceptor.Level.BODY);
+}

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/CacheInterceptor.java → okhttplib/src/main/java/com/mylove/okhttp/CacheInterceptor.java

@@ -8,9 +8,6 @@ import okhttp3.Response;
 
 /**
  * @author myLove
- * @time 2017/11/7 16:26
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
  class CacheInterceptor implements Interceptor {

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/CacheUtils.java → okhttplib/src/main/java/com/mylove/okhttp/CacheUtils.java

@@ -13,9 +13,6 @@ import java.io.OutputStreamWriter;
 
 /**
  * @author myLove
- * @time 2017/11/7 17:03
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class CacheUtils {

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/CallType.java → okhttplib/src/main/java/com/mylove/okhttp/CallType.java

@@ -2,9 +2,6 @@ package com.mylove.okhttp;
 
 /**
  * @author myLove
- * @time 2017/11/15 14:02
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 enum CallType {

+ 33 - 30
okhttp2/src/main/java/com/mylove/okhttp/DownloadObservable.java → okhttplib/src/main/java/com/mylove/okhttp/DownloadObservable.java

@@ -11,6 +11,13 @@ import java.io.InputStream;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
+import io.reactivex.Observable;
+import io.reactivex.ObservableEmitter;
+import io.reactivex.ObservableOnSubscribe;
+import io.reactivex.Observer;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.Disposable;
+import io.reactivex.schedulers.Schedulers;
 import okhttp3.Call;
 import okhttp3.Callback;
 import okhttp3.FormBody;
@@ -18,16 +25,9 @@ import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.Response;
 import okhttp3.ResponseBody;
-import rx.Observable;
-import rx.Subscriber;
-import rx.android.schedulers.AndroidSchedulers;
-import rx.schedulers.Schedulers;
 
 /**
  * @author myLove
- * @time 2017/11/24 13:38
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class DownloadObservable {
@@ -51,6 +51,7 @@ class DownloadObservable {
                     OkHttpClient httpClient = new OkHttpClient();
                     okHttpClient = httpClient.newBuilder()
                             .addNetworkInterceptor(new CacheInterceptor())
+                            .addInterceptor(Cache.HTTP_LOGGING_INTERCEPTOR)
                             .cache(Cache.privateCache(context))
                             .connectTimeout(30, TimeUnit.SECONDS)
                             .readTimeout(30, TimeUnit.SECONDS)
@@ -88,10 +89,15 @@ class DownloadObservable {
 
     void request(String url, Map<Object, Object> oMap, final onOkHttpListener onOkHttpListener) {
         getObservable(url, oMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new Subscriber<ResultMsg>() {
+                .subscribe(new Observer<String>() {
                     @Override
-                    public void onCompleted() {
-                        onOkHttpListener.onCompleted();
+                    public void onSubscribe(Disposable d) {
+
+                    }
+
+                    @Override
+                    public void onNext(String str) {
+                        onOkHttpListener.onSuccess(str);
                     }
 
                     @Override
@@ -100,36 +106,36 @@ class DownloadObservable {
                     }
 
                     @Override
-                    public void onNext(ResultMsg s) {
-                        onOkHttpListener.onSuccess(s);
+                    public void onComplete() {
+                        onOkHttpListener.onCompleted();
                     }
                 });
     }
 
-    private Observable<ResultMsg> getObservable(final String url, final Map<Object, Object> oMap) {
-        return Observable.create(new Observable.OnSubscribe<ResultMsg>() {
+    private Observable<String> getObservable(final String url, final Map<Object, Object> oMap) {
+        return Observable.create(new ObservableOnSubscribe<String>() {
             @Override
-            public void call(Subscriber<? super ResultMsg> subscriber) {
-                send(url, oMap, subscriber);
+            public void subscribe(ObservableEmitter<String> e) {
+                send(url, oMap, e);
             }
         });
     }
 
-    private void send(final String url, final Map<Object, Object> oMap, final Subscriber<? super ResultMsg> subscriber) {
+    private void send(final String url, final Map<Object, Object> oMap, final ObservableEmitter<String> subscriber) {
         InternetBean bean = Internet.ifInternet(mContext);
         if (bean.getStatus()) {
             Call call = okHttpClient.newCall(getRequest(url, oMap));
-            sendCall(url,call,subscriber);
+            sendCall(url, call, subscriber);
         } else {
             subscriber.onError(new Exception(bean.getMsg()));
-            subscriber.onCompleted();
+            subscriber.onComplete();
         }
     }
 
     /**
      * 请求
      */
-    private void sendCall(String url, Call call, Subscriber<? super ResultMsg> subscriber) {
+    private void sendCall(String url, Call call, ObservableEmitter<String> subscriber) {
         if (callType == CallType.SYNC) {
             sync(url, call, subscriber);
         } else if (callType == CallType.ASYNC) {
@@ -140,7 +146,7 @@ class DownloadObservable {
     /**
      * 异步请求
      */
-    private void sync(final String url, Call call, final Subscriber<? super ResultMsg> subscriber) {
+    private void sync(final String url, Call call, final ObservableEmitter<String> subscriber) {
         try {
             Response execute = call.execute();
             if (execute.isSuccessful()) {
@@ -151,18 +157,18 @@ class DownloadObservable {
         } catch (IOException e) {
             subscriber.onError(e);
         }
-        subscriber.onCompleted();
+        subscriber.onComplete();
     }
 
     /**
      * 同步请求
      */
-    private void async(final String url, Call call, final Subscriber<? super ResultMsg> subscriber) {
+    private void async(final String url, Call call, final ObservableEmitter<String> subscriber) {
         call.enqueue(new Callback() {
             @Override
             public void onFailure(@NonNull Call call, @NonNull IOException e) {
                 subscriber.onError(e);
-                subscriber.onCompleted();
+                subscriber.onComplete();
             }
 
             @Override
@@ -177,7 +183,7 @@ class DownloadObservable {
      *
      * @param body
      */
-    private void save(ResponseBody body, String url, Subscriber<? super ResultMsg> subscriber) {
+    private void save(ResponseBody body, String url, ObservableEmitter<String> subscriber) {
         if (null == fileName && "".equals(fileName) && fileName.length() <= 0) {
             int lastIndexOf = url.lastIndexOf("/");
             String pathStr = url.subSequence(lastIndexOf + 1, url.length()).toString();
@@ -195,10 +201,7 @@ class DownloadObservable {
                 fos.write(buf, 0, len);
             }
             fos.flush();
-            ResultMsg msg = new ResultMsg();
-            msg.setCode("200");
-            msg.setResult(fileName);
-            subscriber.onNext(msg);
+            subscriber.onNext(fileName);
         } catch (Exception e) {
             subscriber.onError(e);
         } finally {
@@ -213,7 +216,7 @@ class DownloadObservable {
                 subscriber.onError(e);
             }
         }
-        subscriber.onCompleted();
+        subscriber.onComplete();
     }
 
     /**

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/DownloadRequest.java → okhttplib/src/main/java/com/mylove/okhttp/DownloadRequest.java

@@ -7,9 +7,6 @@ import java.util.Map;
 
 /**
  * @author myLove
- * @time 2017/11/24 13:36
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 public class DownloadRequest {

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/FileUtil.java → okhttplib/src/main/java/com/mylove/okhttp/FileUtil.java

@@ -9,9 +9,6 @@ import java.io.IOException;
 
 /**
  * @author myLove
- * @time 2017/11/24 13:55
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class FileUtil {

+ 37 - 0
okhttplib/src/main/java/com/mylove/okhttp/FormatUtil.java

@@ -0,0 +1,37 @@
+package com.mylove.okhttp;
+
+import java.util.Map;
+
+/**
+ * 字符串工具类
+ */
+class FormatUtil {
+
+    /**
+     * 判断字符串是否为空
+     *
+     * @param str
+     * @return true 不为空, false 为空
+     */
+    static boolean isNotEmpty(String str) {
+        return str != null && !"null".equals(str) && str.trim().length() != 0;
+    }
+
+    /**
+     * 判断字符串是否为空
+     *
+     * @param str
+     * @return true 为空,false 不为空
+     */
+    static boolean isEmpty(String str) {
+        return str == null || "null".equals(str) || str.trim().length() == 0;
+    }
+
+    /**
+     * 判断MAP是否为空
+     */
+    static <K, V> boolean isMapNotEmpty(Map<K, V> map) {
+        return map != null && map.size() > 0;
+    }
+
+}

+ 3 - 6
okhttp2/src/main/java/com/mylove/okhttp/Internet.java → okhttplib/src/main/java/com/mylove/okhttp/Internet.java

@@ -5,9 +5,6 @@ import android.content.Context;
 
 /**
  * @author myLove
- * @time 2017/11/15 13:42
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class Internet {
@@ -22,7 +19,7 @@ class Internet {
                 msg.setMsg("网络异常");
                 return msg;
             case 0:
-                if (!InternetUtil.isNetWorkConnected(mContext)) {
+                if (InternetUtil.isNetWorkConnected(mContext)) {
                     msg.setStatus(false);
                     msg.setMsg("网络异常");
                     return msg;
@@ -31,7 +28,7 @@ class Internet {
                     return msg;
                 }
             case 1:
-                if (!InternetUtil.isNetWorkConnected(mContext)) {
+                if (InternetUtil.isNetWorkConnected(mContext)) {
                     msg.setStatus(false);
                     msg.setMsg("WIFI网络异常");
                     return msg;
@@ -40,7 +37,7 @@ class Internet {
                     return msg;
                 }
             default:
-                if (!InternetUtil.isNetWorkConnected(mContext)) {
+                if (InternetUtil.isNetWorkConnected(mContext)) {
                     msg.setStatus(false);
                     msg.setMsg("网络异常");
                     return msg;

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/InternetBean.java → okhttplib/src/main/java/com/mylove/okhttp/InternetBean.java

@@ -2,9 +2,6 @@ package com.mylove.okhttp;
 
 /**
  * @author myLove
- * @time 2017/12/14 17:24
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class InternetBean {

+ 11 - 32
okhttp2/src/main/java/com/mylove/okhttp/InternetUtil.java → okhttplib/src/main/java/com/mylove/okhttp/InternetUtil.java

@@ -9,30 +9,27 @@ import android.net.wifi.WifiManager;
 
 /**
  * @author myLove
- * @time 2017/11/7 16:08
- * @e-mail mylove.520.y@gmail.com
- * @overview 网络工具类
  */
 
- class InternetUtil {
+class InternetUtil {
     /**
      * 判断是否有网络连接
      */
-     static boolean isNetWorkConnected(Context context) {
+    static boolean isNetWorkConnected(Context context) {
         ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo networkInfo = null;
         if (connectivityManager != null) {
             networkInfo = connectivityManager.getActiveNetworkInfo();
         }
-        return networkInfo != null && networkInfo.isAvailable();
+        return networkInfo == null || !networkInfo.isAvailable();
     }
 
     /**
      * 判断WIFI网络是否可用
-     *
-     * @msg 测试没用
+     * <p>
+     * 测试没用
      */
-     static boolean isWifiConnected(Context context) {
+    static boolean isWifiConnected(Context context) {
         ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo networkInfo = null;
         if (connectivityManager != null) {
@@ -43,10 +40,10 @@ import android.net.wifi.WifiManager;
 
     /**
      * 判断MOBILE网络是否可用
-     *
-     * @msg 测试没用
+     * <p>
+     * 测试没用
      */
-     static boolean isMobileConnected(Context context) {
+    static boolean isMobileConnected(Context context) {
         ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo networkInfo = null;
         if (connectivityManager != null) {
@@ -58,24 +55,13 @@ import android.net.wifi.WifiManager;
     /**
      * 获取当前网络连接的类型信息
      */
-     static int getConnectedType(Context context) {
+    static int getConnectedType(Context context) {
         int i = -1;
         ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
         if (networkInfo != null) {
             if (networkInfo.isAvailable()) {
                 i = networkInfo.getType();
-//                int type = networkInfo.getType();
-//                if (type == ConnectivityManager.TYPE_MOBILE) {
-//                    JLog.d(networkInfo.getExtraInfo());
-//                    if (networkInfo.getExtraInfo().toLowerCase() == "cmnet") {
-//                        JLog.d("CMNET");
-//                    } else {
-//                        JLog.d("CMWAP");
-//                    }
-//                } else if (type == ConnectivityManager.TYPE_WIFI) {
-//                    JLog.d("WIFI");
-//                }
             }
         }
         return i;
@@ -83,11 +69,8 @@ import android.net.wifi.WifiManager;
 
     /**
      * 获取当前ip地址
-     *
-     * @param context
-     * @return
      */
-     static String getLocalIpAddress(Context context) {
+    static String getLocalIpAddress(Context context) {
         try {
             WifiManager wifiManager = (WifiManager) context.getApplicationContext()
                     .getSystemService(Context.WIFI_SERVICE);
@@ -98,14 +81,10 @@ import android.net.wifi.WifiManager;
         } catch (Exception ex) {
             return " 获取IP出错!!!!请保证是WIFI,或者请重新打开网络!\n" + ex.getMessage();
         }
-        // return null;
     }
 
     /**
      * 将ip的整数形式转换成ip形式
-     *
-     * @param ipInt
-     * @return
      */
     private static String int2ip(int ipInt) {
         return String.valueOf(ipInt & 0xFF) + "." +

+ 29 - 35
okhttp2/src/main/java/com/mylove/okhttp/MD5keyUtil.java → okhttplib/src/main/java/com/mylove/okhttp/MD5keyUtil.java

@@ -2,48 +2,45 @@ package com.mylove.okhttp;
 
 /**
  * @author myLove
- * @time 2017/11/7 17:05
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class MD5keyUtil {
     /*
-    * 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的, 这里把它们实现成为static final是表示了只读,切能在同一个进程空间内的多个 Instance间共享
-    */
-    static final int S11 = 7;
+     * 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的, 这里把它们实现成为static final是表示了只读,切能在同一个进程空间内的多个 Instance间共享
+     */
+    private static final int S11 = 7;
 
-    static final int S12 = 12;
+    private static final int S12 = 12;
 
-    static final int S13 = 17;
+    private static final int S13 = 17;
 
-    static final int S14 = 22;
+    private static final int S14 = 22;
 
-    static final int S21 = 5;
+    private static final int S21 = 5;
 
-    static final int S22 = 9;
+    private static final int S22 = 9;
 
-    static final int S23 = 14;
+    private static final int S23 = 14;
 
-    static final int S24 = 20;
+    private static final int S24 = 20;
 
-    static final int S31 = 4;
+    private static final int S31 = 4;
 
-    static final int S32 = 11;
+    private static final int S32 = 11;
 
-    static final int S33 = 16;
+    private static final int S33 = 16;
 
-    static final int S34 = 23;
+    private static final int S34 = 23;
 
-    static final int S41 = 6;
+    private static final int S41 = 6;
 
-    static final int S42 = 10;
+    private static final int S42 = 10;
 
-    static final int S43 = 15;
+    private static final int S43 = 15;
 
-    static final int S44 = 21;
+    private static final int S44 = 21;
 
-    static final byte[] PADDING = {-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    private static final byte[] PADDING = {-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
     /*
@@ -57,12 +54,10 @@ class MD5keyUtil {
 
     private static byte[] buffer = new byte[64]; // input buffer
 
-      /*
+    /*
      * digestHexStr是keyBean的唯一一个公共成员,是最新一次计算结果的 16进制ASCII表示.
      */
 
-     String digestHexStr;
-
     /*
      * digest,是最新一次计算结果的2进制内部表示,表示128bit的keyBean值.
      */
@@ -71,18 +66,18 @@ class MD5keyUtil {
     /*
      * getkeyBeanofStr是类keyBean最主要的公共方法,入口参数是你想要进行keyBean变换的字符串 返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
      */
-     String getkeyBeanofStr(String inbuf) {
+    String getkeyBeanofStr(String inbuf) {
         keyBeanInit();
         keyBeanUpdate(inbuf.getBytes(), inbuf.length());
         keyBeanFinal();
-        digestHexStr = "";
+        StringBuilder digestHexStr = new StringBuilder();
         for (int i = 0; i < 16; i++) {
-            digestHexStr += byteHEX(digest[i]);
+            digestHexStr.append(byteHEX(digest[i]));
         }
-        return digestHexStr;
+        return digestHexStr.toString();
     }
 
-     static MD5keyUtil mBean = null;
+    private static MD5keyUtil mBean = null;
 
     static MD5keyUtil newInstance() {
         if (mBean == null) {
@@ -94,7 +89,7 @@ class MD5keyUtil {
 
 
     // 这是keyBean这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
-     MD5keyUtil() {
+    private MD5keyUtil() {
         keyBeanInit();
         return;
     }
@@ -324,19 +319,18 @@ class MD5keyUtil {
     /*
      * b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算
      */
-     static long b2iu(byte b) {
+    private static long b2iu(byte b) {
         return b < 0 ? b & 0x7F + 128 : b;
     }
 
     /*
      * byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示, 因为java中的byte的toString无法实现这一点,我们又没有C语言中的 sprintf(outbuf,"%02X",ib)
      */
-     static String byteHEX(byte ib) {
+    private static String byteHEX(byte ib) {
         char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
         char[] ob = new char[2];
         ob[0] = Digit[(ib >>> 4) & 0X0F];
         ob[1] = Digit[ib & 0X0F];
-        String s = new String(ob);
-        return s;
+        return new String(ob);
     }
 }

+ 61 - 98
okhttp2/src/main/java/com/mylove/okhttp/ObservableRequest.java → okhttplib/src/main/java/com/mylove/okhttp/ObservableRequest.java

@@ -10,6 +10,13 @@ import java.io.IOException;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
+import io.reactivex.Observable;
+import io.reactivex.ObservableEmitter;
+import io.reactivex.ObservableOnSubscribe;
+import io.reactivex.Observer;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.Disposable;
+import io.reactivex.schedulers.Schedulers;
 import okhttp3.Call;
 import okhttp3.Callback;
 import okhttp3.FormBody;
@@ -19,20 +26,12 @@ import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.RequestBody;
 import okhttp3.Response;
-import rx.Observable;
-import rx.Subscriber;
-import rx.android.schedulers.AndroidSchedulers;
-import rx.schedulers.Schedulers;
 
 /**
  * @author myLove
- * @time 2017/11/15 14:19
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 class ObservableRequest {
-
     @SuppressLint("StaticFieldLeak")
     private static ObservableRequest instance;
     @SuppressLint("StaticFieldLeak")
@@ -42,9 +41,6 @@ class ObservableRequest {
 
     private static OkHttpClient okHttpClient;
     private String mCacheUrl = "";
-    private MediaType mediaType = MediaType.parse("text/xml; charset=UTF-8");
-    private static String urlMsg;
-    private static String label;
 
     static ObservableRequest getInstance(Context context, RequestType type1, CallType type2) {
         if (instance == null) {
@@ -54,6 +50,7 @@ class ObservableRequest {
                     OkHttpClient httpClient = new OkHttpClient();
                     okHttpClient = httpClient.newBuilder()
                             .addNetworkInterceptor(new CacheInterceptor())
+                            .addInterceptor(Cache.HTTP_LOGGING_INTERCEPTOR)
                             .cache(Cache.privateCache(context))
                             .connectTimeout(30, TimeUnit.SECONDS)
                             .readTimeout(30, TimeUnit.SECONDS)
@@ -67,35 +64,17 @@ class ObservableRequest {
         return instance;
     }
 
-    static ObservableRequest getInstance(String msg, String labelStr, Context context, RequestType type1, CallType type2) {
-        if (instance == null) {
-            synchronized (ObservableRequest.class) {
-                if (instance == null) {
-                    instance = new ObservableRequest();
-                    OkHttpClient httpClient = new OkHttpClient();
-                    okHttpClient = httpClient.newBuilder()
-                            .addNetworkInterceptor(new CacheInterceptor())
-                            .cache(Cache.privateCache(context))
-                            .connectTimeout(30, TimeUnit.SECONDS)
-                            .readTimeout(30, TimeUnit.SECONDS)
-                            .build();
-                }
-            }
-        }
-        urlMsg = msg;
-        label = labelStr;
-        mContext = context;
-        requestType = type1;
-        callType = type2;
-        return instance;
-    }
-
     void request(String url, Map<Object, Object> oMap, final onOkHttpListener onOkHttpListener) {
         getObservable(url, oMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new Subscriber<ResultMsg>() {
+                .subscribe(new Observer<String>() {
                     @Override
-                    public void onCompleted() {
-                        onOkHttpListener.onCompleted();
+                    public void onSubscribe(Disposable d) {
+
+                    }
+
+                    @Override
+                    public void onNext(String str) {
+                        onOkHttpListener.onSuccess(str);
                     }
 
                     @Override
@@ -104,22 +83,22 @@ class ObservableRequest {
                     }
 
                     @Override
-                    public void onNext(ResultMsg s) {
-                        onOkHttpListener.onSuccess(s);
+                    public void onComplete() {
+                        onOkHttpListener.onCompleted();
                     }
                 });
     }
 
-    private Observable<ResultMsg> getObservable(final String url, final Map<Object, Object> oMap) {
-        return Observable.unsafeCreate(new Observable.OnSubscribe<ResultMsg>() {
+    private Observable<String> getObservable(final String url, final Map<Object, Object> oMap) {
+        return Observable.create(new ObservableOnSubscribe<String>() {
             @Override
-            public void call(Subscriber<? super ResultMsg> subscriber) {
-                send(url, oMap, subscriber);
+            public void subscribe(ObservableEmitter<String> e) {
+                send(url, oMap, e);
             }
         });
     }
 
-    private void send(String url, Map<Object, Object> map, Subscriber<? super ResultMsg> subscriber) {
+    private void send(String url, Map<Object, Object> map, ObservableEmitter<String> subscriber) {
         if (FormatUtil.isMapNotEmpty(map)) {
             mCacheUrl = url + map.toString();
         } else {
@@ -132,14 +111,11 @@ class ObservableRequest {
         } else {
             String json = CacheUtils.getInstance(mContext).getCacheToLocalJson(mCacheUrl);
             if (FormatUtil.isNotEmpty(json)) {
-                ResultMsg msg = new ResultMsg();
-                msg.setCode("404");
-                msg.setResult(json);
-                subscriber.onNext(msg);
+                subscriber.onNext(json);
             } else {
                 subscriber.onError(new Error(bean.getMsg()));
             }
-            subscriber.onCompleted();
+            subscriber.onComplete();
         }
 
     }
@@ -147,7 +123,7 @@ class ObservableRequest {
     /**
      * 请求
      */
-    void sendCall(Call call, Subscriber<? super ResultMsg> subscriber) {
+    private void sendCall(Call call, ObservableEmitter<String> subscriber) {
         if (callType == CallType.SYNC) {
             sync(call, subscriber);
         } else if (callType == CallType.ASYNC) {
@@ -158,88 +134,72 @@ class ObservableRequest {
     /**
      * 同步请求
      */
-    private void sync(Call call, Subscriber<? super ResultMsg> subscriber) {
+    private void sync(Call call, ObservableEmitter<String> subscriber) {
         try {
             Response execute = call.execute();
-            ResultMsg msg = new ResultMsg();
-            int code = execute.code();
-            msg.setCode(code + "");
-            msg.setResult("");
             if (execute.isSuccessful()) {
                 String str = execute.body().string();
-                if (OkHttpUtil.isLOG) {
-                    Log.v("onResponse-->>>", str);
+                if (OkHttpInfo.isLOG) {
+                    Log.v(OkHttpInfo.TAG, str);
                 }
-                msg.setResult(str);
                 if (!str.toUpperCase().contains("<!DOCTYPE HTML>")) {
                     if (FormatUtil.isNotEmpty(mCacheUrl)) {
                         CacheUtils.getInstance(mContext).setCacheToLocalJson(mCacheUrl, str);
                     }
                 }
-                subscriber.onNext(msg);
-                subscriber.onCompleted();
+                subscriber.onNext(str);
+                subscriber.onComplete();
             } else {
                 String json = CacheUtils.getInstance(mContext).getCacheToLocalJson(mCacheUrl);
                 if (FormatUtil.isNotEmpty(json)) {
-                    msg.setResult(json);
-                    subscriber.onNext(msg);
+                    subscriber.onNext(json);
                 } else {
                     subscriber.onError(new Exception("请求失败"));
                 }
-                subscriber.onCompleted();
+                subscriber.onComplete();
             }
         } catch (IOException e) {
             String json = CacheUtils.getInstance(mContext).getCacheToLocalJson(mCacheUrl);
-            ResultMsg msg = new ResultMsg();
-            msg.setCode("404");
             if (FormatUtil.isNotEmpty(json)) {
-                msg.setResult(json);
-                subscriber.onNext(msg);
+                subscriber.onNext(json);
             } else {
                 subscriber.onError(e);
             }
             e.printStackTrace();
-            subscriber.onCompleted();
+            subscriber.onComplete();
         }
     }
 
     /**
      * 异步请求
      */
-    private void async(Call call, final Subscriber<? super ResultMsg> subscriber) {
+    private void async(Call call, final ObservableEmitter<String> subscriber) {
         call.enqueue(new Callback() {
             @Override
             public void onFailure(@NonNull Call call, @NonNull IOException e) {
                 String json = CacheUtils.getInstance(mContext).getCacheToLocalJson(mCacheUrl);
-                ResultMsg msg = new ResultMsg();
-                msg.setCode("404");
                 if (FormatUtil.isNotEmpty(json)) {
-                    msg.setResult(json);
-                    subscriber.onNext(msg);
+                    subscriber.onNext(json);
                 } else {
                     subscriber.onError(e);
                 }
                 e.printStackTrace();
-                subscriber.onCompleted();
+                subscriber.onComplete();
             }
 
             @Override
             public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                 String str = response.body().string();
-                if (OkHttpUtil.isLOG) {
-                    Log.v("onResponse-->>>", str);
+                if (OkHttpInfo.isLOG) {
+                    Log.v(OkHttpInfo.TAG, str);
                 }
-                ResultMsg msg = new ResultMsg();
-                int code = response.code();
-                msg.setCode(code + "");
-                msg.setResult(str);
                 if (!str.toUpperCase().contains("<!DOCTYPE HTML>")) {
                     if (FormatUtil.isNotEmpty(mCacheUrl)) {
                         CacheUtils.getInstance(mContext).setCacheToLocalJson(mCacheUrl, str);
                     }
                 }
-                subscriber.onNext(msg);
-                subscriber.onCompleted();
+                subscriber.onNext(str);
+                subscriber.onComplete();
             }
         });
     }
@@ -285,25 +245,28 @@ class ObservableRequest {
     }
 
     private Request postXMLToSoap(String url, Map<Object, Object> oMap) {
-        if (!FormatUtil.isMapNotEmpty(oMap)) {
-            throw new NullPointerException("请求的数据不能为空");
+        if (FormatUtil.isEmpty(OkHttpInfo.soapDataTopString)) {
+            throw new NullPointerException("OkHttpInfo.soapDataTopString不能为空");
+        }
+        if (OkHttpInfo.soapDataBottomString != null) {
+            throw new NullPointerException("OkHttpInfo.soapDataBottomString为null");
         }
         StringBuilder sb = new StringBuilder();
-        sb.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:").append(label).append("=\"http://www.orion.com/lpz\">");
-        sb.append("<soapenv:Header/>");
-        sb.append("<soapenv:Body>");
-        sb.append("<").append(label).append(":").append(urlMsg).append(">");
-        for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
-            String key = entry.getKey().toString();
-            String value = entry.getValue().toString();
-            sb.append("<").append(label).append(":").append(key).append(">").append(value).append("</").append(label).append(":").append(key).append(">");
+        if (FormatUtil.isMapNotEmpty(oMap)) {
+            for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
+                String key = entry.getKey().toString();
+                String value = entry.getValue().toString();
+                sb.append("<").append(key).append(">").append(value).append("</").append(key).append(">");
+            }
+        }
+        MediaType mediaType = MediaType.parse(OkHttpInfo.soapMediaType);
+        String str = OkHttpInfo.soapDataTopString + sb + OkHttpInfo.soapDataBottomString;
+        if (OkHttpInfo.isLOG) {
+            Log.v(OkHttpInfo.TAG, str);
         }
-        sb.append("</").append(label).append(":").append(urlMsg).append(">");
-        sb.append("</soapenv:Body>");
-        sb.append("</soapenv:Envelope>");
         return new Request.Builder()
                 .url(url)
-                .post(RequestBody.create(mediaType, sb.toString()))
+                .post(RequestBody.create(mediaType, str))
                 .build();
     }
 
@@ -380,8 +343,8 @@ class ObservableRequest {
             }
             str = new StringBuilder(str.substring(0, str.length() - 1));
         }
-        if (OkHttpUtil.isLOG) {
-            Log.v("getURL-->>>", str.toString());
+        if (OkHttpInfo.isLOG) {
+            Log.v(OkHttpInfo.TAG, str.toString());
         }
         return new Request.Builder()
                 .url(str.toString())

+ 22 - 0
okhttplib/src/main/java/com/mylove/okhttp/OkHttpInfo.java

@@ -0,0 +1,22 @@
+package com.mylove.okhttp;
+
+/**
+ * @author myLove
+ */
+public class OkHttpInfo {
+    public static boolean isLOG = true;
+    /**
+     * soap协议类型
+     */
+    public static String soapMediaType = "text/xml; charset=UTF-8";
+    /**
+     * soap请求数据前半部分xml
+     */
+    public static String soapDataTopString = "";
+    /**
+     * soap请求数据后半部分xml
+     */
+    public static String soapDataBottomString = "";
+
+    public static String TAG = "OkHttpUtil--->>>>";
+}

+ 0 - 4
okhttp2/src/main/java/com/mylove/okhttp/OkHttpUtil.java → okhttplib/src/main/java/com/mylove/okhttp/OkHttpUtil.java

@@ -5,9 +5,6 @@ import android.content.Context;
 
 /**
  * @author myLove
- * @time 2017/11/2 14:41
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 public class OkHttpUtil {
@@ -15,7 +12,6 @@ public class OkHttpUtil {
     private static OkHttpUtil instance;
     @SuppressLint("StaticFieldLeak")
     private static Context mContext;
-    public static boolean isLOG = true;
 
     public static OkHttpUtil getInstance(Context context) {
         if (instance == null) {

+ 0 - 3
okhttp2/src/main/java/com/mylove/okhttp/RequestType.java → okhttplib/src/main/java/com/mylove/okhttp/RequestType.java

@@ -2,9 +2,6 @@ package com.mylove.okhttp;
 
 /**
  * @author myLove
- * @time 2017/11/15 14:15
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 enum RequestType {

+ 4 - 7
okhttp2/src/main/java/com/mylove/okhttp/XMLRequest.java → okhttplib/src/main/java/com/mylove/okhttp/XMLRequest.java

@@ -7,9 +7,6 @@ import java.util.Map;
 
 /**
  * @author myLove
- * @time 2018/1/4 15:14
- * @e-mail love@yanyi.red
- * @overview
  */
 
 public class XMLRequest {
@@ -37,11 +34,11 @@ public class XMLRequest {
         return instance;
     }
 
-    public void sync(String urlMsg, String labelStr, Map<Object, Object> map, onOkHttpListener onOkHttpListener) {
-        ObservableRequest.getInstance(urlMsg, labelStr, mContext, requestType, CallType.SYNC).request(url, map, onOkHttpListener);
+    public void sync(Map<Object, Object> map, onOkHttpListener onOkHttpListener) {
+        ObservableRequest.getInstance(mContext, requestType, CallType.SYNC).request(url, map, onOkHttpListener);
     }
 
-    public void async(String urlMsg, String labelStr, Map<Object, Object> map, onOkHttpListener onOkHttpListener) {
-        ObservableRequest.getInstance(urlMsg, labelStr, mContext, requestType, CallType.ASYNC).request(url, map, onOkHttpListener);
+    public void async(Map<Object, Object> map, onOkHttpListener onOkHttpListener) {
+        ObservableRequest.getInstance(mContext, requestType, CallType.ASYNC).request(url, map, onOkHttpListener);
     }
 }

+ 1 - 4
okhttp2/src/main/java/com/mylove/okhttp/onOkHttpListener.java → okhttplib/src/main/java/com/mylove/okhttp/onOkHttpListener.java

@@ -2,15 +2,12 @@ package com.mylove.okhttp;
 
 /**
  * @author myLove
- * @time 2017/11/2 14:51
- * @e-mail mylove.520.y@gmail.com
- * @overview
  */
 
 public interface onOkHttpListener {
     void onCompleted();
 
-    void onSuccess(ResultMsg requestMsg);
+    void onSuccess(String message);
 
     void onFailure(Throwable t);
 }

+ 0 - 0
okhttp2/src/main/res/values/strings.xml → okhttplib/src/main/res/values/strings.xml


+ 0 - 0
okhttp2/src/test/java/com/mylove/okhttp/ExampleUnitTest.java → okhttplib/src/test/java/com/mylove/okhttp/ExampleUnitTest.java


+ 1 - 1
settings.gradle

@@ -1 +1 @@
-include ':app', ':okhttp2'
+include ':app', ':okhttplib'