mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-04 06:00:11 +00:00
优化:发送通道Bark
/Gotify
支持HTTP基本认证 【格式:http://username:password@domain.com/uri】 #170
This commit is contained in:
parent
ad65e094b7
commit
271fa6a102
@ -41,8 +41,17 @@ class BarkUtils {
|
||||
val requestUrl: String = setting.server //推送地址
|
||||
Log.i(TAG, "requestUrl:$requestUrl")
|
||||
|
||||
val request = XHttp.post(requestUrl)
|
||||
.params("title", title)
|
||||
//支持HTTP基本认证(Basic Authentication)
|
||||
val regex = "^(https?://)([^:]+):([^@]+)@(.+)"
|
||||
val matches = Regex(regex, RegexOption.IGNORE_CASE).findAll(requestUrl).toList().flatMap(MatchResult::groupValues)
|
||||
Log.i(TAG, "matches = $matches")
|
||||
val request = if (matches.isNotEmpty()) {
|
||||
XHttp.post(matches[1] + matches[4]).addInterceptor(BasicAuthInterceptor(matches[2], matches[3]))
|
||||
} else {
|
||||
XHttp.post(requestUrl)
|
||||
}
|
||||
|
||||
request.params("title", title)
|
||||
.params("body", content)
|
||||
.params("isArchive", 1)
|
||||
if (!TextUtils.isEmpty(setting.group)) request.params("group", setting.group)
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.idormy.sms.forwarder.utils.sender
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
|
||||
class BasicAuthInterceptor(user: String, password: String) : Interceptor {
|
||||
|
||||
private val credentials: String
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request: Request = chain.request()
|
||||
val authenticatedRequest: Request = request.newBuilder()
|
||||
.header("Authorization", credentials).build()
|
||||
return chain.proceed(authenticatedRequest)
|
||||
}
|
||||
|
||||
init {
|
||||
credentials = Credentials.basic(user, password)
|
||||
}
|
||||
}
|
@ -39,8 +39,17 @@ class GotifyUtils {
|
||||
val requestUrl: String = setting.webServer //推送地址
|
||||
Log.i(TAG, "requestUrl:$requestUrl")
|
||||
|
||||
XHttp.post(requestUrl)
|
||||
.params("title", title)
|
||||
//支持HTTP基本认证(Basic Authentication)
|
||||
val regex = "^(https?://)([^:]+):([^@]+)@(.+)"
|
||||
val matches = Regex(regex, RegexOption.IGNORE_CASE).findAll(requestUrl).toList().flatMap(MatchResult::groupValues)
|
||||
Log.i(TAG, "matches = $matches")
|
||||
val request = if (matches.isNotEmpty()) {
|
||||
XHttp.post(matches[1] + matches[4]).addInterceptor(BasicAuthInterceptor(matches[2], matches[3]))
|
||||
} else {
|
||||
XHttp.post(requestUrl)
|
||||
}
|
||||
|
||||
request.params("title", title)
|
||||
.params("message", content)
|
||||
.params("priority", setting.priority)
|
||||
.keepJson(true)
|
||||
|
Loading…
Reference in New Issue
Block a user