原文:
blog.csdn.net/weixin_44385486/article/details/126481493
一、前言
今天公司領導提出一個功能莺戒,說實現(xiàn)一個文件的簽字+蓋章功能伴嗡,然后自己進行了簡單的學習,對文檔進行數(shù)字簽名與簽署紙質(zhì)文檔的原因大致相同从铲,數(shù)字簽名通過使用計算機加密來驗證 (身份驗證:驗證人員和產(chǎn)品所聲明的身份是否屬實的過程瘪校。例如,通過驗證用于簽名代碼的數(shù)字簽名來確認軟件發(fā)行商的代碼來源和完整性名段。)數(shù)字信息阱扬,如文檔、電子郵件和宏伸辟。數(shù)字簽名有助于確保:真實性麻惶,完整性,不可否認性信夫。目前市面上的電子簽章產(chǎn)品也是多樣化窃蹋,但是不管是哪個廠家的產(chǎn)品,在線簽章簡單易用静稻,同時也能保證簽章的有效性警没,防篡改,防偽造姊扔,穩(wěn)定惠奸,可靠就是好產(chǎn)品梅誓。
此次開源的系統(tǒng)模擬演示了文件在OA系統(tǒng)中的流轉(zhuǎn)恰梢,主要為辦公系統(tǒng)跨平臺在線處理Office文檔提供了完美的解決方案。Word文檔在線處理的核心環(huán)節(jié)梗掰,包括:起草文檔嵌言、領導審批、核稿及穗、領導蓋章摧茴、正式發(fā)文。PageOffice產(chǎn)品支持PC端Word文檔在線處理的所有環(huán)節(jié)埂陆;MobOffice產(chǎn)品支持了移動端領導審批和領導蓋章的功能苛白。支持PC端和移動端對文檔審批和蓋章的互認娃豹。然后此次博客中使用的卓正軟件的電子簽章采用自主知識產(chǎn)權的核心智能識別驗證技術,確保文檔安全可靠购裙。采用 COM懂版、ActiveX嵌入式技術開發(fā),確保軟件能夠支持多種應用躏率。遵循《中華人民共和國電子簽名法》關于電子簽名的規(guī)范躯畴,同時支持國際通用的 RSA算法后控,符合國家安全標準稠炬。
PageOffice和MobOffice產(chǎn)品結合使用為跨平臺處理Office文件提供了完美的解決方案,主要功能有word在線編輯保存和留痕凉当,word和pdf文件在線蓋章(電子印章)夯到。
推薦:2022年Java面試題整理 持續(xù)更新中
二嚷缭、項目源碼及部署
1、項目結構及使用框架
該簽字+蓋章流程系統(tǒng)使用了SpringBoot+thymeleaf實現(xiàn)的耍贾,然后jar包依賴使用了maven
- 控制層
@Controller
@RequestMapping("/mobile")
public class MobileOfficeController {
@Value("${docpath}")
private String docPath;
@Value("${moblicpath}")
private String moblicpath;
@Autowired
DocService m_docService;
/**
* 添加MobOffice的服務器端授權程序Servlet(必須)
*
*/
@RequestMapping("/opendoc")
public void opendoc(HttpServletRequest request, HttpServletResponse response, HttpSession session,String type,String userName)throws Exception {
String fileName = "";
userName= URLDecoder.decode(userName,"utf-8");
Doc doc=m_docService.getDocById(1);
if(type.equals("word")){
fileName = doc.getDocName();
}else{
fileName = doc.getPdfName();
}
OpenModeType openModeType = OpenModeType.docNormalEdit;
if (fileName.endsWith(".doc")) {
openModeType = OpenModeType.docNormalEdit;
} else if (fileName.endsWith(".pdf")) {
String mode = request.getParameter("mode");
if (mode.equals("normal")) {
openModeType = OpenModeType.pdfNormal;
} else {
openModeType = OpenModeType.pdfReadOnly;
}
}
MobOfficeCtrl mobCtrl = new MobOfficeCtrl(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")
public void savedoc(HttpServletRequest request, HttpServletResponse response){
FileSaver fs = new FileSaver(request, response);
fs.saveToFile(docPath+fs.getFileName());
fs.close();
}
}
- 項目業(yè)務層源碼
@Service
public class DocServiceImpl implements DocService {
@Autowired
DocMapper docMapper;
@Override
public Doc getDocById(int id) throws Exception {
Doc doc=docMapper.getDocById(id);
//如果doc為null的話峭状,頁面所有doc.屬性都報錯
if(doc==null) {
doc=new Doc();
}
return doc;
}
@Override
public Integer addDoc(Doc doc) throws Exception {
int id=docMapper.addDoc(doc);
return id;
}
@Override
public Integer updateStatusForDocById(Doc doc) throws Exception {
int id=docMapper.updateStatusForDocById(doc);
return id;
}
@Override
public Integer updateDocNameForDocById(Doc doc) throws Exception {
int id=docMapper.updateDocNameForDocById(doc);
return id;
}
@Override
public Integer updatePdfNameForDocById(Doc doc) throws Exception {
int id=docMapper.updatePdfNameForDocById(doc);
return id;
}
}
- 拷貝文件
public class CopyFileUtil {
//拷貝文件
public static boolean copyFile(String oldPath, String newPath) throws Exception {
boolean copyStatus=false;
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在時
InputStream inStream = new FileInputStream(oldPath); //讀入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
int length;
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字節(jié)數(shù) 文件大小
//System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
fs.close();
inStream.close();
copyStatus=true;
}else{
copyStatus=false;
}
return copyStatus;
}
}
- 二維碼源碼
public class QRCodeUtil {
private String codeText;//二維碼內(nèi)容
private BarcodeFormat barcodeFormat;//二維碼類型
private int width;//圖片寬度
private int height;//圖片高度
private String imageformat;//圖片格式
private int backColorRGB;//背景色,顏色RGB的數(shù)值既可以用十進制表示逼争,也可以用十六進制表示
private int codeColorRGB;//二維碼顏色
private ErrorCorrectionLevel errorCorrectionLevel;//二維碼糾錯能力
private String encodeType;
public QRCodeUtil() {
codeText = "www.zhuozhengsoft.com";
barcodeFormat = BarcodeFormat.PDF_417;
width = 400;
height = 400;
imageformat = "png";
backColorRGB = 0xFFFFFFFF;
codeColorRGB = 0xFF000000;
errorCorrectionLevel = ErrorCorrectionLevel.H;
encodeType = "UTF-8";
}
public QRCodeUtil(String text) {
codeText = text;
barcodeFormat = BarcodeFormat.PDF_417;
width = 400;
height = 400;
imageformat = "png";
backColorRGB = 0xFFFFFFFF;
codeColorRGB = 0xFF000000;
errorCorrectionLevel = ErrorCorrectionLevel.H;
encodeType = "UTF-8";
}
public String getCodeText() {
return codeText;
}
public void setCodeText(String codeText) {
this.codeText = codeText;
}
public BarcodeFormat getBarcodeFormat() {
return barcodeFormat;
}
public void setBarcodeFormat(BarcodeFormat barcodeFormat) {
this.barcodeFormat = barcodeFormat;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getImageformat() {
return imageformat;
}
public void setImageformat(String imageformat) {
this.imageformat = imageformat;
}
public int getBackColorRGB() {
return backColorRGB;
}
public void setBackColorRGB(int backColorRGB) {
this.backColorRGB = backColorRGB;
}
public int getCodeColorRGB() {
return codeColorRGB;
}
public void setCodeColorRGB(int codeColorRGB) {
this.codeColorRGB = codeColorRGB;
}
public ErrorCorrectionLevel getErrorCorrectionLevel() {
return errorCorrectionLevel;
}
public void setErrorCorrectionLevel(ErrorCorrectionLevel errorCorrectionLevel) {
this.errorCorrectionLevel = errorCorrectionLevel;
}
private BufferedImage toBufferedImage(BitMatrix bitMatrix) {
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? this.codeColorRGB: this.backColorRGB);
}
}
return image;
}
private byte[] writeToBytes(BitMatrix bitMatrix)
throws IOException {
try {
BufferedImage bufferedimage = toBufferedImage(bitMatrix);
//將圖片保存到臨時路徑中
File file = java.io.File.createTempFile("~pic","."+ this.imageformat);
//System.out.println("臨時圖片路徑:"+file.getPath());
ImageIO.write(bufferedimage,this.imageformat,file);
//獲取圖片轉(zhuǎn)換成的二進制數(shù)組
FileInputStream fis = new FileInputStream(file);
int fileSize = fis.available();
byte[] imageBytes = new byte[fileSize];
fis.read(imageBytes);
fis.close();
//刪除臨時文件
if (file.exists()) {
file.delete();
}
return imageBytes;
} catch (Exception e) {
System.out.println(" Image err :" + e.getMessage());
return null;
}
}
//獲取二維碼圖片的字節(jié)數(shù)組
public byte[] getQRCodeBytes()
throws IOException {
try {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
//設置二維碼參數(shù)
Map hints = new HashMap();
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);
}
BitMatrix bitMatrix = multiFormatWriter.encode(this.codeText, BarcodeFormat.QR_CODE, this.width, this.height, hints);
byte[] bytes = writeToBytes(bitMatrix);
return bytes;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
2优床、項目下載及部署
- 項目源碼下載地址:https://download.csdn.net/download/weixin_44385486/86427996
- 下載項目源碼后,使用idea導入slndemo項目并運行
- 將項目slndemo下的slndemodata.zip壓縮包拷貝到本地D盤根目錄下并解壓
- 點擊啟動項目
三誓焦、功能展示
1胆敞、項目啟動后登錄首頁
- 項目地址:
http://localhost:8888/pc/login
- 賬戶:張三 密碼:123456
2、系統(tǒng)首頁功能簡介
這是一個簡單的Demo項目杂伟,模擬Word文件在辦公系統(tǒng)中的主要流轉(zhuǎn)環(huán)節(jié)移层,并不意味著PageOffice產(chǎn)品只能支持這樣的文檔處理流程。PageOffice產(chǎn)品只提供文檔在線處理的功能赫粥,包括:打開观话、編輯、保存越平、動態(tài)填充频蛔、文檔合并、套紅秦叛、留痕晦溪、蓋章等上百項功能(詳細請參考PageOffice產(chǎn)品開發(fā)包中的示例),不提供流程控制功能挣跋,所以不管開發(fā)什么樣的Web系統(tǒng)三圆,只要是需要在線處理Office文檔,都可以根據(jù)自己的項目需要,調(diào)用PageOffice產(chǎn)品相應的功能即可舟肉。「注意:為了簡化代碼邏輯修噪,此演示程序只能創(chuàng)建一個文檔進行流轉(zhuǎn)÷访模」
3割按、點擊起草文檔
- 點擊起草文檔,點擊提交
- 點擊代辦文檔磷籍,然后點擊編輯适荣,當你點擊編輯時你沒有下載PageOffice,他會提醒你安裝院领,你點擊安裝之后弛矛,關閉瀏覽器,重新打開瀏覽器就能編輯了比然!
- 我們使用了PageOffice企業(yè)版丈氓,必須要注冊序列化
- 版 本:PageOffice企業(yè)版5(試用)
- 序列號:35N8V-2YUC-LY77-W14XL
- 當我們注冊成功以后,就可以編輯發(fā)布的文件或者公告了
- 編輯好以后點擊保存
- 點擊審批
4强法、審批
- 登錄李總審批
- 退出系統(tǒng)万俗,然后輸入李總
- 然后點擊批閱,下一步
- 登錄趙六進行審核稿子
5饮怯、審稿
- 審稿
- 審核然后到蓋章環(huán)節(jié)
- 使用王總登錄進行蓋章
6闰歪、蓋章和簽字的實現(xiàn)
- 王總登錄
- 點擊蓋章
- 點擊加蓋印章
- 我們蓋章前需要輸入姓名+密碼,需要輸入錯誤報錯
- 正確的賬戶密碼是:
- 賬戶:王五
- 密碼:123456
- 登錄成功后有選擇王五的個人章進行簽字
- 簽字成功
- 公司蓋章蓖墅,重復以上步驟
- 簽字蓋章成功
7库倘、完整簽字蓋章文件
- 保存之后發(fā)布文件
- 公司文件展示
- 蓋章簽字后的文件