pull/7/head
233 2 years ago
commit 724a02d991

@ -0,0 +1 @@
3213

@ -0,0 +1,258 @@
from openpyxl import load_workbook
from openpyxl.styles import *
import time
import warnings
warnings.filterwarnings('ignore')
#判断是否在校
#此处为入校申请
def inschool (u,a):
wb = load_workbook('Student.xlsx')
ws = wb.active
u_inschool = u+1
state = ws.cell(row=u_inschool, column=3).value
if state == 'y' and a == 1:
print("您已在学校,不能提交入校申请")
#在校状态不能申请入校
elif state == 'n' and a == 1:
print("您可以正常申请入校")
#离校状态可以正常申请入校
return 1
#填写表格
def write_form (a,c,p):
print("=============================================")
print("开始填表")
#申请类型
application = int(a)
#姓名
name = input("请输入姓名:")
#学号
id = input("请输入学号:")
#联系电话
phone = input("请输入联系电话:")
#时间
Time = ''
while Time == '':
t1 = input("请输入入校时间格式样例2022-07-22 23:00:00要求为当日且不能早于6点晚于22点")
# t1 = str('2022-10-23 21:00:00')
Time = str(time_judge(t1))
#校门
door = ''
while door == '':
d = int(input("请选择校门1.东门 2.南门 3.西门 4.北门):"))
door = door_choice(d)
#以下为前端数据,此处用输入代替
#地址
province = input("请输入省市:")
district = input("请输入区:")
place = input("请输入详细地址:")
#健康码
health_code = ''
while health_code == '':
h = str(input("请输入健康码状态(绿/黄/红):"))
health_code = health_code_judge(h)
#行程码
Tour_code = input("请输入行程码状态:")
#核酸
NAT = ''
while NAT == '':
n = str(input("请输入核酸状态(阴/阳):"))
NAT = NAT_judge(n)
#申请状态
application_count = int(c + 1)
#通过状态
Pass = int(p)
#提交确认
submit = Submit(name,id,phone,Time,door,province,district,place,health_code,Tour_code,NAT)
if submit == 'n':
print("填写取消,返回上级菜单")
return 0
#封装
data = data_set(application,name,id,phone,Time,door,province,district,place,health_code,Tour_code,NAT,application_count,Pass)
#print(data)
#写入excel
write(data)
#调整excel格式
style('Form.xlsx')
#判断时间合理性
def time_judge(t11):
t1 = time.strptime(t11, "%Y-%m-%d %H:%M:%S")
t = time.localtime()
year = str(t.tm_year)
mon = str(t.tm_mon)
day2 = str(t.tm_mday)
hour = str(t.tm_hour)
minute = str(t.tm_min)
sec = str(t.tm_sec)
t22 = str(year + '-' + mon + '-' + day2 + ' ' + hour + ':' + minute + ':' + sec)
t2 = time.strptime(t22, "%Y-%m-%d %H:%M:%S")
#判断填写时间是否比当前时间早
tl = (time.mktime(t1)-time.mktime(t2))
if tl <= 0:
print("请输入比当前时间晚的时间")
return ''
#判断日期是否为当日
day1 = str(t1.tm_mday)
if day1 != day2:
print("申请只能为当日")
return ''
hour1 = t1.tm_hour
minute1 = t1.tm_min
sec1 = t1.tm_sec
#判断申请时间是否晚于6点
if hour1 < 6:
print("入校必须晚于6点")
return ''
#判断申请时间是否早于10点
if hour1 > 22:
print("入校必须早于22点")
return ''
elif hour1 == 22 and minute1 != 0 and sec1 != 0:
print("入校必须早于22点")
return ''
return t11
#选择校门
def door_choice(d):
if d == 1:
return 'East'
elif d == 2:
return 'South'
elif d == 3:
return 'West'
elif d == 4:
return 'North'
else:
print("请选择正确的校门!")
return ''
#判断健康码信息填写正确性
def health_code_judge(h):
if h != "绿" and h != "" and h != "":
print("请输入正确的健康码信息")
return ''
else:
return h
#判断核酸信息填写正确性
def NAT_judge(n):
if n != "" and n != "":
print("请输入正确的核酸信息")
return ''
else:
return n
#提交确认
def Submit(name,id,phone,Time,door,province,district,place,health_code,Tour_code,NAT):
print("=============================================")
print("申请类型为:入校申请")
print("姓名:" + name)
print("学号:" + id)
print("联系电话:" + phone)
print("时间:" + Time)
print("校门:" + door)
print("省市:" + province)
print("区:" + district)
print("详细地址:" + place)
print("健康码信息:" + health_code)
print("行程码信息:" + Tour_code)
print("核酸:" + NAT)
print("申请状态:待审核")
print("通过状态:待审核")
submit = input("以上为填写信息是否提交y/n")
return submit
#数据封装
def data_set(application,name,id,phone,time,door,province,district,place,health_code,Tour_code,NAT,application_count,Pass):
data_form = {
"application": application,
"name": name,
"id": id,
"phone": phone,
"time": time,
"door": door,
"province": province,
"district": district,
"place": place,
"health_code": health_code,
"Tour_code": Tour_code,
"NAT": NAT,
"application_count": application_count,
"Pass": Pass
}
return data_form
#数据写入excel
def write(data):
wb = load_workbook('Form.xlsx')
ws = wb.active
d = (
data["application"],
data["name"],
data["id"],
data["phone"],
data["time"],
data["door"],
data["province"],
data["district"],
data["place"],
data["health_code"],
data["Tour_code"],
data["NAT"],
data["application_count"],
data["Pass"]
)
ws.append(d)
wb.save('Form.xlsx')
print("提交成功!")
#调整excel格式
def style(file):
wb = load_workbook(file)
ws = wb.active
for row in ws.iter_rows():
for cell in row:
if cell is not None:
cell.alignment = Alignment(horizontal='center',vertical='center')
wb.save(file)
#代码运行主体
x = 1
while x:
user = int(input("请选择用户1.张三 2.李四 3.王五):"))
print("您选择的是入校申请")
#申请类型1为入校申请 2为出校申请 此处默认为1
application = 1
#申请状态0无1有
application_count = 0
#通过状态默认为0
Pass = 0
if inschool(user,application):
write_form(application,application_count,Pass)
x = 0
else:
print("请返回上级菜单,提交申请请选择出校申请")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

@ -0,0 +1,12 @@
<component name="ArtifactManager">
<artifact type="jar" name="OCR_baidu:jar">
<output-path>$PROJECT_DIR$/out/artifacts/OCR_baidu_jar</output-path>
<root id="archive" name="OCR_baidu.jar">
<element id="module-output" name="OCR_baidu" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/json-20160810.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/slf4j-simple-1.7.25.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/aip-java-sdk-4.16.11.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/slf4j-api-1.7.25.jar" path-in-jar="/" />
</root>
</artifact>
</component>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
</component>
</project>

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="aip-java-sdk-4.16.11">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/aip-java-sdk-4.16.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="json-20160810">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/json-20160810.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/lib/json-20160810.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="slf4j-api-1.7.25">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/slf4j-api-1.7.25.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="slf4j-simple-1.7.25">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/slf4j-simple-1.7.25.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CodeInsightWorkspaceSettings">
<option name="optimizeImportsOnTheFly" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/OCR_baidu.iml" filepath="$PROJECT_DIR$/OCR_baidu.iml" />
</modules>
</component>
</project>

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: OCR

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="aip-java-sdk-4.16.11" level="project" />
<orderEntry type="library" name="json-20160810" level="project" />
<orderEntry type="library" name="slf4j-api-1.7.25" level="project" />
<orderEntry type="library" name="slf4j-simple-1.7.25" level="project" />
</component>
</module>

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: HealthCode

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: HealthCode

File diff suppressed because it is too large Load Diff

@ -0,0 +1,138 @@
import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import java.util.HashMap;
public class CovidTestRep {
private String Name;
private String Time;
private String Status;
public CovidTestRep() {
Name = "";
Time = "";
Status = "";
}
public String getName() {
return Name;
}
public String getData() {
return Time;
}
public String getStatus() {
return Status;
}
public void setStatus(String status) {
Status = status;
}
public void setName(String name) {
Name = name;
}
public void setData(String data) {
Time = data;
}
public void Print() {
System.out.println("Name:" + this.Name);
System.out.println("Data:" + this.Time);
System.out.println("Status:" + this.Status);
}
public static void main(String[] args) {
String path = "C:/Users//16491/eclipse-workspace/OCR_baidu/src/3.jpg";// 初始化一个AipOcr
ocr3(path);
}
public static String Judge(String path) {
CovidTestRep Ctr=new CovidTestRep();
Ctr=ocr3(path);
String StatusNameTime=Ctr.Status+","+Ctr.Name+","+Ctr.Time;
return StatusNameTime;
}
public static CovidTestRep ocr3(String path) {
final String APP_ID = "28049220";
final String API_KEY = "qyKlUy6xSapA89DTPomExteq";
final String SECRET_KEY = "q5EYpXULVh5gC3firLU1nGaymwIwOMBd";
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 可选:设置网络连接参数
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(10000);
// 可选:设置代理服务器地址, http和socket二选一或者均不设置
// client.setHttpProxy("proxy_host", proxy_port); // 设置http代理
// client.setSocketProxy("proxy_host", proxy_port); // 设置socket代理
// 可选设置log4j日志输出格式若不设置则使用默认配置
// 也可以直接通过jvm启动参数设置此环境变量
System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
// 调用接口
JSONObject res = client.basicGeneral(path, new HashMap<String, String>());
/*Map<String,Object> m=res.toMap();
Set s=m.entrySet();*//*
for (Object str : s) {
System.out.println(str);
}
//System.out.println(s);*/
String str= res.toString(0);
/*for(int i=0;i<str.length();i++)
{char c=str.charAt(i);
System.out.println(i);
System.out.println(c);
}*/
//System.out.println(str);
String s="";
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||c=='{'||c=='"'||c==':'||c=='}'||c==''||c=='_'){
continue;
}
else
s+=c;
if(c==']')break;
}
//System.out.println(s);
CovidTestRep CTR=new CovidTestRep();
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='姓'&&s.charAt(i+1)=='名')
{
String Na= CTR.getName();
i=i+3;
for(;s.charAt(i)!=',';i++)
{
Na+=s.charAt(i);
}
CTR.setName(Na);
}
if(s.charAt(i)=='采'&&s.charAt(i+1)=='样'&&s.charAt(i+2)=='时'&&s.charAt(i+3)=='间')
{
String Da= CTR.getData();
i=i+5;
for(;s.charAt(i)!=',';i++)
{
Da+=s.charAt(i);
}
CTR.setData(Da);
}
if(s.charAt(i)=='检'&&s.charAt(i+1)=='测'&&s.charAt(i+2)=='结'&&s.charAt(i+3)=='果')
{
String St= CTR.getStatus();
i=i+5;
for(;s.charAt(i)!=']';i++)
{
St+=s.charAt(i);
}
CTR.setStatus(St);
}
}
return CTR;
}
}

@ -0,0 +1,129 @@
import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import java.util.HashMap;
public class HealthCode {
private String Name;
private String Data;
private String Status;
public HealthCode() {
Name = "";
Data = "";
Status = "";
}
public String getName() {
return Name;
}
public String getData() {
return Data;
}
public String getStatus() {
return Status;
}
public void setStatus(String status) {
Status = status;
}
public void setName(String name) {
Name = name;
}
public void setData(String data) {
Data = data;
}
public void Print() {
System.out.println("Name:" + this.Name);
System.out.println("Data:" + this.Data);
System.out.println("Status:" + this.Status);
}
public static void main(String[] args) {
String path = "C:/Users//16491/eclipse-workspace/OCR_baidu/src/1.jpg";
System.out.println(Judge(path));
}
public static String Judge(String path) {
HealthCode H = new HealthCode();
H = ocr1(path);
String StatusNameData = "S"+H.Status + "," + H.Name + "," + H.Data+"E";
return StatusNameData;
}
/*class OCR {
//设置APPID/AK/SK
public OCR(){
}*/
public static HealthCode ocr1(String path) {
final String APP_ID = "28049220";
final String API_KEY = "qyKlUy6xSapA89DTPomExteq";
final String SECRET_KEY = "q5EYpXULVh5gC3firLU1nGaymwIwOMBd";
// 初始化一个AipOcr
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 可选:设置网络连接参数
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(60000);
// 可选:设置代理服务器地址, http和socket二选一或者均不设置
// client.setHttpProxy("proxy_host", proxy_port); // 设置http代理
// client.setSocketProxy("proxy_host", proxy_port); // 设置socket代理
// 可选设置log4j日志输出格式若不设置则使用默认配置
// 也可以直接通过jvm启动参数设置此环境变量
System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
// 调用接口
JSONObject res = client.basicGeneral(path, new HashMap<String, String>());
String str= res.toString(0);
int flag = 0;
int flag1 = 0;
int flag2 = 0;
HealthCode HC = new HealthCode();
for (int i = 16; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '[' && flag == 0) {
flag = 1;
} else if (flag == 1 && c == ']') {
break;
} else {
if (i == 27) {
String N = HC.getName();
for (; str.charAt(i) != '\"'; i++) {
N = N + str.charAt(i);
}
HC.setName(N);
}
if (str.charAt(i) == '-' && flag1 == 0) {
flag1 = 1;
String D = HC.getData();
for (i = i - 4; str.charAt(i) != '\"'; i++) {
D = D + str.charAt(i);
}
HC.setData(D);
}
if (str.charAt(i) == '码' && flag2 == 0) {
flag2 = 1;
String S = HC.getStatus();
S = S + str.charAt(i - 1);
HC.setStatus(S);
}
}
}
return HC;
}
}

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: HealthCode

@ -0,0 +1,146 @@
import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import java.util.HashMap;
public class TripCode {
private String Status;
private String Telephone;
private String Time;
private String District;
public TripCode() {
Status = "";
Telephone = "";
Time = "";
District = "";
}
public void setStatus(String status) {
Status = status;
}
public void setTelephone(String telephone) {
Telephone = telephone;
}
public void setTime(String time) {
Time = time;
}
public void setDistrict(String district) {
District = district;
}
public String getTelephone() {
return Telephone;
}
public String getStatus() {
return Status;
}
public String getDistrict() {
return District;
}
public String getTime() {
return Time;
}
public void Print() {
System.out.println("Status:" + this.Status);
System.out.println("Telephone:" + this.Telephone);
System.out.println("Time:" + this.Time);
System.out.println("District:" + this.District);
}
public static void main(String[] args) {
String path = "C:\\Users\\16491\\Desktop\\1.jpg";
System.out.println(Judge(path));
}
/*};
class OCR2 {
//设置APPID/AK/SK*/
public static String Judge(String path) {
TripCode T = new TripCode();
T = ocr2(path);
String InfM = T.Status + "," + T.Telephone + "," + T.Time + "," + T.District;
return InfM;
}
public static TripCode ocr2(String path) {
final String APP_ID = "28049220";
final String API_KEY = "qyKlUy6xSapA89DTPomExteq";
final String SECRET_KEY = "q5EYpXULVh5gC3firLU1nGaymwIwOMBd";
// 初始化一个AipOcr
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 可选:设置网络连接参数
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(10000);
// 可选:设置代理服务器地址, http和socket二选一或者均不设置
// client.setHttpProxy("proxy_host", proxy_port); // 设置http代理
// client.setSocketProxy("proxy_host", proxy_port); // 设置socket代理
// 可选设置log4j日志输出格式若不设置则使用默认配置
// 也可以直接通过jvm启动参数设置此环境变量
System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
// 调用接口
JSONObject res = client.basicGeneral(path, new HashMap<String, String>());
//System.out.println(res);
String str = res.toString(0);
//System.out.println(str);
String s = "";
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '{' || c == '"' || c == ':' || c == '}' || c == '' || c == '_') {
continue;
} else
s += c;
if (c == ']') break;
}
//System.out.println(s);
TripCode TC = new TripCode();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '的' && s.charAt(i + 1) == '动' && s.charAt(i + 2) == '态' && s.charAt(i + 3) == '行' && s.charAt(i + 4) == '程' && s.charAt(i + 5) == '卡') {
String tel = TC.getTelephone();
for(;s.charAt(i)!=',';i--);
i++;
for (; s.charAt(i) != ','; i++) {
tel += s.charAt(i);
}
TC.setTelephone(tel);
}
if (s.charAt(i) == '请' && s.charAt(i + 1) == '收' && s.charAt(i + 2) == '下') {
String St = TC.getStatus();
i = i + 3;
for (; s.charAt(i) != ','; i++) {
St += s.charAt(i);
}
TC.setStatus(St);
}
if (s.charAt(i) == '更' && s.charAt(i + 1) == '新' && s.charAt(i + 2) == '于') {
String Data = TC.getTime();
i = i + 3;
for (; s.charAt(i) != ','; i++) {
Data += s.charAt(i);
}
TC.setTime(Data);
}
if (s.charAt(i) == '到' && s.charAt(i + 1) == '达' && s.charAt(i + 2) == '或' && s.charAt(i + 3) == '途' && s.charAt(i + 4) == '经') {
String Dis = TC.getDistrict();
i = i + 5;
for (; s.charAt(i) != ']'; i++) {
Dis += s.charAt(i);
}
TC.setDistrict(Dis);
}
}
return TC;
}
}

@ -0,0 +1,13 @@
from openpyxl import load_workbook
from openpyxl.styles import *
def style(file):
wb = load_workbook(file)
ws = wb.active
for row in ws.iter_rows():
for cell in row:
if cell is not None:
cell.alignment = Alignment(horizontal='center',vertical='center')
wb.save(file)
style('测试3.xlsx')

@ -0,0 +1 @@
二点发发发的
Loading…
Cancel
Save