add 昊华外网查询

master
wanghao 2 months ago
parent 511212d59f
commit e0b6e04e55

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="com.codeverse.userSettings.MarscodeWorkspaceAppSettingsState">
<option name="ckgOperationStatus" value="SUCCESS" />
<option name="progress" value="0.90625" />
</component>
</project>

@ -21,6 +21,11 @@
android:name=".SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" />
<activity android:name=".IntentSelectActivity"
android:theme="@style/traceActivityStyle"
android:exported="false"/>
<activity
android:name=".ShuangqianActivity2"
android:theme="@style/traceActivityStyle"

@ -24,6 +24,7 @@ public class HomeActivity extends BaseActivity {
RadioButton button2 = this.findViewById(R.id.home_2);
RadioButton button1_1 = this.findViewById(R.id.home_1_1);
RadioButton button4 = this.findViewById(R.id.home_4);
RadioButton button3 = this.findViewById(R.id.home_3);
Intent intent = new Intent(this, ShuangqianActivity.class);
button1.setOnClickListener(v -> {
intent.putExtra("type",true);
@ -40,6 +41,12 @@ public class HomeActivity extends BaseActivity {
button4.setOnClickListener(v -> {
startActivity(new Intent(this, SettingsActivity.class));
});
button3.setOnClickListener(v -> {
startActivity(new Intent(this, IntentSelectActivity.class));
});
}
@Override

@ -0,0 +1,230 @@
package com.example.writeepc;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.databinding.DataBindingUtil;
import com.example.writeepc.adapter.MyMesInfoAdapter;
import com.example.writeepc.base.BaseActivity;
import com.example.writeepc.base.okgo.MyRecultCall;
import com.example.writeepc.base.okgo.MyResult;
import com.example.writeepc.been.MESInfo;
import com.example.writeepc.databinding.ActivityIntentSelectBinding;
import com.example.writeepc.utils.SharedPreferencesUtils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.uhf.api.cls.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.MediaType;
import okhttp3.RequestBody;
public class IntentSelectActivity extends BaseActivity {
private final Handler handler = new Handler();
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private ActivityIntentSelectBinding binding;
private MyMesInfoAdapter adapter;
private Button traceSanButton;
private boolean sanState = true;
private Runnable runnable;
private Runnable tokenRunnable;
private MyKeyReceiver keyReceiver;
private String ip;
private String token;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_intent_select);
initUHFRManager1();
// 设置功率
String powerTrace1 = SharedPreferencesUtils.getstring("powerTrace", "22");
int powerTrace = Integer.parseInt(powerTrace1);
Reader.READER_ERR readerErr = uhfrManager.setPower(powerTrace, powerTrace);
Log.e("TAG", "追溯设置功率" + powerTrace1 + ":" + readerErr.name());
initDialog();
adapter = new MyMesInfoAdapter(this);
binding.setAdapter(adapter);
traceSanButton = binding.traceSanButton;
runnable = () -> {
if (sanState) {
handler.removeCallbacks(runnable);
} else {
readEPC(12);
handler.postDelayed(runnable, 1000);
}
};
tokenRunnable = () -> {
requestToken();
};
handler.postDelayed(tokenRunnable, 0);
keyReceiver = new MyKeyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.rfid.FUN_KEY");
registerReceiver(keyReceiver, intentFilter);
String ACTION_CLOSE_SCAN = "com.rfid.CLOSE_SCAN";
Intent toKillService = new Intent();
toKillService.setAction(ACTION_CLOSE_SCAN);
sendBroadcast(toKillService);
binding.dataEpc.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() == 24) {
haohuaMesSelect(s.toString());
}
}
});
ip = SharedPreferencesUtils.getstring("ip", "https://rfidpub.haohuatire.com:7443");
}
private void requestToken() {
Map<String, String> map = new HashMap<>();
map.put("AppId", "app-20250704032545-nmmhn8jw");
map.put("AppSecret", "dXJZQKubbqhSPCugtA49rsDGACmN5CMD4ItTfP11+DA=");
OkGo.<MyResult>post(ip + "/UMInterface/Auth/AccessToken").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
MyResult body = response.body();
if (body.getCode() == 200) {
String dataJson = body.getDataJson();
JsonObject jsonObject = JsonParser.parseString(dataJson).getAsJsonObject();
token = jsonObject.get("Token").getAsString();
Log.e("TAG", "onSuccess:token=" + token);
binding.traceSanButton1.setVisibility(View.GONE);
handler.postDelayed(tokenRunnable, 60 * 1000 * 90);
} else {
tipsDialog.setTip(false, body.getInfo());
tipsDialog.show();
binding.traceSanButton1.setVisibility(View.VISIBLE);
}
}
});
}
public void intentRequestToken(View view) {
requestToken();
}
public void dataReadRFID(View view) {
if (sanState) {
handler.postDelayed(runnable, 0);
sanState = false;
traceSanButton.setBackgroundResource(R.drawable.button_bg2);
traceSanButton.setText("停止扫描");
} else {
sanState = true;
handler.removeCallbacks(runnable);
traceSanButton.setBackgroundResource(R.drawable.button_bg1);
traceSanButton.setText("开始扫描");
}
}
@Override
protected void readTidReault(boolean readState, String result, byte[] rdata) {
super.readTidReault(readState, result, rdata);
binding.dataEpc.setText(result);
if (readState) {
dataReadRFID(null);
}
}
private void haohuaMesSelect(String result) {
OkGo.<MyResult>post(ip + "/UMInterface/RFID/sellTyreTracingBack")
.headers("Token", token)
.params("rfid", result).execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
MyResult body = response.body();
try {
if (body.getCode() == 200) {
String dataJson = body.getDataJson();
if (dataJson == null || dataJson.equals("[]")) {
tipsDialog.setTip(false, "未查询到相关信息");
tipsDialog.show();
adapter.setList(null);
return;
}
dataJson = dataJson.replace("[{", "").replace("\"", "").trim();
String[] split = dataJson.split(",");
List<MESInfo> mesInfos = new ArrayList<>();
for (String item : split) {
String[] split1 = item.split(":");
MESInfo mesInfo = new MESInfo();
mesInfo.setTitle(split1[0]);
mesInfo.setInfo(split1[1]);
mesInfos.add(mesInfo);
}
;
adapter.setList(mesInfos);
} else {
tipsDialog.setTip(false, body.getInfo());
tipsDialog.show();
adapter.setList(null);
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常,解析失败");
tipsDialog.show();
}
adapter.notifyDataSetChanged();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(keyReceiver);
}
private class MyKeyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
var keydown = intent.getBooleanExtra("keydown", false);
if (!keydown) {
dataReadRFID(null);
}
}
}
}

@ -32,7 +32,7 @@ public class SettingsActivity extends AppCompatActivity {
List<String> powerList = Arrays.asList(getResources().getStringArray(R.array.power));
powerBinding.setSelection(powerList.indexOf(bindingPower));
powerTrace.setSelection(powerList.indexOf(tracePower));
settingIp.setText(SharedPreferencesUtils.getstring("ip", null));
settingIp.setText(SharedPreferencesUtils.getstring("ip", "https://rfidpub.haohuatire.com:7443"));
}
public void saveInfo(View view) {

@ -62,9 +62,9 @@ public class MyApplication extends Application {
HttpsUtils.SSLParams sslParams1 = HttpsUtils.getSslSocketFactory(); // 方法一:信任所有证书,不安全有风险
builder.sslSocketFactory(sslParams1.sSLSocketFactory, sslParams1.trustManager);
builder.addInterceptor(loggingInterceptor);
builder.readTimeout(6000, TimeUnit.MILLISECONDS); // 全局的读取超时时间
builder.writeTimeout(6000, TimeUnit.MILLISECONDS); // 全局的写入超时时间
builder.connectTimeout(6000, TimeUnit.MILLISECONDS); // 全局的连接超时时间
builder.readTimeout(10000, TimeUnit.MILLISECONDS); // 全局的读取超时时间
builder.writeTimeout(10000, TimeUnit.MILLISECONDS); // 全局的写入超时时间
builder.connectTimeout(10000, TimeUnit.MILLISECONDS); // 全局的连接超时时间
builder.cookieJar(new CookieJarImpl(new MemoryCookieStore())); // 使用内存保持cookieapp退出后cookie消失
OkGo.getInstance().init(this).setOkHttpClient(builder.build()) // 建议设置OkHttpClient不设置将使用默认的
.setCacheMode(CacheMode.NO_CACHE) // 全局统一缓存模式,默认不使用缓存,可以不传

@ -23,7 +23,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">
<RadioButton
android:id="@+id/home_1"
@ -67,8 +68,19 @@
android:drawablePadding="10dp"
android:gravity="center"
android:text="解绑"
android:textSize="20sp"
android:visibility="gone"/>
<RadioButton
android:id="@+id/home_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/ic_info"
android:drawablePadding="10dp"
android:gravity="center"
android:text="轮胎信息查询"
android:textSize="20sp" />
<RadioButton
android:id="@+id/home_4"
android:layout_width="match_parent"
@ -83,27 +95,6 @@
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:visibility="gone">
<RadioButton
android:id="@+id/home_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/ic_info"
android:drawablePadding="10dp"
android:gravity="center"
android:text="轮胎信息查询"
android:textSize="20sp" />
</RadioGroup>
</LinearLayout>

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="adapter"
type="com.example.writeepc.adapter.MyMesInfoAdapter" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".IntentSelectActivity">
<TextView
style="@style/info_text"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#6750A4"
android:letterSpacing="0.2"
android:text="轮胎追溯"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="扫描RFID:" />
<EditText
android:id="@+id/data_epc"
style="@style/san_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/data_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:padding="20dp"
android:textSize="18sp"
android:visibility="gone" />
<TextView
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="查询信息"
android:textColor="@color/blue" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:adapter="@{adapter}"
android:padding="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp">
<Button
android:id="@+id/trace_san_button1"
style="@style/button_style"
android:layout_width="150dp"
android:layout_height="55dp"
android:onClick="intentRequestToken"
android:background="@drawable/button_bg2"
android:text="重新连接" />
<Button
android:id="@+id/trace_san_button"
style="@style/button_style"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="55dp"
android:onClick="dataReadRFID"
android:background="@drawable/button_bg1"
android:text="开始扫描" />
</LinearLayout>
</LinearLayout>
</layout>

@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="20dp"
android:visibility="gone"
android:orientation="horizontal">
<TextView
@ -71,29 +71,24 @@
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:visibility="gone">
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_gravity="center|left"
android:text="请求地址:" />
<EditText
android:id="@+id/setting_ip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="45dp"
android:layout_gravity="center"
android:entries="@array/power"
android:lines="1"
android:textAlignment="center" />
</LinearLayout>
<View
android:layout_width="match_parent"

Loading…
Cancel
Save