增加 风神接口

fengshen
wanghao 2 months ago
parent 511212d59f
commit 2f48e3f31d

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidTestResultsUserPreferences">
<option name="androidTestResultsTableState">
<map>
<entry key="-941396539">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Tests" value="360" />
<entry key="alps k62v1_3h" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="-531529726">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Pixel_2_API_33" value="120" />
<entry key="Tests" value="360" />
<entry key="alps k62v1_3h" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="1094103868">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Tests" value="360" />
<entry key="alps k62v1_3h" value="120" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
</map>
</option>
</component>
</project>

@ -31,8 +31,8 @@ android {
dataBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_15
targetCompatibility JavaVersion.VERSION_15
}
}

@ -0,0 +1,140 @@
package com.example.writeepc;
import android.util.Log;
import com.example.writeepc.been.MESInfo;
import junit.framework.TestCase;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ShuangqianActivity2Test extends TestCase {
public void test() {
String result = """
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRFIDBindingInfoResponse xmlns="http://tempuri.org/">
<GetRFIDBindingInfoResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="品牌" type="xs:string" minOccurs="0"/>
<xs:element name="规格" type="xs:string" minOccurs="0"/>
<xs:element name="花纹类型" type="xs:string" minOccurs="0"/>
<xs:element name="胎号" type="xs:string" minOccurs="0"/>
<xs:element name="DOT" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<>123</>
<>1234</>
<>1235</>
<>1236</>
<DOT>1236</DOT>
</Table>
</NewDataSet>
</diffgr:diffgram>
</GetRFIDBindingInfoResult>
</GetRFIDBindingInfoResponse>
</soap:Body>
</soap:Envelope>
""";
String regex = "<Table .*\">";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(result);
if (!matcher.find()) {
System.out.println("未找到匹配的内容");
return;
}
String matched = matcher.group();// 匹配内容
int beginIndex = matcher.start() + matched.length();
int endIndex = result.indexOf("</Table>");
Log.e("TAG", "test1:" + beginIndex);
Log.e("TAG", "test2:" + endIndex);
if (beginIndex >= endIndex) {
System.out.println("未找到匹配的内容");
return;
}
result = result.substring(beginIndex, endIndex);
System.out.println("截取内容:" + result);
// <品牌>风神</品牌><规格>10.00R20</规格><花纹类型>AGC08</花纹类型)<胎号>ZB250901399</胎号><DOT>3625</DOT>
String[] str=new String[]{"品牌","规格","花纹类型","胎号","DOT"};
for (String s : str) {
String tag = "<" + s + ">";
System.out.println("-"+result.substring(result.indexOf(tag) + tag.length(), result.indexOf("</"+s+">"))+"-");
}
/* InputStream inputStream = new StringBufferInputStream(result);
XmlPullParser parser = Xml.newPullParser();
parser.setInput(inputStream, "utf-8"); // 设置输入流和编码
int eventType = parser.getEventType();
boolean isInTable = false; // 是否进入<Table>节点
while (eventType != XmlPullParser.END_DOCUMENT) {
String tagName = parser.getName();
System.out.println("tab name :"+tagName);
switch (eventType) {
case XmlPullParser.START_TAG:
// 找到<Table>节点,初始化数据对象
if ("Table".equals(tagName)) {
isInTable = true;
} else if (isInTable) {
switch (tagName) {
case "品牌":
String trim = parser.nextText().trim();
System.out.println(trim);
break;
case "规格":
String trim2 = parser.nextText().trim();
System.out.println(trim2);
break;
case "花纹类型":
String trim3 = parser.nextText().trim();
System.out.println(trim3);
break;
case "胎号":
String trim4 = parser.nextText().trim();
System.out.println(trim4);
break;
case "DOT":
String trim5 = parser.nextText().trim();
System.out.println(trim5);
break;
}
}
break;
case XmlPullParser.END_TAG:
// 退出<Table>节点
if ("Table".equals(tagName)) {
isInTable = false;
}
break;
}
eventType = parser.next(); // 解析下一个事件
}*/
}
}

@ -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", "http://10.72.36.3:8090/FSRFID.asmx"));
}
public void saveInfo(View view) {

@ -2,6 +2,7 @@ package com.example.writeepc;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
@ -20,6 +21,8 @@ import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.uhf.api.cls.Reader;
import java.time.Year;
public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
private ActivityShuangqianBinding binding;
@ -29,19 +32,15 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_shuangqian);
String ACTION_SCAN_INIT = "com.rfid.SCAN_INIT";
Intent intent = new Intent();
intent.setAction(ACTION_SCAN_INIT);
sendBroadcast(intent);
initUHFRManager1();
initDialog();
int powerBinding = Integer.parseInt(SharedPreferencesUtils.getstring("powerBinding", "22"));
Reader.READER_ERR readerErr = uhfrManager.setPower(powerBinding, powerBinding);
// Reader.READER_ERR readerErr = uhfrManager.setPower(powerBinding, powerBinding);
myReceiver = new MyScannerReceiver(this);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.rfid.SCAN");
@ -50,6 +49,10 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
binding.setTitle(type ? "MES轮胎绑定" : "解绑");
binding.setType(type);
// uriLastStr = type ? "barcodeAndRFIDBinding" : "unBinding";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.socketYear.setText(String.valueOf(Year.now().getValue()));
}
}
// 读取
@ -73,50 +76,53 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
public void submit(View view) {
String epc = binding.socketEpc.getText().toString();
String code = binding.socketBarcode.getText().toString();
if (epc.isEmpty() || code.isEmpty()) return;
haohuaSubmit(epc, code);
// callWebService(buildSoapRequest(epc, code));//双钱
String year = binding.socketYear.getText().toString();
if (epc.isEmpty() || code.isEmpty() || year.isEmpty()) return;
// haohuaSubmit(epc, code);
callWebService(buildSoapRequest(epc, code, year));// 双钱
}
// 解绑
public void unBindingSubmit(View view) {
String epc = binding.socketEpc.getText().toString();
String code = binding.socketBarcode.getText().toString();
haohuaSubmit(epc, code);
}
private void haohuaSubmit(String epc, String code) {
OkGo.<MyResult>post("http://192.168.26.26:5050/UMInterface/RFID/" + uriLastStr)
.params("rfid", epc).params("barCode", code).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
MyResult body = response.body();
try {
if (body.getCode() == 200) {
tipsDialog.setTip(true, body.getInfo());
tipsDialog.show();
binding.socketBarcode.setText(null);
binding.socketEpc.setText(null);
} else {
tipsDialog.setTip(false, body.getInfo());
tipsDialog.show();
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
MyResult body = response.body();
try {
if (body.getCode() == 200) {
tipsDialog.setTip(true, body.getInfo());
tipsDialog.show();
binding.socketBarcode.setText(null);
binding.socketEpc.setText(null);
} else {
tipsDialog.setTip(false, body.getInfo());
tipsDialog.show();
}
});
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
}
});
}
private void callWebService(String soapRequest) {
// 发送 POST 请求
OkGo.<String>post("http://10.135.55.206:99/WebService.asmx").headers("Content-Type", "text/xml; charset=utf-8").upString(soapRequest, mediaType).execute(new StringCallback() {
OkGo.<String>post(SharedPreferencesUtils.getstring("ip", "http://10.72.36.3:8090/FSRFID.asmx"))
.headers("Content-Type", "text/xml; charset=utf-8")
.upString(soapRequest, mediaType)
.execute(new StringCallback() {
@Override
public void onStart(Request<String, ? extends Request> request) {
super.onStart(request);
@ -128,40 +134,20 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
// 处理响应结果
String result = response.body();
try {
String str = "<faultstring>";
int faultstringIndex = result.indexOf(str);
if (faultstringIndex > -1) {
String faultstring =
result.substring(faultstringIndex + str.length(), result.indexOf("</faultstring>"));
tipsDialog.setTip(false, faultstring);
tipsDialog.show();
return;
}
int codeIndex = result.indexOf("<Code>");
if (codeIndex > -1) {
String resultCode =
result.substring(codeIndex + 6, result.indexOf("</Code>"));
String resultMsg =
result.substring(result.indexOf("<Msg>") + 5, result.indexOf("</Msg>"));
if (resultCode.equals("200")) {
tipsDialog.setTip(true, resultMsg);
tipsDialog.show();
binding.socketBarcode.setText(null);
binding.socketEpc.setText(null);
} else {
tipsDialog.setTip(false, resultMsg);
tipsDialog.show();
}
// clearView(null);
}
String str = "<SubmitRFIDBindingInfoResult>";
String subStringResult =
result.substring(result.indexOf(str) + str.length(), result.indexOf("</SubmitRFIDBindingInfoResult>")).trim();
boolean equals = subStringResult.equals("OK");
tipsDialog.setTip(equals, subStringResult);
tipsDialog.show();
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
}
@Override
public void onFinish() {
super.onFinish();
@ -171,20 +157,26 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
}
// 创建提交信息
private String buildSoapRequest(String epcid, String barcode) {
String soapRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<RFID_BarcodBind xmlns=\"http://tempuri.org/\">" +
"<epcid>" + epcid + "</epcid>" +
"<barcode>" + barcode + "</barcode>" +
"</RFID_BarcodBind>" +
"</soap:Body>" +
"</soap:Envelope>";
return soapRequest;
private String buildSoapRequest(String epcid, String barcode, String year) {
return String.format("""
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header>
<tem:MySoapHeader>
<tem:UserName>RFID-MES</tem:UserName>
<tem:PassWord>Yh#14ulh!6hk9ue4ml</tem:PassWord>
</tem:MySoapHeader>
</soap:Header>
<soap:Body>
<tem:SubmitRFIDBindingInfo>
<tem:RFIDCode>%s</tem:RFIDCode>
<tem:GreenTyreNo>%s</tem:GreenTyreNo>
<tem:YearNo>%s</tem:YearNo>
</tem:SubmitRFIDBindingInfo>
</soap:Body>
</soap:Envelope>
""", epcid, barcode, year);
}
@Override
public void getScannerData(String data) {
binding.socketBarcode.setText(data);

@ -37,6 +37,8 @@ import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ShuangqianActivity2 extends BaseActivity {
private ActivityShuangqian2Binding binding;
@ -46,6 +48,7 @@ public class ShuangqianActivity2 extends BaseActivity {
private Handler handler = new Handler();
private Runnable runnable;
private MyKeyReceiver keyReceiver;
private List<MESInfo> mesInfos;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -59,7 +62,10 @@ public class ShuangqianActivity2 extends BaseActivity {
Log.e("TAG", "追溯设置功率" + powerTrace1 + ":" + readerErr.name());
initDialog();
adapter = new MyMesInfoAdapter(this);
mesInfos = new ArrayList<>();
adapter.setList(mesInfos);
binding.setAdapter(adapter);
traceSanButton = binding.traceSanButton;
runnable = new Runnable() {
@Override
@ -81,7 +87,7 @@ public class ShuangqianActivity2 extends BaseActivity {
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) {
@ -95,7 +101,7 @@ public class ShuangqianActivity2 extends BaseActivity {
@Override
public void afterTextChanged(Editable s) {
if (s.length()==24){
if (s.length() == 24) {
haohuaMesSelect(s.toString());
}
@ -131,7 +137,7 @@ public class ShuangqianActivity2 extends BaseActivity {
if (readState) {
dataReadRFID(null);
// callWebService(buildSelectRequest(result));
callWebService(buildSelectRequest(result));
// haohuaMesSelect(result);
@ -185,7 +191,7 @@ public class ShuangqianActivity2 extends BaseActivity {
private void callWebService(String soapRequest) {
// 发送 POST 请求
OkGo.<String>post("http://10.135.55.206:99/WebService.asmx")
OkGo.<String>post(SharedPreferencesUtils.getstring("ip", "http://10.72.36.3:8090/FSRFID.asmx"))
.headers("Content-Type", "text/xml; charset=utf-8")
.upString(soapRequest, mediaType)
.execute(new StringCallback() {
@ -198,39 +204,42 @@ public class ShuangqianActivity2 extends BaseActivity {
@Override
public void onSuccess(Response<String> response) {
// 处理响应结果
String result = response.body();
try {
String str = "<faultstring>";
int faultstringIndex = result.indexOf(str);
if (faultstringIndex > -1) {
String faultstring =
result.substring(faultstringIndex + str.length(), result.indexOf("</faultstring>"));
tipsDialog.setTip(false, faultstring);
mesInfos.clear();
String result = response.body();
String regex = "<Table .*\">";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(result);
if (!matcher.find()) {
tipsDialog.setTip(false, "未找到匹配的内容");
tipsDialog.show();
return;
}
int codeIndex = result.indexOf("<Code>");
if (codeIndex > -1) {
String resultCode =
result.substring(codeIndex + 6, result.indexOf("</Code>"));
if (resultCode.equals("200")) {
String resultMsg =
result.substring(result.indexOf("<Entity>") + 8, result.indexOf("</Entity>"));
jiexi(resultMsg);
return;
}
String resultMsg =
result.substring(result.indexOf("<Msg>") + 5, result.indexOf("</Msg>"));
tipsDialog.setTip(false, resultMsg);
String matched = matcher.group();// 匹配内容
int beginIndex = matcher.start() + matched.length();
int endIndex = result.indexOf("</Table>");
Log.e("TAG", "test1:" + beginIndex);
Log.e("TAG", "test2:" + endIndex);
if (beginIndex >= endIndex) {
tipsDialog.setTip(false, "未找到匹配的内容");
tipsDialog.show();
return;
}
String[] str = new String[]{"品牌", "规格", "花纹类型", "胎号", "DOT"};
for (String s : str) {
String tag = "<" + s + ">";
MESInfo mesInfo = new MESInfo();
mesInfo.setTitle(s);
mesInfo.setInfo(result.substring(result.indexOf(tag) + tag.length(), result.indexOf("</" + s + ">")));
mesInfos.add(mesInfo);
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
}
adapter.notifyDataSetChanged();
}
@Override
public void onFinish() {
@ -242,16 +251,22 @@ public class ShuangqianActivity2 extends BaseActivity {
// 创建验证信息
private String buildSelectRequest(String epcid) {
StringBuilder soapRequest = new StringBuilder();
soapRequest.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soapRequest.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
soapRequest.append("<soap:Body>");
soapRequest.append("<TyreTracingBack xmlns=\"http://tempuri.org/\">");
soapRequest.append("<epcid>").append(epcid).append("</epcid>");
soapRequest.append("</TyreTracingBack>");
soapRequest.append("</soap:Body>");
soapRequest.append("</soap:Envelope>");
return soapRequest.toString();
String soapRequest = String.format("""
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header>
<tem:MySoapHeader>
<tem:UserName>RFID-MES</tem:UserName>
<tem:PassWord>Yh#14ulh!6hk9ue4ml</tem:PassWord>
</tem:MySoapHeader>
</soap:Header>
<soap:Body>
<tem:GetRFIDBindingInfo>
<tem:RFIDCode>%s</tem:RFIDCode>
</tem:GetRFIDBindingInfo>
</soap:Body>
</soap:Envelope>
""", epcid);
return soapRequest;
}
private void jiexi(String msg) {
@ -330,6 +345,12 @@ public class ShuangqianActivity2 extends BaseActivity {
}
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(keyReceiver);
}
private class MyKeyReceiver extends BroadcastReceiver {
@Override
@ -340,10 +361,4 @@ public class ShuangqianActivity2 extends BaseActivity {
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(keyReceiver);
}
}

@ -67,7 +67,8 @@
android:drawablePadding="10dp"
android:gravity="center"
android:text="解绑"
android:textSize="20sp" />
android:textSize="20sp"
android:visibility="gone" />
<RadioButton
android:id="@+id/home_4"
@ -81,6 +82,15 @@
android:text="设置"
android:textSize="20sp" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawablePadding="10dp"
android:gravity="center"
android:textSize="20sp" />
</RadioGroup>
<RadioGroup
@ -103,7 +113,6 @@
android:textSize="20sp" />
</RadioGroup>
</LinearLayout>

@ -58,27 +58,27 @@
</LinearLayout>
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="55dp"-->
<!-- android:layout_marginTop="20dp"-->
<!-- android:orientation="horizontal">-->
<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="胎胚年份:" />-->
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="胎胚年份:" />
<!-- <EditText-->
<!-- android:id="@+id/socket_year"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_gravity="center"-->
<!-- android:gravity="center"-->
<!-- />-->
<!-- </LinearLayout>-->
<EditText
android:id="@+id/socket_year"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"

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

Loading…
Cancel
Save