Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发票识别连接器 done #101

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ocrinvoice_fdddf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
target/
.DS_Store
54 changes: 54 additions & 0 deletions ocrinvoice_fdddf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# OrcInvoice
增值税发票识别

## 逻辑详情

### rollTicketOcr

增值税发票卷票识别, 参考:https://market.aliyun.com/apimarket/detail/cmapi00042852

入参:
RollTicketRequest(String url, String img)

出参:
RollTicketResponse

### invoiceOcr

增值税发票识别, 参考: https://market.aliyun.com/apimarket/detail/cmapi027758

入参:
OcrInvoiceRequest(String url, String img, Integer pdf_no)

出参:
OcrInvoiceResponse

### invoiceCheck

增值发票验真, 参考:https://market.aliyun.com/apimarket/detail/cmapi00050226

入参:
InvoiceCheckRequest(String fphm, String kprq, String fpdm, String xym, String bhsje)

出参:
InvoiceCheckResponse



## 使用步骤说明

1. 应用集成中心中添加连接器:增值税发票识别和校验
2. 配置应用配置参数:填写连接器名称,appCode
3. 逻辑中调用连接器的方法
![Snipaste_2024-04-20_19-32-54.jpg](Snipaste_2024-04-20_19-32-54.jpg)


## 应用演示链接

https://dev-test430-qa.app.codewave.163.com/aliyun1
https://dev-test430-qa.app.codewave.163.com/aliyun2
https://dev-test430-qa.app.codewave.163.com/aliyun3

[使用了本依赖库的制品应用链接]

https://dev-test430-qa.app.codewave.163.com/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml"
Binary file not shown.
74 changes: 74 additions & 0 deletions ocrinvoice_fdddf/jar/nasl-metadata-maven-plugin-1.3.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.netease.lowcode</groupId>
<artifactId>nasl-metadata-maven-plugin</artifactId>
<version>1.3.0</version>
<packaging>maven-plugin</packaging>

<name>Nasl Metadata Maven Plugin</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.0.1</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.3.9</version>
</dependency>

<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<goalPrefix>nasl-metadata-maven-plugin</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
</build>
</project>
78 changes: 78 additions & 0 deletions ocrinvoice_fdddf/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fdddf</groupId>
<artifactId>ocrinvoice</artifactId>
<name>增值税发票识别和校验</name>
<description>增值税发票识别、增值税发票核验、增值税发票(卷票)识别</description>
<version>1.0.5</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nasl.ide.version>3.3</nasl.ide.version>
</properties>
<dependencies>
<!--本案例是本地系统引入nasl-metadata-collector-0.8.0.jar的方式。
若把nasl-metadata-collector-0.8.0.jar安装到自己的maven仓库,
注意修改artifactId和groupId的情况下,不要使用<scope>system</scope>,会在发布时造成依赖中断。
不修改artifactId和groupId的情况下,nasl-metadata-maven-plugin会做特殊处理-->
<dependency>
<artifactId>nasl-metadata-collector</artifactId>
<groupId>com.netease.lowcode</groupId>
<version>0.8.0</version>
<optional>true</optional>
<scope>system</scope>
<systemPath>${project.basedir}/jar/nasl-metadata-collector-0.8.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.netease.lowcode</groupId>
<artifactId>nasl-metadata-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<jarWithDependencies>false</jarWithDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>archive</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.fdddf.ocrinvoice;

import com.fdddf.ocrinvoice.jmininvoice.AliyunJminInvocieValidate;
import com.fdddf.ocrinvoice.jmininvoice.InvoiceCheckRequest;
import com.fdddf.ocrinvoice.jmininvoice.InvoiceCheckResponse;
import com.fdddf.ocrinvoice.ocrinvoice.AliyunOcrInvoice;
import com.fdddf.ocrinvoice.ocrinvoice.OcrInvoiceRequest;
import com.fdddf.ocrinvoice.ocrinvoice.OcrInvoiceResponse;
import com.fdddf.ocrinvoice.rollticket.AliyunOcrRollTicket;
import com.fdddf.ocrinvoice.rollticket.RollTicketResponse;
import com.fdddf.ocrinvoice.rollticket.RollTicketRequest;
import com.netease.lowcode.core.annotation.NaslConnector;

import java.util.function.Function;

@NaslConnector(connectorKind = "invoiceOcr")
public class InvoiceOcrConnector {
private String appCode;

@NaslConnector.Creator
public InvoiceOcrConnector initBean(String appCode) {
InvoiceOcrConnector connector = new InvoiceOcrConnector();
connector.appCode = appCode;
return connector;
}

@NaslConnector.Tester
public Boolean test(String appCode) {
return null != appCode;
}

/**
* 卷票识别
*
* @param request RollTicketRequest
* @return RollTicketInvoice
*/
@NaslConnector.Logic
public RollTicketResponse rollTicketOcr(RollTicketRequest request) {
AliyunOcrRollTicket aliyunOcrRollTicket = new AliyunOcrRollTicket();
return aliyunOcrRollTicket.request(this.appCode, request);
}

/**
* 发票识别
*
* @param request OcrInvoiceRequest
* @return OcrInvoiceResponse
*/
@NaslConnector.Logic
public OcrInvoiceResponse invoiceOcr(OcrInvoiceRequest request) {
AliyunOcrInvoice aliyunOcrInvoice = new AliyunOcrInvoice();
return aliyunOcrInvoice.request(this.appCode, request);
}

/**
* 发票校验
*
* @param req InvoiceCheckRequest
* @return InvoiceCheckResult
*/
@NaslConnector.Logic
public InvoiceCheckResponse invoiceCheck(InvoiceCheckRequest req) {
AliyunJminInvocieValidate aliyunJminInvocieValidate = new AliyunJminInvocieValidate();
return aliyunJminInvocieValidate.request(this.appCode, req);
}

/**
* 测试触发器,暂无用
*
* @param msg String
* @param handleMsg Function<String, String>
*/
@NaslConnector.Trigger
public void testTrigger(String msg, Function<String, String> handleMsg) {
handleMsg.apply(msg);
}

public static void main(String[] args) {
System.out.println("hello world");

InvoiceOcrConnector connector = new InvoiceOcrConnector().initBean("ffbd4a857cf045219e2cb6a8970c0f56");
RollTicketRequest request = new RollTicketRequest("https://lankuaiji.cn/img/roll_ticket.jpg", "");
RollTicketResponse result = connector.rollTicketOcr(request);
System.out.println(result.data.invoiceNumber);
System.out.println(result.data.buyerName);
System.out.println(result.data.sellerName);

OcrInvoiceRequest request2 = new OcrInvoiceRequest("https://fapiao.youshang.com/zx/wp-content/uploads/2020/01/20160831113346-1157589472.png", "", 1);
OcrInvoiceResponse result2 = connector.invoiceOcr(request2);
System.out.println(result2.data.invoiceCode);
System.out.println(result2.data.invoiceNumber);
System.out.println(result2.data.invoiceDate);

InvoiceCheckRequest request3 = new InvoiceCheckRequest("24617000000027471236", "20240418", "", "", "55.93");
InvoiceCheckResponse result3 = connector.invoiceCheck(request3);
System.out.println(result3.ret_message);
System.out.println(result3.code);
System.out.println(result3.data.result);

connector.testTrigger("123", new Function<String, String>() {
@Override
public String apply(String s) {
return null;
}
});
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.fdddf.ocrinvoice.jmininvoice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fdddf.ocrinvoice.rollticket.AliyunOcrRollTicket;
import com.fdddf.ocrinvoice.utils.HttpUtils;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
* 【聚美智数】发票查验-增值税发票查验
* <a href="https://market.aliyun.com/apimarket/detail/cmapi00050226">API</a>
*/
public class AliyunJminInvocieValidate {
private static final Logger log = LoggerFactory.getLogger(AliyunOcrRollTicket.class);

/**
* @param appCode appCode
* @param req InvoiceCheckRequest
* @return InvoiceCheckResponse
*/
public InvoiceCheckResponse request(String appCode, InvoiceCheckRequest req) throws RuntimeException {
if (appCode.isEmpty() || !req.validate()) {
throw new RuntimeException("appCode、fphm、fprq不能为空");
}
try {
String host = "https://jminvoice.market.alicloudapi.com";
String path = "/invoice/validate";
String method = "POST";
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + appCode);
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>();
Map<String, String> bodys = new HashMap<String, String>();
bodys.put("bhsje", req.bhsje);
bodys.put("fpdm", req.fpdm);
bodys.put("fphm", req.fphm);
bodys.put("kprq", req.kprq);
bodys.put("xym", req.xym);

HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
System.out.println(response.toString());
String bodyString = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println(bodyString);
return JSONObject.toJavaObject(JSON.parseObject(bodyString), InvoiceCheckResponse.class);
} catch (Exception e) {
log.error("request error", e);
throw new RuntimeException(e);
}
}
}
Loading
Loading