forked from miaoMiaoDaShi/YangYanNew
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc0ed53
commit 357761c
Showing
50 changed files
with
364 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/com/yangyan/xxp/yangyannew/app/GlobalHttpHandlerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2017 JessYan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yangyan.xxp.yangyannew.app | ||
|
||
import android.content.Context | ||
import android.text.TextUtils | ||
import com.google.gson.Gson | ||
|
||
import com.google.gson.reflect.TypeToken | ||
import com.jess.arms.http.GlobalHttpHandler | ||
import com.jess.arms.http.log.RequestInterceptor | ||
import okhttp3.HttpUrl | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import timber.log.Timber | ||
|
||
/** | ||
* ================================================ | ||
* 展示 [GlobalHttpHandler] 的用法 | ||
* | ||
* | ||
* Created by JessYan on 04/09/2017 17:06 | ||
* [Contact me](mailto:[email protected]) | ||
* [Follow me](https://github.com/JessYanCoding) | ||
* ================================================ | ||
*/ | ||
class GlobalHttpHandlerImpl(private val context: Context) : GlobalHttpHandler { | ||
|
||
/** | ||
* 用户信息 | ||
*/ | ||
private val mUserInfoString by Preference("userInfo", "") | ||
|
||
/** | ||
* 这里可以先客户端一步拿到每一次 Http 请求的结果, 可以先解析成 Json, 再做一些操作, 如检测到 token 过期后 | ||
* 重新请求 token, 并重新执行请求 | ||
* | ||
* @param httpResult 服务器返回的结果 (已被框架自动转换为字符串) | ||
* @param chain [Interceptor.Chain] | ||
* @param response [Response] | ||
* @return | ||
*/ | ||
override fun onHttpResultResponse(httpResult: String?, chain: Interceptor.Chain, response: Response): Response { | ||
if (!TextUtils.isEmpty(httpResult) && RequestInterceptor.isJson(response.body()!!.contentType())) { | ||
|
||
} | ||
|
||
/* 这里如果发现 token 过期, 可以先请求最新的 token, 然后在拿新的 token 放入 Request 里去重新请求 | ||
注意在这个回调之前已经调用过 proceed(), 所以这里必须自己去建立网络请求, 如使用 Okhttp 使用新的 Request 去请求 | ||
create a new request and modify it accordingly using the new token | ||
Request newRequest = chain.request().newBuilder().header("token", newToken) | ||
.build(); | ||
retry the request | ||
response.body().close(); | ||
如果使用 Okhttp 将新的请求, 请求成功后, 再将 Okhttp 返回的 Response return 出去即可 | ||
如果不需要返回新的结果, 则直接把参数 response 返回出去即可 */ | ||
return response | ||
} | ||
|
||
/** | ||
* 这里可以在请求服务器之前拿到 [Request], 做一些操作比如给 [Request] 统一添加 token 或者 header 以及参数加密等操作 | ||
* | ||
* @param chain [Interceptor.Chain] | ||
* @param request [Request] | ||
* @return | ||
*/ | ||
override fun onHttpRequestBefore(chain: Interceptor.Chain, request: Request): Request { | ||
/* 如果需要再请求服务器之前做一些操作, 则重新返回一个做过操作的的 Request 如增加 Header, 不做操作则直接返回参数 request | ||
return chain.request().newBuilder().header("token", tokenId) | ||
.build(); */ | ||
|
||
|
||
return if (request.url().host().equals(HttpUrl.get(Constant.API_HOST).host())) request.newBuilder() | ||
.header("Referer", "https://app.mmzztt.com") | ||
.build() | ||
else request | ||
|
||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/yangyan/xxp/yangyannew/app/SSLSocketClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.yangyan.xxp.yangyannew.app; | ||
|
||
import java.security.SecureRandom; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
import javax.net.ssl.HostnameVerifier; | ||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLSession; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
/** | ||
* Author : zhongwenpeng | ||
* Email : [email protected] | ||
* Time : 2018/2/26 | ||
* Description : | ||
*/ | ||
|
||
public class SSLSocketClient { | ||
|
||
//获取这个SSLSocketFactory | ||
public static javax.net.ssl.SSLSocketFactory getSSLSocketFactory() { | ||
try { | ||
SSLContext sslContext = SSLContext.getInstance("SSL"); | ||
sslContext.init(null, getTrustManagers(), new SecureRandom()); | ||
return sslContext.getSocketFactory(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
//获取TrustManager | ||
private static TrustManager[] getTrustManagers() { | ||
TrustManager[] trustAllCerts = new TrustManager[]{getTrustManager()}; | ||
return trustAllCerts; | ||
} | ||
|
||
//获取HostnameVerifier | ||
public static HostnameVerifier getHostnameVerifier() { | ||
HostnameVerifier hostnameVerifier = new HostnameVerifier() { | ||
@Override | ||
public boolean verify(String s, SSLSession sslSession) { | ||
return true; | ||
} | ||
}; | ||
return hostnameVerifier; | ||
} | ||
|
||
public static X509TrustManager getTrustManager(){ | ||
return new MyTrustManager(); | ||
} | ||
|
||
private static final class MyTrustManager implements X509TrustManager { | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
|
||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
|
||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return new X509Certificate[0]; | ||
} | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
app/src/main/java/com/yangyan/xxp/yangyannew/di/component/FavoriteComponent.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/com/yangyan/xxp/yangyannew/di/module/CategoryChildModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
app/src/main/java/com/yangyan/xxp/yangyannew/di/module/CategoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
app/src/main/java/com/yangyan/xxp/yangyannew/di/module/FavoriteModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
app/src/main/java/com/yangyan/xxp/yangyannew/di/module/HomeModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
app/src/main/java/com/yangyan/xxp/yangyannew/glide/PerloadModelProvider.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.