时区从网页获取

This commit is contained in:
Administrator 2025-07-10 10:50:27 +08:00
parent 024a1db06c
commit 4e090aca7e
5 changed files with 39 additions and 10 deletions

View File

@ -31,7 +31,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import com.example.retention.R;
import com.example.studyapp.autoJS.AutoJsUtil;
import com.example.studyapp.device.ChangeDeviceInfoUtil;

View File

@ -45,7 +45,9 @@ class ScriptJobService : JobIntentService() {
// ClashUtil.startProxy(applicationContext)
ClashUtil.switchProxyWithPort(CountryCode.switchCountry())
// ClashUtil.switchProxyGroup("PROXY", "my-socks5-proxy", "http://127.0.0.1:6170")
changeDevice(packageName, bigoDevice, afDevice, object : ChangeCallBack {
val geoInfo: String = IpUtil.fetchGeoInfo()
val timeZone: String = IpUtil.getTimeZone(geoInfo)
changeDevice(packageName, bigoDevice, afDevice, timeZone, object : ChangeCallBack {
override fun changeSuccess() {
runCatching {
AutoJsUtil.runAutojsScript(applicationContext)

View File

@ -13,6 +13,7 @@ import com.example.studyapp.proxy.ClashUtil
import com.example.studyapp.update.ChangeCallBack
import com.example.studyapp.update.UpdateUtil.changeDevice
import com.example.studyapp.utils.CountryCode
import com.example.studyapp.utils.IpUtil
import com.example.studyapp.utils.LogFileUtil
import com.example.studyapp.utils.ShellUtils
import org.json.JSONObject
@ -53,11 +54,13 @@ class StartJobService : JobIntentService() {
bigoDevice: JSONObject?,
afDevice: JSONObject?
) {
ClashUtil.startProxy(applicationContext)
// ClashUtil.startProxy(applicationContext)
// ClashUtil.switchProxyGroup("PROXY", "DIRECT", "http://127.0.0.1:6170")
ClashUtil.switchProxyWithPort(CountryCode.switchCountry())
// ClashUtil.switchProxyGroup("PROXY", "my-socks5-proxy", "http://127.0.0.1:6170")
changeDevice(packageName, bigoDevice, afDevice, object : ChangeCallBack {
val geoInfo: String = IpUtil.fetchGeoInfo()
val timeZone: String = IpUtil.getTimeZone(geoInfo)
changeDevice(packageName, bigoDevice, afDevice,timeZone, object : ChangeCallBack {
override fun changeSuccess() {
AutoJsUtil.runAutojsScript(applicationContext)
setRunning(false)

View File

@ -15,8 +15,14 @@ import org.json.JSONException
import org.json.JSONObject
object UpdateUtil {
val scope = CoroutineScope(Dispatchers.IO)
fun changeDevice(recordPackageName: String, bigoDeviceObject:JSONObject?, afDeviceObject:JSONObject?, callback: ChangeCallBack){
val scope = CoroutineScope(Dispatchers.IO)
fun changeDevice(
recordPackageName: String,
bigoDeviceObject: JSONObject?,
afDeviceObject: JSONObject?,
time: String,
callback: ChangeCallBack
) {
try {
val padCode = ShellUtils.execRootCmdAndGetResult("getprop ro.boot.pad_code")
Log.d("TAG", "changeDevice: $padCode")
@ -134,7 +140,9 @@ object UpdateUtil {
val date1 = afDeviceObject.optString(".date1", "")
val date2 = afDeviceObject.optString(".date2", "")
val bootId = afDeviceObject.optString("BootId", "")
if (time.isNotEmpty()){
timeZone = time
}
val afDevice = AfInfo()
afDevice.advertiserId = advertiserId
afDevice.model = model
@ -279,16 +287,19 @@ object UpdateUtil {
val jsonString = jsonObject.toString()
val response = Api.updatePad(jsonString)
val dataList = response.data
if (response.isSuccess() && dataList!= null && dataList.isNotEmpty()){
if (response.isSuccess() && dataList != null && dataList.isNotEmpty()) {
val padTask = dataList[0]
scope.launch {
Log.d("TAG", "changeDevice: $padTask")
var loop = true
var loop = true
while (loop) {
delay(5000)
val result = Api.padTaskDetail(padTask.taskId)
if (result == 3) {
Log.d("ChangeDeviceInfoUtil", "changeDeviceInfo changeDeviceInfo success")
Log.d(
"ChangeDeviceInfoUtil",
"changeDeviceInfo changeDeviceInfo success"
)
loop = false
callback.changeSuccess()
} else if (result == -1) {

View File

@ -81,6 +81,20 @@ public class IpUtil {
}
}
public static String getTimeZone(String geoInfo)
{
try {
if (!TextUtils.isEmpty(geoInfo))
{
JSONObject json = new JSONObject(geoInfo);
return json.optString("timezone", "");
}
} catch (Exception e) {
LogFileUtil.logAndWrite(Log.ERROR, "IpUtil", "getTimeZone: JSON error", e);
}
return "";
}
public static String checkClientIp(String excludeCountry)
{
try {