原文:
blog.csdn.net/weixin_44385486/article/details/126481493

一、前语

今天公司领导提出一个功用,说完结一个文件的签字+盖章功用,然后自己进行了简略的学习,对文档进行数字签名与签署纸质文档的原因大致相同,数字签名通过运用计算机加密来验证 (身份验证:验证人员和产品所声明的身份是否事实的进程。例如,通过验证用于签名代码的数字签名来供认软件发行商的代码来历和完好性。)数字信息,如文档、电子邮件和宏。数字签名有助于确保:真实性,完好性,不可否认性。现在市面上的电子签章产品也是多样化,但是不论是哪个厂家的产品,在线签章简略易用,一同也能确保签章的有效性,防篡改,防伪造,安稳,可靠便是好产品。

此次开源的体系模仿演示了文件在OA体系中的流转,首要为作业体系跨途径在线处理Office文档供给了完美的解决方案。Word文档在线处理的中心环节,包括:起草文档、领导阅读、核稿、领导盖章、正式发文。PageOffice产品支撑PC端Word文档在线处理的全部环节;MobOffice产品支撑了移动端领导阅读和领导盖章的功用。支撑PC端和移动端对文档阅读和盖章的互认。然后此次博客中运用的卓正软件的电子签章选用自主常识产权的中心智能识别验证技术,确保文档安全可靠。选用 COM、ActiveX嵌入式技术开发,确保软件能够支撑多种使用。遵从《中华人民共和国电子签名法》关于电子签名的标准,一同支撑世界通用的 RSA算法,符合国家安全标准。

PageOffice和MobOffice产品结合运用为跨途径处理Office文件供给了完美的解决方案,首要功用有word在线修正保存和留痕,word和pdf文件在线盖章(电子印章)。

举荐:SpringBoot2全套教程下载地址 想稳固springboot常识的能够学习一下

二、项目源码及安置

1、项目结构及运用框架

该签字+盖章流程体系运用了SpringBoot+thymeleaf完结的,然后jar包依靠运用了maven

SpringBoot完成电子文件签字+合同体系!

  • 控制层
@Controller
@RequestMapping("/mobile")
publicclassMobileOfficeController{
@Value("${docpath}")
privateStringdocPath;
@Value("${moblicpath}")
privateStringmoblicpath;
@Autowired
DocServicem_docService;
/**
*添加MobOffice的服务器端授权程序Servlet(必须)
*
*/
@RequestMapping("/opendoc")
publicvoidopendoc(HttpServletRequestrequest,HttpServletResponseresponse,HttpSessionsession,Stringtype,StringuserName)throwsException{
StringfileName="";
userName=URLDecoder.decode(userName,"utf-8");
Docdoc=m_docService.getDocById(1);
if(type.equals("word")){
fileName=doc.getDocName();
}else{
fileName=doc.getPdfName();
}
OpenModeTypeopenModeType=OpenModeType.docNormalEdit;
if(fileName.endsWith(".doc")){
openModeType=OpenModeType.docNormalEdit;
}elseif(fileName.endsWith(".pdf")){
Stringmode=request.getParameter("mode");
if(mode.equals("normal")){
openModeType=OpenModeType.pdfNormal;
}else{
openModeType=OpenModeType.pdfReadOnly;
}
}
MobOfficeCtrlmobCtrl=newMobOfficeCtrl(request,response);
mobCtrl.setSysPath(moblicpath);
mobCtrl.setServerPage("/mobserver.zz");
//mobCtrl.setZoomSealServer("http://xxx.xxx.xxx.xxx:8080/ZoomSealEnt/enserver.zz");
mobCtrl.setSaveFilePage("/mobile/savedoc?testid="+Math.random());
mobCtrl.webOpen("file://"+docPath+fileName,openModeType,userName);
}
@RequestMapping("/savedoc")
publicvoidsavedoc(HttpServletRequestrequest,HttpServletResponseresponse){
FileSaverfs=newFileSaver(request,response);
fs.saveToFile(docPath+fs.getFileName());
fs.close();
}
}
  • 项目业务层源码
@Service
publicclassDocServiceImplimplementsDocService{
@Autowired
DocMapperdocMapper;
@Override
publicDocgetDocById(intid)throwsException{
Docdoc=docMapper.getDocById(id);
//假如doc为null的话,页面全部doc.特点都报错
if(doc==null){
doc=newDoc();
}
returndoc;
}
@Override
publicIntegeraddDoc(Docdoc)throwsException{
intid=docMapper.addDoc(doc);
returnid;
}
@Override
publicIntegerupdateStatusForDocById(Docdoc)throwsException{
intid=docMapper.updateStatusForDocById(doc);
returnid;
}
@Override
publicIntegerupdateDocNameForDocById(Docdoc)throwsException{
intid=docMapper.updateDocNameForDocById(doc);
returnid;
}
@Override
publicIntegerupdatePdfNameForDocById(Docdoc)throwsException{
intid=docMapper.updatePdfNameForDocById(doc);
returnid;
}
}
  • 仿制文件
publicclassCopyFileUtil{
//仿制文件
publicstaticbooleancopyFile(StringoldPath,StringnewPath)throwsException{
booleancopyStatus=false;
intbytesum=0;
intbyteread=0;
Fileoldfile=newFile(oldPath);
if(oldfile.exists()){//文件存在时
InputStreaminStream=newFileInputStream(oldPath);//读入原文件
FileOutputStreamfs=newFileOutputStream(newPath);
byte[]buffer=newbyte[1444];
intlength;
while((byteread=inStream.read(buffer))!=-1){
bytesum+=byteread;//字节数文件巨细
//System.out.println(bytesum);
fs.write(buffer,0,byteread);
}
fs.close();
inStream.close();
copyStatus=true;
}else{
copyStatus=false;
}
returncopyStatus;
}
}
  • 二维码源码
publicclassQRCodeUtil{
privateStringcodeText;//二维码内容
privateBarcodeFormatbarcodeFormat;//二维码类型
privateintwidth;//图片宽度
privateintheight;//图片高度
privateStringimageformat;//图片格式
privateintbackColorRGB;//背景色,颜色RGB的数值既能够用十进制表明,也能够用十六进制表明
privateintcodeColorRGB;//二维码颜色
privateErrorCorrectionLevelerrorCorrectionLevel;//二维码纠错才干
privateStringencodeType;
publicQRCodeUtil(){
codeText="www.zhuozhengsoft.com";
barcodeFormat=BarcodeFormat.PDF_417;
width=400;
height=400;
imageformat="png";
backColorRGB=0xFFFFFFFF;
codeColorRGB=0xFF000000;
errorCorrectionLevel=ErrorCorrectionLevel.H;
encodeType="UTF-8";
}
publicQRCodeUtil(Stringtext){
codeText=text;
barcodeFormat=BarcodeFormat.PDF_417;
width=400;
height=400;
imageformat="png";
backColorRGB=0xFFFFFFFF;
codeColorRGB=0xFF000000;
errorCorrectionLevel=ErrorCorrectionLevel.H;
encodeType="UTF-8";
}
publicStringgetCodeText(){
returncodeText;
}
publicvoidsetCodeText(StringcodeText){
this.codeText=codeText;
}
publicBarcodeFormatgetBarcodeFormat(){
returnbarcodeFormat;
}
publicvoidsetBarcodeFormat(BarcodeFormatbarcodeFormat){
this.barcodeFormat=barcodeFormat;
}
publicintgetWidth(){
returnwidth;
}
publicvoidsetWidth(intwidth){
this.width=width;
}
publicintgetHeight(){
returnheight;
}
publicvoidsetHeight(intheight){
this.height=height;
}
publicStringgetImageformat(){
returnimageformat;
}
publicvoidsetImageformat(Stringimageformat){
this.imageformat=imageformat;
}
publicintgetBackColorRGB(){
returnbackColorRGB;
}
publicvoidsetBackColorRGB(intbackColorRGB){
this.backColorRGB=backColorRGB;
}
publicintgetCodeColorRGB(){
returncodeColorRGB;
}
publicvoidsetCodeColorRGB(intcodeColorRGB){
this.codeColorRGB=codeColorRGB;
}
publicErrorCorrectionLevelgetErrorCorrectionLevel(){
returnerrorCorrectionLevel;
}
publicvoidsetErrorCorrectionLevel(ErrorCorrectionLevelerrorCorrectionLevel){
this.errorCorrectionLevel=errorCorrectionLevel;
}
privateBufferedImagetoBufferedImage(BitMatrixbitMatrix){
intwidth=bitMatrix.getWidth();
intheight=bitMatrix.getHeight();
BufferedImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
for(intx=0;x<width;x++){
for(inty=0;y<height;y++){
image.setRGB(x,y,bitMatrix.get(x,y)?this.codeColorRGB:this.backColorRGB);
}
}
returnimage;
}
privatebyte[]writeToBytes(BitMatrixbitMatrix)
throwsIOException{
try{
BufferedImagebufferedimage=toBufferedImage(bitMatrix);
//将图片保存到暂时路径中
Filefile=java.io.File.createTempFile("~pic","."+this.imageformat);
//System.out.println("暂时图片路径:"+file.getPath());
ImageIO.write(bufferedimage,this.imageformat,file);
//获取图片转换成的二进制数组
FileInputStreamfis=newFileInputStream(file);
intfileSize=fis.available();
byte[]imageBytes=newbyte[fileSize];
fis.read(imageBytes);
fis.close();
//删去暂时文件
if(file.exists()){
file.delete();
}
returnimageBytes;
}catch(Exceptione){
System.out.println("Imageerr:"+e.getMessage());
returnnull;
}
}
//获取二维码图片的字节数组
publicbyte[]getQRCodeBytes()
throwsIOException{
try{
MultiFormatWritermultiFormatWriter=newMultiFormatWriter();
//设置二维码参数
Maphints=newHashMap();
if(this.errorCorrectionLevel!=null){
//设置二维码的纠错级别
hints.put(EncodeHintType.ERROR_CORRECTION,this.errorCorrectionLevel);
}
if(this.encodeType!=null&&this.encodeType.trim().length()>0){
//设置编码方法
hints.put(EncodeHintType.CHARACTER_SET,this.encodeType);
}
BitMatrixbitMatrix=multiFormatWriter.encode(this.codeText,BarcodeFormat.QR_CODE,this.width,this.height,hints);
byte[]bytes=writeToBytes(bitMatrix);
returnbytes;
}catch(Exceptione){
e.printStackTrace();
returnnull;
}
}
}

2、项目下载及安置

  • 项目源码下载地址:download.csdn.net/download/we…
  • 下载项目源码后,运用idea导入slndemo项目并运行

SpringBoot完成电子文件签字+合同体系!

  • 将项目slndemo下的slndemodata.zip压缩包仿制到本地D盘根目录下并解压
  • 点击启动项目

SpringBoot完成电子文件签字+合同体系!

三、功用展示

1、项目启动后登录首页

  • 项目地址:http://localhost:8888/pc/login
  • 账户:张三 暗码:123456

SpringBoot完成电子文件签字+合同体系!

2、体系首页功用简介

这是一个简略的Demo项目,模仿Word文件在作业体系中的首要流转环节,并不意味着PageOffice产品只能支撑这样的文档处理流程。PageOffice产品只供给文档在线处理的功用,包括:翻开、修正、保存、动态填充、文档兼并、套红、留痕、盖章等上百项功用(具体请参阅PageOffice产品开发包中的示例),不供给流程控制功用,所以不论开发什么样的Web体系,只要是需求在线处理Office文档,都能够根据自己的项目需求,调用PageOffice产品相应的功用即可。「留心:为了简化代码逻辑,此演示程序只能创建一个文档进行流转。」

3、点击起草文档

  • 点击起草文档,点击提交
  • 点击署理文档,然后点击修正,当你点击修正时你没有下载PageOffice,他会提示你设备,你点击设备之后,封闭浏览器,重新翻开浏览器就能修正了!

SpringBoot完成电子文件签字+合同体系!

  • 我们运用了PageOffice企业版,必需求注册序列化
  • 版 本:PageOffice企业版5(试用)
  • 序列号:35N8V-2YUC-LY77-W14XL

SpringBoot完成电子文件签字+合同体系!

  • 当我们注册成功往后,就能够修正发布的文件或许公告了

SpringBoot完成电子文件签字+合同体系!

  • 修正好往后点击保存
  • 点击阅读

4、阅读

  • 登录李总阅读

SpringBoot完成电子文件签字+合同体系!

  • 退出体系,然后输入李总

SpringBoot完成电子文件签字+合同体系!

  • 然后点击阅读,下一步

SpringBoot完成电子文件签字+合同体系!

  • 登录赵六进行审阅稿子

5、审稿

  • 审稿

SpringBoot完成电子文件签字+合同体系!

  • 审阅然后到盖章环节

SpringBoot完成电子文件签字+合同体系!

  • 运用王总登录进行盖章

SpringBoot完成电子文件签字+合同体系!

6、盖章和签字的完结

  • 王总登录

SpringBoot完成电子文件签字+合同体系!

  • 点击盖章
  • 点击加盖印章
  • 我们盖章前需求输入姓名+暗码,需求输入过错报错

SpringBoot完成电子文件签字+合同体系!

  • 正确的账户暗码是:
  • 账户:王五
  • 暗码:123456

SpringBoot完成电子文件签字+合同体系!

  • 登录成功后有挑选王五的个人章进行签字

SpringBoot完成电子文件签字+合同体系!

  • 签字成功
  • 公司盖章,重复以上进程

SpringBoot完成电子文件签字+合同体系!

  • 签字盖章成功

SpringBoot完成电子文件签字+合同体系!

7、完好签字盖章文件

  • 保存之后发布文件

SpringBoot完成电子文件签字+合同体系!

  • 公司文件展示
  • 盖章签字后的文件

SpringBoot完成电子文件签字+合同体系!