wordpress 站群注意,养生馆室内设计,罗湖商城网站建设找哪家公司好,制作公众号的平台1.发现base64编码对同一张图片编码好像不会改变 用word文档的查重#xff0c;似乎是一模一样的
于是去看了一下CSDN
1.1.base64编码原理
编码原理 使用 Base64 进行编码#xff0c;大致可以分为 4 步#xff1a; 将原始数据每三个字节作为一组#xff0c;一共是 24 个 …1.发现base64编码对同一张图片编码好像不会改变 用word文档的查重似乎是一模一样的
于是去看了一下CSDN
1.1.base64编码原理
编码原理 使用 Base64 进行编码大致可以分为 4 步 将原始数据每三个字节作为一组一共是 24 个 bit将 24 个 bit 分为四组每组 6 个 bit在每组前面加两个 00扩展成 32 个 bit即四个字节根据下标得到扩展后每个字节的对应符号 1.2.更改代码逻辑
所以可以用base64编码来判断文件是否重复
2.更改数据库添加字段
2.1.改了下invoice表 2.2.改了一下image表 3.美化界面
3.1.识别界面 3.2.文件上传界面 3.3.数据预览界面 4.从源码找出了预览图片的请求
4.1.F12的源代码中找出图片预览的代码 4.2.从源代码打开访问链接查看代码路径
hocalhost:44203/Forguncy/Upload/93ec3707-18f2-4803-b415-66106d47e875_blackpig.png?imageSize0 4.3.解析出访问路径的代码
var page Forguncy.Page;
var imageUrlCell page.getCell(image_url);
var codeCell page.getCell(img_code);var img http://${window.location.host}/Forguncy/Upload/codeCell.getValue();
imageUrlCell.setValue(img);4.4.将url嵌入页面 5.再次修改代码逻辑
5.1.识别
// 获取当前页面上名称为account的单元格
// 获取当前页面
var page Forguncy.Page;
var access_token page.getCell(access_token).getValue();var invoiceTypeChooseCell page.getCell(invoice_type_choose);var invoiceCodeCell page.getCell(invoice_code);
var invoiceNumCell page.getCell(invoice_num);
var invoiceDateCell page.getCell(invoice_date);
var invoiceTypeCell page.getCell(invoice_type);
var checkCodeCell page.getCell(check_code);
var totalAmountCell page.getCell(total_amount);
var invoiceImgIdCell page.getCell(invoice_img_id);var imgIdCell page.getCell(img_id);
var imageBase64Cell page.getCell(image_base64);var identifyResultCell page.getCell(identify_result);var isRepeatCell page.getCell(is_repeat);
var errorCell page.getCell(error);var imageBase64 imageBase64Cell.getValue();//直接发送百度AI识别请求
InvoiceIdentificationPost(imageBase64);function InvoiceIdentificationPost(imageBase64) {//获取单元格的值var data {//传入请求地址token: access_token, imageUrl: imageBase64};console.log(***发送百度AI*发票识别*请求***);Forguncy.Helper.post(customapi/fapiaoapi/vatinvoicebyimg, data, function (res) {console.log(res: res);let jsonData JSON.parse(res);if (jsonData.words_result undefined || jsonData.words_result null) {alert(发送百度AI发票识别请求失败: jsonData.error_msg);errorCell.setValue(发送百度AI发票识别请求失败);return;}jsonData jsonData.words_result;console.log(jsonData);//获取发票类型let invoiceType invoiceTypeChooseCell.getValue();console.log(获取发票类型 invoiceType);//获取不到自动识别if (invoiceType || invoiceType null) {console.log(jsonData.InvoiceType);invoiceType translateInvoiceType(jsonData.InvoiceType);}console.log(识别发票类型 invoiceType);//识别不到if (invoiceType || invoiceType null) {console.log(无法自动识别出发票类型);alert(无法自动识别出发票类型请手动选择发票类型);errorCell.setValue(无法自动识别出发票类型请手动选择发票类型);return;}invoiceCodeCell.setValue(jsonData.InvoiceCode);invoiceNumCell.setValue(jsonData.InvoiceNum);invoiceDateCell.setValue(convertDateFormat(jsonData.InvoiceDate));invoiceTypeCell.setValue(invoiceType);invoiceImgIdCell.setValue(imgIdCell.getValue());let checkCode jsonData.CheckCode;/*** 处理分类逻辑*/// 发票金额// 增值税专票、电子专票、区块链电子发票、机动车销售发票、货运专票填写不含税金额// 二手车销售发票填写车价合计// 全电发票专用发票、全电发票普通发票填写价税合计金额// 其他类型发票可为空if (invoiceType elec_invoice_special || invoiceType elec_invoice_normal) {console.log(价税合计金额);//价税合计金额totalAmountCell.setValue(jsonData.AmountInFiguers);} else if (invoiceType used_vehicle_invoice) {console.log(车价合计);//车价合计totalAmountCell.setValue(jsonData.AmountInFiguers);} else {console.log(不含税金额);// 不含税金额totalAmountCell.setValue(jsonData.TotalAmount);}//invoice_code:全电发票专用发票、全电发票普通发票此参数可为空if (invoiceType ! elec_invoice_special invoiceType ! elec_invoice_normal) {//其他的类型不能为空if (jsonData.InvoiceCode || jsonData.InvoiceCode null) {alert(发票代码不可为空请核对发票类型);errorCell.setValue(发票代码不可为空请核对发票类型);return;}}//校验码。填写发票校验码后6位。//增值税电子专票、普票、电子普票、卷票、//区块链电子发票、通行费增值税电子普通发票此参数必填if (invoiceType elec_special_vat_invoice || invoiceType normal_invoice || invoiceType elec_normal_invoice || invoiceType roll_normal_invoice || invoiceType blockchain_invoice || invoiceType toll_elec_normal_invoice) {console.log(需要校验码);if (checkCode ! checkCode ! null) {checkCode getLastSixDigits(checkCode);console.log(checkCode);checkCodeCell.setValue(checkCode);} else {alert(校验码不可为空请核对发票类型);errorCell.setValue(校验码不可为空请核对发票类型);return;}} else {console.log(不需要校验码);checkCodeCell.setValue(checkCode);}identifyResultCell.setValue(JSON.stringify(jsonData));//后续操作//判断发票是否重复,并修改数据库if (errorCell.getValue() null) {editDataBase();} else {//重置errorCellerrorCell.setValue(null);}});
}//日期格式转换
function convertDateFormat(inputDateString) {// 使用正则表达式提取数字var numbersArray inputDateString.match(/\d/g);// 将数字字符串拼接在一起var outputDateString numbersArray.join();return outputDateString;
}//发票类型自动识别转换
function translateInvoiceType(chineseInvoiceType) {var translationMap {//增值税专票、电子专票、区块链电子发票、机动车销售发票、货运专票填写不含税金额电子专用发票: elec_special_vat_invoice,普通发票(电子): elec_normal_invoice,电子普通发票: elec_normal_invoice,普通发票(卷式): roll_normal_invoice,卷式普通发票: roll_normal_invoice,通行费增值税电子普通发票: toll_elec_normal_invoice,区块链电子发票: blockchain_invoice, // 全电发票专用发票、全电发票普通发票填写价税合计金额全电发票(专用发票): elec_invoice_special,电子发票(专用发票): elec_invoice_special,全电发票(普通发票): elec_invoice_normal,电子发票(普通发票): elec_invoice_normal,货运运输业增值税专用发票: special_freight_transport_invoice,机动车销售发票: motor_vehicle_invoice, //二手车销售发票填写车价合计二手车销售发票: used_vehicle_invoice,普通发票: normal_invoice,专用发票: special_vat_invoice,};// 检查输入的中文发票类型是否在映射中如果是则返回对应的英文翻译否则返回原始值for (var chineseType in translationMap) {if (chineseInvoiceType.includes(chineseType)) {return translationMap[chineseType];}}// 如果未找到匹配的中文发票类型则返回空值return ;
}//获取发票校验码后六位数
function getLastSixDigits(str) {// 通过正则表达式匹配字符串中的数字const matches str.match(/\d/g);// 如果有匹配到数字if (matches) {// 获取最后一个匹配到的数字const lastNumber matches[matches.length - 1];// 如果数字的长度大于等于六位则返回后六位if (lastNumber.length 6) {return lastNumber.slice(-6);} else {// 如果数字的长度小于六位则直接返回该数字return lastNumber;}} else {// 如果没有匹配到数字则返回空字符串或其他适当的值return ;}
}function editDataBase() {Forguncy.getTableData(invoice, {invoice_num: page.getCell(invoice_num).getValue()}, function (data) {console.log(发票重复识别);alert(识别到重复发票请核对发票信息);errorCell.setValue(校验码不可为空请核对发票类型);isRepeatCell.setValue(重复);Forguncy.modifyTablesData({image: {editRows: [{primaryKey: {ID: imgIdCell.getValue()}, values: {is_identify: 重复识别,}}], deleteRows: [{ID: data.img_id}],}, invoice: {// 修改操作editRows: [{primaryKey: {invoice_num: invoiceNumCell.getValue(),}, values: {invoice_code: invoiceCodeCell.getValue(),invoice_date: invoiceDateCell.getValue(),invoice_type: invoiceTypeCell.getValue(),check_code: checkCodeCell.getValue(),total_amount: totalAmountCell.getValue(),is_repeat: isRepeatCell.getValue(),img_id: imgIdCell.getValue()}}]},});}, function (errorMessage) {isRepeatCell.setValue(未重复);Forguncy.modifyTablesData({invoice: {// 添加操作addRows: [{invoice_code: invoiceCodeCell.getValue(),invoice_num: invoiceNumCell.getValue(),invoice_date: invoiceDateCell.getValue(),invoice_type: invoiceTypeCell.getValue(),check_code: checkCodeCell.getValue(),total_amount: totalAmountCell.getValue(),is_repeat: isRepeatCell.getValue(),img_id: imgIdCell.getValue()}]}, image: {editRows: [{primaryKey: {ID: imgIdCell.getValue()}, values: {is_identify: 已识别,}},]}});});
}
5.2验真
// 获取当前页面上名称为account的单元格
// 获取当前页面
var page Forguncy.Page;
var access_token page.getCell(access_token).getValue();
var invoiceCode page.getCell(invoice_code).getValue();
var invoiceNum page.getCell(invoice_num).getValue();
var invoiceDate page.getCell(invoice_date).getValue();
var invoiceType page.getCell(invoice_type).getValue();
var checkCode page.getCell(check_code).getValue();
var totalAmount page.getCell(total_amount).getValue();var imgIdCell page.getCell(invoice_img_id);
var errorCell page.getCell(error);var verifyResultCell page.getCell(verify_result);
//重复条件
var isRepeatCell page.getCell(is_repeat);
var isVerifyCell page.getCell(is_verify);//获取单元格的值
var data {//传入请求地址token: access_token,invoice_code: invoiceCode,invoice_num: invoiceNum,invoice_date: invoiceDate,invoice_type: invoiceType,check_code: checkCode,total_amount: totalAmount,
};console.log(************发票信息显示****************);
console.log(代码: invoiceCode);
console.log(*号码*: invoiceNum);
console.log(日期: invoiceDate);
console.log(类型: invoiceType);
console.log(校验码: checkCode);
console.log(金额: totalAmount);
console.log(**************************************);//初始化
isVerifyCell.setValue(不需要);
/*** 判断是否满足验真条件减少发送请求次数节约成本*/
if (isRepeatCell.getValue() null) {//1.判断没有进行发票识别操作alert(请先识别发票);console.log(请先识别发票);} else if (invoiceNum || invoiceType || invoiceDate || invoiceNum null || invoiceType null || invoiceDate null) {//2.判断必须值为空alert(识别失败无法验真);console.log(识别失败无法验真);} else if (isRepeatCell.getValue() 重复) {//3.重复识别先检索数据库console.log(重复识别检索数据库中字段);// 检索数据库中invoice_num值对应的对象Forguncy.getTableData(invoice, {invoice_num: page.getCell(invoice_num).getValue()},function (data) {// 检索到重复识别if (data.result null) {console.log(发票未验真);isVerifyCell.setValue(需要);InvoiceVerificationPost();}else {if (data.invoice_code ! invoiceCode invoiceCode ! ) {console.log(发票代码不一致需要重新验真);isVerifyCell.setValue(需要);}if (data.invoice_date ! invoiceDate) {console.log(发票日期不一致需要重新验真);isVerifyCell.setValue(需要);}if (data.invoice_type ! invoiceType) {console.log(发票类型不一致需要重新验真);isVerifyCell.setValue(需要);}if (data.check_code ! checkCode checkCode ! ) {console.log(校验码不一致需要重新验真);isVerifyCell.setValue(需要);}if (data.total_amount ! totalAmount totalAmount ! ) {console.log(发票金额不一致需要重新验真);isVerifyCell.setValue(需要);}console.log(isVerifyCell.getValue());if (isVerifyCell.getValue() 不需要) {console.log(发票一致直接输出验真结果);console.log(data.result);verifyResultCell.setValue(data.result);}}if (isVerifyCell.getValue() 需要) {InvoiceVerificationPost();//验真后置空isRepeatCell.setValue();isVerifyCell.setValue();}},function (errorMessage) {//数据库检索到invoice_num才能进入程序按逻辑一定能检索到数据库中对象这个模块无法执行到alert(啊你黑入程序了 Error: errorMessage);return false;});
}if (isRepeatCell.getValue() 未重复) {InvoiceVerificationPost();//验真后置空isRepeatCell.setValue();isVerifyCell.setValue();
}function InvoiceVerificationPost(){/*** 4.百度AI验真请求一次两毛*/console.log(发送百度AI验真请求);Forguncy.Helper.post(customapi/fapiaoapi/vatinvoiceverification, data, function (res) {console.log(res: res);let jsonData JSON.parse(res);console.log(jsonData);verifyResultCell.setValue(jsonData.VerifyMessage);Forguncy.modifyTablesData({invoice: {editRows: [{primaryKey:{invoice_num: invoiceNum},values: {result: jsonData.VerifyMessage,}},]},image: {editRows: [{primaryKey:{ID: imgIdCell.getValue()},values: {is_identify: 已验真,}},]}});});
}