小程序端login demo
This commit is contained in:
@@ -2,7 +2,9 @@ package com.cwhelp.common.api.baidu;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baidu.aip.ocr.AipOcr;
|
||||
import com.cwhelp.common.api.baidu.entity.vatinvoice.TrainResult;
|
||||
import com.cwhelp.common.api.baidu.entity.vatinvoice.VatInvoiceResult;
|
||||
import com.cwhelp.common.enums.InvoiceTypeEnum;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
@@ -41,9 +43,34 @@ public class BaiduAipOCR {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static VatInvoiceResult queryBaiduVatInvoiceApi(File file){
|
||||
public static Object queryBaiduVatInvoiceApi(File file, int invoiceType){
|
||||
byte[] data = null;
|
||||
try {
|
||||
data = getDataByFile(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject result = null;
|
||||
if(invoiceType == InvoiceTypeEnum.TRAIN_INVOICE.getCode()){
|
||||
result = client.trainTicket(data, null);
|
||||
return JSON.parseObject(result.toString(), TrainResult.class);
|
||||
}else if(invoiceType == InvoiceTypeEnum.METRO_INVOICE.getCode()){
|
||||
return null;
|
||||
}else if(invoiceType == InvoiceTypeEnum.MEAL_INVOICE.getCode()){
|
||||
return null;
|
||||
}else {
|
||||
result = client.vatInvoice(data, null);
|
||||
return JSON.parseObject(result.toString(), VatInvoiceResult.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取图片字节数组
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static byte[] getDataByFile(File file){
|
||||
byte[] data = null;
|
||||
// 读取图片字节数组
|
||||
try {
|
||||
InputStream in = new FileInputStream(file);
|
||||
data = new byte[in.available()];
|
||||
@@ -52,9 +79,7 @@ public class BaiduAipOCR {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject result = client.vatInvoice(data, null);
|
||||
VatInvoiceResult vatInvoiceResult = JSON.parseObject(result.toString(), VatInvoiceResult.class);
|
||||
return vatInvoiceResult;
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.cwhelp.common.api.baidu.entity.vatinvoice;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Created by huangjc on 2019/12/3 0003.
|
||||
*/
|
||||
@Data
|
||||
public class TrainResult {
|
||||
|
||||
private String log_id;
|
||||
|
||||
private TrainWordsResult words_result;
|
||||
|
||||
private String words_result_num;
|
||||
|
||||
private String direction;
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.cwhelp.common.api.baidu.entity.vatinvoice;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/12/7 0007.
|
||||
*/
|
||||
@Data
|
||||
public class TrainWordsResult {
|
||||
|
||||
/**
|
||||
* 请求标识码,随机数,唯一。
|
||||
*/
|
||||
private long logId;
|
||||
|
||||
/**
|
||||
* 车票号
|
||||
*/
|
||||
private String ticketNum;
|
||||
|
||||
/**
|
||||
* 始发站
|
||||
*/
|
||||
private String startingStation;
|
||||
|
||||
/**
|
||||
* 车次号
|
||||
*/
|
||||
private String trainNum;
|
||||
|
||||
/**
|
||||
* 到达站
|
||||
*/
|
||||
private String destinationStation;
|
||||
|
||||
/**
|
||||
* 出发日期
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
* 车票金额
|
||||
*/
|
||||
private String ticketRates;
|
||||
|
||||
/**
|
||||
* 席别
|
||||
*/
|
||||
private String seatCategory;
|
||||
|
||||
/**
|
||||
* 乘客姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.cwhelp.common.constant;
|
||||
|
||||
/**
|
||||
* Created by huangjc on 2019/12/2 0002.
|
||||
*/
|
||||
public class ApiConst {
|
||||
|
||||
/**
|
||||
* 假定用户角色名中包含‘api’的为小程序权限用户
|
||||
*/
|
||||
public static final String API_PREMISSION_USER_STR = "api";
|
||||
|
||||
/**
|
||||
* 操作成功
|
||||
*/
|
||||
public static final int API_OPT_SUCCESS_CODE = 200;
|
||||
|
||||
public static final String API_OPT_SUCCESS_MSG = "操作成功";
|
||||
|
||||
public static final String API_LOGIN_SUCCESS_MSG = "登录成功";
|
||||
|
||||
public static final int API_PARAM_BLANK_CODE = 201;
|
||||
|
||||
public static final String API_PARAM_BLANK_MSG = "缺少必要参数";
|
||||
|
||||
public static final int API_NOT_PREMISSION_CODE = 202;
|
||||
|
||||
public static final String API_NOT_PREMISSION_MSG = "没有权限,请到财务帮后台进行授权";
|
||||
|
||||
public static final int API_LOGIN_PWD_ERR_CODE = 203;
|
||||
|
||||
public static final String API_LOGIN_PWD_ERR_MSG = "用户名或密码错误";
|
||||
|
||||
public static final int API_UPLOAD_PICTURE_FAILED_CODE = 204;
|
||||
|
||||
public static final String API_UPLOAD_PICTURE_FAILED_MSG = "上传图片失败";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.cwhelp.common.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Created by huangjc on 2019/12/3 0003.
|
||||
*/
|
||||
@Getter
|
||||
public enum InvoiceTypeEnum {
|
||||
|
||||
TRAIN_INVOICE(1, "通用火车票"),
|
||||
METRO_INVOICE(2, "地铁票"),
|
||||
MEAL_INVOICE(3, "饭票"),
|
||||
ADD_VALUE_TAX_INVOICE(4, "增值税发票");
|
||||
|
||||
InvoiceTypeEnum(int code, String name){
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private int code;
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -15,4 +15,14 @@ public class ResultVo<T> {
|
||||
private String msg;
|
||||
// 响应数据
|
||||
private T data;
|
||||
|
||||
public ResultVo(){
|
||||
|
||||
}
|
||||
|
||||
public ResultVo(Integer code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user