张波

提交代码

Showing 81 changed files with 5607 additions and 0 deletions
  1 +*.iml
  2 +.gradle
  3 +/local.properties
  4 +/.idea
  5 +.DS_Store
  6 +/build
  7 +/captures
  8 +.externalNativeBuild
  9 +.cxx
  10 +local.properties
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="EclipseCodeFormatterProjectSettings">
  4 + <option name="projectSpecificProfile">
  5 + <ProjectSpecificProfile>
  6 + <option name="formatter" value="ECLIPSE" />
  7 + <option name="importOrder" value="java;javax;org;android;androidx;com;" />
  8 + <option name="pathToConfigFileJava" value="$PROJECT_DIR$/config/CodeQuality/WonderTek_CodeFormatter_Convention_v1.0.xml" />
  9 + <option name="selectedJavaProfile" value="WonderTek_CodeFormatter_Convention_v1.0" />
  10 + </ProjectSpecificProfile>
  11 + </option>
  12 + </component>
  13 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
  5 + </component>
  6 +</project>
  1 +/build
  1 +plugins {
  2 + id 'com.android.application'
  3 + id 'kotlin-android'
  4 + id 'kotlin-android-extensions'
  5 +}
  6 +
  7 +android {
  8 + compileSdkVersion var.compileSdkVersion
  9 + buildToolsVersion var.buildToolsVersion
  10 +
  11 + defaultConfig {
  12 + applicationId "com.example.myapplication"
  13 + minSdkVersion var.minSdkVersion
  14 + targetSdkVersion var.targetSdkVersion
  15 + versionCode 1
  16 + versionName "1.0"
  17 +
  18 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  19 + multiDexEnabled true
  20 + ndk {
  21 + // noinspection ChromeOsAbiSupport
  22 + abiFilters "armeabi-v7a", "arm64-v8a", "x86"
  23 + }
  24 +
  25 + javaCompileOptions {
  26 + annotationProcessorOptions {
  27 + arguments = [AROUTER_MODULE_NAME: project.getName()]
  28 + }
  29 + }
  30 + }
  31 +
  32 + buildTypes {
  33 + release {
  34 + minifyEnabled false
  35 + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  36 + }
  37 + }
  38 +
  39 + lintOptions {
  40 + abortOnError false
  41 + }
  42 +
  43 + compileOptions {
  44 + // Java兼容性设置为Java 8
  45 + sourceCompatibility JavaVersion.VERSION_1_8
  46 + targetCompatibility JavaVersion.VERSION_1_8
  47 + }
  48 +}
  49 +
  50 +repositories {
  51 + flatDir {
  52 + dirs 'libs'
  53 + }
  54 +}
  55 +
  56 +dependencies {
  57 +// implementation 'androidx.appcompat:appcompat:1.6.1'
  58 + implementation "com.google.android.material:material:1.4.0"
  59 +// implementation project(path: ':wdstartup')
  60 + implementation 'com.wd:startup:1.0.0'
  61 +}
  1 +# Add project specific ProGuard rules here.
  2 +# You can control the set of applied configuration files using the
  3 +# proguardFiles setting in build.gradle.
  4 +#
  5 +# For more details, see
  6 +# http://developer.android.com/guide/developing/tools/proguard.html
  7 +
  8 +# If your project uses WebView with JS, uncomment the following
  9 +# and specify the fully qualified class name to the JavaScript interface
  10 +# class:
  11 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  12 +# public *;
  13 +#}
  14 +
  15 +# Uncomment this to preserve the line number information for
  16 +# debugging stack traces.
  17 +#-keepattributes SourceFile,LineNumberTable
  18 +
  19 +# If you keep the line number information, uncomment this to
  20 +# hide the original source file name.
  21 +#-renamesourcefileattribute SourceFile
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + package="com.example.myapplication">
  5 + <!-- 请求网络 -->
  6 + <uses-permission android:name="android.permission.INTERNET" />
  7 + <uses-feature
  8 + android:name="android.software.leanback"
  9 + android:required="false" />
  10 + <application
  11 + android:name=".MyApplication"
  12 + android:allowBackup="true"
  13 + android:fullBackupContent="@xml/backup_rules"
  14 + android:icon="@mipmap/ic_launcher"
  15 + android:label="@string/app_name"
  16 + android:roundIcon="@mipmap/ic_launcher_round"
  17 + android:supportsRtl="true"
  18 + android:theme="@style/Theme.MyApplication"
  19 + tools:targetApi="31">
  20 +
  21 + <activity
  22 + android:name="com.example.myapplication.MainActivity"
  23 + android:exported="true"
  24 + android:launchMode="singleTask">
  25 + <intent-filter>
  26 + <action android:name="android.intent.action.MAIN" />
  27 + <category android:name="android.intent.category.LAUNCHER" />
  28 + </intent-filter>
  29 + </activity>
  30 + </application>
  31 +</manifest>
  1 +
  2 +package com.example.myapplication;
  3 +
  4 +import android.app.Activity;
  5 +import android.os.Bundle;
  6 +
  7 +import androidx.annotation.Nullable;
  8 +
  9 +/**
  10 + * @ProjectName: PeopleDailyVideo
  11 + * @Package: com.people.displayui.main
  12 + * @ClassName: WelcomeActivity
  13 + * @Description: 启动APP过渡页面
  14 + * @Author: wd
  15 + * @CreateDate: 2022/10/28 17:36
  16 + * @UpdateUser: wd
  17 + * @UpdateDate: 2022/10/28 17:36
  18 + * @UpdateRemark: 更新说明:
  19 + * @Version: 1.0
  20 + */
  21 +public class MainActivity extends Activity {
  22 +
  23 + @Override
  24 + protected void onCreate(@Nullable Bundle savedInstanceState) {
  25 + super.onCreate(savedInstanceState);
  26 + // 直接进入首页
  27 + }
  28 +}
  1 +
  2 +package com.example.myapplication;
  3 +
  4 +import android.app.Application;
  5 +import android.util.Log;
  6 +
  7 +/**
  8 + * @author devel
  9 + * @time 2024/8/28 星期三 16:23
  10 + */
  11 +public class MyApplication extends Application {
  12 + @Override
  13 + public void onCreate() {
  14 + super.onCreate();
  15 + Log.e("zzzz","MyApplication onCreate");
  16 + // test
  17 + }
  18 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:width="108dp"
  4 + android:height="108dp"
  5 + android:viewportWidth="108"
  6 + android:viewportHeight="108">
  7 + <path
  8 + android:fillColor="#3DDC84"
  9 + android:pathData="M0,0h108v108h-108z" />
  10 + <path
  11 + android:fillColor="#00000000"
  12 + android:pathData="M9,0L9,108"
  13 + android:strokeWidth="0.8"
  14 + android:strokeColor="#33FFFFFF" />
  15 + <path
  16 + android:fillColor="#00000000"
  17 + android:pathData="M19,0L19,108"
  18 + android:strokeWidth="0.8"
  19 + android:strokeColor="#33FFFFFF" />
  20 + <path
  21 + android:fillColor="#00000000"
  22 + android:pathData="M29,0L29,108"
  23 + android:strokeWidth="0.8"
  24 + android:strokeColor="#33FFFFFF" />
  25 + <path
  26 + android:fillColor="#00000000"
  27 + android:pathData="M39,0L39,108"
  28 + android:strokeWidth="0.8"
  29 + android:strokeColor="#33FFFFFF" />
  30 + <path
  31 + android:fillColor="#00000000"
  32 + android:pathData="M49,0L49,108"
  33 + android:strokeWidth="0.8"
  34 + android:strokeColor="#33FFFFFF" />
  35 + <path
  36 + android:fillColor="#00000000"
  37 + android:pathData="M59,0L59,108"
  38 + android:strokeWidth="0.8"
  39 + android:strokeColor="#33FFFFFF" />
  40 + <path
  41 + android:fillColor="#00000000"
  42 + android:pathData="M69,0L69,108"
  43 + android:strokeWidth="0.8"
  44 + android:strokeColor="#33FFFFFF" />
  45 + <path
  46 + android:fillColor="#00000000"
  47 + android:pathData="M79,0L79,108"
  48 + android:strokeWidth="0.8"
  49 + android:strokeColor="#33FFFFFF" />
  50 + <path
  51 + android:fillColor="#00000000"
  52 + android:pathData="M89,0L89,108"
  53 + android:strokeWidth="0.8"
  54 + android:strokeColor="#33FFFFFF" />
  55 + <path
  56 + android:fillColor="#00000000"
  57 + android:pathData="M99,0L99,108"
  58 + android:strokeWidth="0.8"
  59 + android:strokeColor="#33FFFFFF" />
  60 + <path
  61 + android:fillColor="#00000000"
  62 + android:pathData="M0,9L108,9"
  63 + android:strokeWidth="0.8"
  64 + android:strokeColor="#33FFFFFF" />
  65 + <path
  66 + android:fillColor="#00000000"
  67 + android:pathData="M0,19L108,19"
  68 + android:strokeWidth="0.8"
  69 + android:strokeColor="#33FFFFFF" />
  70 + <path
  71 + android:fillColor="#00000000"
  72 + android:pathData="M0,29L108,29"
  73 + android:strokeWidth="0.8"
  74 + android:strokeColor="#33FFFFFF" />
  75 + <path
  76 + android:fillColor="#00000000"
  77 + android:pathData="M0,39L108,39"
  78 + android:strokeWidth="0.8"
  79 + android:strokeColor="#33FFFFFF" />
  80 + <path
  81 + android:fillColor="#00000000"
  82 + android:pathData="M0,49L108,49"
  83 + android:strokeWidth="0.8"
  84 + android:strokeColor="#33FFFFFF" />
  85 + <path
  86 + android:fillColor="#00000000"
  87 + android:pathData="M0,59L108,59"
  88 + android:strokeWidth="0.8"
  89 + android:strokeColor="#33FFFFFF" />
  90 + <path
  91 + android:fillColor="#00000000"
  92 + android:pathData="M0,69L108,69"
  93 + android:strokeWidth="0.8"
  94 + android:strokeColor="#33FFFFFF" />
  95 + <path
  96 + android:fillColor="#00000000"
  97 + android:pathData="M0,79L108,79"
  98 + android:strokeWidth="0.8"
  99 + android:strokeColor="#33FFFFFF" />
  100 + <path
  101 + android:fillColor="#00000000"
  102 + android:pathData="M0,89L108,89"
  103 + android:strokeWidth="0.8"
  104 + android:strokeColor="#33FFFFFF" />
  105 + <path
  106 + android:fillColor="#00000000"
  107 + android:pathData="M0,99L108,99"
  108 + android:strokeWidth="0.8"
  109 + android:strokeColor="#33FFFFFF" />
  110 + <path
  111 + android:fillColor="#00000000"
  112 + android:pathData="M19,29L89,29"
  113 + android:strokeWidth="0.8"
  114 + android:strokeColor="#33FFFFFF" />
  115 + <path
  116 + android:fillColor="#00000000"
  117 + android:pathData="M19,39L89,39"
  118 + android:strokeWidth="0.8"
  119 + android:strokeColor="#33FFFFFF" />
  120 + <path
  121 + android:fillColor="#00000000"
  122 + android:pathData="M19,49L89,49"
  123 + android:strokeWidth="0.8"
  124 + android:strokeColor="#33FFFFFF" />
  125 + <path
  126 + android:fillColor="#00000000"
  127 + android:pathData="M19,59L89,59"
  128 + android:strokeWidth="0.8"
  129 + android:strokeColor="#33FFFFFF" />
  130 + <path
  131 + android:fillColor="#00000000"
  132 + android:pathData="M19,69L89,69"
  133 + android:strokeWidth="0.8"
  134 + android:strokeColor="#33FFFFFF" />
  135 + <path
  136 + android:fillColor="#00000000"
  137 + android:pathData="M19,79L89,79"
  138 + android:strokeWidth="0.8"
  139 + android:strokeColor="#33FFFFFF" />
  140 + <path
  141 + android:fillColor="#00000000"
  142 + android:pathData="M29,19L29,89"
  143 + android:strokeWidth="0.8"
  144 + android:strokeColor="#33FFFFFF" />
  145 + <path
  146 + android:fillColor="#00000000"
  147 + android:pathData="M39,19L39,89"
  148 + android:strokeWidth="0.8"
  149 + android:strokeColor="#33FFFFFF" />
  150 + <path
  151 + android:fillColor="#00000000"
  152 + android:pathData="M49,19L49,89"
  153 + android:strokeWidth="0.8"
  154 + android:strokeColor="#33FFFFFF" />
  155 + <path
  156 + android:fillColor="#00000000"
  157 + android:pathData="M59,19L59,89"
  158 + android:strokeWidth="0.8"
  159 + android:strokeColor="#33FFFFFF" />
  160 + <path
  161 + android:fillColor="#00000000"
  162 + android:pathData="M69,19L69,89"
  163 + android:strokeWidth="0.8"
  164 + android:strokeColor="#33FFFFFF" />
  165 + <path
  166 + android:fillColor="#00000000"
  167 + android:pathData="M79,19L79,89"
  168 + android:strokeWidth="0.8"
  169 + android:strokeColor="#33FFFFFF" />
  170 +</vector>
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:aapt="http://schemas.android.com/aapt"
  3 + android:width="108dp"
  4 + android:height="108dp"
  5 + android:viewportWidth="108"
  6 + android:viewportHeight="108">
  7 + <path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
  8 + <aapt:attr name="android:fillColor">
  9 + <gradient
  10 + android:endX="85.84757"
  11 + android:endY="92.4963"
  12 + android:startX="42.9492"
  13 + android:startY="49.59793"
  14 + android:type="linear">
  15 + <item
  16 + android:color="#44000000"
  17 + android:offset="0.0" />
  18 + <item
  19 + android:color="#00000000"
  20 + android:offset="1.0" />
  21 + </gradient>
  22 + </aapt:attr>
  23 + </path>
  24 + <path
  25 + android:fillColor="#FFFFFF"
  26 + android:fillType="nonZero"
  27 + android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
  28 + android:strokeWidth="1"
  29 + android:strokeColor="#00000000" />
  30 +</vector>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:id="@+id/rl_parent"
  4 + android:layout_width="match_parent"
  5 + android:layout_height="match_parent"
  6 + android:background="@color/white" />
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <background android:drawable="@drawable/ic_launcher_background" />
  4 + <foreground android:drawable="@drawable/ic_launcher_foreground" />
  5 + <monochrome android:drawable="@drawable/ic_launcher_foreground" />
  6 +</adaptive-icon>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <background android:drawable="@drawable/ic_launcher_background" />
  4 + <foreground android:drawable="@drawable/ic_launcher_foreground" />
  5 + <monochrome android:drawable="@drawable/ic_launcher_foreground" />
  6 +</adaptive-icon>
No preview for this file type
No preview for this file type
No preview for this file type
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <color name="purple_200">#FFBB86FC</color>
  4 + <color name="purple_500">#FF6200EE</color>
  5 + <color name="purple_700">#FF3700B3</color>
  6 + <color name="teal_200">#FF03DAC5</color>
  7 + <color name="teal_700">#FF018786</color>
  8 + <color name="black">#FF000000</color>
  9 + <color name="white">#FFFFFFFF</color>
  10 +</resources>
  1 +<resources>
  2 + <string name="app_name">My Application</string>
  3 +</resources>
  1 +<resources xmlns:tools="http://schemas.android.com/tools">
  2 + <!-- Base application theme. -->
  3 + <style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
  4 + <!-- Primary brand color. -->
  5 + <item name="colorPrimary">@color/purple_500</item>
  6 + <item name="colorPrimaryVariant">@color/purple_700</item>
  7 + <item name="colorOnPrimary">@color/white</item>
  8 + <!-- Secondary brand color. -->
  9 + <item name="colorSecondary">@color/teal_200</item>
  10 + <item name="colorSecondaryVariant">@color/teal_700</item>
  11 + <item name="colorOnSecondary">@color/black</item>
  12 + <!-- Status bar color. -->
  13 + <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
  14 + <!-- Customize your theme here. -->
  15 + </style>
  16 +</resources>
  1 +<?xml version="1.0" encoding="utf-8"?><!--
  2 + Sample backup rules file; uncomment and customize as necessary.
  3 + See https://developer.android.com/guide/topics/data/autobackup
  4 + for details.
  5 + Note: This file is ignored for devices older that API 31
  6 + See https://developer.android.com/about/versions/12/backup-restore
  7 +-->
  8 +<full-backup-content>
  9 + <!--
  10 + <include domain="sharedpref" path="."/>
  11 + <exclude domain="sharedpref" path="device.xml"/>
  12 +-->
  13 +</full-backup-content>
  1 +apply plugin: 'maven'
  2 +
  3 +buildscript {
  4 + ext.kotlin_version = "1.4.32"
  5 + repositories {
  6 + mavenLocal()
  7 + mavenCentral()
  8 + // 以下四行代码为阿里gradle源,需要的人自己放開使用
  9 + maven { url 'https://maven.aliyun.com/repository/google' }
  10 + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
  11 + maven { url 'https://maven.aliyun.com/repository/public' }
  12 + maven { url 'https://maven.aliyun.com/repository/jcenter' }
  13 + maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases' }
  14 + //阿里云 maven
  15 + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
  16 + maven { url 'https://maven.aliyun.com/repository/releases' }
  17 +
  18 + google()
  19 +
  20 + maven { url "https://jitpack.io" }
  21 + //华为
  22 + maven { url 'https://developer.huawei.com/repo/' }
  23 + //阿里云QuickTracking
  24 + maven { url 'https://repo1.maven.org/maven2/' }
  25 +
  26 + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
  27 + maven {
  28 + url 'https://maven.aliyun.com/nexus/content/repositories/google/'
  29 + name 'aliyun-google'
  30 + }
  31 +
  32 + // TingYun
  33 + maven { url "https://nexus2.tingyun.com/nexus/content/repositories/snapshots/" }
  34 + }
  35 +
  36 + dependencies {
  37 + classpath "com.android.tools.build:gradle:4.0.2"
  38 + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  39 + classpath 'com.billy.android:autoregister:1.4.2'
  40 + // NOTE: Do not place your application dependencies here; they belong
  41 + // in the individual module build.gradle files
  42 + }
  43 +}
  44 +
  45 +allprojects {
  46 + repositories {
  47 + mavenLocal()
  48 + mavenCentral()
  49 + // 以下四行代码为阿里gradle源,需要的人自己放開使用
  50 + maven { url 'https://maven.aliyun.com/repository/google' }
  51 + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
  52 + maven { url 'https://maven.aliyun.com/repository/public' }
  53 + maven { url 'https://maven.aliyun.com/repository/jcenter' }
  54 + maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases' }
  55 + //阿里云 maven
  56 + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
  57 + maven { url 'https://maven.aliyun.com/repository/releases' }
  58 + google()
  59 +
  60 + maven { url "https://jitpack.io" }
  61 + //华为
  62 + maven { url 'https://developer.huawei.com/repo/' }
  63 + //阿里云QuickTracking
  64 + maven { url 'https://repo1.maven.org/maven2/' }
  65 + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
  66 + maven {
  67 + url 'https://maven.aliyun.com/nexus/content/repositories/google/'
  68 + name 'aliyun-google'
  69 + }
  70 +
  71 + flatDir { dirs 'src/main/libs' }
  72 +
  73 + // 快马私库
  74 + maven {
  75 + credentials {
  76 + username '6708d1cf6f4c940bd257c88d'
  77 + password 'Wm51gc4rARyr'
  78 + }
  79 + url 'https://packages.aliyun.com/6708d221eef79c23d7b02189/maven/repo-higom'
  80 + }
  81 + }
  82 +
  83 + project.configurations.configureEach {
  84 + resolutionStrategy.eachDependency { details ->
  85 + if (details.requested.group == 'com.android.android.support' && !details.requested.name.contains('multidex')) {
  86 + details.useVersion "28.0.0"
  87 + }
  88 +
  89 + }
  90 + }
  91 +
  92 + // 强制依赖
  93 + configurations.configureEach {
  94 + exclude group: 'com.alipay.android.phone.thirdparty', module: 'securityguard-build'
  95 + resolutionStrategy {
  96 + force 'androidx.activity:activity:1.2.1'
  97 + force 'androidx.annotation:annotation:1.1.0'
  98 + force 'androidx.appcompat:appcompat:1.2.0'
  99 + force 'androidx.arch.core:core-common:2.1.0'
  100 + force 'androidx.arch.core:core-runtime:2.1.0'
  101 + force 'androidx.core:core-ktx:1.6.0'
  102 + force 'androidx.core:core:1.5.0'
  103 + force 'androidx.collection:collection:1.1.0'
  104 + force 'androidx.constraintlayout:constraintlayout:2.0.4'
  105 + force 'androidx.constraintlayout:constraintlayout-solver:2.0.4'
  106 + force 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
  107 + force 'androidx.fragment:fragment:1.3.1'
  108 + force 'androidx.lifecycle:lifecycle-common:2.3.0'
  109 + force 'androidx.multidex:multidex:2.0.1'
  110 + force 'androidx.recyclerview:recyclerview:1.2.0'
  111 + force 'androidx.vectordrawable:vectordrawable:1.1.0'
  112 + force 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
  113 + force 'com.squareup.okhttp3:okhttp:4.9.1'
  114 + force 'com.squareup.okio:okio:2.7.0'
  115 + force 'org.jetbrains.kotlin:kotlin-stdlib:1.4.32'
  116 + force 'org.jetbrains.kotlin:kotilin-stdlib-jdk8:1.4.32'
  117 + force 'org.jetbrains:annotations:15.0'
  118 + force 'net.sf.proguard:proguard-base:6.1.0'
  119 + }
  120 + }
  121 +}
  122 +
  123 +ext {
  124 + var = [
  125 + // SDK And Tools
  126 + applicationId : "com.wondertek.dss",
  127 + minSdkVersion : 25,
  128 + targetSdkVersion : 30,
  129 + compileSdkVersion: 30,
  130 + buildToolsVersion: "30.0.3",
  131 + // 版本号,正式版本 1.0.0 1000080 后两位,80即标识为发布版本
  132 + // 测试版本 1.0.0_TF1 1000001 后两位,01即为测试版本号,01-79
  133 + // 升级版本 1.0.0_RC1 1000081 后两位,81即为升级版本号,81-99
  134 + versionName : "1.0.0", // release正式
  135 + debugVnName : "", // debug开发模式 用于区分debug模式下上报的日志
  136 + versionCode : 100,
  137 + //此版本号是SDK版本,不能随便改
  138 + aar_version : "1.0.0",
  139 + ]
  140 +
  141 +}
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<profiles version="12">
  3 + <profile kind="CodeFormatterProfile" name="WonderTek_CodeFormatter_Convention_v1.0"
  4 + version="12">
  5 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert" />
  6 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations"
  7 + value="insert" />
  8 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration"
  9 + value="insert" />
  10 + <setting
  11 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression"
  12 + value="do not insert" />
  13 + <setting
  14 + id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration"
  15 + value="insert" />
  16 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment"
  17 + value="common_lines" />
  18 + <setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries"
  19 + value="true" />
  20 + <setting
  21 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters"
  22 + value="insert" />
  23 + <setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter"
  24 + value="do not insert" />
  25 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package"
  26 + value="insert" />
  27 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation"
  28 + value="common_lines" />
  29 + <setting
  30 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant"
  31 + value="do not insert" />
  32 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1" />
  33 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while"
  34 + value="do not insert" />
  35 + <setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags"
  36 + value="insert" />
  37 + <setting
  38 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration"
  39 + value="do not insert" />
  40 + <setting
  41 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws"
  42 + value="do not insert" />
  43 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement"
  44 + value="common_lines" />
  45 + <setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true" />
  46 + <setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4" />
  47 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator"
  48 + value="do not insert" />
  49 + <setting
  50 + id="org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration"
  51 + value="common_lines" />
  52 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments"
  53 + value="insert" />
  54 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments"
  55 + value="insert" />
  56 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits"
  57 + value="do not insert" />
  58 + <setting
  59 + id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration"
  60 + value="do not insert" />
  61 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for"
  62 + value="insert" />
  63 + <setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off" />
  64 + <setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1" />
  65 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="49" />
  66 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1" />
  67 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1" />
  68 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator"
  69 + value="insert" />
  70 + <setting
  71 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations"
  72 + value="insert" />
  73 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement"
  74 + value="common_lines" />
  75 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant"
  76 + value="16" />
  77 + <setting
  78 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference"
  79 + value="do not insert" />
  80 + <setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true" />
  81 + <setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch"
  82 + value="true" />
  83 + <setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on" />
  84 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block"
  85 + value="insert" />
  86 + <setting
  87 + id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return"
  88 + value="insert" />
  89 + <setting
  90 + id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration"
  91 + value="20" />
  92 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter"
  93 + value="do not insert" />
  94 + <setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line"
  95 + value="false" />
  96 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field"
  97 + value="insert" />
  98 + <setting
  99 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments"
  100 + value="insert" />
  101 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block"
  102 + value="insert" />
  103 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator"
  104 + value="do not insert" />
  105 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations"
  106 + value="1" />
  107 + <setting
  108 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer"
  109 + value="do not insert" />
  110 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for"
  111 + value="do not insert" />
  112 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch"
  113 + value="do not insert" />
  114 + <setting
  115 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments"
  116 + value="do not insert" />
  117 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method"
  118 + value="insert" />
  119 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch"
  120 + value="do not insert" />
  121 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references"
  122 + value="16" />
  123 + <setting
  124 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration"
  125 + value="insert" />
  126 + <setting
  127 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression"
  128 + value="do not insert" />
  129 + <setting
  130 + id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant"
  131 + value="insert" />
  132 + <setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column"
  133 + value="false" />
  134 + <setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error" />
  135 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter"
  136 + value="insert" />
  137 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits"
  138 + value="insert" />
  139 + <setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block"
  140 + value="true" />
  141 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration"
  142 + value="end_of_line" />
  143 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard"
  144 + value="do not insert" />
  145 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation"
  146 + value="do not insert" />
  147 + <setting
  148 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments"
  149 + value="do not insert" />
  150 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch"
  151 + value="insert" />
  152 + <setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120" />
  153 + <setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false" />
  154 + <setting
  155 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression"
  156 + value="do not insert" />
  157 + <setting
  158 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant"
  159 + value="insert" />
  160 + <setting
  161 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation"
  162 + value="do not insert" />
  163 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator"
  164 + value="insert" />
  165 + <setting
  166 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration"
  167 + value="insert" />
  168 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for"
  169 + value="do not insert" />
  170 + <setting
  171 + id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments"
  172 + value="true" />
  173 + <setting
  174 + id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable"
  175 + value="insert" />
  176 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration"
  177 + value="end_of_line" />
  178 + <setting
  179 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation"
  180 + value="do not insert" />
  181 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch"
  182 + value="16" />
  183 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for"
  184 + value="insert" />
  185 + <setting
  186 + id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body"
  187 + value="0" />
  188 + <setting
  189 + id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments"
  190 + value="insert" />
  191 + <setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line"
  192 + value="false" />
  193 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16" />
  194 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause"
  195 + value="common_lines" />
  196 + <setting
  197 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference"
  198 + value="insert" />
  199 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer"
  200 + value="do not insert" />
  201 + <setting
  202 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations"
  203 + value="insert" />
  204 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation"
  205 + value="do not insert" />
  206 + <setting
  207 + id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call"
  208 + value="16" />
  209 + <setting
  210 + id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header"
  211 + value="true" />
  212 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces"
  213 + value="insert" />
  214 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default"
  215 + value="do not insert" />
  216 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional"
  217 + value="insert" />
  218 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line" />
  219 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration"
  220 + value="end_of_line" />
  221 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body"
  222 + value="end_of_line" />
  223 + <setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true" />
  224 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters"
  225 + value="do not insert" />
  226 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch"
  227 + value="insert" />
  228 + <setting
  229 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation"
  230 + value="do not insert" />
  231 + <setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true" />
  232 + <setting
  233 + id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration"
  234 + value="20" />
  235 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_type_parameters" value="16" />
  236 + <setting
  237 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments"
  238 + value="insert" />
  239 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation"
  240 + value="16" />
  241 + <setting
  242 + id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration"
  243 + value="20" />
  244 + <setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error" />
  245 + <setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment"
  246 + value="true" />
  247 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement"
  248 + value="do not insert" />
  249 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try"
  250 + value="insert" />
  251 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing"
  252 + value="do not insert" />
  253 + <setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment"
  254 + value="true" />
  255 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer"
  256 + value="insert" />
  257 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator"
  258 + value="insert" />
  259 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator"
  260 + value="do not insert" />
  261 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer"
  262 + value="20" />
  263 + <setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column"
  264 + value="true" />
  265 + <setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1" />
  266 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation"
  267 + value="common_lines" />
  268 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case"
  269 + value="insert" />
  270 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis"
  271 + value="do not insert" />
  272 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources"
  273 + value="do not insert" />
  274 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert"
  275 + value="insert" />
  276 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if"
  277 + value="do not insert" />
  278 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments"
  279 + value="do not insert" />
  280 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter"
  281 + value="insert" />
  282 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration"
  283 + value="insert" />
  284 + <setting
  285 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression"
  286 + value="do not insert" />
  287 + <setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true" />
  288 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement"
  289 + value="insert" />
  290 + <setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false" />
  291 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="20" />
  292 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body"
  293 + value="insert" />
  294 + <setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header"
  295 + value="true" />
  296 + <setting
  297 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration"
  298 + value="do not insert" />
  299 + <setting
  300 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant"
  301 + value="do not insert" />
  302 + <setting
  303 + id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration"
  304 + value="16" />
  305 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration"
  306 + value="0" />
  307 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression"
  308 + value="16" />
  309 + <setting
  310 + id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer"
  311 + value="do not insert" />
  312 + <setting
  313 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters"
  314 + value="do not insert" />
  315 + <setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line"
  316 + value="false" />
  317 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if"
  318 + value="insert" />
  319 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type"
  320 + value="insert" />
  321 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block"
  322 + value="insert" />
  323 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration"
  324 + value="end_of_line" />
  325 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case"
  326 + value="end_of_line" />
  327 + <setting
  328 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration"
  329 + value="do not insert" />
  330 + <setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false" />
  331 + <setting
  332 + id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression"
  333 + value="16" />
  334 + <setting
  335 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation"
  336 + value="do not insert" />
  337 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while"
  338 + value="insert" />
  339 + <setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled" />
  340 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch"
  341 + value="do not insert" />
  342 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="16" />
  343 + <setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true" />
  344 + <setting
  345 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration"
  346 + value="do not insert" />
  347 + <setting id="org.eclipse.jdt.core.formatter.wrap_before_conditional_operator"
  348 + value="true" />
  349 + <setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases"
  350 + value="true" />
  351 + <setting
  352 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression"
  353 + value="do not insert" />
  354 + <setting
  355 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized"
  356 + value="do not insert" />
  357 + <setting id="org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines"
  358 + value="2147483647" />
  359 + <setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries"
  360 + value="true" />
  361 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration"
  362 + value="end_of_line" />
  363 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for"
  364 + value="insert" />
  365 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="16" />
  366 + <setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations"
  367 + value="false" />
  368 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause"
  369 + value="common_lines" />
  370 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation"
  371 + value="80" />
  372 + <setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column"
  373 + value="false" />
  374 + <setting id="org.eclipse.jdt.core.compiler.source" value="1.8" />
  375 + <setting
  376 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized"
  377 + value="do not insert" />
  378 + <setting
  379 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws"
  380 + value="insert" />
  381 + <setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4" />
  382 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant"
  383 + value="insert" />
  384 + <setting
  385 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression"
  386 + value="insert" />
  387 + <setting
  388 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference"
  389 + value="do not insert" />
  390 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional"
  391 + value="insert" />
  392 + <setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true" />
  393 + <setting
  394 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer"
  395 + value="insert" />
  396 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try"
  397 + value="do not insert" />
  398 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources"
  399 + value="insert" />
  400 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="1" />
  401 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation"
  402 + value="do not insert" />
  403 + <setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer"
  404 + value="1" />
  405 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard"
  406 + value="do not insert" />
  407 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1" />
  408 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration"
  409 + value="16" />
  410 + <setting
  411 + id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration"
  412 + value="16" />
  413 + <setting
  414 + id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw"
  415 + value="insert" />
  416 + <setting id="org.eclipse.jdt.core.formatter.wrap_before_assignment_operator"
  417 + value="false" />
  418 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement"
  419 + value="do not insert" />
  420 + <setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8" />
  421 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch"
  422 + value="end_of_line" />
  423 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces"
  424 + value="do not insert" />
  425 + <setting
  426 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters"
  427 + value="insert" />
  428 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation"
  429 + value="do not insert" />
  430 + <setting
  431 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer"
  432 + value="do not insert" />
  433 + <setting
  434 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression"
  435 + value="do not insert" />
  436 + <setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true" />
  437 + <setting
  438 + id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration"
  439 + value="do not insert" />
  440 + <setting
  441 + id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters"
  442 + value="insert" />
  443 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration"
  444 + value="common_lines" />
  445 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16" />
  446 + <setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false" />
  447 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_type_arguments" value="16" />
  448 + <setting
  449 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference"
  450 + value="do not insert" />
  451 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator"
  452 + value="do not insert" />
  453 + <setting
  454 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant"
  455 + value="do not insert" />
  456 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation"
  457 + value="16" />
  458 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations"
  459 + value="do not insert" />
  460 + <setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line"
  461 + value="true" />
  462 + <setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch"
  463 + value="true" />
  464 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement"
  465 + value="do not insert" />
  466 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator"
  467 + value="insert" />
  468 + <setting
  469 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration"
  470 + value="do not insert" />
  471 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1" />
  472 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label"
  473 + value="do not insert" />
  474 + <setting
  475 + id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header"
  476 + value="true" />
  477 + <setting
  478 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression"
  479 + value="do not insert" />
  480 + <setting
  481 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration"
  482 + value="do not insert" />
  483 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional"
  484 + value="insert" />
  485 + <setting
  486 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference"
  487 + value="do not insert" />
  488 + <setting
  489 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters"
  490 + value="do not insert" />
  491 + <setting
  492 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments"
  493 + value="do not insert" />
  494 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast"
  495 + value="do not insert" />
  496 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert"
  497 + value="insert" />
  498 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1" />
  499 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement"
  500 + value="do not insert" />
  501 + <setting
  502 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference"
  503 + value="do not insert" />
  504 + <setting
  505 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference"
  506 + value="do not insert" />
  507 + <setting
  508 + id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression"
  509 + value="16" />
  510 + <setting
  511 + id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer"
  512 + value="do not insert" />
  513 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration"
  514 + value="insert" />
  515 + <setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true" />
  516 + <setting
  517 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration"
  518 + value="do not insert" />
  519 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if"
  520 + value="do not insert" />
  521 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon"
  522 + value="do not insert" />
  523 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator"
  524 + value="do not insert" />
  525 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try"
  526 + value="do not insert" />
  527 + <setting
  528 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments"
  529 + value="do not insert" />
  530 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast"
  531 + value="do not insert" />
  532 + <setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true" />
  533 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow"
  534 + value="insert" />
  535 + <setting
  536 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration"
  537 + value="do not insert" />
  538 + <setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false" />
  539 + <setting
  540 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration"
  541 + value="insert" />
  542 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration"
  543 + value="16" />
  544 + <setting
  545 + id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference"
  546 + value="do not insert" />
  547 + <setting
  548 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters"
  549 + value="do not insert" />
  550 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for"
  551 + value="do not insert" />
  552 + <setting
  553 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws"
  554 + value="insert" />
  555 + <setting
  556 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression"
  557 + value="do not insert" />
  558 + <setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body"
  559 + value="true" />
  560 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16" />
  561 + <setting
  562 + id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments"
  563 + value="insert" />
  564 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator"
  565 + value="do not insert" />
  566 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer"
  567 + value="end_of_line" />
  568 + <setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true" />
  569 + <setting
  570 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration"
  571 + value="insert" />
  572 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters"
  573 + value="insert" />
  574 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch"
  575 + value="do not insert" />
  576 + <setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8" />
  577 + <setting
  578 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference"
  579 + value="do not insert" />
  580 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation"
  581 + value="insert" />
  582 + <setting
  583 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments"
  584 + value="do not insert" />
  585 + <setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration"
  586 + value="common_lines" />
  587 + <setting
  588 + id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer"
  589 + value="do not insert" />
  590 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case"
  591 + value="do not insert" />
  592 + <setting
  593 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations"
  594 + value="do not insert" />
  595 + <setting
  596 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration"
  597 + value="insert" />
  598 + <setting
  599 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference"
  600 + value="do not insert" />
  601 + <setting
  602 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration"
  603 + value="do not insert" />
  604 + <setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested"
  605 + value="true" />
  606 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast"
  607 + value="insert" />
  608 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant"
  609 + value="end_of_line" />
  610 + <setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration"
  611 + value="end_of_line" />
  612 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="1" />
  613 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for"
  614 + value="insert" />
  615 + <setting
  616 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized"
  617 + value="insert" />
  618 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments"
  619 + value="do not insert" />
  620 + <setting
  621 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration"
  622 + value="do not insert" />
  623 + <setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header"
  624 + value="16" />
  625 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while"
  626 + value="do not insert" />
  627 + <setting
  628 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant"
  629 + value="do not insert" />
  630 + <setting
  631 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments"
  632 + value="do not insert" />
  633 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation"
  634 + value="do not insert" />
  635 + <setting
  636 + id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters"
  637 + value="do not insert" />
  638 + <setting
  639 + id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header"
  640 + value="true" />
  641 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow"
  642 + value="insert" />
  643 + <setting
  644 + id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration"
  645 + value="insert" />
  646 + <setting
  647 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws"
  648 + value="do not insert" />
  649 + <setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="false" />
  650 + <setting
  651 + id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters"
  652 + value="do not insert" />
  653 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional"
  654 + value="insert" />
  655 + <setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description"
  656 + value="false" />
  657 + <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement"
  658 + value="do not insert" />
  659 + <setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space" />
  660 + <setting
  661 + id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations"
  662 + value="do not insert" />
  663 + <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1" />
  664 + <setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120" />
  665 + <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation"
  666 + value="do not insert" />
  667 + <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch"
  668 + value="insert" />
  669 + </profile>
  670 +</profiles>
  1 +# Project-wide Gradle settings.
  2 +# IDE (e.g. Android Studio) users:
  3 +# Gradle settings configured through the IDE *will override*
  4 +# any settings specified in this file.
  5 +# For more details on how to configure your build environment visit
  6 +# http://www.gradle.org/docs/current/userguide/build_environment.html
  7 +# Specifies the JVM arguments used for the daemon process.
  8 +# The setting is particularly useful for tweaking memory settings.
  9 +#org.gradle.jvmargs=-Xmx2048m
  10 +# When configured, Gradle will run in incubating parallel mode.
  11 +# This option should only be used with decoupled projects. More details, visit
  12 +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
  13 +# org.gradle.parallel=true
  14 +# AndroidX package structure to make it clearer which packages are bundled with the
  15 +# Android operating system, and which are packaged with your app's APK
  16 +# https://developer.android.com/topic/libraries/support-library/androidx-rn
  17 +android.useAndroidX=true
  18 +# Automatically convert third-party libraries to use AndroidX
  19 +android.enableJetifier=true
  20 +android.enableResourceOptimizations=false
  21 +#建议您关闭 R8 后再进行混淆
  22 +android.enableR8=false
  23 +android.enableR8.libraries=false
  24 +# 如果使用最新稳定版本 Android Studio 3.5 或以上,那么您需要在 gradle.properties 里面新增
  25 +android.buildOnlyTargetAbi=false
  26 +#网络请求接口版本 202204151851
  27 +requestVersion=107
  28 +#设置组件是否作为app还是lib,true是lib ,false 是app
  29 +#分享
  30 +isShareModule=true
  31 +#播放器
  32 +isPlayerModule=true
  33 +#是否直播模块运行 false可以单独运行
  34 +isLiveModule=true
  35 +org.gradle.daemon=true
  36 +org.gradle.parallel=true
  37 +org.gradle.configureondemand=true
  38 +org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
  39 +# Kotlin code style for this project: "official" or "obsolete":
  40 +kotlin.code.style=official
  41 +# Enables namespacing of each library's R class so that its R class includes only the
  42 +# resources declared in the library itself and none from the library's dependencies,
  43 +# thereby reducing the size of the R class for that library
  44 +#android.nonTransitiveRClass=true
  45 +
  46 +
No preview for this file type
  1 +#Fri Oct 23 14:37:25 CST 2020
  2 +distributionBase=GRADLE_USER_HOME
  3 +distributionPath=wrapper/dists
  4 +zipStoreBase=GRADLE_USER_HOME
  5 +zipStorePath=wrapper/dists
  6 +distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-6.8-all.zip
  1 +#!/usr/bin/env sh
  2 +
  3 +##############################################################################
  4 +##
  5 +## Gradle start up script for UN*X
  6 +##
  7 +##############################################################################
  8 +
  9 +# Attempt to set APP_HOME
  10 +# Resolve links: $0 may be a link
  11 +PRG="$0"
  12 +# Need this for relative symlinks.
  13 +while [ -h "$PRG" ] ; do
  14 + ls=`ls -ld "$PRG"`
  15 + link=`expr "$ls" : '.*-> \(.*\)$'`
  16 + if expr "$link" : '/.*' > /dev/null; then
  17 + PRG="$link"
  18 + else
  19 + PRG=`dirname "$PRG"`"/$link"
  20 + fi
  21 +done
  22 +SAVED="`pwd`"
  23 +cd "`dirname \"$PRG\"`/" >/dev/null
  24 +APP_HOME="`pwd -P`"
  25 +cd "$SAVED" >/dev/null
  26 +
  27 +APP_NAME="Gradle"
  28 +APP_BASE_NAME=`basename "$0"`
  29 +
  30 +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  31 +DEFAULT_JVM_OPTS=""
  32 +
  33 +# Use the maximum available, or set MAX_FD != -1 to use that value.
  34 +MAX_FD="maximum"
  35 +
  36 +warn () {
  37 + echo "$*"
  38 +}
  39 +
  40 +die () {
  41 + echo
  42 + echo "$*"
  43 + echo
  44 + exit 1
  45 +}
  46 +
  47 +# OS specific support (must be 'true' or 'false').
  48 +cygwin=false
  49 +msys=false
  50 +darwin=false
  51 +nonstop=false
  52 +case "`uname`" in
  53 + CYGWIN* )
  54 + cygwin=true
  55 + ;;
  56 + Darwin* )
  57 + darwin=true
  58 + ;;
  59 + MINGW* )
  60 + msys=true
  61 + ;;
  62 + NONSTOP* )
  63 + nonstop=true
  64 + ;;
  65 +esac
  66 +
  67 +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
  68 +
  69 +# Determine the Java command to use to start the JVM.
  70 +if [ -n "$JAVA_HOME" ] ; then
  71 + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  72 + # IBM's JDK on AIX uses strange locations for the executables
  73 + JAVACMD="$JAVA_HOME/jre/sh/java"
  74 + else
  75 + JAVACMD="$JAVA_HOME/bin/java"
  76 + fi
  77 + if [ ! -x "$JAVACMD" ] ; then
  78 + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
  79 +
  80 +Please set the JAVA_HOME variable in your environment to match the
  81 +location of your Java installation."
  82 + fi
  83 +else
  84 + JAVACMD="java"
  85 + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  86 +
  87 +Please set the JAVA_HOME variable in your environment to match the
  88 +location of your Java installation."
  89 +fi
  90 +
  91 +# Increase the maximum file descriptors if we can.
  92 +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
  93 + MAX_FD_LIMIT=`ulimit -H -n`
  94 + if [ $? -eq 0 ] ; then
  95 + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
  96 + MAX_FD="$MAX_FD_LIMIT"
  97 + fi
  98 + ulimit -n $MAX_FD
  99 + if [ $? -ne 0 ] ; then
  100 + warn "Could not set maximum file descriptor limit: $MAX_FD"
  101 + fi
  102 + else
  103 + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
  104 + fi
  105 +fi
  106 +
  107 +# For Darwin, add options to specify how the application appears in the dock
  108 +if $darwin; then
  109 + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
  110 +fi
  111 +
  112 +# For Cygwin, switch paths to Windows format before running java
  113 +if $cygwin ; then
  114 + APP_HOME=`cygpath --path --mixed "$APP_HOME"`
  115 + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
  116 + JAVACMD=`cygpath --unix "$JAVACMD"`
  117 +
  118 + # We build the pattern for arguments to be converted via cygpath
  119 + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
  120 + SEP=""
  121 + for dir in $ROOTDIRSRAW ; do
  122 + ROOTDIRS="$ROOTDIRS$SEP$dir"
  123 + SEP="|"
  124 + done
  125 + OURCYGPATTERN="(^($ROOTDIRS))"
  126 + # Add a user-defined pattern to the cygpath arguments
  127 + if [ "$GRADLE_CYGPATTERN" != "" ] ; then
  128 + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
  129 + fi
  130 + # Now convert the arguments - kludge to limit ourselves to /bin/sh
  131 + i=0
  132 + for arg in "$@" ; do
  133 + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
  134 + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
  135 +
  136 + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
  137 + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
  138 + else
  139 + eval `echo args$i`="\"$arg\""
  140 + fi
  141 + i=$((i+1))
  142 + done
  143 + case $i in
  144 + (0) set -- ;;
  145 + (1) set -- "$args0" ;;
  146 + (2) set -- "$args0" "$args1" ;;
  147 + (3) set -- "$args0" "$args1" "$args2" ;;
  148 + (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
  149 + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
  150 + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
  151 + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
  152 + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
  153 + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
  154 + esac
  155 +fi
  156 +
  157 +# Escape application args
  158 +save () {
  159 + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
  160 + echo " "
  161 +}
  162 +APP_ARGS=$(save "$@")
  163 +
  164 +# Collect all arguments for the java command, following the shell quoting and substitution rules
  165 +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
  166 +
  167 +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
  168 +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
  169 + cd "$(dirname "$0")"
  170 +fi
  171 +
  172 +exec "$JAVACMD" "$@"
  1 +@if "%DEBUG%" == "" @echo off
  2 +@rem ##########################################################################
  3 +@rem
  4 +@rem Gradle startup script for Windows
  5 +@rem
  6 +@rem ##########################################################################
  7 +
  8 +@rem Set local scope for the variables with windows NT shell
  9 +if "%OS%"=="Windows_NT" setlocal
  10 +
  11 +set DIRNAME=%~dp0
  12 +if "%DIRNAME%" == "" set DIRNAME=.
  13 +set APP_BASE_NAME=%~n0
  14 +set APP_HOME=%DIRNAME%
  15 +
  16 +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  17 +set DEFAULT_JVM_OPTS=
  18 +
  19 +@rem Find java.exe
  20 +if defined JAVA_HOME goto findJavaFromJavaHome
  21 +
  22 +set JAVA_EXE=java.exe
  23 +%JAVA_EXE% -version >NUL 2>&1
  24 +if "%ERRORLEVEL%" == "0" goto init
  25 +
  26 +echo.
  27 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  28 +echo.
  29 +echo Please set the JAVA_HOME variable in your environment to match the
  30 +echo location of your Java installation.
  31 +
  32 +goto fail
  33 +
  34 +:findJavaFromJavaHome
  35 +set JAVA_HOME=%JAVA_HOME:"=%
  36 +set JAVA_EXE=%JAVA_HOME%/bin/java.exe
  37 +
  38 +if exist "%JAVA_EXE%" goto init
  39 +
  40 +echo.
  41 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
  42 +echo.
  43 +echo Please set the JAVA_HOME variable in your environment to match the
  44 +echo location of your Java installation.
  45 +
  46 +goto fail
  47 +
  48 +:init
  49 +@rem Get command-line arguments, handling Windows variants
  50 +
  51 +if not "%OS%" == "Windows_NT" goto win9xME_args
  52 +
  53 +:win9xME_args
  54 +@rem Slurp the command line arguments.
  55 +set CMD_LINE_ARGS=
  56 +set _SKIP=2
  57 +
  58 +:win9xME_args_slurp
  59 +if "x%~1" == "x" goto execute
  60 +
  61 +set CMD_LINE_ARGS=%*
  62 +
  63 +:execute
  64 +@rem Setup the command line
  65 +
  66 +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
  67 +
  68 +@rem Execute Gradle
  69 +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
  70 +
  71 +:end
  72 +@rem End local scope for the variables with windows NT shell
  73 +if "%ERRORLEVEL%"=="0" goto mainEnd
  74 +
  75 +:fail
  76 +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
  77 +rem the _cmd.exe /c_ return code!
  78 +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
  79 +exit /b 1
  80 +
  81 +:mainEnd
  82 +if "%OS%"=="Windows_NT" endlocal
  83 +
  84 +:omega
  1 +rootProject.name = "wdnetwork"
  2 +include ':app'
  3 +include ':wdnetwork'
  1 +plugins {
  2 + id 'com.android.library'
  3 + id 'kotlin-android'
  4 + id 'maven'
  5 +}
  6 +
  7 +android {
  8 + compileSdkVersion var.compileSdkVersion
  9 +
  10 + defaultConfig {
  11 + minSdkVersion var.minSdkVersion
  12 + targetSdkVersion var.targetSdkVersion
  13 + versionCode var.versionCode
  14 + versionName var.versionName
  15 +
  16 + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  17 + consumerProguardFiles "consumer-rules.pro"
  18 +
  19 + buildConfigField "String", "API_VERSION", "\"${requestVersion}\""
  20 + }
  21 +
  22 + buildTypes {
  23 + release {
  24 + minifyEnabled false
  25 + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  26 + }
  27 + }
  28 + compileOptions {
  29 + sourceCompatibility JavaVersion.VERSION_1_8
  30 + targetCompatibility JavaVersion.VERSION_1_8
  31 + }
  32 +
  33 + // 自定义AAR包名
  34 + android.libraryVariants.all { variant ->
  35 + variant.outputs.all {
  36 + if (outputFileName != null && outputFileName.endsWith(".aar")) {
  37 + def fileName = "${project.name}-${buildType.name}-v${var.aar_version}.aar"
  38 + outputFileName = fileName
  39 + }
  40 + }
  41 + }
  42 +}
  43 +
  44 +dependencies {
  45 + api 'com.squareup.okhttp3:okhttp:4.8.0'
  46 + api 'com.squareup.retrofit2:retrofit:2.9.0'
  47 + api 'com.squareup.retrofit2:converter-gson:2.9.0'
  48 + api 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
  49 + //rxjava
  50 + api 'io.reactivex.rxjava2:rxjava:2.2.8'
  51 + api 'io.reactivex.rxjava2:rxandroid:2.1.0'
  52 + //解析bean
  53 + api 'com.alibaba:fastjson:1.2.62'
  54 + implementation 'com.wd:log:1.0.0'
  55 + implementation 'com.wd:wdkitcore:1.0.5'
  56 +// implementation 'com.wd:servicekit:1.0.3'
  57 + implementation 'com.wd:wdinterface:1.0.3'
  58 + api 'com.alibaba:arouter-api:1.5.2'
  59 +
  60 +// //依赖工程
  61 +// compileOnly project(path: ':lib_utils')
  62 +// compileOnly project(path: ':lib_livedatabus')
  63 +}
  64 +
  65 +uploadArchives {
  66 + repositories {
  67 + mavenDeployer {
  68 + repository(url: "https://packages.aliyun.com/6708d221eef79c23d7b02189/maven/repo-higom/") {
  69 + authentication(userName: '6708d1cf6f4c940bd257c88d', password: 'Wm51gc4rARyr')
  70 + }
  71 + pom.project {
  72 + artifactId 'wdnetwork'
  73 + version '1.0.0'
  74 + groupId 'com.wd'
  75 + packaging 'aar'
  76 + }
  77 + }
  78 + }
  79 +}
  1 +# Add project specific ProGuard rules here.
  2 +# You can control the set of applied configuration files using the
  3 +# proguardFiles setting in build.gradle.
  4 +#
  5 +# For more details, see
  6 +# http://developer.android.com/guide/developing/tools/proguard.html
  7 +
  8 +# If your project uses WebView with JS, uncomment the following
  9 +# and specify the fully qualified class name to the JavaScript interface
  10 +# class:
  11 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  12 +# public *;
  13 +#}
  14 +
  15 +# Uncomment this to preserve the line number information for
  16 +# debugging stack traces.
  17 +#-keepattributes SourceFile,LineNumberTable
  18 +
  19 +# If you keep the line number information, uncomment this to
  20 +# hide the original source file name.
  21 +#-renamesourcefileattribute SourceFile
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="com.wd.capability.network">
  4 +
  5 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  6 +</manifest>
  1 +
  2 +package com.wd.capability.network;
  3 +
  4 +import android.text.TextUtils;
  5 +
  6 +import androidx.annotation.NonNull;
  7 +
  8 +import com.wd.base.log.Logger;
  9 +import com.wd.capability.network.bean.MetaBean;
  10 +import com.wd.capability.network.response.BaseResponse;
  11 +import com.wd.capability.network.response.ExceptionHandle;
  12 +import com.wd.capability.network.response.ResponseException;
  13 +import com.wd.capability.network.utils.HostUtil;
  14 +import com.wd.foundation.wdinterface.toast.IToast;
  15 +import com.wd.foundation.wdkitcore.router.ArouterServiceManager;
  16 +
  17 +import io.reactivex.Observer;
  18 +import io.reactivex.disposables.Disposable;
  19 +
  20 +/**
  21 + * 网络数据返回处理类
  22 + *
  23 + * @author shishuangxi_wd
  24 + * @date 2022/6/24 15:24
  25 + */
  26 +public abstract class BaseObserver<T> implements Observer<BaseResponse<T>> {
  27 + private final int SUCCESS_CODE_0 = 0;
  28 +
  29 + private final int SUCCESS_CODE = 200;
  30 +
  31 + private final int UNAUTHORIZED_CODE = 401;
  32 +
  33 + private final int BAD_REQUEST_CODE = 400;
  34 +
  35 + @Override
  36 + public void onSubscribe(Disposable d) {
  37 +
  38 + }
  39 +
  40 + @Override
  41 + public void onComplete() {
  42 +
  43 + }
  44 +
  45 + // @Override
  46 + // public void onNext(BaseResponse<T> value) {
  47 + // /** 根据code返回值处理业务 */
  48 + // if (value != null && (0 == value.getCode() || 200 == value.getCode())) {
  49 + // // 记录服务器时间
  50 + // HostUtil.serverTime = value.getTimestamp();
  51 + // onSuccess(value.getData());
  52 + // //携带上其他数据,比如MD5,特殊需要出来的用这个,带上msg,带上code
  53 + // onSuccess(value.getData(), value.getMeta(), value.getMessage(), value.getCode());
  54 + // } else if (401 == value.getCode()) {
  55 + // // 统一处理的业务逻辑
  56 + // delealCode(value.getCode());
  57 + // }else if (400 == value.getCode()) {
  58 + // dealSpecialCode(value.getCode(), value.getMessage());
  59 + // } else {
  60 + // // 返回其他code交给子类处理
  61 + // dealSpecialCode(value.getCode(), value.getMessage());
  62 + // }
  63 + // }
  64 + @Override
  65 + public void onNext(BaseResponse<T> value) {
  66 + if (value == null) {
  67 + IToast toaster = ArouterServiceManager.provide(IToast.class);
  68 + // handle null value
  69 + if (toaster != null) {
  70 + toaster.showShort("网络请求,出现异常");
  71 + }
  72 + return;
  73 + }
  74 + int code = value.getCode();
  75 + switch (code) {
  76 + case SUCCESS_CODE_0:
  77 + case SUCCESS_CODE:
  78 + handleSuccess(value);
  79 + break;
  80 + case UNAUTHORIZED_CODE:
  81 + handleUnauthorized(value);
  82 + break;
  83 + case BAD_REQUEST_CODE:
  84 + handleBadRequest(value);
  85 + break;
  86 + default:
  87 + handleOtherCode(value);
  88 + break;
  89 + }
  90 + }
  91 +
  92 + private void handleSuccess(@NonNull BaseResponse<T> value) {
  93 + // 记录服务器时间
  94 + HostUtil.serverTime = value.getTimestamp();
  95 + onSuccess(value.getData());
  96 + // 携带上其他数据,比如MD5,特殊需要出来的用这个,带上msg,带上code
  97 + onSuccess(value.getData(), value.getMeta(), value.getMessage(), value.getCode());
  98 + }
  99 +
  100 + private void handleUnauthorized(@NonNull BaseResponse<T> value) {
  101 + // 统一处理的业务逻辑
  102 + delealCode(value.getCode());
  103 + }
  104 +
  105 + private void handleBadRequest(@NonNull BaseResponse<T> value) {
  106 + // 返回其他code交给子类处理
  107 + dealSpecialCode(value.getCode(), value.getMessage());
  108 + }
  109 +
  110 + private void handleOtherCode(@NonNull BaseResponse<T> value) {
  111 + // 返回其他code交给子类处理
  112 + dealSpecialCode(value.getCode(), value.getMessage());
  113 + }
  114 +
  115 + /** 处理一些特殊的返回值 */
  116 + protected abstract void dealSpecialCode(int code, String message);
  117 +
  118 + /**
  119 + * 异常处理 网络异常、解析异常
  120 + */
  121 + @Override
  122 + public void onError(Throwable e) {
  123 + if (e == null) {
  124 + _onError(ExceptionHandle.NET_ERROR_TIPS_IN_PAGE);
  125 + return;
  126 + }
  127 +
  128 + // 真实错误信息
  129 + String realMessage = e.getMessage();
  130 + if (!TextUtils.isEmpty(realMessage)) {
  131 + Logger.e("---接口异常---" + realMessage);
  132 + }
  133 + ResponseException responseException = ExceptionHandle.handleException(e);
  134 +
  135 + // 上报用
  136 + int errorCode = responseException.code;
  137 + _onErrorWithCode(errorCode, realMessage);
  138 +
  139 + // Toast提示的错误信息
  140 + String toastMessage;
  141 + if (ExceptionHandle.showErrorTips(responseException)) {
  142 + toastMessage = ExceptionHandle.NET_ERROR_TIPS_IN_PAGE;
  143 + } else {
  144 + toastMessage = "";
  145 + }
  146 + _onError(toastMessage);
  147 +
  148 + }
  149 +
  150 + /**
  151 + * 返回的数据
  152 + *
  153 + * @param t
  154 + */
  155 + protected abstract void onSuccess(T t);
  156 +
  157 + /**
  158 + * 返回的数据
  159 + *
  160 + * @param t
  161 + * @param metaBean
  162 + * @param msg
  163 + * @param code
  164 + */
  165 + protected void onSuccess(T t, MetaBean metaBean, String msg, int code) {
  166 +
  167 + }
  168 +
  169 + /**
  170 + * 统一code 处理 比如单点登录 与后台统一确定
  171 + */
  172 + private void delealCode(int resultCode) {
  173 + switch (resultCode) {
  174 + case 400:
  175 + break;
  176 + default:
  177 + break;
  178 +
  179 + }
  180 + }
  181 +
  182 + protected void _onError(String message) {
  183 +
  184 + }
  185 +
  186 + protected void _onErrorWithCode(int errorCode, String message) {
  187 +
  188 + }
  189 +
  190 +}
  1 +/*
  2 + * Copyright 2016 jeasonlzy(廖子尧)
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package com.wd.capability.network;
  18 +
  19 +import java.io.IOException;
  20 +import java.io.InputStream;
  21 +import java.security.KeyManagementException;
  22 +import java.security.KeyStore;
  23 +import java.security.NoSuchAlgorithmException;
  24 +import java.security.cert.Certificate;
  25 +import java.security.cert.CertificateException;
  26 +import java.security.cert.CertificateFactory;
  27 +import java.security.cert.X509Certificate;
  28 +
  29 +import javax.net.ssl.HostnameVerifier;
  30 +import javax.net.ssl.KeyManager;
  31 +import javax.net.ssl.KeyManagerFactory;
  32 +import javax.net.ssl.SSLContext;
  33 +import javax.net.ssl.SSLSession;
  34 +import javax.net.ssl.SSLSocketFactory;
  35 +import javax.net.ssl.TrustManager;
  36 +import javax.net.ssl.TrustManagerFactory;
  37 +import javax.net.ssl.X509TrustManager;
  38 +
  39 +/**
  40 + * @author qts
  41 + */
  42 +public class HttpsUtils {
  43 +
  44 + public static class SslParams {
  45 + public SSLSocketFactory sslSocketFactory;
  46 +
  47 + public X509TrustManager trustManager;
  48 + }
  49 +
  50 + public static SslParams getSslSocketFactory() {
  51 + return getSslSocketFactoryBase(null, null, null);
  52 + }
  53 +
  54 + /**
  55 + * https单向认证
  56 + * 可以额外配置信任服务端的证书策略,否则默认是按CA证书去验证的,若不是CA可信任的证书,则无法通过验证
  57 + */
  58 + public static SslParams getSslSocketFactory(X509TrustManager trustManager) {
  59 + return getSslSocketFactoryBase(trustManager, null, null);
  60 + }
  61 +
  62 + /**
  63 + * https单向认证
  64 + * 用含有服务端公钥的证书校验服务端证书
  65 + */
  66 + public static SslParams getSslSocketFactory(InputStream... certificates) {
  67 + return getSslSocketFactoryBase(null, null, null, certificates);
  68 + }
  69 +
  70 + /**
  71 + * https双向认证
  72 + * bksFile 和 password -> 客户端使用bks证书校验服务端证书
  73 + * certificates -> 用含有服务端公钥的证书校验服务端证书
  74 + */
  75 + public static SslParams getSslSocketFactory(InputStream bksFile, String password, InputStream... certificates) {
  76 + return getSslSocketFactoryBase(null, bksFile, password, certificates);
  77 + }
  78 +
  79 + /**
  80 + * https双向认证
  81 + * bksFile 和 password -> 客户端使用bks证书校验服务端证书
  82 + * X509TrustManager -> 如果需要自己校验,那么可以自己实现相关校验,如果不需要自己校验,那么传null即可
  83 + */
  84 + public static SslParams getSslSocketFactory(InputStream bksFile, String password, X509TrustManager trustManager) {
  85 + return getSslSocketFactoryBase(trustManager, bksFile, password);
  86 + }
  87 +
  88 + private static SslParams getSslSocketFactoryBase(X509TrustManager trustManager, InputStream bksFile,
  89 + String password, InputStream... certificates) {
  90 + SslParams sslParams = new SslParams();
  91 + try {
  92 + KeyManager[] keyManagers = prepareKeyManager(bksFile, password);
  93 + TrustManager[] trustManagers = prepareTrustManager(certificates);
  94 + X509TrustManager manager;
  95 + if (trustManager != null) {
  96 + // 优先使用用户自定义的TrustManager
  97 + manager = trustManager;
  98 + } else if (trustManagers != null) {
  99 + // 然后使用默认的TrustManager
  100 + manager = chooseTrustManager(trustManagers);
  101 + } else {
  102 + // 否则使用不安全的TrustManager
  103 + manager = UnSafeTrustManager;
  104 + }
  105 + // 创建TLS类型的SSLContext对象, that uses our TrustManager
  106 + SSLContext sslContext = SSLContext.getInstance("TLS");
  107 + // 用上面得到的trustManagers初始化SSLContext,这样sslContext就会信任keyStore中的证书
  108 + // 第一个参数是授权的密钥管理器,用来授权验证,比如授权自签名的证书验证。第二个是被授权的证书管理器,用来验证服务器端的证书
  109 + sslContext.init(keyManagers, new TrustManager[] {manager}, null);
  110 + // 通过sslContext获取SSLSocketFactory对象
  111 + sslParams.sslSocketFactory = sslContext.getSocketFactory();
  112 + sslParams.trustManager = manager;
  113 + return sslParams;
  114 + } catch (NoSuchAlgorithmException e) {
  115 + throw new AssertionError(e);
  116 + } catch (KeyManagementException e) {
  117 + throw new AssertionError(e);
  118 + }
  119 + }
  120 +
  121 + private static KeyManager[] prepareKeyManager(InputStream bksFile, String password) {
  122 + try {
  123 + if (bksFile == null || password == null) {
  124 + return null;
  125 + }
  126 + KeyStore clientKeyStore = KeyStore.getInstance("BKS");
  127 + clientKeyStore.load(bksFile, password.toCharArray());
  128 + KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  129 + kmf.init(clientKeyStore, password.toCharArray());
  130 + return kmf.getKeyManagers();
  131 + } catch (Exception e) {
  132 + e.printStackTrace();
  133 + }
  134 + return null;
  135 + }
  136 +
  137 + private static TrustManager[] prepareTrustManager(InputStream... certificates) {
  138 + if (certificates == null || certificates.length <= 0) {
  139 + return null;
  140 + }
  141 + try {
  142 + CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
  143 + // 创建一个默认类型的KeyStore,存储我们信任的证书
  144 + KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
  145 + keyStore.load(null);
  146 + int index = 0;
  147 + for (InputStream certStream : certificates) {
  148 + String certificateAlias = Integer.toString(index++);
  149 + // 证书工厂根据证书文件的流生成证书 cert
  150 + Certificate cert = certificateFactory.generateCertificate(certStream);
  151 + // 将 cert 作为可信证书放入到keyStore中
  152 + keyStore.setCertificateEntry(certificateAlias, cert);
  153 + try {
  154 + if (certStream != null) {
  155 + certStream.close();
  156 + }
  157 + } catch (IOException e) {
  158 + e.printStackTrace();
  159 + }
  160 + }
  161 + // 我们创建一个默认类型的TrustManagerFactory
  162 + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  163 + // 用我们之前的keyStore实例初始化TrustManagerFactory,这样tmf就会信任keyStore中的证书
  164 + tmf.init(keyStore);
  165 + // 通过tmf获取TrustManager数组,TrustManager也会信任keyStore中的证书
  166 + return tmf.getTrustManagers();
  167 + } catch (Exception e) {
  168 + e.printStackTrace();
  169 + }
  170 + return null;
  171 + }
  172 +
  173 + private static X509TrustManager chooseTrustManager(TrustManager[] trustManagers) {
  174 + for (TrustManager trustManager : trustManagers) {
  175 + if (trustManager instanceof X509TrustManager) {
  176 + return (X509TrustManager) trustManager;
  177 + }
  178 + }
  179 + return null;
  180 + }
  181 +
  182 + /**
  183 + * 为了解决客户端不信任服务器数字证书的问题,网络上大部分的解决方案都是让客户端不对证书做任何检查,
  184 + * 这是一种有很大安全漏洞的办法
  185 + */
  186 + public static X509TrustManager UnSafeTrustManager = new X509TrustManager() {
  187 + @Override
  188 + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  189 + }
  190 +
  191 + @Override
  192 + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  193 + }
  194 +
  195 + @Override
  196 + public X509Certificate[] getAcceptedIssuers() {
  197 + return new X509Certificate[] {};
  198 + }
  199 + };
  200 +
  201 + /**
  202 + * 此类是用于主机名验证的基接口。 在握手期间,如果 URL 的主机名和服务器的标识主机名不匹配,
  203 + * 则验证机制可以回调此接口的实现程序来确定是否应该允许此连接。策略可以是基于证书的或依赖于其他验证方案。
  204 + * 当验证 URL 主机名使用的默认规则失败时使用这些回调。如果主机名是可接受的,则返回 true
  205 + */
  206 + public static HostnameVerifier UnSafeHostnameVerifier = new HostnameVerifier() {
  207 + @Override
  208 + public boolean verify(String hostname, SSLSession session) {
  209 + return true;
  210 + }
  211 + };
  212 +}
  1 +
  2 +package com.wd.capability.network;
  3 +
  4 +import java.util.HashMap;
  5 +import java.util.Map;
  6 +
  7 +import android.text.TextUtils;
  8 +
  9 +import com.wd.foundation.wdkitcore.tools.SpUtils;
  10 +
  11 +import okhttp3.Interceptor;
  12 +
  13 +/**
  14 + * 网络管理类
  15 + *
  16 + * @author shishuangxi_wd
  17 + * @date 2022/7/4 14:17
  18 + */
  19 +public class NetManager {
  20 + /**
  21 + * 默认环境设置
  22 + */
  23 + public static final String BASE_URL_DEFAULT = "2";
  24 +
  25 + /**
  26 + * 可选择的环境
  27 + */
  28 + public static final String BASE_URL_SIT = "1";
  29 +
  30 + public static final String BASE_URL_UAT = "2";
  31 +
  32 + public static final String BASE_URL_REL = "3";
  33 +
  34 + public static final String BASE_URL_DEV = "4";
  35 +
  36 + private static NetManager instance;
  37 +
  38 + /**
  39 + * 中文端sit环境
  40 + */
  41 + public static String baseUrlSit = "https://pd-apis-sit.pdnews.cn/";
  42 +
  43 + /**
  44 + * uat环境url
  45 + */
  46 + public static String baseUrlUat = "https://pd-apis-uat.pdnews.cn/";
  47 +
  48 + /**
  49 + * 正式环境url
  50 + */
  51 + public static String baseUrlRel = "https://pdapis.pdnews.cn/";
  52 +
  53 + /**
  54 + * dev环境url
  55 + */
  56 + public static String baseUrlDev = "https://pd-apis-dev.pdnews.cn/";
  57 +
  58 + private String baseUrl;
  59 +
  60 + private String mToken;
  61 +
  62 + private String mVersionCode;
  63 +
  64 + public Builder builder;
  65 +
  66 + private Map<String, String> mHeaderMap = new HashMap<>();
  67 +
  68 + private NetManager() {
  69 + builder = new Builder();
  70 + }
  71 +
  72 + public static NetManager getNetManager() {
  73 + if (instance == null) {
  74 + synchronized (NetManager.class) {
  75 + if (instance == null) {
  76 + instance = new NetManager();
  77 + }
  78 + }
  79 + }
  80 + return instance;
  81 + }
  82 +
  83 + public void setToken(String token) {
  84 + mToken = token;
  85 + }
  86 +
  87 + public String getToken() {
  88 + return mToken;
  89 +
  90 + }
  91 +
  92 + public void setBaseUrl(String baseUrl) {
  93 + if (TextUtils.isEmpty(baseUrl)) {
  94 + return;
  95 + }
  96 + }
  97 +
  98 + public String getBaseUrl() {
  99 + if (TextUtils.isEmpty(baseUrl)) {
  100 + baseUrl = baseUrlRel;
  101 + }
  102 + return baseUrl;
  103 + }
  104 +
  105 + public void setVersionCode(String versionCode) {
  106 + mVersionCode = versionCode;
  107 + }
  108 +
  109 + /**
  110 + * 添加基础头信息
  111 + */
  112 + public void addHeaderParameter(Map<String, String> map) {
  113 + if (map != null && map.size() > 0) {
  114 + mHeaderMap.putAll(map);
  115 + }
  116 + }
  117 +
  118 + public static String getUrlTag() {
  119 + String tag = SpUtils.getBaseUrlTag();
  120 + if (TextUtils.isEmpty(tag)) {
  121 + SpUtils.saveBaseUrlTag(NetManager.BASE_URL_DEFAULT);
  122 + tag = NetManager.BASE_URL_DEFAULT;
  123 + }
  124 + return tag;
  125 + }
  126 +
  127 + public void addHeaderKey(String key, String value) {
  128 + mHeaderMap.put(key, TextUtils.isEmpty(value) ? "" : value);
  129 + }
  130 +
  131 + public void clearHeaderParameter() {
  132 + mHeaderMap.clear();
  133 + }
  134 +
  135 + public Map<String, String> getHeaderParameter() {
  136 + return mHeaderMap;
  137 + }
  138 +
  139 + public static class Builder {
  140 +
  141 + private long connectTimeout = 10;
  142 +
  143 + private long readTimeout = 10;
  144 +
  145 + private long writeTimeout = 10;
  146 +
  147 + private Interceptor mInterceptor;
  148 +
  149 + private String cacheFile = "api_cache";
  150 +
  151 + private long cacheTime = 60 * 60 * 24 * 3;
  152 +
  153 + public long getConnectTimeout() {
  154 + return connectTimeout;
  155 + }
  156 +
  157 + public long getReadTimeout() {
  158 + return readTimeout;
  159 + }
  160 +
  161 + public long getWriteTimeout() {
  162 + return writeTimeout;
  163 + }
  164 +
  165 + public void setConnectTimeout(long connectTimeout) {
  166 + this.connectTimeout = connectTimeout;
  167 + }
  168 +
  169 + public void setReadTimeout(long readTimeout) {
  170 + this.readTimeout = readTimeout;
  171 + }
  172 +
  173 + public void setWriteTimeout(long writeTimeout) {
  174 + this.writeTimeout = writeTimeout;
  175 + }
  176 +
  177 + public void setCacheFile() {
  178 +
  179 + }
  180 +
  181 + public void setInterceptor(Interceptor interceptor) {
  182 + mInterceptor = interceptor;
  183 + }
  184 +
  185 + public Interceptor getInterceptor() {
  186 + return mInterceptor;
  187 + }
  188 +
  189 + public String getCacheFile() {
  190 + return cacheFile;
  191 + }
  192 +
  193 + public void setCacheFile(String cacheFile) {
  194 + this.cacheFile = cacheFile;
  195 + }
  196 +
  197 + public long getCacheTime() {
  198 + return cacheTime;
  199 + }
  200 +
  201 + public void setCacheTime(long cacheTime) {
  202 + this.cacheTime = cacheTime;
  203 + }
  204 +
  205 + }
  206 +}
  1 +
  2 +package com.wd.capability.network;
  3 +
  4 +import java.net.Inet4Address;
  5 +import java.net.InetAddress;
  6 +import java.net.NetworkInterface;
  7 +import java.util.Enumeration;
  8 +import java.util.UUID;
  9 +
  10 +import android.content.Context;
  11 +import android.net.ConnectivityManager;
  12 +import android.net.NetworkInfo;
  13 +import android.net.wifi.WifiInfo;
  14 +import android.net.wifi.WifiManager;
  15 +import android.telephony.TelephonyManager;
  16 +
  17 +import com.wd.foundation.wdinterface.toast.IToast;
  18 +import com.wd.foundation.wdkitcore.router.ArouterServiceManager;
  19 +import com.wd.foundation.wdkitcore.tools.AppContext;
  20 +import com.wd.foundation.wdkitcore.tools.ResUtils;
  21 +
  22 +/**
  23 + * 网络相关工具类
  24 + *
  25 + * @author wondertek
  26 + * @date 2018/08/24
  27 + */
  28 +public class NetworkUtils {
  29 +
  30 + /**
  31 + * 检查网络是否连接
  32 + *
  33 + * @return true 已连接 false 未连接
  34 + */
  35 + public static Boolean isNetAvailable() {
  36 + try {
  37 + ConnectivityManager connectivity =
  38 + (ConnectivityManager) AppContext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  39 + if (connectivity != null) {
  40 + NetworkInfo info = connectivity.getActiveNetworkInfo();
  41 + if (info != null && info.isConnected()) {
  42 +
  43 + if (info.getState() == NetworkInfo.State.CONNECTED) {
  44 + return true;
  45 + }
  46 + }
  47 + }
  48 + } catch (Exception e) {
  49 + return false;
  50 + }
  51 + return false;
  52 + }
  53 +
  54 + /**
  55 + * 判断是否是wifi连接
  56 + *
  57 + * @return
  58 + */
  59 + public static boolean isWifi() {
  60 + ConnectivityManager mConnectivityManager =
  61 + (ConnectivityManager) AppContext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  62 + if (mConnectivityManager == null) {
  63 + return false;
  64 + }
  65 + NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
  66 + if (mWiFiNetworkInfo != null) {
  67 + return mWiFiNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI;
  68 + }
  69 + return false;
  70 + }
  71 +
  72 + /**
  73 + * 判断WIFI网络是否可用
  74 + *
  75 + * @return
  76 + */
  77 + public static boolean isWifiConnected() {
  78 + ConnectivityManager mConnectivityManager =
  79 + (ConnectivityManager) AppContext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  80 + if (mConnectivityManager == null) {
  81 + return false;
  82 + }
  83 + NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  84 + if (mWiFiNetworkInfo != null) {
  85 + return mWiFiNetworkInfo.isAvailable();
  86 + }
  87 + return false;
  88 + }
  89 +
  90 + /**
  91 + * 获取ipv4地址
  92 + *
  93 + * @param context
  94 + * @return IPv4地址
  95 + */
  96 + public static String getIpAddress(Context context) {
  97 +
  98 + String ipAdress = "";
  99 + // 获取WiFi服务
  100 + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  101 + // 判断WiFi是否开启
  102 + if (wifiManager.isWifiEnabled()) {
  103 + // 已经开启了WiFi
  104 + WifiInfo wifiInfo = wifiManager.getConnectionInfo();
  105 + int ipAddress = wifiInfo.getIpAddress();
  106 + ipAdress = intToIp(ipAddress);
  107 +
  108 + } else {
  109 + // 未开启WiFi
  110 + ipAdress = getLocalIpAddress();
  111 + }
  112 +
  113 + boolean isRightIp = isRightIp(ipAdress);
  114 + if (!isRightIp) {
  115 + ipAdress = "";
  116 + }
  117 +
  118 + return ipAdress;
  119 +
  120 + }
  121 +
  122 + /**
  123 + * 获取本机IPv4地址
  124 + *
  125 + * @return 本机IPv4地址
  126 + */
  127 + private static String getLocalIpAddress() {
  128 +
  129 + try {
  130 + for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
  131 + NetworkInterface intf = en.nextElement();
  132 + for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
  133 + InetAddress inetAddress = enumIpAddr.nextElement();
  134 + if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
  135 + return inetAddress.getHostAddress().toString();
  136 + }
  137 + }
  138 + }
  139 + } catch (Exception ex) {
  140 + ex.printStackTrace();
  141 + }
  142 + return "";
  143 + }
  144 +
  145 + private static String intToIp(int ipInt) {
  146 + StringBuilder sb = new StringBuilder();
  147 + sb.append(ipInt & 0xFF).append(".");
  148 + sb.append((ipInt >> 8) & 0xFF).append(".");
  149 + sb.append((ipInt >> 16) & 0xFF).append(".");
  150 + sb.append((ipInt >> 24) & 0xFF);
  151 + return sb.toString();
  152 + }
  153 +
  154 + private static boolean isRightIp(String ipAddress) {
  155 +
  156 + try {
  157 + String[] ips = ipAddress.split("\\.");
  158 + if (ips.length == 4) {
  159 + for (String ip : ips) {
  160 + if (Integer.parseInt(ip) < 0 || Integer.parseInt(ip) > 255) {
  161 + return false;
  162 + }
  163 + }
  164 + return true;
  165 + } else {
  166 + return false;
  167 + }
  168 + } catch (Exception e) {
  169 + e.printStackTrace();
  170 + }
  171 +
  172 + return false;
  173 + }
  174 +
  175 + /**
  176 + * 获取当前的网络状态 :没有网络-0:WIFI网络1:4G网络-4:3G网络-3:2G网络-2
  177 + * 自定义
  178 + *
  179 + * @return
  180 + */
  181 + public static int getAPNType() {
  182 + int netType = 0;
  183 + ConnectivityManager manager =
  184 + (ConnectivityManager) AppContext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  185 + // !!需要修改
  186 + NetworkInfo networkInfo = manager.getActiveNetworkInfo();
  187 + // NetworkInfo对象为空 则代表没有网络
  188 + if (networkInfo == null) {
  189 + return netType;
  190 + }
  191 + int nType = networkInfo.getType();
  192 + if (nType == ConnectivityManager.TYPE_WIFI) {
  193 + // WIFI
  194 + netType = 1;
  195 + } else if (nType == ConnectivityManager.TYPE_MOBILE) {
  196 + int nSubType = networkInfo.getSubtype();
  197 + TelephonyManager telephonyManager =
  198 + (TelephonyManager) AppContext.getContext().getSystemService(Context.TELEPHONY_SERVICE);
  199 + if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming()) {
  200 + netType = 4;
  201 + // 3G 联通的3G为UMTS或HSDPA 电信的3G为EVDO
  202 + } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
  203 + || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0 && !telephonyManager.isNetworkRoaming()) {
  204 + netType = 3;
  205 + // 2G 移动和联通的2G为GPRS或EGDE,电信的2G为CDMA
  206 + } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE
  207 + || nSubType == TelephonyManager.NETWORK_TYPE_CDMA && !telephonyManager.isNetworkRoaming()) {
  208 + netType = 2;
  209 + } else if (nSubType == TelephonyManager.NETWORK_TYPE_NR) {
  210 + netType = 5;
  211 + } else {
  212 + netType = 2;
  213 + }
  214 + }
  215 + return netType;
  216 + }
  217 +
  218 + public static void onFailed(Context context, int errorCode, String errorMessage) {
  219 + IToast toaster = ArouterServiceManager.provide(IToast.class);
  220 + // handle null value
  221 + if (toaster != null) {
  222 + toaster
  223 + .showLong(String.format(ResUtils.getString(R.string.network_request_failed), errorCode, errorMessage));
  224 + }
  225 + }
  226 +
  227 + /**
  228 + * 请求头 TraceID 生成32位随机数
  229 + */
  230 + public static String getRandomUUIDForTraceID() {
  231 + try {
  232 + String randomUuidForTraceId = UUID.randomUUID().toString().toUpperCase().replaceAll("-", "");
  233 + return randomUuidForTraceId;
  234 + } catch (Exception e) {
  235 + return "";
  236 + }
  237 + }
  238 +}
  1 +
  2 +package com.wd.capability.network;
  3 +
  4 +import java.io.File;
  5 +import java.util.concurrent.TimeUnit;
  6 +
  7 +import android.content.Context;
  8 +import android.text.TextUtils;
  9 +
  10 +import com.google.gson.Gson;
  11 +import com.google.gson.GsonBuilder;
  12 +import com.wd.capability.network.adapter.DoubleDefaultAdapter;
  13 +import com.wd.capability.network.adapter.IntegerDefaultAdapter;
  14 +import com.wd.capability.network.adapter.LongDefaultAdapter;
  15 +import com.wd.capability.network.adapter.StringNullAdapter;
  16 +import com.wd.capability.network.interceptor.BaseInterceptor;
  17 +import com.wd.capability.network.interceptor.LoggingInterceptor;
  18 +import com.wd.capability.network.interceptor.MultiDomainInterceptor;
  19 +import com.wd.capability.network.interceptor.TokenInterceptor;
  20 +
  21 +import io.reactivex.Observable;
  22 +import io.reactivex.Observer;
  23 +import io.reactivex.android.schedulers.AndroidSchedulers;
  24 +import io.reactivex.schedulers.Schedulers;
  25 +import okhttp3.Cache;
  26 +import okhttp3.ConnectionPool;
  27 +import okhttp3.OkHttpClient;
  28 +import retrofit2.Retrofit;
  29 +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
  30 +import retrofit2.converter.gson.GsonConverterFactory;
  31 +
  32 +/**
  33 + * @author wonder
  34 + * @date 2020/5/10
  35 + * RetrofitClient封装单例类, 实现网络请求
  36 + */
  37 +public class RetrofitClient {
  38 +
  39 + /**
  40 + * 缓存大小
  41 + */
  42 + private static final int CACHE_TIMEOUT = 100 * 1024 * 1024;
  43 +
  44 + /**
  45 + * 服务端根路径
  46 + */
  47 + public static String baseUrl = NetManager.getNetManager().getBaseUrl();
  48 +
  49 + private static Context mContext;
  50 +
  51 + private static OkHttpClient okHttpClient;
  52 +
  53 + private static Retrofit retrofit;
  54 +
  55 + private static Gson gson;
  56 +
  57 + private Cache cache = null;
  58 +
  59 + private File httpCacheDirectory;
  60 +
  61 + public static void init(Context context) {
  62 + mContext = context;
  63 + }
  64 +
  65 + private static class SingletonHolder {
  66 + private static RetrofitClient INSTANCE = new RetrofitClient();
  67 + }
  68 +
  69 + public static RetrofitClient getInstance() {
  70 + return SingletonHolder.INSTANCE;
  71 + }
  72 +
  73 + private RetrofitClient() {
  74 + this(baseUrl);
  75 + }
  76 +
  77 + private RetrofitClient(String url) {
  78 + if (mContext == null) {
  79 + return;
  80 + }
  81 + if (TextUtils.isEmpty(url)) {
  82 + url = baseUrl;
  83 + }
  84 +
  85 + if (httpCacheDirectory == null) {
  86 + httpCacheDirectory = new File(mContext.getCacheDir(), NetManager.getNetManager().builder.getCacheFile());
  87 + }
  88 + try {
  89 + if (cache == null) {
  90 + cache = new Cache(httpCacheDirectory, CACHE_TIMEOUT);
  91 + }
  92 + } catch (Exception e) {
  93 + e.printStackTrace();
  94 + }
  95 +
  96 + HttpsUtils.SslParams sslParams = HttpsUtils.getSslSocketFactory();
  97 + OkHttpClient.Builder builder = new OkHttpClient.Builder().cache(cache);
  98 + builder.addInterceptor(new MultiDomainInterceptor())
  99 + .addInterceptor(new BaseInterceptor(mContext))
  100 + .addInterceptor(new TokenInterceptor(mContext));
  101 + if (BuildConfig.DEBUG) {
  102 + builder.addInterceptor(new LoggingInterceptor());
  103 + }
  104 + okHttpClient = builder.readTimeout(NetManager.getNetManager().builder.getReadTimeout(), TimeUnit.SECONDS)
  105 + .connectTimeout(NetManager.getNetManager().builder.getConnectTimeout(), TimeUnit.SECONDS)
  106 + .writeTimeout(NetManager.getNetManager().builder.getWriteTimeout(), TimeUnit.SECONDS)
  107 + // 这里你可以根据自己的机型设置同时连接的个数和时间,我这里8个,和每个保持时间为10s
  108 + .connectionPool(new ConnectionPool(8, 10, TimeUnit.SECONDS))
  109 + .build();
  110 + retrofit = new Retrofit.Builder().client(okHttpClient)
  111 + .addConverterFactory(GsonConverterFactory.create(buildGson()))
  112 + .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
  113 + .baseUrl(url)
  114 + .build();
  115 + }
  116 +
  117 + /**
  118 + * create you ApiService
  119 + * Create an implementation of the API endpoints defined by the {@code service} interface.
  120 + */
  121 + public <T> T create(final Class<T> service) {
  122 + if (service == null) {
  123 + throw new RuntimeException("Api service is null!");
  124 + }
  125 + return retrofit.create(service);
  126 + }
  127 +
  128 + /**
  129 + * 线程切换
  130 + *
  131 + * @param observable
  132 + * @param subscriber
  133 + * @param <T>
  134 + * @return
  135 + */
  136 + public static <T> T execute(Observable<T> observable, Observer<T> subscriber) {
  137 + observable.subscribeOn(Schedulers.io())
  138 + .unsubscribeOn(Schedulers.io())
  139 + .observeOn(AndroidSchedulers.mainThread())
  140 + .subscribe(subscriber);
  141 + return null;
  142 + }
  143 +
  144 + /**
  145 + * 同步进行
  146 + *
  147 + * @param observable
  148 + * @param subscriber
  149 + * @param <T>
  150 + * @return
  151 + */
  152 + public static <T> T executeSynchronize(Observable<T> observable, Observer<T> subscriber) {
  153 + observable.subscribeOn(AndroidSchedulers.mainThread())
  154 + .unsubscribeOn(AndroidSchedulers.mainThread())
  155 + .observeOn(AndroidSchedulers.mainThread())
  156 + .subscribe(subscriber);
  157 + return null;
  158 + }
  159 +
  160 + /**
  161 + * 增加后台返回""和"null"的处理
  162 + * 1.int=>0
  163 + * 2.double=>0.00
  164 + * 3.long=>0L
  165 + *
  166 + * @return
  167 + */
  168 + public static Gson buildGson() {
  169 + if (gson == null) {
  170 + gson = new GsonBuilder().registerTypeAdapter(Integer.class, new IntegerDefaultAdapter())
  171 + .registerTypeAdapter(int.class, new IntegerDefaultAdapter())
  172 + .registerTypeAdapter(Double.class, new DoubleDefaultAdapter())
  173 + .registerTypeAdapter(double.class, new DoubleDefaultAdapter())
  174 + .registerTypeAdapter(Long.class, new LongDefaultAdapter())
  175 + .registerTypeAdapter(long.class, new LongDefaultAdapter())
  176 + .registerTypeAdapter(String.class, new StringNullAdapter())
  177 + .create();
  178 + }
  179 + return gson;
  180 + }
  181 +}
  1 +/*
  2 + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
  3 + */
  4 +
  5 +package com.wd.capability.network.adapter;
  6 +
  7 +import com.google.gson.JsonDeserializationContext;
  8 +import com.google.gson.JsonDeserializer;
  9 +import com.google.gson.JsonElement;
  10 +import com.google.gson.JsonParseException;
  11 +import com.google.gson.JsonPrimitive;
  12 +import com.google.gson.JsonSerializationContext;
  13 +import com.google.gson.JsonSerializer;
  14 +import com.google.gson.JsonSyntaxException;
  15 +
  16 +import java.lang.reflect.Type;
  17 +
  18 +/**
  19 + * 描述:
  20 + *
  21 + * @author : lvjinhui
  22 + * @since: 2022/6/25
  23 + */
  24 +public class DoubleDefaultAdapter implements JsonSerializer<Double>, JsonDeserializer<Double> {
  25 + @Override
  26 + public Double deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
  27 + try {
  28 + if ("".equals(json.getAsString()) || "null".equals(json.getAsString())) {//定义为double类型,如果后台返回""或者null,则返回0.00
  29 + return 0.00;
  30 + }
  31 + } catch (Exception ignore) {
  32 + }
  33 + try {
  34 + return json.getAsDouble();
  35 + } catch (NumberFormatException e) {
  36 + throw new JsonSyntaxException(e);
  37 + }
  38 + }
  39 +
  40 + @Override
  41 + public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) {
  42 + return new JsonPrimitive(src);
  43 + }
  44 +
  45 +}
  1 +/*
  2 + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
  3 + */
  4 +
  5 +package com.wd.capability.network.adapter;
  6 +
  7 +import com.google.gson.JsonDeserializationContext;
  8 +import com.google.gson.JsonDeserializer;
  9 +import com.google.gson.JsonElement;
  10 +import com.google.gson.JsonParseException;
  11 +import com.google.gson.JsonPrimitive;
  12 +import com.google.gson.JsonSerializationContext;
  13 +import com.google.gson.JsonSerializer;
  14 +import com.google.gson.JsonSyntaxException;
  15 +
  16 +import java.lang.reflect.Type;
  17 +
  18 +/**
  19 + * 描述:对返回值为空处理
  20 + *
  21 + * @author : lvjinhui
  22 + * @since: 2022/6/25
  23 + */
  24 +public class IntegerDefaultAdapter implements JsonSerializer<Integer>, JsonDeserializer<Integer> {
  25 + @Override
  26 + public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
  27 + throws JsonParseException {
  28 + try {
  29 + /**
  30 + * 定义为int类型,如果后台返回""或者null,则返回0
  31 + */
  32 + if ("".equals(json.getAsString()) || "null".equals(json.getAsString())) {
  33 + return 0;
  34 + }
  35 + } catch (Exception ignore) {
  36 + ignore.printStackTrace();
  37 + }
  38 + try {
  39 + return json.getAsInt();
  40 + } catch (NumberFormatException e) {
  41 + throw new JsonSyntaxException(e);
  42 + }
  43 + }
  44 +
  45 + @Override
  46 + public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
  47 + return new JsonPrimitive(src);
  48 + }
  49 +}
  1 +/*
  2 + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
  3 + */
  4 +
  5 +package com.wd.capability.network.adapter;
  6 +
  7 +import com.google.gson.JsonDeserializationContext;
  8 +import com.google.gson.JsonDeserializer;
  9 +import com.google.gson.JsonElement;
  10 +import com.google.gson.JsonParseException;
  11 +import com.google.gson.JsonPrimitive;
  12 +import com.google.gson.JsonSerializationContext;
  13 +import com.google.gson.JsonSerializer;
  14 +import com.google.gson.JsonSyntaxException;
  15 +
  16 +import java.lang.reflect.Type;
  17 +
  18 +/**
  19 + * 描述:对返回值为空处理
  20 + *
  21 + * @author : lvjinhui
  22 + * @since: 2022/6/25
  23 + */
  24 +public class LongDefaultAdapter implements JsonSerializer<Long>, JsonDeserializer<Long> {
  25 + @Override
  26 + public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
  27 + throws JsonParseException {
  28 + try {
  29 + /**
  30 + * 定义为long类型,如果后台返回""或者null,则返回0
  31 + */
  32 + if ("".equals(json.getAsString()) || "null".equals(json.getAsString())) {
  33 + return 0L;
  34 + }
  35 + } catch (Exception ignore) {
  36 + }
  37 + try {
  38 + return json.getAsLong();
  39 + } catch (NumberFormatException e) {
  40 + throw new JsonSyntaxException(e);
  41 + }
  42 + }
  43 +
  44 + @Override
  45 + public JsonElement serialize(Long src, Type typeOfSrc, JsonSerializationContext context) {
  46 + return new JsonPrimitive(src);
  47 + }
  48 +}
  1 +/*
  2 + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
  3 + */
  4 +
  5 +package com.wd.capability.network.adapter;
  6 +
  7 +import com.google.gson.TypeAdapter;
  8 +import com.google.gson.stream.JsonReader;
  9 +import com.google.gson.stream.JsonToken;
  10 +import com.google.gson.stream.JsonWriter;
  11 +
  12 +import java.io.IOException;
  13 +
  14 +/**
  15 + * 描述:
  16 + *
  17 + * @author : lvjinhui
  18 + * @since: 2022/6/25
  19 + */
  20 +public class StringNullAdapter extends TypeAdapter<String> {
  21 + @Override
  22 + public String read(JsonReader reader) throws IOException {
  23 + if (reader.peek() == JsonToken.NULL) {
  24 + reader.nextNull();
  25 + return "";//原先是返回Null,这里改为返回空字符串
  26 + }
  27 +
  28 + String jsonStr = reader.nextString();
  29 + if("null".equals(jsonStr)) {
  30 + return "";
  31 + }else {
  32 + return jsonStr;
  33 + }
  34 + }
  35 +
  36 + @Override
  37 + public void write(JsonWriter writer, String value) throws IOException {
  38 + if (value == null) {
  39 + writer.nullValue();
  40 + return;
  41 + }
  42 + writer.value(value);
  43 + }
  44 +
  45 +}
  1 +package com.wd.capability.network.api;
  2 +
  3 +
  4 +import com.wd.capability.network.bean.TokenBean;
  5 +import com.wd.capability.network.response.BaseResponse;
  6 +
  7 +import okhttp3.RequestBody;
  8 +import retrofit2.Call;
  9 +import retrofit2.http.Body;
  10 +import retrofit2.http.Header;
  11 +import retrofit2.http.POST;
  12 +
  13 +/**
  14 + * 描述:接口定义
  15 + *
  16 + * @author : lvjinhui
  17 + * @since: 2022/12/15
  18 + */
  19 +public interface IRefreshToken {
  20 +
  21 + @POST("api/rmrb-user-center/auth/zh/c/refreshToken")
  22 + Call<BaseResponse<TokenBean>> getJwtToken(@Header("RMRB-X-TOKEN")String token, @Body RequestBody body);
  23 +
  24 +}
  1 +package com.wd.capability.network.bean;
  2 +
  3 +/**
  4 + * Time:2022/10/10
  5 + * Author:ypf
  6 + * Description:
  7 + */
  8 +public class FetchAccessTokenBean {
  9 +
  10 +
  11 + private String access_token;
  12 + private String expires_in;
  13 + private String scope;
  14 + private String token_type;
  15 +
  16 + public FetchAccessTokenBean() {
  17 + }
  18 +
  19 + public String getAccess_token() {
  20 + return access_token;
  21 + }
  22 +
  23 + public void setAccess_token(String access_token) {
  24 + this.access_token = access_token;
  25 + }
  26 +
  27 + public String getExpires_in() {
  28 + return expires_in;
  29 + }
  30 +
  31 + public void setExpires_in(String expires_in) {
  32 + this.expires_in = expires_in;
  33 + }
  34 +
  35 + public String getScope() {
  36 + return scope;
  37 + }
  38 +
  39 + public void setScope(String scope) {
  40 + this.scope = scope;
  41 + }
  42 +
  43 + public String getToken_type() {
  44 + return token_type;
  45 + }
  46 +
  47 + public void setToken_type(String token_type) {
  48 + this.token_type = token_type;
  49 + }
  50 +}
  1 +package com.wd.capability.network.bean;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * 描述:存放md5值
  7 + *
  8 + * @author : lvjinhui
  9 + * @since: 2022/10/26
  10 + */
  11 +public class MetaBean implements Serializable {
  12 +
  13 + /**
  14 + * 接口的md5比较
  15 + */
  16 + private String md5;
  17 +
  18 + /**
  19 + * feed组件配置动态接口,访问到的数据配置的md5值
  20 + */
  21 + private String fmd5;
  22 +
  23 + public String getMd5() {
  24 + return md5;
  25 + }
  26 +
  27 + public void setMd5(String md5) {
  28 + this.md5 = md5;
  29 + }
  30 +
  31 + public String getFmd5() {
  32 + return fmd5;
  33 + }
  34 +
  35 + public void setFmd5(String fmd5) {
  36 + this.fmd5 = fmd5;
  37 + }
  38 +}
  1 +
  2 +package com.wd.capability.network.bean;
  3 +
  4 +public class NetworkEventConstants {
  5 + /**
  6 + * 强制退出登录,去登录页面
  7 + */
  8 + public static final String FORCE_USER_LOGIN_OUT = "force_user_login_out";
  9 +
  10 + /**
  11 + * 网络请求流量超标
  12 + */
  13 + public static final String FLOW_TOO_LARGE = "flow_toolarge";
  14 +}
  1 +package com.wd.capability.network.bean;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * 描述:token
  7 + *
  8 + * @author : lvjinhui
  9 + * @since: 2022/9/1
  10 + */
  11 +public class TokenBean implements Serializable {
  12 +
  13 + private String jwtToken;
  14 +
  15 + private String refreshToken;
  16 +
  17 + public String getJwtToken() {
  18 + return jwtToken;
  19 + }
  20 +
  21 + public void setJwtToken(String jwtToken) {
  22 + this.jwtToken = jwtToken;
  23 + }
  24 +
  25 + public String getRefreshToken() {
  26 + return refreshToken;
  27 + }
  28 +
  29 + public void setRefreshToken(String refreshToken) {
  30 + this.refreshToken = refreshToken;
  31 + }
  32 +}
  1 +
  2 +package com.wd.capability.network.cachedata;
  3 +
  4 +import org.json.JSONArray;
  5 +import org.json.JSONException;
  6 +import org.json.JSONObject;
  7 +
  8 +import android.os.SystemClock;
  9 +import android.text.TextUtils;
  10 +
  11 +import com.google.gson.annotations.Expose;
  12 +import com.google.gson.annotations.SerializedName;
  13 +import com.wd.base.log.Logger;
  14 +import com.wd.capability.network.NetManager;
  15 +import com.wd.foundation.wdkitcore.tools.AssertUtils;
  16 +import com.wd.foundation.wdkitcore.tools.JsonUtils;
  17 +
  18 +/**
  19 + * 描述:
  20 + * TODO 上抛,业务层处理
  21 + *
  22 + * @author : lvjinhui
  23 + * @since: 2022/10/16
  24 + */
  25 +public class CacheData {
  26 +
  27 + /**
  28 + * 1天的缓存数据(ms)
  29 + */
  30 + public static final long oneDayTime = 24 * 60 * 60 * 1000;
  31 +
  32 + /**
  33 + * 底部导航栏缓存的数据key
  34 + */
  35 + public static final String bottomCacheKey = "bottom_cache_data_key";
  36 +
  37 + /**
  38 + * 头部频道缓存的数据key
  39 + */
  40 + public static final String channelCacheDataKey = "channel_data_cache_id_";
  41 +
  42 + /**
  43 + * 页面page组件的数据key
  44 + */
  45 + public static final String comPageInfoCacheKey = "com_pageInfo_cache_id_";
  46 +
  47 + /**
  48 + * 页面组件的数据key
  49 + */
  50 + public static final String compGroupInfoDataCacheKey = "com_data_info_cache_id_";
  51 +
  52 + /**
  53 + * 数据源接口缓存
  54 + */
  55 + public static final String dataSourceCacheKey = "data_source_data_cache_type_";
  56 +
  57 + /**
  58 + * 我的页面头部信息key
  59 + */
  60 + public static final String mineTopInfoCacheKey = "mine_top_info_cache_id_";
  61 +
  62 + /**
  63 + * 关注列表头部信息key
  64 + */
  65 + public static final String attentionTopInfoCacheKey = "attention_top_info_cache_id_";
  66 +
  67 + private static final String TAG = "CacheData";
  68 +
  69 + @SerializedName("networkData")
  70 + @Expose
  71 + public Object networkData;
  72 +
  73 + @SerializedName("updateTimeInMillis")
  74 + @Expose
  75 + public long updateTimeInMillis;
  76 +
  77 + @SerializedName("md5")
  78 + @Expose
  79 + public String md5;
  80 +
  81 + public static void saveDataToPreference(String cachePreferenceKey, Object data, String responseMd5) {
  82 + if (data != null) {
  83 + CacheData cacheData = new CacheData();
  84 + cacheData.networkData = data;
  85 + cacheData.updateTimeInMillis = SystemClock.uptimeMillis();
  86 + cacheData.md5 = responseMd5;
  87 + CacheDataPreferenceUtil.getInstance()
  88 + .setString(cachePreferenceKey, JsonUtils.convertObjectToJson(cacheData));
  89 + }
  90 + }
  91 +
  92 + public String getNetWorkData() {
  93 + if (networkData != null) {
  94 + return JsonUtils.convertObjectToJson(networkData);
  95 + }
  96 + return "";
  97 + }
  98 +
  99 + /**
  100 + * 比较缓存和接口返回数据是否一致
  101 + *
  102 + * @param key
  103 + * @param resultData
  104 + * @return
  105 + */
  106 + public static boolean isSameData(String key, Object resultData) {
  107 + if (!TextUtils.isEmpty(key) && resultData != null) {
  108 + String cacheDataStr = CacheDataPreferenceUtil.getInstance().getString(key);
  109 + if (TextUtils.isEmpty(cacheDataStr)) {
  110 + return false;
  111 + }
  112 + // 保存的数据转成CacheData
  113 + CacheData cacheData = JsonUtils.convertJsonToObject(cacheDataStr, CacheData.class);
  114 + if (cacheData != null) {
  115 + // 获取保存的NetWorkData 和 resultData 比较
  116 + if (cacheData.getNetWorkData().equals(JsonUtils.convertObjectToJson(resultData))) {
  117 + Logger.t(TAG).e("接口返回数据和缓存数据一致");
  118 + return true;
  119 + }
  120 + }
  121 + }
  122 + return false;
  123 + }
  124 +
  125 + /**
  126 + * 间隔多久进行刷新
  127 + *
  128 + * @return
  129 + */
  130 + public boolean needRefresh(long refreshTime) {
  131 + long currentTimeMillis = SystemClock.uptimeMillis();
  132 + // 当前时间减去保存数据的时间 > 刷新间隔时间 就要进行刷新
  133 + if (Math.abs(currentTimeMillis - updateTimeInMillis) > refreshTime) {
  134 + return true;
  135 + }
  136 + return false;
  137 + }
  138 +
  139 + /**
  140 + * 是否需要刷新
  141 + *
  142 + * @param responseMd5
  143 + * @return
  144 + */
  145 + public boolean needRefreshByMd5(String responseMd5) {
  146 + if (TextUtils.isEmpty(md5) || TextUtils.isEmpty(responseMd5)) {
  147 + return false;
  148 + }
  149 + if (!md5.equals(responseMd5)) {
  150 + return true;
  151 + }
  152 + return false;
  153 + }
  154 +
  155 + /**
  156 + * 获取到保存的数据
  157 + *
  158 + * @param key
  159 + * @return
  160 + */
  161 + public static CacheData getLocalCacheData(String key) {
  162 + if (!TextUtils.isEmpty(key)) {
  163 + String cacheDataStr = CacheDataPreferenceUtil.getInstance().getString(key);
  164 + if (!TextUtils.isEmpty(cacheDataStr)) {
  165 + // 保存的数据转成CacheData
  166 + CacheData cacheData = JsonUtils.convertJsonToObject(cacheDataStr, CacheData.class);
  167 + if (cacheData != null) {
  168 + return cacheData;
  169 + }
  170 + }
  171 + }
  172 + return null;
  173 + }
  174 +
  175 + /**
  176 + * 判断关注tab缓存是否存在
  177 + *
  178 + * @param userId
  179 + * @return
  180 + */
  181 + // public static boolean haveMyFollowLocalCacheData(String userId) {
  182 + // CacheData userFollowCache = CacheData.getLocalCacheData(CacheData.mineFollowCacheKey + userId);
  183 + // if (userFollowCache != null && !TextUtils.isEmpty(userFollowCache.getNetWorkData())) {
  184 + // return true;
  185 + // }
  186 + // return false;
  187 + // }
  188 +
  189 + /**
  190 + * 预置的正式环境 底部预置数据
  191 + *
  192 + * @return
  193 + */
  194 + public static String getBottomPresetsData() {
  195 + String tag = NetManager.getUrlTag();
  196 + String bottomPresetsData = "";
  197 + if (NetManager.BASE_URL_REL.equals(tag)) {
  198 + bottomPresetsData = AssertUtils.readJsonFile("bottomPresetsData.json");
  199 + }
  200 + // else if (NetManager.BASE_URL_SIT.equals(tag)) {
  201 + // bottomPresetsData = AssertUtils.readJsonFile("bottomPresetsData_sit.json");
  202 + // } else if (NetManager.BASE_URL_UAT.equals(tag)) {
  203 + // bottomPresetsData = AssertUtils.readJsonFile("bottomPresetsData_uat.json");
  204 + // }
  205 +
  206 + if (bottomPresetsData != null) {
  207 + return bottomPresetsData;
  208 + }
  209 + return "";
  210 + }
  211 +
  212 + /**
  213 + * 预置的正式环境 频道预置数据
  214 + *
  215 + * @return
  216 + */
  217 + public static String getChannelPresetsData(String id) {
  218 + String tag = NetManager.getUrlTag();
  219 + String channelPresetsData = "";
  220 + if (NetManager.BASE_URL_REL.equals(tag)) {
  221 + channelPresetsData = AssertUtils.readJsonFile("channelPresetsData.json");
  222 + }
  223 + // else if (NetManager.BASE_URL_SIT.equals(tag)){
  224 + // channelPresetsData = AssertUtils.readJsonFile("channelPresetsData_sit.json");
  225 + // } else if (NetManager.BASE_URL_UAT.equals(tag)){
  226 + // channelPresetsData = AssertUtils.readJsonFile("channelPresetsData_uat.json");
  227 + // }
  228 + try {
  229 + JSONObject jsonObject = new JSONObject(channelPresetsData);
  230 + if (jsonObject != null) {
  231 + JSONArray jsonArray = jsonObject.optJSONArray("presetsData");
  232 + if (jsonArray != null && jsonArray.length() > 0) {
  233 + for (int i = 0; i < jsonArray.length(); i++) {
  234 + JSONObject jsonObject1 = jsonArray.getJSONObject(i);
  235 + String id1 = jsonObject1.optString("id");
  236 + if (id.equals(id1)) {
  237 + return jsonObject1.toString();
  238 + }
  239 + }
  240 + }
  241 + }
  242 + } catch (JSONException e) {
  243 + e.printStackTrace();
  244 + }
  245 + return "";
  246 + }
  247 +
  248 +}
  1 +
  2 +package com.wd.capability.network.cachedata;
  3 +
  4 +import android.text.TextUtils;
  5 +
  6 +import com.wd.foundation.wdkitcore.tools.SpUtils;
  7 +
  8 +/**
  9 + * 描述:保存缓存数据
  10 + * TODO 上抛,业务层处理
  11 + *
  12 + * @author : lvjinhui
  13 + * @since: 2022/10/16
  14 + */
  15 +public class CacheDataPreferenceUtil {
  16 +
  17 + private static CacheDataPreferenceUtil instance;
  18 +
  19 + private CacheDataPreferenceUtil() {
  20 +
  21 + }
  22 +
  23 + public static CacheDataPreferenceUtil getInstance() {
  24 + if (instance == null) {
  25 + instance = new CacheDataPreferenceUtil();
  26 + }
  27 + return instance;
  28 + }
  29 +
  30 + /**
  31 + * 保存数据
  32 + *
  33 + * @param key
  34 + * @param data
  35 + */
  36 + protected void setString(String key, String data) {
  37 + if (TextUtils.isEmpty(key)) {
  38 + return;
  39 + }
  40 + SpUtils.saveNetworkDataCache(key, data);
  41 + }
  42 +
  43 + /**
  44 + * 获取保存的数据
  45 + *
  46 + * @param key
  47 + * @return
  48 + */
  49 + protected String getString(String key) {
  50 + if (TextUtils.isEmpty(key)) {
  51 + return "";
  52 + }
  53 + String networkDataCache = SpUtils.getNetworkDataCache(key);
  54 + return networkDataCache;
  55 + }
  56 +
  57 +}
  1 +
  2 +package com.wd.capability.network.constant;
  3 +
  4 +/**
  5 + * 描述:网络相关常量定义
  6 + * TODO 待拆,往上抛
  7 + *
  8 + * @author : lvjinhui
  9 + * data: 2022/7/13
  10 + */
  11 +public abstract class NetConstant {
  12 +
  13 + /**
  14 + * wifi
  15 + */
  16 + public static final String NET_WIFI_TYPE = "1";
  17 +
  18 + /**
  19 + * 数据网络
  20 + */
  21 + public static final String NET_CELL_TYPE = "0";
  22 +
  23 + /**
  24 + * 无网络
  25 + */
  26 + public static final String NET_ERROR_TYPE = "2";
  27 +
  28 + // ************************网关*****************************
  29 + /**
  30 + * 中文端的 sit 0af1f9085e484c97b2a44704bae72c07
  31 + */
  32 + public static final String APPCODE_VALUE_SIT = "0af1f9085e484c97b2a44704bae72c07";
  33 + /**
  34 + * 海外的 sit
  35 + */
  36 + // public static final String APPCODE_VALUE_SIT = "13454e77e1394ce694df74e0b2e65bb5";
  37 +
  38 + /**
  39 + * uat
  40 + */
  41 + public static final String APPCODE_VALUE_UTA = "83092caa603a421aa0222308b3f6b27a";
  42 +
  43 + /**
  44 + * release
  45 + */
  46 + public static final String APPCODE_VALUE_RELEASE = "3d4181bceeb94d9780e10dbb6c67bbf6";
  47 +
  48 + /**
  49 + * dev
  50 + */
  51 + public static final String APPCODE_VALUE_DEV = "ff33172859e14f9a8299e3bd769e79f9";
  52 +
  53 + /**
  54 + * 网关APPCODE
  55 + */
  56 + public static final String APPCODE_SIT = "APPCODE " + APPCODE_VALUE_SIT;
  57 +
  58 + public static final String APPCODE_UTA = "APPCODE " + APPCODE_VALUE_UTA;
  59 +
  60 + public static final String APPCODE_RELEASE = "APPCODE " + APPCODE_VALUE_RELEASE;
  61 +
  62 + public static final String APPCODE_DEV = "APPCODE " + APPCODE_VALUE_DEV;
  63 +
  64 + public static final int API_CONNECT_TIME_OUT = 10;
  65 +
  66 + public static final int API_IM_CONNECT_TIME_OUT = 10;
  67 +
  68 + public static final int API_READ_TIME_OUT = 10;
  69 +
  70 + public static final int API_WRITE_TIME_OUT = 10;
  71 +
  72 + public static final String API_SP_NAME_NET = "net";
  73 +
  74 + public static final String API_SP_KEY_NET_COOKIE_SET = "cookie_set";
  75 +
  76 + public static final String API_SP_KEY_NET_HEADER_AUTH = "header_auth";
  77 +
  78 + public static final int REQUEST_SUCCESS_CODE = 200;
  79 +
  80 +}
  1 +
  2 +package com.wd.capability.network.constant;
  3 +
  4 +/**
  5 + * 入参常量类
  6 + *
  7 + * @author shishuangxi_wd
  8 + * @date 2022/6/25 11:29
  9 + */
  10 +public class ParameterConstant {
  11 + /**
  12 + * JSON 格式
  13 + */
  14 + public final static String HEADER_JSON_TYPE = "application/json; charset=utf-8";
  15 +
  16 + public final static String CONTENTTYPE = "Content-Type";
  17 +
  18 + public final static String PLAT = "plat";
  19 +
  20 + public final static String TIMESTAMP = "timestamp";
  21 +
  22 + public final static String SYSTEM = "system";
  23 +
  24 + public static final String DEVICE_ID = "device_id";
  25 +
  26 + public final static String VERSIONCODE = "versionCode";
  27 +
  28 + public final static String VERSIONNAME = "version_name";
  29 +
  30 + /**
  31 + * app版本-h5协议用
  32 + */
  33 + public final static String APP_VERSION = "appVersion";
  34 +
  35 + public final static String BUILDVERSION = "build_version";
  36 +
  37 + /**
  38 + * 添加cookie值到header,value形式为
  39 + */
  40 + public final static String COOKIE = "cookie";
  41 +
  42 + public final static String USERAGENT = "User-Agent";
  43 +
  44 + public final static String OS_VERSION = "os_version";
  45 +
  46 + public final static String CITY = "city";
  47 +
  48 + public final static String CITY_CODE = "city_dode";
  49 +
  50 + public final static String AD_CODE = "adcode";
  51 +
  52 + public static final String USER_ID = "userId";
  53 + public static final String USER_NAME = "userName";
  54 + public static final String USER_TYPE = "userType";
  55 + public static final String USER_HEADER_URL = "userHeaderUrl";
  56 +
  57 + public static final String REFRESH_TOKEN = "refreshToken";
  58 +
  59 + public static final String DEVICEID = "deviceId";
  60 +
  61 + public static final String RMRB_X_TOKEN = "RMRB-X-TOKEN";
  62 +
  63 + public static final String IMEI = "imei";
  64 +
  65 + public final static String CHANNEL = "channel";
  66 + public static final String TIME = "time";
  67 + /**
  68 + * 语言国际化
  69 + */
  70 + public final static String ACCEPT_LANGUAGE = "Accept-Language";
  71 +
  72 + /**
  73 + * 端标识-h5协议用
  74 + */
  75 + public final static String LANG = "lang";
  76 +
  77 + /**
  78 + * 状态栏高度
  79 + */
  80 + public final static String SCREEN_STATUS_BAR_HEIGHT = "screenStatusBarHeight";
  81 +
  82 + /**
  83 + * 屏幕高度
  84 + */
  85 + public final static String SCREEN_HEIGHT = "screenHeight";
  86 +
  87 + /**
  88 + * 屏幕宽度
  89 + */
  90 + public final static String SCREEN_WIDTH = "screenWidth";
  91 +
  92 + /**
  93 + * 环境
  94 + */
  95 + public final static String ENVIRONMENT = "environment";
  96 +
  97 + /**
  98 + * light (亮色模式)、dark(暗色模式)
  99 + */
  100 + public final static String DARK_MODE = "darkMode";
  101 +
  102 + /**
  103 + * 经度
  104 + */
  105 + public final static String LONGITUDE = "longitude";
  106 +
  107 + /**
  108 + * 纬度
  109 + */
  110 + public final static String LATITUDE = "latitude";
  111 +
  112 + /**
  113 + * 地址信息
  114 + */
  115 + public final static String ADDRESS = "address";
  116 +
  117 + /**
  118 + * 网络环境:0:无网 1:WiFi 2:2G 3:3G 4:4G 5:5G
  119 + */
  120 + public final static String NETWORK_STATUS = "networkStatus";
  121 +
  122 + /**
  123 + * App服务协议
  124 + */
  125 + public final static String AGREEMENT_URL = "agreementURL";
  126 +
  127 + public static final String CONTENTID = "contentId";
  128 +
  129 + public static final String CONTENT_TYPE = "contentType";
  130 +
  131 + public static final String CONTENTIDS = "contentIds";
  132 +
  133 + public static final String CONTENT_SOURCE = "contentSource";
  134 +
  135 + public static final String RETURN_COUNT = "returnCount";
  136 +
  137 + public static final String ITEMID = "itemId";
  138 +
  139 + public final static String TAG = "tag";
  140 +
  141 + public final static String STRATEGY = "strategy";
  142 +
  143 + public final static String USERID = "userId";
  144 +
  145 + public static final String SEARCH_TYPE = "searchType";
  146 +
  147 + public final static String PAGENUM = "pageNum";
  148 +
  149 + public final static String PAGESIZE = "pageSize";
  150 +
  151 + public static final String KEYWORD = "keyword";
  152 +
  153 + public final static String SERIALS_ID = "serialsId";
  154 +
  155 + public static final String CREATORID = "creatorId";
  156 +
  157 + public static final String NAME = "name";
  158 +
  159 + public static final String INTRODUCTION = "introduction";
  160 +
  161 + public static final String HEADER_PHOTO_URL = "headerPhotoUrl";
  162 +
  163 + public static final String COUNTRY_CODE = "countryCode";
  164 +
  165 + public static final String PROCINCE_CODE = "provinceCode";
  166 +
  167 + public static final String CITYCODE = "cityCode";
  168 +
  169 + public static final String DISTRICT_CODE = "districtCode";
  170 +
  171 + public static final String PERIOD = "period";
  172 +
  173 + public static final String COMMENT_ID = "commentId";
  174 +
  175 + public static final String CREATOR_DIRECTORY_ID = "creatorDirectoryId";
  176 +
  177 + public static final String EXCLUDE_IDS = "excludeIds";
  178 + public static final String STATUS = "status";
  179 + public static final String TITLE = "title";
  180 + public static final String CHANNELID = "channelId";
  181 + /**
  182 + * 提交评论
  183 + */
  184 + public static final String COMMENT_CONTENT = "commentContent";
  185 + public static final String COMMENT_TYPE = "commentType";
  186 + public static final String COMMENT_PICS = "commentPics";
  187 + public static final String TARGET_ID = "targetId";
  188 + public static final String TARGET_TYPE = "targetType";
  189 + public static final String PARENT_ID = "parentId";
  190 + public static final String ROOT_COMMENT_ID = "rootCommentId";
  191 + public static final String TARGET_REL_ID ="targetRelId" ;
  192 + public static final String TARGET_REL_TYPE ="targetRelType" ;
  193 + //绑定关系
  194 + public static final String CONTENT_RELLD ="contentRelId" ;
  195 + //绑定
  196 + public static final String CONTENT_REL_TYPE ="relType" ;
  197 + public static final String CONTENT_REL_ID ="relId" ;
  198 +
  199 + public static final String SHARE_OPT ="shareOpt" ;
  200 +
  201 + public static final String REQUEST_TYPE ="type" ;
  202 +
  203 + public static final String REQUEST_TARGET_TITLE ="targetTitle" ;
  204 + public static final String REQUEST_KEY_ARTICLE="keyArticle" ;
  205 + public static final String REQUEST_TARGET_REL_OBJECT_ID ="targetRelObjectId" ;
  206 + /**
  207 + * 客户端日志链路追踪traceid生成:在每个请求头加上参数Key:EagleEye-TraceID ,value为32位生成随机值
  208 + */
  209 + public final static String EagleEyeTraceID = "EagleEye-TraceID";
  210 +
  211 +}
  1 +
  2 +package com.wd.capability.network.cookie;
  3 +
  4 +import java.util.List;
  5 +
  6 +import com.wd.capability.network.cookie.store.CookieStore;
  7 +
  8 +import okhttp3.Cookie;
  9 +import okhttp3.CookieJar;
  10 +import okhttp3.HttpUrl;
  11 +
  12 +/**
  13 + * @author wondertek
  14 + * @date 2020/5/13
  15 + */
  16 +public class CookieJarImpl implements CookieJar {
  17 +
  18 + private CookieStore cookieStore;
  19 +
  20 + public CookieJarImpl(CookieStore cookieStore) {
  21 + if (cookieStore == null) {
  22 + throw new IllegalArgumentException("cookieStore can not be null!");
  23 + }
  24 + this.cookieStore = cookieStore;
  25 + }
  26 +
  27 + @Override
  28 + public synchronized void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
  29 + cookieStore.saveCookie(url, cookies);
  30 + }
  31 +
  32 + @Override
  33 + public synchronized List<Cookie> loadForRequest(HttpUrl url) {
  34 + return cookieStore.loadCookie(url);
  35 + }
  36 +
  37 + public CookieStore getCookieStore() {
  38 + return cookieStore;
  39 + }
  40 +}
  1 +package com.wd.capability.network.cookie.store;
  2 +
  3 +import java.util.List;
  4 +
  5 +import okhttp3.Cookie;
  6 +import okhttp3.HttpUrl;
  7 +
  8 +/**
  9 + * @author wondertek
  10 + * @date 2020/5/13
  11 + */
  12 +public interface CookieStore {
  13 +
  14 + /**
  15 + * 保存url对应所有cookie
  16 + *
  17 + * @param url
  18 + * @param cookie
  19 + */
  20 + void saveCookie(HttpUrl url, List<Cookie> cookie);
  21 +
  22 + /**
  23 + * 保存url对应所有cookie
  24 + *
  25 + * @param url
  26 + * @param cookie
  27 + */
  28 + void saveCookie(HttpUrl url, Cookie cookie);
  29 +
  30 +
  31 + /**
  32 + * 加载url所有的cookie
  33 + *
  34 + * @param url
  35 + * @return
  36 + */
  37 + List<Cookie> loadCookie(HttpUrl url);
  38 +
  39 +
  40 + /**
  41 + * 获取当前所有保存的cookie
  42 + *
  43 + * @return
  44 + */
  45 + List<Cookie> getAllCookie();
  46 +
  47 +
  48 + /**
  49 + * 获取当前url对应的所有的cookie
  50 + *
  51 + * @param url
  52 + * @return
  53 + */
  54 + List<Cookie> getCookie(HttpUrl url);
  55 +
  56 +
  57 + /**
  58 + * 根据url和cookie移除对应的cookie
  59 + *
  60 + * @param url
  61 + * @param cookie
  62 + * @return
  63 + */
  64 + boolean removeCookie(HttpUrl url, Cookie cookie);
  65 +
  66 +
  67 + /**
  68 + * 根据url移除所有的cookie
  69 + *
  70 + * @param url
  71 + * @return
  72 + */
  73 + boolean removeCookie(HttpUrl url);
  74 +
  75 +
  76 + /**
  77 + * 移除所有的cookie
  78 + *
  79 + * @return
  80 + */
  81 + boolean removeAllCookie();
  82 +}
  1 +package com.wd.capability.network.cookie.store;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Set;
  7 +
  8 +import okhttp3.Cookie;
  9 +import okhttp3.HttpUrl;
  10 +
  11 +/**
  12 + *
  13 + * @author wondertek
  14 + * @date 2020/5/13
  15 + */
  16 +public class MemoryCookieStore implements CookieStore {
  17 +
  18 + private final HashMap<String, List<Cookie>> memoryCookies = new HashMap<>();
  19 +
  20 + @Override
  21 + public synchronized void saveCookie(HttpUrl url, List<Cookie> cookies) {
  22 + List<Cookie> oldCookies = memoryCookies.get(url.host());
  23 + List<Cookie> needRemove = new ArrayList<>();
  24 + for (Cookie newCookie : cookies) {
  25 + for (Cookie oldCookie : oldCookies) {
  26 + if (newCookie.name().equals(oldCookie.name())) {
  27 + needRemove.add(oldCookie);
  28 + }
  29 + }
  30 + }
  31 + oldCookies.removeAll(needRemove);
  32 + oldCookies.addAll(cookies);
  33 + }
  34 +
  35 + @Override
  36 + public synchronized void saveCookie(HttpUrl url, Cookie cookie) {
  37 + List<Cookie> cookies = memoryCookies.get(url.host());
  38 + List<Cookie> needRemove = new ArrayList<>();
  39 + for (Cookie item : cookies) {
  40 + if (cookie.name().equals(item.name())) {
  41 + needRemove.add(item);
  42 + }
  43 + }
  44 + cookies.removeAll(needRemove);
  45 + cookies.add(cookie);
  46 + }
  47 +
  48 + @Override
  49 + public synchronized List<Cookie> loadCookie(HttpUrl url) {
  50 + List<Cookie> cookies = memoryCookies.get(url.host());
  51 + if (cookies == null) {
  52 + cookies = new ArrayList<>();
  53 + memoryCookies.put(url.host(), cookies);
  54 + }
  55 + return cookies;
  56 + }
  57 +
  58 + @Override
  59 + public synchronized List<Cookie> getAllCookie() {
  60 + List<Cookie> cookies = new ArrayList<>();
  61 + Set<String> httpUrls = memoryCookies.keySet();
  62 + for (String url : httpUrls) {
  63 + cookies.addAll(memoryCookies.get(url));
  64 + }
  65 + return cookies;
  66 + }
  67 +
  68 + @Override
  69 + public List<Cookie> getCookie(HttpUrl url) {
  70 + List<Cookie> cookies = new ArrayList<>();
  71 + List<Cookie> urlCookies = memoryCookies.get(url.host());
  72 + if (urlCookies != null) {
  73 + cookies.addAll(urlCookies);
  74 + }
  75 + return cookies;
  76 + }
  77 +
  78 + @Override
  79 + public synchronized boolean removeCookie(HttpUrl url, Cookie cookie) {
  80 + List<Cookie> cookies = memoryCookies.get(url.host());
  81 + return (cookie != null) && cookies.remove(cookie);
  82 + }
  83 +
  84 + @Override
  85 + public synchronized boolean removeCookie(HttpUrl url) {
  86 + return memoryCookies.remove(url.host()) != null;
  87 + }
  88 +
  89 + @Override
  90 + public synchronized boolean removeAllCookie() {
  91 + memoryCookies.clear();
  92 + return true;
  93 + }
  94 +}
  1 +package com.wd.capability.network.cookie.store;
  2 +
  3 +import java.io.ByteArrayInputStream;
  4 +import java.io.ByteArrayOutputStream;
  5 +import java.io.IOException;
  6 +import java.io.ObjectInputStream;
  7 +import java.io.ObjectOutputStream;
  8 +import java.util.ArrayList;
  9 +import java.util.Collection;
  10 +import java.util.HashMap;
  11 +import java.util.List;
  12 +import java.util.Locale;
  13 +import java.util.Map;
  14 +import java.util.Set;
  15 +import java.util.concurrent.ConcurrentHashMap;
  16 +
  17 +import android.content.Context;
  18 +import android.content.SharedPreferences;
  19 +import android.os.SystemClock;
  20 +import android.text.TextUtils;
  21 +
  22 +
  23 +import com.wd.base.log.Logger;
  24 +
  25 +import okhttp3.Cookie;
  26 +import okhttp3.HttpUrl;
  27 +
  28 +/**
  29 + *
  30 + * @author wondertek
  31 + * @date 2017/5/13
  32 + */
  33 +public class PersistentCookieStore implements CookieStore {
  34 +
  35 + private static final String LOG_TAG = "PersistentCookieStore";
  36 + /**
  37 + * cookie使用prefs保存
  38 + */
  39 + private static final String COOKIE_PREFS = "wonder_cookie";
  40 + /**
  41 + * cookie持久化的统一前缀
  42 + */
  43 + private static final String COOKIE_NAME_PREFIX = "cookie_";
  44 +
  45 + private final HashMap<String, ConcurrentHashMap<String, Cookie>> cookies;
  46 + private final SharedPreferences cookiePrefs;
  47 +
  48 + public PersistentCookieStore(Context context) {
  49 + cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE);
  50 + cookies = new HashMap<>();
  51 +
  52 + //将持久化的cookies缓存到内存中,数据结构为 Map<Url.host, Map<Cookie.name, Cookie>>
  53 + Map<String, ?> prefsMap = cookiePrefs.getAll();
  54 + for (Map.Entry<String, ?> entry : prefsMap.entrySet()) {
  55 + if ((entry.getValue()) != null && !entry.getKey().startsWith(COOKIE_NAME_PREFIX)) {
  56 + //获取url对应的所有cookie的key,用","分割
  57 + String[] cookieNames = TextUtils.split((String) entry.getValue(), ",");
  58 + for (String name : cookieNames) {
  59 + //根据对应cookie的Key,从xml中获取cookie的真实值
  60 + String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
  61 + if (encodedCookie != null) {
  62 + Cookie decodedCookie = decodeCookie(encodedCookie);
  63 + if (decodedCookie != null) {
  64 + if (!cookies.containsKey(entry.getKey())) {
  65 + cookies.put(entry.getKey(), new ConcurrentHashMap<String, Cookie>());
  66 + }
  67 + cookies.get(entry.getKey()).put(name, decodedCookie);
  68 + }
  69 + }
  70 + }
  71 + }
  72 + }
  73 + }
  74 +
  75 + private String getCookieToken(Cookie cookie) {
  76 + return cookie.name() + "@" + cookie.domain();
  77 + }
  78 +
  79 + /** 当前cookie是否过期 */
  80 + private static boolean isCookieExpired(Cookie cookie) {
  81 + return cookie.expiresAt() < SystemClock.uptimeMillis();
  82 + }
  83 +
  84 + /** 根据当前url获取所有需要的cookie,只返回没有过期的cookie */
  85 + @Override
  86 + public List<Cookie> loadCookie(HttpUrl url) {
  87 + ArrayList<Cookie> ret = new ArrayList<>();
  88 + if (cookies.containsKey(url.host())) {
  89 + Collection<Cookie> urlCookies = cookies.get(url.host()).values();
  90 + for (Cookie cookie : urlCookies) {
  91 + if (isCookieExpired(cookie)) {
  92 + removeCookie(url, cookie);
  93 + } else {
  94 + ret.add(cookie);
  95 + }
  96 + }
  97 + }
  98 + return ret;
  99 + }
  100 +
  101 + /** 将url的所有Cookie保存在本地 */
  102 + @Override
  103 + public void saveCookie(HttpUrl url, List<Cookie> urlCookies) {
  104 + if (!cookies.containsKey(url.host())) {
  105 + cookies.put(url.host(), new ConcurrentHashMap<String, Cookie>(16));
  106 + }
  107 + for (Cookie cookie : urlCookies) {
  108 + //当前cookie是否过期
  109 + if (isCookieExpired(cookie)) {
  110 + removeCookie(url, cookie);
  111 + } else {
  112 + saveCookie(url, cookie, getCookieToken(cookie));
  113 + }
  114 + }
  115 + }
  116 +
  117 + @Override
  118 + public void saveCookie(HttpUrl url, Cookie cookie) {
  119 + if (!cookies.containsKey(url.host())) {
  120 + cookies.put(url.host(), new ConcurrentHashMap<String, Cookie>(16));
  121 + }
  122 + //当前cookie是否过期
  123 + if (isCookieExpired(cookie)) {
  124 + removeCookie(url, cookie);
  125 + } else {
  126 + saveCookie(url, cookie, getCookieToken(cookie));
  127 + }
  128 + }
  129 +
  130 + /**
  131 + * 保存cookie,并将cookies持久化到本地,数据结构为
  132 + * Url.host -> Cookie1.name,Cookie2.name,Cookie3.name
  133 + * cookie_Cookie1.name -> CookieString
  134 + * cookie_Cookie2.name -> CookieString
  135 + */
  136 + private void saveCookie(HttpUrl url, Cookie cookie, String name) {
  137 + //内存缓存
  138 + cookies.get(url.host()).put(name, cookie);
  139 + //文件缓存
  140 + SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
  141 + prefsWriter.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet()));
  142 + prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie)));
  143 + prefsWriter.apply();
  144 + }
  145 +
  146 + /** 根据url移除当前的cookie */
  147 + @Override
  148 + public boolean removeCookie(HttpUrl url, Cookie cookie) {
  149 + String name = getCookieToken(cookie);
  150 + if (cookies.containsKey(url.host()) && cookies.get(url.host()).containsKey(name)) {
  151 + //内存移除
  152 + cookies.get(url.host()).remove(name);
  153 + //文件移除
  154 + SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
  155 + if (cookiePrefs.contains(COOKIE_NAME_PREFIX + name)) {
  156 + prefsWriter.remove(COOKIE_NAME_PREFIX + name);
  157 + }
  158 + prefsWriter.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet()));
  159 + prefsWriter.apply();
  160 + return true;
  161 + } else {
  162 + return false;
  163 + }
  164 + }
  165 +
  166 + @Override
  167 + public boolean removeCookie(HttpUrl url) {
  168 + if (cookies.containsKey(url.host())) {
  169 + //文件移除
  170 + Set<String> cookieNames = cookies.get(url.host()).keySet();
  171 + SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
  172 + for (String cookieName : cookieNames) {
  173 + if (cookiePrefs.contains(COOKIE_NAME_PREFIX + cookieName)) {
  174 + prefsWriter.remove(COOKIE_NAME_PREFIX + cookieName);
  175 + }
  176 + }
  177 + prefsWriter.remove(url.host()).apply();
  178 + //内存移除
  179 + cookies.remove(url.host());
  180 + return true;
  181 + } else {
  182 + return false;
  183 + }
  184 + }
  185 +
  186 + @Override
  187 + public boolean removeAllCookie() {
  188 + SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
  189 + prefsWriter.clear().apply();
  190 + cookies.clear();
  191 + return true;
  192 + }
  193 +
  194 + /** 获取所有的cookie */
  195 + @Override
  196 + public List<Cookie> getAllCookie() {
  197 + List<Cookie> ret = new ArrayList<>();
  198 + for (String key : cookies.keySet()) {
  199 + ret.addAll(cookies.get(key).values());
  200 + }
  201 + return ret;
  202 + }
  203 +
  204 + @Override
  205 + public List<Cookie> getCookie(HttpUrl url) {
  206 + List<Cookie> ret = new ArrayList<>();
  207 + Map<String, Cookie> mapCookie = cookies.get(url.host());
  208 + if (mapCookie != null) {
  209 + ret.addAll(mapCookie.values());
  210 + }
  211 + return ret;
  212 + }
  213 +
  214 + /**
  215 + * cookies 序列化成 string
  216 + *
  217 + * @param cookie 要序列化的cookie
  218 + * @return 序列化之后的string
  219 + */
  220 + private String encodeCookie(SerializableHttpCookie cookie) {
  221 + if (cookie == null) {
  222 + return null;
  223 + }
  224 + ByteArrayOutputStream os = new ByteArrayOutputStream();
  225 + try {
  226 + ObjectOutputStream outputStream = new ObjectOutputStream(os);
  227 + outputStream.writeObject(cookie);
  228 + } catch (IOException e) {
  229 + Logger.t(LOG_TAG).d( "IOException in encodeCookie", e);
  230 + return null;
  231 + }
  232 + return byteArrayToHexString(os.toByteArray());
  233 + }
  234 +
  235 + /**
  236 + * 将字符串反序列化成cookies
  237 + *
  238 + * @param cookieString cookies string
  239 + * @return cookie object
  240 + */
  241 + private Cookie decodeCookie(String cookieString) {
  242 + byte[] bytes = hexStringToByteArray(cookieString);
  243 + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
  244 + Cookie cookie = null;
  245 + try {
  246 + ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
  247 + cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
  248 + } catch (IOException e) {
  249 + Logger.t(LOG_TAG).d( "IOException in decodeCookie", e);
  250 + } catch (ClassNotFoundException e) {
  251 + Logger.t(LOG_TAG).d( "ClassNotFoundException in decodeCookie", e);
  252 + }
  253 + return cookie;
  254 + }
  255 +
  256 + /**
  257 + * 二进制数组转十六进制字符串
  258 + *
  259 + * @param bytes byte array to be converted
  260 + * @return string containing hex values
  261 + */
  262 + private String byteArrayToHexString(byte[] bytes) {
  263 + StringBuilder sb = new StringBuilder(bytes.length * 2);
  264 + for (byte element : bytes) {
  265 + int v = element & 0xff;
  266 + if (v < 16) {
  267 + sb.append('0');
  268 + }
  269 + sb.append(Integer.toHexString(v));
  270 + }
  271 + return sb.toString().toUpperCase(Locale.US);
  272 + }
  273 +
  274 + /**
  275 + * 十六进制字符串转二进制数组
  276 + *
  277 + * @param hexString string of hex-encoded values
  278 + * @return decoded byte array
  279 + */
  280 + private byte[] hexStringToByteArray(String hexString) {
  281 + int len = hexString.length();
  282 + byte[] data = new byte[len / 2];
  283 + for (int i = 0; i < len; i += 2) {
  284 + data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16));
  285 + }
  286 + return data;
  287 + }
  288 +}
  1 +package com.wd.capability.network.cookie.store;
  2 +
  3 +import java.io.IOException;
  4 +import java.io.ObjectInputStream;
  5 +import java.io.ObjectOutputStream;
  6 +import java.io.Serializable;
  7 +
  8 +import okhttp3.Cookie;
  9 +
  10 +/**
  11 + * @author wondertek
  12 + */
  13 +public class SerializableHttpCookie implements Serializable {
  14 + private static final long serialVersionUID = 6374381323722046732L;
  15 +
  16 + private transient final Cookie cookie;
  17 + private transient Cookie clientCookie;
  18 +
  19 + public SerializableHttpCookie(Cookie cookie) {
  20 + this.cookie = cookie;
  21 + }
  22 +
  23 + public Cookie getCookie() {
  24 + Cookie bestCookie = cookie;
  25 + if (clientCookie != null) {
  26 + bestCookie = clientCookie;
  27 + }
  28 + return bestCookie;
  29 + }
  30 +
  31 + private void writeObject(ObjectOutputStream out) throws IOException {
  32 + out.writeObject(cookie.name());
  33 + out.writeObject(cookie.value());
  34 + out.writeLong(cookie.expiresAt());
  35 + out.writeObject(cookie.domain());
  36 + out.writeObject(cookie.path());
  37 + out.writeBoolean(cookie.secure());
  38 + out.writeBoolean(cookie.httpOnly());
  39 + out.writeBoolean(cookie.hostOnly());
  40 + out.writeBoolean(cookie.persistent());
  41 + }
  42 +
  43 + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  44 + String name = (String) in.readObject();
  45 + String value = (String) in.readObject();
  46 + long expiresAt = in.readLong();
  47 + String domain = (String) in.readObject();
  48 + String path = (String) in.readObject();
  49 + boolean secure = in.readBoolean();
  50 + boolean httpOnly = in.readBoolean();
  51 + boolean hostOnly = in.readBoolean();
  52 + boolean persistent = in.readBoolean();
  53 + Cookie.Builder builder = new Cookie.Builder();
  54 + builder = builder.name(name);
  55 + builder = builder.value(value);
  56 + builder = builder.expiresAt(expiresAt);
  57 + builder = hostOnly ? builder.hostOnlyDomain(domain) : builder.domain(domain);
  58 + builder = builder.path(path);
  59 + builder = secure ? builder.secure() : builder;
  60 + builder = httpOnly ? builder.httpOnly() : builder;
  61 + clientCookie = builder.build();
  62 + }
  63 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +import java.net.URLEncoder;
  6 +import java.util.Map;
  7 +import java.util.Set;
  8 +import java.util.concurrent.ConcurrentHashMap;
  9 +
  10 +import android.content.Context;
  11 +import android.os.SystemClock;
  12 +import android.text.TextUtils;
  13 +
  14 +import com.wd.capability.network.NetManager;
  15 +import com.wd.capability.network.NetworkUtils;
  16 +import com.wd.capability.network.constant.NetConstant;
  17 +import com.wd.capability.network.constant.ParameterConstant;
  18 +import com.wd.foundation.wdinterface.ILoginService;
  19 +import com.wd.foundation.wdinterface.IProvinceService;
  20 +import com.wd.foundation.wdinterface.app.IAppInfoService;
  21 +import com.wd.foundation.wdkitcore.router.ArouterServiceManager;
  22 +
  23 +import okhttp3.Interceptor;
  24 +import okhttp3.Request;
  25 +import okhttp3.Response;
  26 +
  27 +/**
  28 + * @author wondertek
  29 + * @date 2021/3/5
  30 + */
  31 +public class BaseInterceptor implements Interceptor {
  32 + private final ConcurrentHashMap<String, String> headers = new ConcurrentHashMap<String, String>();
  33 +
  34 + private Context context;
  35 +
  36 + public BaseInterceptor(Context mContext) {
  37 + this.context = mContext;
  38 + headers.clear();
  39 + }
  40 +
  41 + @Override
  42 + public Response intercept(Chain chain) throws IOException {
  43 + Request.Builder builder = chain.request().newBuilder();
  44 + headers.put(ParameterConstant.CONTENTTYPE, ParameterConstant.HEADER_JSON_TYPE);
  45 + IAppInfoService appInfoService = ArouterServiceManager.provide(IAppInfoService.class);
  46 + headers.put(ParameterConstant.PLAT, appInfoService.getPlat());
  47 + headers.put(ParameterConstant.TIMESTAMP, SystemClock.uptimeMillis() + "");
  48 + headers.put(ParameterConstant.SYSTEM, appInfoService.getSystem());
  49 + headers.put(ParameterConstant.IMEI, appInfoService.getDeviceId());
  50 + headers.put(ParameterConstant.DEVICE_ID, appInfoService.getDeviceId());
  51 +
  52 + headers.put(ParameterConstant.VERSIONCODE, appInfoService.getVersionCode());
  53 + headers.put(ParameterConstant.VERSIONNAME, appInfoService.getVersionName());
  54 + headers.put(ParameterConstant.BUILDVERSION, appInfoService.getBuildVersion());
  55 + headers.put(ParameterConstant.USERAGENT, System.getProperty("http.agent"));
  56 + /**
  57 + * 客户端日志链路追踪traceid生成:在每个请求头加上参数Key:EagleEye-TraceID ,value为32位生成随机值
  58 + */
  59 + headers.put(ParameterConstant.EagleEyeTraceID, NetworkUtils.getRandomUUIDForTraceID());
  60 +
  61 + try {
  62 + // 获取手机系统版本号
  63 + headers.put(ParameterConstant.OS_VERSION, appInfoService.getOsVersion());
  64 + IProvinceService provinceService = ArouterServiceManager.provide(IProvinceService.class);
  65 + String city = provinceService.getCityName();
  66 + String districtCode = provinceService.getProvinceCode();
  67 + String cityCode = provinceService.getCityId();
  68 + if (!TextUtils.isEmpty(city)) {
  69 + headers.put(ParameterConstant.CITY, URLEncoder.encode(city, "UTF-8"));
  70 + }
  71 + if (!TextUtils.isEmpty(districtCode)) {
  72 + headers.put(ParameterConstant.AD_CODE, URLEncoder.encode(districtCode, "UTF-8"));
  73 + }
  74 + if (!TextUtils.isEmpty(cityCode)) {
  75 + headers.put(ParameterConstant.CITY_CODE, URLEncoder.encode(cityCode, "UTF-8"));
  76 + }
  77 +
  78 + } catch (Exception e) {
  79 +
  80 + }
  81 + ILoginService loginService = ArouterServiceManager.provide(ILoginService.class);
  82 + String token = loginService.getUserToken();
  83 + if (!TextUtils.isEmpty(token)) {
  84 + headers.put(ParameterConstant.RMRB_X_TOKEN, token);
  85 + headers.put(ParameterConstant.USER_TYPE, loginService.getUserType() + "");
  86 + headers.put(ParameterConstant.COOKIE, "RMRB-X-TOKEN=" + token);
  87 + } else {
  88 + headers.put(ParameterConstant.RMRB_X_TOKEN, "");
  89 + headers.remove(ParameterConstant.USER_TYPE);
  90 + headers.put(ParameterConstant.COOKIE, "");
  91 + }
  92 +
  93 + String userId = loginService.getUserId();
  94 + if (!TextUtils.isEmpty(userId)) {
  95 + headers.put(ParameterConstant.USER_ID, userId);
  96 + } else {
  97 + headers.remove(ParameterConstant.USER_ID);
  98 + }
  99 +
  100 + // 添加测试头作为测试
  101 + String tag = NetManager.getUrlTag();
  102 + if (NetManager.BASE_URL_SIT.equals(tag)) {
  103 + // sit环境
  104 + headers.put("X-Ca-Stage", "TEST");
  105 + headers.put("Authorization", NetConstant.APPCODE_SIT);
  106 + headers.put("appCode", NetConstant.APPCODE_VALUE_SIT);
  107 + } else if (NetManager.BASE_URL_UAT.equals(tag)) {
  108 + // uat环境
  109 + headers.put("X-Ca-Stage", "PRE");
  110 + headers.put("Authorization", NetConstant.APPCODE_UTA);
  111 + headers.put("appCode", NetConstant.APPCODE_VALUE_UTA);
  112 + } else if (NetManager.BASE_URL_DEV.equals(tag)) {
  113 + // dev环境
  114 + headers.put("X-Ca-Stage", "TEST");
  115 + headers.put("Authorization", NetConstant.APPCODE_DEV);
  116 + headers.put("appCode", NetConstant.APPCODE_VALUE_DEV);
  117 + } else {
  118 + // 正式环境
  119 + headers.put("X-Ca-Stage", "RELEASE");
  120 + headers.put("Authorization", NetConstant.APPCODE_RELEASE);
  121 + headers.put("appCode", NetConstant.APPCODE_VALUE_RELEASE);
  122 + }
  123 +
  124 + // 渠道号
  125 + headers.put(ParameterConstant.CHANNEL, appInfoService.getChannelCode());
  126 +
  127 + // 英文端新增-语言国际化
  128 + headers.put(ParameterConstant.ACCEPT_LANGUAGE, "zh");
  129 +
  130 + Map<String, String> headerParameter = NetManager.getNetManager().getHeaderParameter();
  131 + if (headerParameter != null && headerParameter.size() > 0) {
  132 + headers.putAll(headerParameter);
  133 + }
  134 + Set<String> keys = headers.keySet();
  135 + for (String headerKey : keys) {
  136 + builder.addHeader(headerKey, TextUtils.isEmpty(headers.get(headerKey)) ? "" : headers.get(headerKey))
  137 + .build();
  138 + }
  139 +
  140 + return chain.proceed(builder.build());
  141 + }
  142 +
  143 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +
  6 +import android.content.Context;
  7 +
  8 +import com.wd.capability.network.NetManager;
  9 +import com.wd.capability.network.NetworkUtils;
  10 +
  11 +import okhttp3.CacheControl;
  12 +import okhttp3.Interceptor;
  13 +import okhttp3.Request;
  14 +import okhttp3.Response;
  15 +
  16 +/**
  17 + * @author wondertek
  18 + * @date 2021/3/5
  19 + * 无网络状态下智能读取缓存的拦截器
  20 + */
  21 +public class CacheInterceptor implements Interceptor {
  22 +
  23 + private Context context;
  24 +
  25 + public CacheInterceptor(Context context) {
  26 + this.context = context;
  27 + }
  28 +
  29 + @Override
  30 + public Response intercept(Chain chain) throws IOException {
  31 + Request request = chain.request();
  32 + if (NetworkUtils.isNetAvailable()) {
  33 + Response response = chain.proceed(request);
  34 + // read from cache for 60 s
  35 + int maxAge = 10;
  36 + return response.newBuilder()
  37 + .removeHeader("Pragma")
  38 + .removeHeader("Cache-Control")
  39 + .header("Cache-Control", "public, max-age=" + maxAge)
  40 + .build();
  41 + } else {
  42 + // 读取缓存信息
  43 + request = request.newBuilder().cacheControl(CacheControl.FORCE_CACHE).build();
  44 + Response response = chain.proceed(request);
  45 + // set cache times is 3 days
  46 + long maxStale = NetManager.getNetManager().builder.getCacheTime();
  47 + return response.newBuilder()
  48 + .removeHeader("Pragma")
  49 + .removeHeader("Cache-Control")
  50 + .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
  51 + .build();
  52 + }
  53 + }
  54 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.BufferedReader;
  5 +import java.io.ByteArrayOutputStream;
  6 +import java.io.IOException;
  7 +import java.io.InputStream;
  8 +import java.io.InputStreamReader;
  9 +import java.io.Reader;
  10 +import java.nio.charset.Charset;
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +
  14 +import org.json.JSONObject;
  15 +
  16 +import android.text.TextUtils;
  17 +
  18 +import io.reactivex.annotations.NonNull;
  19 +import okhttp3.FormBody;
  20 +import okhttp3.Headers;
  21 +import okhttp3.Interceptor;
  22 +import okhttp3.MediaType;
  23 +import okhttp3.MultipartBody;
  24 +import okhttp3.Request;
  25 +import okhttp3.RequestBody;
  26 +import okhttp3.Response;
  27 +import okhttp3.ResponseBody;
  28 +import okio.Buffer;
  29 +
  30 +/**
  31 + * @author wondertek
  32 + * @date 2021/3/5
  33 + * 网络请求拦截器
  34 + */
  35 +public class CommonParamInterceptor implements Interceptor {
  36 +
  37 + private static Map<String, String> commonParams;
  38 +
  39 + public synchronized static void setCommonParam(Map<String, String> commonParams) {
  40 + if (commonParams != null) {
  41 + if (CommonParamInterceptor.commonParams != null) {
  42 + CommonParamInterceptor.commonParams.clear();
  43 + } else {
  44 + CommonParamInterceptor.commonParams = new HashMap<>(16);
  45 + }
  46 + for (String paramKey : commonParams.keySet()) {
  47 + CommonParamInterceptor.commonParams.put(paramKey, commonParams.get(paramKey));
  48 + }
  49 + }
  50 + }
  51 +
  52 + public synchronized static void updateOrInsertCommonParam(@NonNull String paramKey, @NonNull String paramValue) {
  53 + if (commonParams == null) {
  54 + commonParams = new HashMap<>(16);
  55 + }
  56 + commonParams.put(paramKey, paramValue);
  57 + }
  58 +
  59 + @Override
  60 + public synchronized Response intercept(Chain chain) throws IOException {
  61 + Request request = rebuildRequest(chain.request());
  62 + Response response = chain.proceed(request);
  63 + // 输出返回结果
  64 + BufferedReader reader = null;
  65 + Reader jsonReader = null;
  66 + try {
  67 + Charset charset;
  68 + charset = Charset.forName("UTF-8");
  69 + ResponseBody responseBody = response.peekBody(Long.MAX_VALUE);
  70 + jsonReader = new InputStreamReader(responseBody.byteStream(), charset);
  71 + reader = new BufferedReader(jsonReader);
  72 + StringBuilder sbJson = new StringBuilder();
  73 + String line = reader.readLine();
  74 + do {
  75 + sbJson.append(line);
  76 + line = reader.readLine();
  77 + } while (line != null);
  78 + } catch (Exception e) {
  79 + e.printStackTrace();
  80 + } finally {
  81 + reader.close();
  82 + jsonReader.close();
  83 + }
  84 + return response;
  85 + }
  86 +
  87 + public static byte[] toByteArray(RequestBody body) throws IOException {
  88 + Buffer buffer = new Buffer();
  89 + body.writeTo(buffer);
  90 + InputStream inputStream = buffer.inputStream();
  91 + ByteArrayOutputStream output = new ByteArrayOutputStream();
  92 + byte[] bufferWrite = new byte[4096];
  93 + int n;
  94 + while (-1 != (n = inputStream.read(bufferWrite))) {
  95 + output.write(bufferWrite, 0, n);
  96 + }
  97 + return output.toByteArray();
  98 + }
  99 +
  100 + private Request rebuildRequest(Request request) throws IOException {
  101 + Request newRequest;
  102 + if ("POST".equals(request.method())) {
  103 + newRequest = rebuildPostRequest(request);
  104 + } else if ("GET".equals(request.method())) {
  105 + newRequest = rebuildGetRequest(request);
  106 + } else {
  107 + newRequest = request;
  108 + }
  109 + return newRequest;
  110 + }
  111 +
  112 + /**
  113 + * 对post请求添加统一参数
  114 + */
  115 + private Request rebuildPostRequest(Request request) {
  116 + // if (commonParams == null || commonParams.size() == 0) {
  117 + // return request;
  118 + // }
  119 + Map<String, String> signParams = new HashMap<>(16);
  120 + RequestBody originalRequestBody = request.body();
  121 + assert originalRequestBody != null;
  122 + RequestBody newRequestBody;
  123 + if (originalRequestBody instanceof FormBody) {
  124 + FormBody.Builder builder = new FormBody.Builder();
  125 + FormBody requestBody = (FormBody) request.body();
  126 + int fieldSize = requestBody == null ? 0 : requestBody.size();
  127 + for (int i = 0; i < fieldSize; i++) {
  128 + builder.add(requestBody.name(i), requestBody.value(i));
  129 + signParams.put(requestBody.name(i), requestBody.value(i));
  130 + }
  131 + if (commonParams != null && commonParams.size() > 0) {
  132 + signParams.putAll(commonParams);
  133 + for (String paramKey : commonParams.keySet()) {
  134 + builder.add(paramKey, commonParams.get(paramKey));
  135 + }
  136 + }
  137 + // ToDo 此处可对参数做签名处理 signParams
  138 + /**
  139 + * String sign = SignUtil.sign(signParams);
  140 + * builder.add("sign", sign);
  141 + */
  142 + newRequestBody = builder.build();
  143 + } else if (originalRequestBody instanceof MultipartBody) {
  144 + MultipartBody requestBody = (MultipartBody) request.body();
  145 + MultipartBody.Builder multipartBodybuilder = new MultipartBody.Builder();
  146 + if (requestBody != null) {
  147 + for (int i = 0; i < requestBody.size(); i++) {
  148 + MultipartBody.Part part = requestBody.part(i);
  149 + multipartBodybuilder.addPart(part);
  150 + MediaType mediaType = part.body().contentType();
  151 + if (mediaType == null) {
  152 + String normalParamKey;
  153 + String normalParamValue;
  154 + try {
  155 + normalParamValue = getParamContent(requestBody.part(i).body());
  156 + Headers headers = part.headers();
  157 + if (!TextUtils.isEmpty(normalParamValue) && headers != null) {
  158 + for (String name : headers.names()) {
  159 + String headerContent = headers.get(name);
  160 + if (!TextUtils.isEmpty(headerContent)) {
  161 + String[] normalParamKeyContainer = headerContent.split("name=\"");
  162 + if (normalParamKeyContainer.length == 2) {
  163 + normalParamKey = normalParamKeyContainer[1].split("\"")[0];
  164 + signParams.put(normalParamKey, normalParamValue);
  165 + break;
  166 + }
  167 + }
  168 + }
  169 + }
  170 + } catch (Exception e) {
  171 + e.printStackTrace();
  172 + }
  173 + }
  174 + }
  175 + }
  176 + if (commonParams != null && commonParams.size() > 0) {
  177 + signParams.putAll(commonParams);
  178 + for (String paramKey : commonParams.keySet()) {
  179 + // 两种方式添加公共参数
  180 + // method 1
  181 + multipartBodybuilder.addFormDataPart(paramKey, commonParams.get(paramKey));
  182 + // method 2
  183 + // MultipartBody.Part part = MultipartBody.Part.createFormData(paramKey,
  184 + // commonParams.get(paramKey));
  185 + // multipartBodybuilder.addPart(part);
  186 + }
  187 + }
  188 + // ToDo 此处可对参数做签名处理 signParams
  189 + /**
  190 + * String sign = SignUtil.sign(signParams);
  191 + * multipartBodybuilder.addFormDataPart("sign", sign);
  192 + */
  193 + newRequestBody = multipartBodybuilder.build();
  194 + } else {
  195 + try {
  196 + JSONObject jsonObject;
  197 + if (originalRequestBody.contentLength() == 0) {
  198 + jsonObject = new JSONObject();
  199 + } else {
  200 + jsonObject = new JSONObject(getParamContent(originalRequestBody));
  201 + }
  202 + if (commonParams != null && commonParams.size() > 0) {
  203 + for (String commonParamKey : commonParams.keySet()) {
  204 + jsonObject.put(commonParamKey, commonParams.get(commonParamKey));
  205 + }
  206 + }
  207 + // ToDo 此处可对参数做签名处理
  208 + /**
  209 + * String sign = SignUtil.sign(signParams);
  210 + * jsonObject.put("sign", sign);
  211 + */
  212 + newRequestBody = RequestBody.Companion.create(jsonObject.toString(), originalRequestBody.contentType());
  213 +
  214 + } catch (Exception e) {
  215 + newRequestBody = originalRequestBody;
  216 + e.printStackTrace();
  217 + }
  218 + }
  219 + return request.newBuilder().method(request.method(), newRequestBody).build();
  220 + }
  221 +
  222 + /**
  223 + * 获取常规post请求参数
  224 + */
  225 + private String getParamContent(RequestBody body) throws IOException {
  226 + Buffer buffer = new Buffer();
  227 + body.writeTo(buffer);
  228 + return buffer.readUtf8();
  229 + }
  230 +
  231 + /**
  232 + * 对get请求做统一参数处理
  233 + */
  234 + private Request rebuildGetRequest(Request request) {
  235 + if (commonParams == null || commonParams.size() == 0) {
  236 + return request;
  237 + }
  238 + String url = request.url().toString();
  239 + int separatorIndex = url.lastIndexOf("?");
  240 + StringBuilder sb = new StringBuilder(url);
  241 + if (separatorIndex == -1) {
  242 + sb.append("?");
  243 + }
  244 + for (String commonParamKey : commonParams.keySet()) {
  245 + sb.append("&").append(commonParamKey).append("=").append(commonParams.get(commonParamKey));
  246 + }
  247 + Request.Builder requestBuilder = request.newBuilder();
  248 + return requestBuilder.url(sb.toString()).build();
  249 + }
  250 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +
  6 +import com.wd.base.log.Logger;
  7 +
  8 +import okhttp3.Interceptor;
  9 +import okhttp3.Request;
  10 +import okhttp3.Response;
  11 +import okhttp3.ResponseBody;
  12 +
  13 +/**
  14 + * @author qts
  15 + */
  16 +public class LoggingInterceptor implements Interceptor {
  17 +
  18 + public static final String LOG_TAG = "LoggingInterceptor";
  19 +
  20 + @Override
  21 + public Response intercept(Chain chain) throws IOException {
  22 + // Chain 里包含了request和response
  23 + Request request = chain.request();
  24 + long t1 = System.nanoTime();
  25 + String format = String.format("发送请求:[%s] %n---headers---%n%s", request.url(), request.headers());
  26 + Logger.t(LOG_TAG).d(format);
  27 + Response response = chain.proceed(request);
  28 + long t2 = System.nanoTime();
  29 + ResponseBody responseBody = response.peekBody(1024 * 1024);
  30 + String format1 = String.format("接收响应:[%s] %n---返回data---%s 耗时:%.1fms", response.request().url(),
  31 + responseBody.string(), (t2 - t1) / 1e6d);
  32 + Logger.t(LOG_TAG).d(format1);
  33 + return response;
  34 + }
  35 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +import java.util.List;
  6 +
  7 +import com.wd.base.log.Logger;
  8 +import com.wd.capability.network.NetManager;
  9 +
  10 +import io.reactivex.annotations.NonNull;
  11 +import okhttp3.HttpUrl;
  12 +import okhttp3.Interceptor;
  13 +import okhttp3.Request;
  14 +import okhttp3.Response;
  15 +
  16 +/**
  17 + * 多域名拦截
  18 + * 通过header参数urlname 判断是否走统一域名
  19 + * 如果
  20 + */
  21 +public class MultiDomainInterceptor implements Interceptor {
  22 +
  23 + @NonNull
  24 + @Override
  25 + public Response intercept(@NonNull Chain chain) throws IOException {
  26 + // 获取原始的originalRequest
  27 + Request originalRequest = chain.request();
  28 + // 获取老的url
  29 + HttpUrl oldUrl = originalRequest.url();
  30 + // 获取originalRequest的创建者builder
  31 + Request.Builder builder = originalRequest.newBuilder();
  32 + // 获取头信息的集合如:manage,mdffx
  33 + List<String> urlnameList = originalRequest.headers("urlname");
  34 + if (urlnameList != null && urlnameList.size() > 0) {
  35 + // 删除原有配置中的值,就是namesAndValues集合里的值
  36 + builder.removeHeader("urlname");
  37 + // 获取头信息中配置的value,如:manage或者mdffx
  38 + String urlname = urlnameList.get(0);
  39 + HttpUrl baseURL = null;
  40 + baseURL = HttpUrl.parse(urlname);
  41 + // 重建新的HttpUrl,需要重新设置的url部分
  42 + HttpUrl newHttpUrl = oldUrl.newBuilder()
  43 + .scheme(baseURL.scheme())// http协议如:http或者https
  44 + .host(baseURL.host())// 主机地址
  45 + .port(baseURL.port())// 端口
  46 + .build();
  47 + Logger.t("MultiDomainInterceptor").d(baseURL.scheme() + "//" + baseURL.host() + "//" + baseURL.port());
  48 + // 获取处理后的新newRequest
  49 + Request newRequest = builder.url(newHttpUrl).build();
  50 + return chain.proceed(newRequest);
  51 + } else {
  52 + String baseUrl = "";
  53 + String tag = NetManager.getUrlTag();
  54 + if (NetManager.BASE_URL_SIT.equals(tag)) {
  55 + baseUrl = NetManager.baseUrlSit;
  56 + } else if (NetManager.BASE_URL_UAT.equals(tag)) {
  57 + baseUrl = NetManager.baseUrlUat;
  58 + } else if (NetManager.BASE_URL_DEV.equals(tag)) {
  59 + baseUrl = NetManager.baseUrlDev;
  60 + } else {
  61 + baseUrl = NetManager.baseUrlRel;
  62 + }
  63 +
  64 + HttpUrl baseURL = HttpUrl.parse(baseUrl);
  65 + // 重建新的HttpUrl,需要重新设置的url部分
  66 + HttpUrl newHttpUrl = oldUrl.newBuilder()
  67 + .scheme(baseURL.scheme())// http协议如:http或者https
  68 + .host(baseURL.host())// 主机地址
  69 + .port(baseURL.port())// 端口
  70 + .build();
  71 + Logger.t("MultiDomainInterceptor").d(baseURL.scheme() + "//" + baseURL.host() + "//" + baseURL.port());
  72 + // 获取处理后的新newRequest
  73 + Request newRequest = builder.url(newHttpUrl).build();
  74 +
  75 + return chain.proceed(newRequest);
  76 + }
  77 + }
  78 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +
  6 +import org.jetbrains.annotations.NotNull;
  7 +
  8 +import android.content.Context;
  9 +
  10 +import okhttp3.Interceptor;
  11 +import okhttp3.Response;
  12 +
  13 +/**
  14 + * 描述:
  15 + *
  16 + * @author : lvjinhui
  17 + * @since: 2022/10/19
  18 + */
  19 +public class NetCacheInterceptor implements Interceptor {
  20 + private Context context;
  21 +
  22 + public NetCacheInterceptor(Context context) {
  23 + this.context = context;
  24 + }
  25 +
  26 + @Override
  27 + public @NotNull Response intercept(@NotNull Chain chain) throws IOException {
  28 + Response response = chain.proceed(chain.request());
  29 + // read from cache for 60 s
  30 + int maxAge = 10;
  31 + return response.newBuilder()
  32 + .removeHeader("Pragma")
  33 + .removeHeader("Cache-Control")
  34 + .header("Cache-Control", "public, max-age=" + maxAge)
  35 + .build();
  36 + }
  37 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +import java.net.ConnectException;
  6 +import java.net.SocketTimeoutException;
  7 +
  8 +import android.text.TextUtils;
  9 +
  10 +import com.wd.base.log.Logger;
  11 +import com.wd.capability.network.constant.ParameterConstant;
  12 +
  13 +import okhttp3.HttpUrl;
  14 +import okhttp3.Interceptor;
  15 +import okhttp3.MediaType;
  16 +import okhttp3.Protocol;
  17 +import okhttp3.Request;
  18 +import okhttp3.Response;
  19 +import okhttp3.ResponseBody;
  20 +
  21 +/** 灾备地址切换 */
  22 +public class RetryCdnInterceptor implements Interceptor {
  23 +
  24 + private static final String TAG = "Interceptor";
  25 +
  26 + private int maxRetry;// 最大重试次数
  27 +
  28 + private int retryNum = 0;// 假如设置为3次重试的话,则最大可能请求4次(默认1次+3次重试)
  29 +
  30 + private int CONNECT_RETRY_TIMES = 2;
  31 +
  32 + private String SERVER_URL2;
  33 +
  34 + private int SERVER_URL2_PORT;
  35 +
  36 + public RetryCdnInterceptor() {
  37 + Logger.t(TAG).d("构造函数" + retryNum);
  38 + maxRetry = CONNECT_RETRY_TIMES;
  39 + }
  40 +
  41 + @Override
  42 + public Response intercept(Chain chain) throws IOException {
  43 + return proceMark(chain, chain.request());
  44 + }
  45 +
  46 + private Response proceMark(Chain chain, Request mrequest) {
  47 + Request request;
  48 + if (mrequest == null) {
  49 + request = chain.request();
  50 + } else {
  51 + request = mrequest;
  52 + }
  53 +
  54 + Response response = null;
  55 + int responseCode = 0;
  56 + String msg = "";
  57 + int code = 0;
  58 + try {
  59 + response = chain.proceed(request);
  60 + Logger.t(TAG)
  61 + .d("intercept:" + response.isSuccessful() + "//" + response.message() + "//" + response.code() + "//"
  62 + + retryNum);
  63 + if (!response.isSuccessful() && (response.code() >= 400 && response.code() < 600)) {
  64 + if (TextUtils.equals(request.url().host(), SERVER_URL2) && request.url().port() == SERVER_URL2_PORT) {
  65 + // todo 备用地址重试
  66 + while (!response.isSuccessful() && (response.code() > 400 && response.code() < 600)
  67 + && retryNum < maxRetry) {
  68 + Logger.t(TAG).d("备用地址404 重试" + retryNum);
  69 + retryNum++;
  70 + response = chain.proceed(request);
  71 + }
  72 + } else {
  73 + Request.Builder builder = request.newBuilder();
  74 + // ALog.e( request.method());
  75 + HttpUrl oldHttpUrl = request.url();
  76 + HttpUrl newFullUrl = oldHttpUrl.newBuilder()
  77 + .scheme(oldHttpUrl.scheme())
  78 + .host(SERVER_URL2)
  79 + .port(SERVER_URL2_PORT)
  80 + .build();
  81 + Logger.t(TAG).d("RetryInterceptor: " + "主地址404异常 调用备用地址" + newFullUrl.host());
  82 + // response= chain.proceed(builder.url(newFullUrl).build());
  83 + return proceMark(chain, builder.url(newFullUrl).build());
  84 + }
  85 +
  86 + responseCode = response.code();
  87 + msg = response.message();
  88 + }
  89 + } catch (SocketTimeoutException timeoutException) {
  90 + Logger.t(TAG).d("SocketTimeoutException" + request.url() + "//" + timeoutException.toString());
  91 + msg = timeoutException.toString();
  92 + code = 408;
  93 + } catch (ConnectException connectException) {
  94 + msg = connectException.toString();
  95 + Logger.t(TAG).d("ConnectException" + request.url() + "//" + connectException.toString());
  96 + } catch (IllegalArgumentException argumentException) {
  97 + msg = argumentException.toString();
  98 + Logger.t(TAG).d("IllegalArgumentException" + request.url() + "//" + argumentException.toString());
  99 + } catch (Exception error) {
  100 + msg = error.toString();
  101 + Logger.t(TAG).d("ExceptionInterceptor" + request.url() + "//" + error.toString());
  102 +
  103 + }
  104 + Logger.t(TAG).d("接口状态重试 : " + retryNum);
  105 + if (retryNum >= maxRetry) {
  106 + Response.Builder responseBuilder = new Response.Builder().code(responseCode)
  107 + .message(msg)
  108 + .request(chain.request())
  109 + .protocol(Protocol.HTTP_1_0)
  110 + .addHeader("content-type", ParameterConstant.HEADER_JSON_TYPE);
  111 + // String responseString = """{"error":This error is generated by ExceptionInterceptor
  112 + // [${status.second}]}""";
  113 + Logger.t(TAG).d("结束重试 : " + retryNum);
  114 + retryNum = 0;
  115 + String responseString = "{}";
  116 + responseBuilder
  117 + .body(ResponseBody.create(MediaType.parse(ParameterConstant.HEADER_JSON_TYPE), responseString));// 将数据设置到body中
  118 + return responseBuilder.build();// builder模式构建response
  119 + }
  120 +
  121 + if (code == 408) {
  122 + // todo 是否是备用地址
  123 + Request request2 = chain.request();
  124 + Logger.t(TAG).d("超时408::::" + request2.url().port());
  125 + if (TextUtils.equals(request.url().host(), SERVER_URL2) && request.url().port() == SERVER_URL2_PORT) {
  126 + retryNum++;
  127 + Logger.t(TAG)
  128 + .d("RetryInterceptor: " + "主地址超时异常 调用备用地址超时 " + request.url().host() + ":"
  129 + + request.url().port());
  130 + Request.Builder builder = request.newBuilder();
  131 + // ALog.e( request.method());
  132 + HttpUrl oldHttpUrl = request.url();
  133 + HttpUrl newFullUrl = oldHttpUrl.newBuilder()
  134 + .scheme(oldHttpUrl.scheme())
  135 + .host(SERVER_URL2)
  136 + .port(SERVER_URL2_PORT)
  137 + .build();
  138 + return proceMark(chain, builder.url(newFullUrl).build());
  139 + } else {
  140 + Request.Builder builder = request.newBuilder();
  141 + // ALog.e( request.method());
  142 + HttpUrl oldHttpUrl = request.url();
  143 + HttpUrl newFullUrl = oldHttpUrl.newBuilder()
  144 + .scheme(oldHttpUrl.scheme())
  145 + .host(SERVER_URL2)
  146 + .port(SERVER_URL2_PORT)
  147 + .build();
  148 + Logger.t(TAG).d("RetryInterceptor: " + "主地址超时异常 调用备用地址" + newFullUrl.host());
  149 + return proceMark(chain, builder.url(newFullUrl).build());
  150 + }
  151 + }
  152 +
  153 + retryNum = 0;
  154 + return response;
  155 + }
  156 +
  157 +}
  1 +
  2 +package com.wd.capability.network.interceptor;
  3 +
  4 +import java.io.IOException;
  5 +import java.util.HashMap;
  6 +
  7 +import org.jetbrains.annotations.NotNull;
  8 +
  9 +import android.content.Context;
  10 +import android.os.Handler;
  11 +import android.os.Looper;
  12 +import android.os.Message;
  13 +import android.text.TextUtils;
  14 +
  15 +import androidx.annotation.NonNull;
  16 +
  17 +import com.wd.base.log.Logger;
  18 +import com.wd.capability.network.RetrofitClient;
  19 +import com.wd.capability.network.api.IRefreshToken;
  20 +import com.wd.capability.network.bean.NetworkEventConstants;
  21 +import com.wd.capability.network.bean.TokenBean;
  22 +import com.wd.capability.network.constant.ParameterConstant;
  23 +import com.wd.capability.network.response.BaseResponse;
  24 +import com.wd.foundation.wdinterface.app.IAppInfoService;
  25 +import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
  26 +import com.wd.foundation.wdkitcore.router.ArouterServiceManager;
  27 +import com.wd.foundation.wdkitcore.tools.JsonUtils;
  28 +import com.wd.foundation.wdkitcore.tools.SpUtils;
  29 +
  30 +import okhttp3.Interceptor;
  31 +import okhttp3.MediaType;
  32 +import okhttp3.Request;
  33 +import okhttp3.RequestBody;
  34 +import okhttp3.Response;
  35 +import retrofit2.Call;
  36 +
  37 +/**
  38 + * 描述:jwtToken 失效
  39 + *
  40 + * @author : lvjinhui
  41 + * @since: 2022/7/18
  42 + */
  43 +public class TokenInterceptor implements Interceptor {
  44 +
  45 + /**
  46 + * 临时token
  47 + */
  48 + private static final int TOKEN_ERROR = 403;
  49 +
  50 + /**
  51 + * 强制下线、封禁、清空登录信息还要跳转登录页面
  52 + */
  53 + private static final int TOKEN_LOSE = 406;
  54 +
  55 + /**
  56 + * refreshToken 失效
  57 + */
  58 + private static final int REFRESH_TOKEN_ERROR = 377;
  59 +
  60 + // 流量过大
  61 + public static final int FLOW_TOOBIG = 429;
  62 +
  63 + private Context mContext;
  64 +
  65 + // 是否流量超标
  66 + private boolean is_flow_big = false;
  67 +
  68 + public TokenInterceptor(Context context) {
  69 + mContext = context;
  70 + }
  71 +
  72 + @Override
  73 + public @NotNull Response intercept(@NotNull Chain chain) throws IOException {
  74 +
  75 + Request originalRequest = chain.request();
  76 + Response response = chain.proceed(originalRequest);
  77 + try {
  78 + int requestCode = response.code();
  79 + // 流量超标
  80 + if (requestCode == FLOW_TOOBIG) {
  81 + handler.sendEmptyMessageDelayed(1, 500);
  82 + }
  83 +
  84 + if (requestCode == TOKEN_LOSE) {
  85 + SpUtils.saveHttp406(true);
  86 + }
  87 +
  88 + if (requestCode == TOKEN_ERROR || requestCode == TOKEN_LOSE) {
  89 +
  90 + String newToken = getNewToken(requestCode);
  91 + // 使用新的Token,创建新的请求
  92 + Request newRequest = chain.request()
  93 + .newBuilder()
  94 + .header(ParameterConstant.RMRB_X_TOKEN, newToken)
  95 + .header(ParameterConstant.COOKIE, "RMRB-X-TOKEN=" + newToken)
  96 + .build();
  97 + // 重新请求
  98 + return chain.proceed(newRequest);
  99 + }
  100 + } catch (Exception e) {
  101 + e.printStackTrace();
  102 + }
  103 +
  104 + return response;
  105 + }
  106 +
  107 + private Handler handler = new Handler(Looper.getMainLooper()) {
  108 + @Override
  109 + public void handleMessage(@NonNull Message msg) {
  110 + super.handleMessage(msg);
  111 + is_flow_big = true;
  112 + LiveDataBus.getInstance().with(NetworkEventConstants.FLOW_TOO_LARGE).postValue(true);
  113 + }
  114 + };
  115 +
  116 + /**
  117 + * 同步请求方式,根据RefreshToken获取最新的Token
  118 + *
  119 + * @return
  120 + */
  121 + private synchronized String getNewToken(int code) throws IOException {
  122 + // 通过一个特定的接口获取新的token,此处要用到同步的retrofit请求
  123 + String newToken = "";
  124 + String paramsRefresh = "";
  125 + IAppInfoService appInfoService = ArouterServiceManager.provide(IAppInfoService.class);
  126 + String deviceId = appInfoService == null ? "" : appInfoService.getDeviceId();
  127 +
  128 + if (!TextUtils.isEmpty(SpUtils.getRefreshToken())) {
  129 + paramsRefresh = SpUtils.getRefreshToken();
  130 + }
  131 + IRefreshToken apiService = RetrofitClient.getInstance().create(IRefreshToken.class);
  132 + HashMap<String, Object> map = new HashMap<>();
  133 + map.put(ParameterConstant.REFRESH_TOKEN, paramsRefresh);
  134 + map.put(ParameterConstant.DEVICEID, deviceId);
  135 + Call<BaseResponse<TokenBean>> call = apiService.getJwtToken(SpUtils.getUserToken(), getBody(map));
  136 + BaseResponse<TokenBean> responseBean = call.execute().body();
  137 + if (responseBean != null) {
  138 + if (REFRESH_TOKEN_ERROR == responseBean.getCode()) {
  139 + SpUtils.saveHttp377(true);
  140 + LiveDataBus.getInstance().with(NetworkEventConstants.FORCE_USER_LOGIN_OUT).postValue(true);
  141 + } else if (0 == responseBean.getCode()) {
  142 + TokenBean tokenBean = responseBean.getData();
  143 + if (tokenBean != null) {
  144 + // 获取新的token成功
  145 + newToken = tokenBean.getJwtToken();
  146 + SpUtils.saveUserToken(newToken);
  147 + String refreshToken = tokenBean.getRefreshToken();
  148 + SpUtils.saveRefreshToken(refreshToken);
  149 + }
  150 + }
  151 +
  152 + }
  153 + return newToken;
  154 + }
  155 +
  156 + private RequestBody getBody(HashMap<String, Object> map) {
  157 + String requestJson = JsonUtils.convertObjectToJson(map);
  158 + Logger.t(LoggingInterceptor.LOG_TAG).d("---request data---" + requestJson);
  159 + RequestBody requestBody = RequestBody.create(MediaType.parse(ParameterConstant.HEADER_JSON_TYPE), requestJson);
  160 + return requestBody;
  161 + }
  162 +
  163 +}
  1 +
  2 +package com.wd.capability.network.onekeylogin;
  3 +
  4 +import com.wd.capability.network.bean.FetchAccessTokenBean;
  5 +import com.wd.capability.network.response.BaseResponse;
  6 +
  7 +import okhttp3.RequestBody;
  8 +import retrofit2.Call;
  9 +import retrofit2.http.Body;
  10 +import retrofit2.http.POST;
  11 +
  12 +/**
  13 + * 描述:使用refreshToken 请求 jwtToken
  14 + *
  15 + * @author : lvjinhui
  16 + * @since: 2022/7/15
  17 + */
  18 +public interface IOneKeyLogin {
  19 +
  20 + /**
  21 + * 获取应用授权Token
  22 + */
  23 + @POST("api/rmrb-user-center/auth/zh/c/fetchAccessToken")
  24 + Call<BaseResponse<FetchAccessTokenBean>> fetchAccessToken(@Body RequestBody body);
  25 +}
  1 +
  2 +package com.wd.capability.network.refreshtoken;
  3 +
  4 +import com.wd.capability.network.bean.TokenBean;
  5 +
  6 +/**
  7 + * 描述:提供给js 刷新token
  8 + *
  9 + * @author : lvjinhui
  10 + * @since: 2022/12/7
  11 + */
  12 +public interface IRefreshTokenForJsCallBack {
  13 +
  14 + /**
  15 + * 成功
  16 + *
  17 + * @param tokenBean
  18 + */
  19 + void onSuccess(TokenBean tokenBean);
  20 +
  21 + /**
  22 + * 提供给js 刷新token
  23 + *
  24 + * @param code
  25 + * @param message
  26 + */
  27 + void onFailed(int code, String message);
  28 +}
  1 +
  2 +package com.wd.capability.network.response;
  3 +
  4 +import com.wd.capability.network.bean.MetaBean;
  5 +
  6 +/**
  7 + * @author wondertek
  8 + * @date 2021/3/5
  9 + * 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
  10 + */
  11 +public class BaseResponse<T> {
  12 + private String code;
  13 +
  14 + private String message;
  15 +
  16 + private T data;
  17 +
  18 + private long timestamp;
  19 +
  20 + private String transNo;
  21 +
  22 + private boolean success;
  23 +
  24 + private MetaBean meta;
  25 +
  26 + public int getCode() {
  27 + try {
  28 + return Integer.parseInt(code);
  29 + } catch (Exception e) {
  30 + e.printStackTrace();
  31 + return -1;
  32 + }
  33 + }
  34 +
  35 + public void setCode(String code) {
  36 + this.code = code;
  37 + }
  38 +
  39 + public String getMessage() {
  40 + return message;
  41 + }
  42 +
  43 + public void setMessage(String message) {
  44 + this.message = message;
  45 + }
  46 +
  47 + public T getData() {
  48 + return data;
  49 + }
  50 +
  51 + public void setData(T data) {
  52 + this.data = data;
  53 + }
  54 +
  55 + public long getTimestamp() {
  56 +
  57 + return timestamp;
  58 + }
  59 +
  60 + public void setTimestamp(long timestamp) {
  61 + this.timestamp = timestamp;
  62 + }
  63 +
  64 + public String getTransNo() {
  65 + return transNo;
  66 + }
  67 +
  68 + public void setTransNo(String transNo) {
  69 + this.transNo = transNo;
  70 + }
  71 +
  72 + public boolean isSuccess() {
  73 + return success;
  74 + }
  75 +
  76 + public void setSuccess(boolean success) {
  77 + this.success = success;
  78 + }
  79 +
  80 + public MetaBean getMeta() {
  81 + return meta;
  82 + }
  83 +
  84 + public void setMeta(MetaBean meta) {
  85 + this.meta = meta;
  86 + }
  87 +
  88 + public String getMd5() {
  89 + if (meta != null) {
  90 + return meta.getMd5();
  91 + }
  92 + return "";
  93 + }
  94 +}
  1 +
  2 +package com.wd.capability.network.response;
  3 +
  4 +import java.net.ConnectException;
  5 +import java.net.UnknownHostException;
  6 +
  7 +import org.json.JSONException;
  8 +
  9 +import android.net.ParseException;
  10 +
  11 +import com.google.gson.JsonParseException;
  12 +import com.wd.capability.network.R;
  13 +import com.wd.foundation.wdkitcore.tools.ResUtils;
  14 +
  15 +import retrofit2.HttpException;
  16 +
  17 +/**
  18 + * @author wondertek
  19 + * @date 2021/3/6
  20 + */
  21 +public class ExceptionHandle {
  22 +
  23 + /**
  24 + * 对应HTTP的状态码
  25 + */
  26 + private static final int UNAUTHORIZED = 401;
  27 +
  28 + private static final int FORBIDDEN = 403;
  29 +
  30 + private static final int NOT_FOUND = 404;
  31 +
  32 + private static final int REQUEST_TIMEOUT = 408;
  33 +
  34 + private static final int INTERNAL_SERVER_ERROR = 500;
  35 +
  36 + private static final int BAD_GATEWAY = 502;
  37 +
  38 + private static final int SERVICE_UNAVAILABLE = 503;
  39 +
  40 + private static final int GATEWAY_TIMEOUT = 504;
  41 +
  42 + /**
  43 + * 二级页面错误提示
  44 + */
  45 + public static final String NET_ERROR_TIPS_IN_PAGE = ResUtils.getString(R.string.tips_check_network);
  46 +
  47 + /**
  48 + * 接口500 情况弹出这个
  49 + */
  50 + public static final String NET_ERROR_500 = ResUtils.getString(R.string.default_get_content_failed);
  51 +
  52 + public static ResponseException handleException(Throwable e) {
  53 + ResponseException ex;
  54 + if (e instanceof HttpException) {
  55 + HttpException httpException = (HttpException) e;
  56 + ex = new ResponseException(e, Error.HTTP_ERROR);
  57 + switch (httpException.code()) {
  58 + case INTERNAL_SERVER_ERROR:
  59 + ex.message = NET_ERROR_500;
  60 + break;
  61 + case UNAUTHORIZED:
  62 + case FORBIDDEN:
  63 + case NOT_FOUND:
  64 + case REQUEST_TIMEOUT:
  65 + case GATEWAY_TIMEOUT:
  66 + case BAD_GATEWAY:
  67 + case SERVICE_UNAVAILABLE:
  68 + default:
  69 + ex.message = NET_ERROR_TIPS_IN_PAGE;
  70 + break;
  71 + }
  72 + return ex;
  73 + } else if (e instanceof ServerException) {
  74 + ServerException resultException = (ServerException) e;
  75 + ex = new ResponseException(resultException, resultException.code);
  76 + ex.message = resultException.message;
  77 + return ex;
  78 + } else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) {
  79 + ex = new ResponseException(e, Error.PARSE_ERROR);
  80 + ex.message = "ParseException";
  81 + return ex;
  82 + } else if (e instanceof ConnectException) {
  83 + ex = new ResponseException(e, Error.NETWORK_ERROR);
  84 + ex.message = "ConnectException";
  85 + return ex;
  86 + } else if (e instanceof UnknownHostException) {
  87 + ex = new ResponseException(e, Error.NETWORK_ERROR);
  88 + ex.message = NET_ERROR_TIPS_IN_PAGE;
  89 + return ex;
  90 + } else {
  91 + ex = new ResponseException(e, Error.UNKNOWN);
  92 + ex.message = NET_ERROR_TIPS_IN_PAGE;
  93 + return ex;
  94 + }
  95 + }
  96 +
  97 + /**
  98 + * 约定异常 这个具体规则需要与服务端或者领导商讨定义
  99 + */
  100 + public static class Error {
  101 + /**
  102 + * 未知错误
  103 + */
  104 + public static final int UNKNOWN = 1000;
  105 +
  106 + /**
  107 + * 解析错误
  108 + */
  109 + public static final int PARSE_ERROR = 1001;
  110 +
  111 + /**
  112 + * 网络错误
  113 + */
  114 + public static final int NETWORK_ERROR = 1002;
  115 +
  116 + /**
  117 + * 协议出错
  118 + */
  119 + public static final int HTTP_ERROR = 1003;
  120 + }
  121 +
  122 + /**
  123 + * 服务器异常
  124 + */
  125 + public class ServerException extends RuntimeException {
  126 + public int code;
  127 +
  128 + public String message;
  129 + }
  130 +
  131 + public static boolean showErrorTips(ResponseException exception) {
  132 +
  133 + if (exception != null && NET_ERROR_TIPS_IN_PAGE.equals(exception.message)) {
  134 + return true;
  135 + }
  136 + return false;
  137 + }
  138 +}
  1 +package com.wd.capability.network.response;
  2 +
  3 +/**
  4 + *
  5 + * @author wondertek
  6 + * @date 2021/3/6
  7 + */
  8 +
  9 +public class ResponseException extends Exception {
  10 + public int code;
  11 + public String message;
  12 +
  13 + public ResponseException(Throwable throwable, int code) {
  14 + super(throwable);
  15 + this.code = code;
  16 + }
  17 +}
  1 +
  2 +package com.wd.capability.network.utils;
  3 +
  4 +/**
  5 + * 描述:对暗号,切换环境
  6 + *
  7 + * @author : lvjinhui
  8 + * @since: 2022/7/27
  9 + */
  10 +public class HostUtil {
  11 +
  12 + public static long serverTime = 0;
  13 +
  14 +}
  1 +/**
  2 + * class name :JsonUtils
  3 + * class description:
  4 + * Copyright:BesTV. All Rights Reserved.
  5 + * creator:xu.chaokun
  6 + * create time:2013-8-16 上午11:20:27
  7 + */
  8 +
  9 +package com.wd.capability.network.utils;
  10 +
  11 +import java.lang.reflect.Field;
  12 +import java.lang.reflect.Method;
  13 +import java.lang.reflect.Type;
  14 +import java.util.List;
  15 +
  16 +import org.json.JSONArray;
  17 +import org.json.JSONObject;
  18 +
  19 +import com.google.gson.Gson;
  20 +import com.google.gson.GsonBuilder;
  21 +import com.google.gson.JsonArray;
  22 +import com.google.gson.JsonElement;
  23 +import com.google.gson.internal.Primitives;
  24 +import com.google.gson.reflect.TypeToken;
  25 +
  26 +/**
  27 + * @author qts
  28 + */
  29 +class JsonUtils {
  30 + private static final String TAG = "JsonUtils";
  31 +
  32 + private final static String SET_HEAD = "set";
  33 + // private static final String SDF = "yyyy-MM-dd HH:mm:ss";
  34 +
  35 + private static Gson createGson() {
  36 + Gson gson = new GsonBuilder().create();
  37 + return gson;
  38 + }
  39 +
  40 + private static String firstUpperCase(String arg) {
  41 + return Character.toUpperCase(arg.charAt(0)) + arg.substring(1);
  42 + }
  43 +
  44 + public static void attributeCopy(JSONObject jsonObject, Object desc) {
  45 + Class descClass = desc.getClass();
  46 + Field[] descFields = descClass.getDeclaredFields();
  47 + if (null != descFields) {
  48 + for (Field field : descFields) {
  49 + String name = firstUpperCase(field.getName());
  50 + Object value = jsonObject.opt(name);
  51 + try {
  52 + if (null != value) {
  53 + Method setMethod = descClass.getDeclaredMethod(SET_HEAD + name, new Class[] {field.getType()});
  54 + setMethod.invoke(desc, value);
  55 + }
  56 + } catch (Exception e) {
  57 + e.printStackTrace();
  58 + }
  59 + }
  60 + }
  61 + }
  62 +
  63 + public static <T> T objFromJson(String json, Class<T> classOfT, String dateFormat) {
  64 + Gson gson = new GsonBuilder().setDateFormat(dateFormat).create();
  65 + Object ret = gson.fromJson(json, classOfT);
  66 + return Primitives.wrap(classOfT).cast(ret);
  67 + }
  68 +
  69 + public static <T> T objFromJson(JSONObject json, Class<T> classOfT) {
  70 + return objFromJson(json.toString(), classOfT);
  71 + }
  72 +
  73 + public static <T> T objFromJson(String json, Class<T> classOfT) {
  74 + Object ret = null;
  75 + Gson gson = createGson();
  76 + ret = gson.fromJson(json, classOfT);
  77 + return Primitives.wrap(classOfT).cast(ret);
  78 + }
  79 +
  80 + public static Object objFromJson(JSONObject json, Type type) {
  81 + return objFromJson(json.toString(), type);
  82 + }
  83 +
  84 + public static <T> String objToJsonArray(List<T> jsonArrayList) {
  85 + Gson gson = createGson();
  86 + JsonElement element = gson.toJsonTree(jsonArrayList, new TypeToken<List<T>>() {}.getType());
  87 +
  88 + if (!element.isJsonArray()) {
  89 + throw new TypeNotPresentException("JsonArray", null);
  90 + }
  91 +
  92 + JsonArray jsonArray = element.getAsJsonArray();
  93 + return jsonArray.toString();
  94 + }
  95 +
  96 + public static Object objFromJson(String json, Type type) {
  97 + Object ret = null;
  98 + Gson gson = createGson();
  99 + ret = gson.fromJson(json, type);
  100 + return ret;
  101 + }
  102 +
  103 + public static String objToJson(Object obj) {
  104 + Gson gson = createGson();
  105 + String ret = gson.toJson(obj);
  106 + return ret;
  107 + }
  108 +
  109 + public static String getJsonString(JSONObject obj, String key, String defValue) {
  110 + String ret = defValue;
  111 + try {
  112 + ret = obj.getString(key);
  113 + } catch (Throwable e) {
  114 + e.printStackTrace();
  115 + }
  116 +
  117 + return ret;
  118 + }
  119 +
  120 + public static JSONObject getJsonObjectSafty(JSONObject src, String objStr) {
  121 + JSONObject ret = null;
  122 + try {
  123 + ret = src.getJSONObject(objStr);
  124 + } catch (Throwable e) {
  125 + e.printStackTrace();
  126 + }
  127 + return ret;
  128 + }
  129 +
  130 + public static JSONArray getJsonArraySafty(JSONObject src, String objStr) {
  131 + JSONArray ret = null;
  132 +
  133 + try {
  134 + ret = src.getJSONArray(objStr);
  135 + } catch (Throwable e) {
  136 + e.printStackTrace();
  137 + }
  138 + return ret;
  139 + }
  140 +
  141 + public static int getJsonInt(JSONObject obj, String key, int defValue) {
  142 + int ret = defValue;
  143 + try {
  144 + ret = obj.getInt(key);
  145 + } catch (Throwable e) {
  146 + e.printStackTrace();
  147 + }
  148 +
  149 + return ret;
  150 + }
  151 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <!--全域异常场景-->
  4 + <!--网络出小差了,请检查网络后重试-->
  5 + <string name="tips_check_network">网络出小差了,请检查网络后重试!</string>
  6 + <!--内容获取失败,用于内容详情页(带重试按钮)-->
  7 + <string name="default_get_content_failed">内容获取失败,请稍后重试</string>
  8 +
  9 + <string name="network_request_failed" formatted="false">网络请求失败,请稍后重试。错误码[%d] %s</string>
  10 +</resources>