o2oa使用手册
第1章 功能简介及概述
第6章 平台部署与配置
  • 6.1 安装部署-在windows系统中部署o2oa开发平台
  • 6.2 安装部署-在linux系统中部署o2oa开发平台
  • 6.3 安装部署-通过docker hub快速部署docker镜像
  • 6.4 安装部署-在宝塔/phpstudy中部署o2oa开发平台
  • 6.5 安装部署-o2oa开发平台之http端口规划
  • 6.6 安装部署-平台服务器版本升级操作说明
  • 6.7 安装部署-私有化部署服务器架构推荐
  • 6.8 安装部署-o2oa开发平台集群部署配置及操作说明
  • 6.9 安装部署-在线部署自定义应用的war包和jar包
  • 6.10 服务器配置与管理-​o2oa主要配置文件说明
  • 6.11 服务器配置与管理-服务器端口冲突和端口修改
  • 6.12 服务器配置与管理-如何修改服务器内存占用率?
  • 6.13 服务器配置与管理-如何访问和操作h2内置数据库
  • 6.14 服务器配置与管理-​如何在o2oa中使用mysql数据库?
  • 6.15 服务器配置与管理-如何修改平台支持的数据库驱动包
  • 6.16 服务器配置与管理-o2oa使用opengauss(华为高斯数据库)配置
  • 6.17 服务器配置与管理-o2oa开发平台平台数据库配置信息样例
  • 6.18 服务器配置与管理-配置o2oa服务器连接o2云
  • 6.19 服务器配置与管理-o2oa实现服务器随操作系统自动启动
  • 6.20 服务器配置与管理-文件存储服务器配置
  • 6.21 服务器配置与管理-工作日节假日配置
  • 6.22 服务器配置与管理-为平台增加全文检索功能
  • 6.23 服务器配置与管理-消息提醒配置说明
  • 6.24 服务器配置与管理-自定义消息提醒
  • 6.25 服务器配置与管理-定制消息通知的内容
  • 6.26 服务器配置与管理-消息通知过滤
  • 6.27 服务器配置与管理-为待办创建配置邮件通知
  • 6.28 服务器配置与管理-待办待阅数据的查询操作和管理
  • 6.29 服务器配置与管理-​自动执行平台数据的备份与恢复
  • 6.30 服务器配置与管理-数据导出导入与系统数据备份
  • 6.31 ​服务器配置与管理-定期自动执行数据备份与恢复
  • 6.32 系统安全-o2oa作为认证中心实现基于oauth2单点认证
  • 6.33 系统安全-o2oa基于nginx的ssl跳转、转发配置
  • 6.34 o2oa(翱途)开发平台如何基于nginx上下文分发的方式快速集群部署
  • 6.35 系统安全-访问日志相关配置
  • 6.36 系统架构-平台集群化部署之基于nginx端口分发机制实现集群部署
  • 6.37 系统安全-审计日志相关配置
  • 6.38 系统安全-平台日志文件说明
  • 6.39 系统架构-基于nginx快速集群部署-上下文分发
  • 6.40 系统安全-o2oa日志输出设置log4j2.xml
  • 6.41 系统安全-用户密码初始化规则的设定
  • 6.42 系统安全-启用https(百度云版)
  • 6.43 系统安全-启用https(腾讯云版)
  • 6.44 系统安全-自签名ssl证书验证https功能
  • 6.45 系统安全-登录密码rsa加密
  • 6.46 系统安全-用户登录ip限制
  • 6.47 系统安全-在用户登录过程中启用图形验证码
  • 6.48 系统安全-平台部署之使用非root用户运行服务
  • 6.49 系统安全-o2server启用国密加密设置
  • 6.50 系统安全-日志应用使用说明
  • 6.51 系统安全-用户重置密码操作
  • 6.52 系统安全-超级管理员(xadmin)密码修改
  • 6.53 系统安全-使用web端运行服务器管理命令
  • 6.54 系统安全-o2server无法正常显示验证码解决办法
  • 6.55 o2oa(翱途)开发平台前端安全配置建议(一)
  • 第16章 开发知识及常见问题
  • 16.1 o2oa如何实现文件跨服务器的备份
  • 16.2 o2oa(翱途)服务器故障排查
  • 16.3 开发知识-让后端代理/接口脚本编写也能像前端一样用上debugger
  • 16.4 常见问题-sqlserver中创建新数据库使用哪个中文编码?
  • 16.5 o2oa(翱途)流程引擎中如何修改,定制流程的流转记录
  • 16.6 mysql数据库备份
  • 16.7 domain不正确的时候如何强制设置成正确的
  • 16.8 配置文件中使用密文存储密码
  • 16.9 常见问题-连接mysql出现 public key retrieval is not allowed 的错误
  • 16.10 常见问题-查看表结构
  • 16.11 常见问题-7.2及以上版本开启web代理后请求中没有正确使用web端口问题解决方式
  • 16.12 linux环境libreoffice安装及使用
  • 16.13 在o2oa中使用网络会议(二):openmeetings与o2oa认证配置
  • 16.14 在o2oa中使用网络会议(一):openmeetings-5.1.0亲手安装整理 step-by-step
  • 16.15 藕粉社区问答系列1
  • 16.16 藕粉社区问答系列2
  • 16.17 藕粉社区问答系列3
  • 16.18 快速入门-平台相关资料汇总
  • 16.19 快速入门-服务器总体介绍汇总
  • 16.20 快速入门-流程表单载入基础数据
  • 16.21 快速入门-常用表单脚本样例汇总
  • 16.22 快速入门-自定义表数据分页样例
  • 16.23 云服务器-阿里云ecs服务器的端口启用
  • 16.24 开发知识-react篇:在o2oa平台框架中使用react
  • 16.25 开发知识-react篇:在o2oa门户页面中使用react
  • 16.26 开发知识-vue篇:在vue应用中集成o2oa
  • 16.27 开发知识-vue篇:使用vue-cli开发o2应用
  • 16.28 开发知识-vue篇:在o2门户页面中使用vue
  • 16.29 平台中使用druid数据库连接及监控
  • 16.30 开发知识-在paas平台上部署o2oa开发平台
  • 16.31 开发知识-如何使用tomcat架设webdav服务器
  • 16.32 开发知识-单个端口模式的nginx和系统配置
  • 16.33 开发知识-linux非root用户如何使用80端口启动o2oa
  • 16.34 开发知识-o2oa平台启用eruda进行移动端调试
  • 16.35 开发知识-神通数据库安装
  • 16.36 开发知识-人大金仓数据安装
  • 16.37 开发知识-中标麒麟安装达梦数据库(dm8)
  • 16.38 开发知识-中标麒麟安装人大金仓详细步骤
  • 16.39 开发知识-使用vnc连接中标麒麟v7操作系统
  • 16.40 开发知识-鲲鹏(arm)麒麟操作系统如何替换yum源?
  • 16.41 开发知识-数据优化知识点
  • 16.42 水印安全-附件水印|加密|文档格式转换图片|pdf
  • 16.43 消息队列-配置activemq、kafka消息队列
  • 16.44 常见问题-数据导出或者导入时发生oom异常
  • 16.45 常见问题-如何让用户在首次登录时,必须对初始密码进行修改
  • 16.46 常见问题-如何在模块部署中控制模块的访问权限
  • 16.47 常见问题-如何在平台中开发ftp文件上传文件的服务?
  • 16.48 常见问题-如何使用服务管理调用webservice
  • 16.49 常见问题-如何使用脚本调用外部服务
  • 16.50 常见问题-如何使用脚本控制流程自动流转
  • 16.51 常见问题-如何通过脚本调用系统内服务
  • 16.52 常见问题-接口代码疑惑解答汇总
  • 16.53 常见问题:maven编译o2server错误: java heap space
  • 16.54 常见问题-集群配置后启动报错:nullpointerexception
  • 16.55 常见问题-服务器错误:can not decrypt token
  • 16.56 常见问题-ios移动办公无法收到验证码
  • 16.57 常见问题-服务器和日志时间相差12小时的问题
  • 16.58 常见问题-为什么127.0.0.1可以访问但其他ip无法访问
  • 16.59 藕粉社区问答系列4
  • 16.60 开发知识-react篇:在react应用中集成o2oa

  • 服务集成-九游会官网登录入口网页

    时间:2022-08-03   

    九游会官网登录入口网页-ag8九游会j9登录入口允许用户自行修改源码或者增加源码来扩展系统服务,也可以包装功能更强的业务服务。本文主要介绍如何在九游会官网登录入口网页-ag8九游会j9登录入口中开发接口与外部系统进行数据交互

    外部系统调用接口发起流程

    1.在服务管理创建接口

    image - 2022-04-25t102300.571.png

    2.以发起一个收文流程为例,接口内容如下:

    /*
      //requesttext为外系统传入的参数:title,from,to等为传入的业务数据(根据实际情况调整),contents为正文数组对象,slaves为附件数组对象,没有的可以不传。 
        假设requesttext = {
            "title" : "关于某某某的九游会官网登录入口网页的公告(标题,必填)",  
            "from" : "办公室(来文单位,必填)",
            "to" : "qhsnynctrsc(oa的部门人事处id,必填)",
            "date" : "2020-05-09(收文日期,选填)",
            "no" : "农123(字号,选填)",
            "key" : "nmt(文件加密私钥,选填,为空则认为没加密)",
            "contents" : [ {
                "filepath" : "http://host?file=aaaa.docx",
                "filename" : "aaaa.docx"
            } ],
            "slaves" : [ {
                "filepath" : "http://host?file=slaves.docx",
                "filename" : "slaves.docx"
            } ]
        }
    */
    try{
        var result = {     
        }
        print( "requesttext=" requesttext );
       
        var requestjson = json.parse(requesttext);
        if( typeof(requestjson) === "string" ){
            requestjson = json.parse(requestjson);
        }
        if(requestjson.title === "" || requestjson.from === "" || requestjson.to === ""){//必填信息校验
            result.state = "nmt0002";
            result.message = "失败";
            result.data = "标题或者来文单位或者oa部门id为空";
        }else{
            var processid = "d75fe1d2-6823-4e33-9798-6218d82f930f";  //需要启动的流程标识
            var identity = "xxxxx@474820e2-4c54-4e5c-8c82-5915d5ca6d2c@i";    //启动人员身份
       
            //传入的参数名和表单字段名不一致,所以重新拼接,subject,input_department,receive_date,input_file_no为流程表单字段标识
            var datastr = '{"subject":"' requestjson.title '","input_department":"' requestjson.from '","receive_date":"' requestjson.date '","input_file_no":"' requestjson.no '"}';
            datastr = json.parse(datastr);
            var applications = resources.getcontext().applications();
            var data = {
                "title": requestjson.title,
                "identity": identity,
                "data" : datastr   //表单数据
            }
            var resp = applications.postquery('x_processplatform_assemble_surface', 'work/process/' processid, json.stringify( data ));  //调用平台启动流程接口
            var result1 = json.parse( resp.tostring() );
            var workid = result1.data[0].work; //返回workid
           
           
            //上传附件-----------------------------------------------------------begin
            var token = gettoken();  
           
            //print( "contents个数:"   requestjson.contents.length);
            //print( "slaves个数:"   requestjson.slaves.length);
            var contentssite = "attachment"; //正文附件放置的附件区域
            var slavessite = "attachment_1"; //普通附件放置的附件区域
            //处理contents
            var conarr = requestjson.contents;
            for(var i=0;i


    将流程数据传回外部系统

    在服务管理创建接口,接口内容如下:

    /*
    requesttext为入参
    */
    try{
        var result = {
           
        }
        var pushdata = {
            
        }
        
        var requestjson = json.parse(requesttext);
        if( typeof(requestjson) === "string" ){
            requestjson = json.parse(requestjson);
        }
        print( "workid=" requestjson.workid);
        
        //通过workid得到所有附件列表
        var applications = resources.getcontext().applications();
        var resp = applications.getquery('x_processplatform_assemble_surface', 'attachment/list/work/' requestjson.workid);
        
        var result1 = json.parse( resp.tostring() );
        var dataarr = result1.data;
        
        var contentarr = [];
        var salvesarr = [];
        
        for(var i=0;i>>>>>>>>尝试对mac进行md5加密");
            var md5util = java.type('com.z.custom.md5util');
            var md5mac = md5util.getmd5( mac );
            print( "md5mac = "   md5mac );
            
            var p3 = new namevaluepair('mac', md5mac);
            heads.add(p3)
        }catch(e){
            print(e);
        }
        print(">>>>>headers:")
        
        var httpconnectionclass = java.type('com.x.base.core.project.connection.httpconnection');
        var doccontent =json.stringify(pushdata);
        print("sendcontent:" doccontent);
        
        var resp = httpconnectionclass.postasstring(url, heads, doccontent);
        print("返回1:"  resp.tostring());
        if(resp.tostring()=='{"state":"nmt0001","message":"成功"}'){
            this.response.setbody(true);
        }else{
            this.response.setbody(false);
        }
        
    }catch(e){
        e.printstacktrace();
        result.state = "nmt0002";
        result.message = "失败";
        result.data = e.name   ": "   e.message
        this.response.setbody(false);
    }

    说明

    sso配置

    gettoken()方法里面的sso名称和sso密钥配置在“系统设置”里
    image - 2022-04-25t102345.436.png

    httpclientutilsupfile类代码

    httpclientutilsupfile类代码如下:

    package com.z.custom;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.concurrent.executorservice;
    import java.util.concurrent.executors;
    import com.google.gson.jsonelement;
    import com.google.gson.jsonobject;
    import com.google.gson.jsonparser;
    import com.x.base.core.project.tools.crypto;
    import org.apache.http.httpentity;
    import org.apache.http.namevaluepair;
    import org.apache.http.client.entity.urlencodedformentity;
    import org.apache.http.client.methods.closeablehttpresponse;
    import org.apache.http.client.methods.httpget;
    import org.apache.http.client.methods.httppost;
    import org.apache.http.entity.contenttype;
    import org.apache.http.entity.mime.multipartentitybuilder;
    import org.apache.http.entity.mime.content.filebody;
    import org.apache.http.entity.mime.content.inputstreambody;
    import org.apache.http.entity.mime.content.stringbody;
    import org.apache.http.impl.client.closeablehttpclient;
    import org.apache.http.impl.client.httpclients;
    import org.apache.http.message.basicnamevaluepair;
    import org.apache.http.util.entityutils;
    import javax.crypto.cipherinputstream;
    public class httpclientutilsupfile {
        public static final int thread_pool_size = 5;
        public interface httpclientdownloadprogress {
            public void onprogress(int prgetinstanceogress);
        }
        private static httpclientutilsupfile httpclientdownload;
        private executorservice downloadexcutorservice;
        private httpclientutilsupfile() {
            downloadexcutorservice = executors.newfixedthreadpool(thread_pool_size);
        }
        public static httpclientutilsupfile getinstance() {
            if (httpclientdownload == null) {
                httpclientdownload = new httpclientutilsupfile();
            }
            return httpclientdownload;
        }
        /**
         * 下载文件
         *
         * @param url
         * @param filepath
         */
        public void download(final string url, final string filepath) { downloadexcutorservice.execute(new runnable() {
                public void run() {
                    httpdownloadfile( url, filepath, null, null);
                }
            });
        }
        /**
         * 下载文件
         *
         * @param url
         * @param filepath
         * @param progress
         *
         */
        public void download(final string url, final string filepath, final httpclientdownloadprogress progress) {
            downloadexcutorservice.execute(new runnable() {
                public void run() {
                    httpdownloadfile(url, filepath, progress, null);
                }
            });
        }
        /**
         *下载文件
         *
         * @param url
         * @param filepath
         */
        private void httpdownloadfile(string url, string filepath,
                                      httpclientdownloadprogress progress, map headmap) {
            closeablehttpclient httpclient = httpclients.createdefault();
            try {
                httpget httpget = new httpget(url);
                setgethead(httpget, headmap);
                closeablehttpresponse response1 = httpclient.execute(httpget);
                try {
                    httpentity httpentity = response1.getentity();
                    long contentlength = httpentity.getcontentlength();
                    inputstream is = httpentity.getcontent();
                    bytearrayoutputstream output = new bytearrayoutputstream();
                    byte[] buffer = new byte[4096];
                    int r = 0;
                    long totalread = 0;
                    while ((r = is.read(buffer)) > 0) {
                        output.write(buffer, 0, r);
                        totalread  = r;
                        if (progress != null) {
                            progress.onprogress((int) (totalread * 100 / contentlength));
                        }
                    }
                    fileoutputstream fos = new fileoutputstream(filepath);
                    output.writeto(fos);
                    output.flush();
                    output.close();
                    fos.close();
                    entityutils.consume(httpentity);
                } finally {
                    response1.close();
                }
            } catch (exception e) {
                e.printstacktrace();
            } finally {
                try {
                    httpclient.close();
                } catch (ioexception e) {
                    e.printstacktrace();
                }
            }
        }
        /**
         * 发送get请求
         *
         * @param url
         * @return
         */
        public string httpget(string url) {
            return httpget(url, null);
        }
        /**
         * 发送get请求
         *
         * @param url
         * @return
         */
        public string httpget(string url, map headmap) {
            string responsecontent = null;
            closeablehttpclient httpclient = httpclients.createdefault();
            try {
                httpget httpget = new httpget(url);
                closeablehttpresponse response1 = httpclient.execute(httpget);
                setgethead(httpget, headmap);
                try {
                    system.out.println(response1.getstatusline());
                    httpentity entity = response1.getentity();
                    responsecontent = getrespstring(entity);
                    system.out.println("debug:"   responsecontent);
                    entityutils.consume(entity);
                } finally {
                    response1.close();
                }
            } catch (exception e) {
                e.printstacktrace();
            } finally {
                try {
                    httpclient.close();
                } catch (ioexception e) {
                    e.printstacktrace();
                }
            }
            return responsecontent;
        }
        public string httppost(string url, map paramsmap) {
            return httppost(url, paramsmap, null);
        }
        /**
         * 发送post请求
         *
         * @param url
         * @param paramsmap
         * @return
         */
        public string httppost(string url, map paramsmap, map headmap) {
            string responsecontent = null;
            closeablehttpclient httpclient = httpclients.createdefault();
            try {
                httppost httppost = new httppost(url);
                setposthead(httppost, headmap);
                setpostparams(httppost, paramsmap);
                closeablehttpresponse response = httpclient.execute(httppost);
                try {
                    system.out.println(response.getstatusline());
                    httpentity entity = response.getentity();
                    responsecontent = getrespstring(entity);
                    entityutils.consume(entity);
                } finally {
                    response.close();
                }
            } catch (exception e) {
                e.printstacktrace();
            } finally {
                try {
                    httpclient.close();
                } catch (ioexception e) {
                    e.printstacktrace();
                }
            }
            system.out.println("responsecontent = "   responsecontent);
            return responsecontent;
        }
        /**
         * 设置post请求的httpheader
         *
         * @param httppost
         * @param headmap
         */
        private void setposthead(httppost httppost, map headmap) {
            if (headmap != null && headmap.size() > 0) {
                set keyset = headmap.keyset();
                for (string key : keyset) {
                    httppost.addheader(key, headmap.get(key));
                }
            }
        }
        /**
         * 设置get请求的httpheader
         *
         * @param httpget
         * @param headmap
         */
        private void setgethead(httpget httpget, map headmap) {
            if (headmap != null && headmap.size() > 0) {
                set keyset = headmap.keyset();
                for (string key : keyset) {
                    httpget.addheader(key, headmap.get(key));
                }
            }
        }
        /**
         * 上传文件的实现方法
         *
         * @param serverurl
         * @param localfilepath
         * @param serverfieldname
         * @param params
         * @return
         * @throws exception
         */
        public string uploadfileimpl(string serverurl, string localfilepath,string serverfieldname, map params, map paramshead)
                throws exception {
            string respstr = null;
            closeablehttpclient httpclient = httpclients.createdefault();
            try {
                httppost httppost = new httppost(serverurl);
                setposthead(httppost, paramshead);
                filebody binfilebody = new filebody(new file(localfilepath));
                multipartentitybuilder multipartentitybuilder = multipartentitybuilder.create();
                // add the file params
                multipartentitybuilder.addpart(serverfieldname, binfilebody);
                setuploadparams(multipartentitybuilder, params);
                httpentity reqentity = multipartentitybuilder.build();
                httppost.setentity(reqentity);
                closeablehttpresponse response = httpclient.execute(httppost);
                try {
                    httpentity resentity = response.getentity();
                    respstr = getrespstring(resentity);
                    entityutils.consume(resentity);
                } finally {
                    response.close();
                }
            } finally {
                httpclient.close();
            }
            system.out.println("resp="   respstr);
            return respstr;
        }
        /**
         * 上传文件的实现方法
         *
         * @param serverurl
         * @param urlfilepath
         * @param urlfilename
         * @param serverfieldname
         * @param params
         * @return
         * @throws exception
         */
        public string uploadurlfileimpl(string serverurl, string urlfilepath,string urlfilename,string serverfieldname, map params, map paramshead)
                throws exception {
            string respstr = null;
            closeablehttpclient httpclient = httpclients.createdefault();
            try {
                httppost httppost = new httppost(serverurl);
                setposthead(httppost, paramshead);
                filebody binfilebody = new filebody(new file(urlfilepath));
                multipartentitybuilder multipartentitybuilder = multipartentitybuilder.create();
                // add the file params
                bufferedinputstream in = getfileinputstream(urlfilepath);
                inputstreambody inputstreambody = new inputstreambody(in,urlfilename);
                multipartentitybuilder.addpart(serverfieldname, inputstreambody);
                setuploadparams(multipartentitybuilder, params);
                httpentity reqentity = multipartentitybuilder.build();
                httppost.setentity(reqentity);
                closeablehttpresponse response = httpclient.execute(httppost);
                try {
                    system.out.println(response.getstatusline());
                    httpentity resentity = response.getentity();
                    respstr = getrespstring(resentity);
                    entityutils.consume(resentity);
                } finally {
                    response.close();
                }
            } finally {
                httpclient.close();
            }
            system.out.println("resp="   respstr);
            return respstr;
        }
        /**
         * 上传文件的实现方法
         * 上传前 需要解密
         * @param serverurl  上传附件服务
         * @param urlfilepath  附件url
         * @param urlfilename  附件名称
         * @param serverfieldname
         * @param params  附件参数
         * @param paramshead  文件头
         * @param skey  密钥
         * @param siv  向量
         * @return
         * @throws exception
         */
        public string uploadbytefileimpl(string serverurl, string urlfilepath,string urlfilename,string serverfieldname, map params, map paramshead,string skey,string siv)
                throws exception {
            string respstr = null;
            closeablehttpclient httpclient = httpclients.createdefault();
            try {
                httppost httppost = new httppost(serverurl);
                setposthead(httppost, paramshead);
                //ilebody binfilebody = new filebody(new file(urlfilepath));
                multipartentitybuilder multipartentitybuilder = multipartentitybuilder.create();
                // add the file params
                bufferedinputstream fis = getfileinputstream(urldecoder.decode(urlfilepath, "utf-8" ));;
                //解密
                cipherinputstream cis = aesfile.decryptedfile(fis,skey,siv);
                if(cis != null){
                    //inputstream inputbytefile = new bytearrayinputstream(bytefile);
                    //bufferedinputstream in = new bufferedinputstream(inputbytefile);
                    inputstreambody inputstreambody = new inputstreambody(cis,urlfilename);
                    multipartentitybuilder.addpart(serverfieldname, inputstreambody);
                    setuploadparams(multipartentitybuilder, params);
                    httpentity reqentity = multipartentitybuilder.build();
                    httppost.setentity(reqentity);
                    closeablehttpresponse response = httpclient.execute(httppost);
                    try {
                        system.out.println(response.getstatusline());
                        httpentity resentity = response.getentity();
                        respstr = getrespstring(resentity);
                        entityutils.consume(resentity);
                    } finally {
                        response.close();
                    }
                }else{
                    respstr = "解密失败";
                }
            } finally {
                httpclient.close();
            }
            system.out.println("resp="   respstr);
            return respstr;
        }
        /**
         * 设置上传时的参数
         *
         * @param multipartentitybuilder
         * @param params
         */
        private void setuploadparams(multipartentitybuilder multipartentitybuilder,
                                     map params) {
            if (params != null && params.size() > 0) {
                set keys = params.keyset();
                for (string key : keys) {
                    multipartentitybuilder.addpart(key, new stringbody(params.get(key),contenttype.application_json));
                }
            }
        }
        /**
         * 获取响应内容
         *
         * @param entity
         * @return
         * @throws exception
         */
        private string getrespstring( httpentity entity ) throws exception {
            if (entity == null) {
                return null;
            }
            inputstream is = entity.getcontent();
            stringbuffer strbuf = new stringbuffer();
            byte[] buffer = new byte[4096];
            int r = 0;
            while ((r = is.read(buffer)) > 0) {
                strbuf.append(new string(buffer, 0, r, "utf-8"));
            }
            return strbuf.tostring();
        }
        /**
         * 设置post请求发送的参数
         *
         * @param httppost
         * @param paramsmap
         * @throws exception
         */
        private void setpostparams(httppost httppost, map paramsmap)
                throws exception {
            if (paramsmap != null && paramsmap.size() > 0) {
                list nvps = new arraylist();
                set keyset = paramsmap.keyset();
                for (string key : keyset) {
                    nvps.add(new basicnamevaluepair(key, paramsmap.get(key)));
                }
                httppost.setentity(new urlencodedformentity(nvps));
            }
        }
        /**
         * 发送post请求
         * @param url
         * @param param
         * @return
         */
        public static string sendpost(string url, string param) {
            printwriter out = null;
            bufferedreader in = null;
            string result = "";
            try {
                url realurl = new ;
                urlconnection conn = realurl.openconnection();
                conn.setrequestproperty("accept", "*/*");
                conn.setrequestproperty("connection", "keep-alive");
                conn.setrequestproperty("content-type", "application/json; charset=utf-8");
                conn.setrequestproperty("user-agent", "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1;sv1)");
                conn.setdooutput(true);
                conn.setdoinput(true);
                out = new printwriter(conn.getoutputstream());
                out.print(param);
                out.flush();
                in = new bufferedreader( new inputstreamreader(conn.getinputstream()));
                string line;
                while ((line = in.readline()) != null) {
                    result  = line;
                }
            } catch (exception e) {
                system.out.println(" post" e);
                e.printstacktrace();
            }
            finally{
                try{
                    if(out!=null){
                        out.close();
                    }
                    if(in!=null){
                        in.close();
                    }
                }
                catch(ioexception ex){
                    ex.printstacktrace();
                }
            }
            system.out.println(result);
            return result;
        }
        /**
         * 根据ssotoken获取人员认证后的真实xtoken
         * @param url
         * @param client
         * @param login_uid
         * @param sso_key
         * @return
         */
        public string gettoken(string url, string client, string login_uid, string sso_key ) {
            long time = new date().gettime();
            string xtoken = null;
            try {
                xtoken = crypto.encrypt( login_uid   "#"   time, sso_key );
                system.out.println(xtoken);
            } catch (exception e1) {
                e1.printstacktrace();
            }
            string string = "{"token": " xtoken ", "client": ""  client  ""}";
            string str = getinstance().sendpost( url,string );
            system.out.println("sso response: "   str );
            try {
                jsonelement jsonobj = new jsonparser().parse(str);
                if( jsonobj != null && jsonobj.getasjsonobject().get("data") != null ){
                    jsonobject data = jsonobj.getasjsonobject().get("data").getasjsonobject();
                    system.out.println("gettoken: "   data.get("token"));
                    return data.get("token").getasstring();
                }
            } catch (exception e) {
                e.printstacktrace();
            }
            return null;
        }
        private bufferedinputstream getfileinputstream(string urlpath) {
            bufferedinputstream bin=null;
            url url;
            try {
                url = new ;
                urlconnection urlconnection = url.openconnection();
                httpurlconnection httpurlconnection = (httpurlconnection) urlconnection;
                httpurlconnection.setconnecttimeout(1000*5);
                httpurlconnection.setrequestmethod("get");
                // 设置字符编码
                httpurlconnection.setrequestproperty("charset", "utf-8");
                httpurlconnection.connect();
                bin = new bufferedinputstream(httpurlconnection.getinputstream());
            } catch (exception e) {
                e.printstacktrace();
            }
            return bin;
        }
        private inputstream getinputstream(string urlpath) {
            inputstream bin=null;
            url url;
            try {
                url = new ;
                urlconnection urlconnection = url.openconnection();
                httpurlconnection httpurlconnection = (httpurlconnection) urlconnection;
                httpurlconnection.setconnecttimeout(1000*5);
                httpurlconnection.setrequestmethod("get");
                // 设置字符编码
                httpurlconnection.setrequestproperty("charset", "utf-8");
                httpurlconnection.connect();
                bin = httpurlconnection.getinputstream();
            } catch (exception e) {
                e.printstacktrace();
            }
            return bin;
        }
        public static void main(string[] args) throws ioexception, exception {
            
        }
    }

    aes加解密

    aesfile类代码:

    package com.z.custom;
    import org.bouncycastle.jce.provider.bouncycastleprovider;
    import sun.misc.base64decoder;
    import javax.crypto.cipher;
    import javax.crypto.cipherinputstream;
    import javax.crypto.keygenerator;
    import javax.crypto.nosuchpaddingexception;
    import javax.crypto.spec.ivparameterspec;
    import javax.crypto.spec.secretkeyspec;
    import java.io.*;
    import java.security.*;
    import java.util.random;
    public class aesfile {
    	@suppresswarnings("static-access")
    	//文件加密的实现方法
    	public static void encryptfile2(string filename,string encryptedfilename,string skey,string siv){
    		try {
    			//导入支持aes/cbc/pkcs7padding的provider
    			security.addprovider(new bouncycastleprovider());
    			fileinputstream fis = new fileinputstream(filename);
    			fileoutputstream fos = new fileoutputstream(encryptedfilename);
    			byte[] keyvalue = skey.getbytes();
    			secretkeyspec encrykey= new secretkeyspec(keyvalue,"aes");//加密秘钥
    			
    			//byte[] ivvalue=new byte[16];
    			byte[] ivvalue = siv.getbytes();
    			random random = new random(system.currenttimemillis());
    			random.nextbytes(ivvalue);
    			ivparameterspec iv = new ivparameterspec(ivvalue);//获取系统时间作为iv
    			fos.write(ivvalue);	//记录iv
    			cipher cipher = cipher.getinstance("aes/cbc/pkcs7padding","bc");
    			cipher.init(cipher.encrypt_mode, encrykey,iv);
    			
    			cipherinputstream cis=new cipherinputstream(fis, cipher);
    			
    			byte[] buffer=new byte[1024];
    			int n=0;
    			while((n=cis.read(buffer))!=-1){
    				fos.write(buffer,0,n);
    			}
    			cis.close();
    			fos.close();
    		} catch (invalidkeyexception e) {
    			// todo auto-generated catch block
    			e.printstacktrace();
    		} catch (filenotfoundexception e) {
    			// todo auto-generated catch block
    			e.printstacktrace();
    		} catch (nosuchalgorithmexception e) {
    			// todo auto-generated catch block
    			e.printstacktrace();
    		} catch (nosuchpaddingexception e) {
    			// todo auto-generated catch block
    			e.printstacktrace();
    		} catch (invalidalgorithmparameterexception e) {
    			// todo auto-generated catch block
    			e.printstacktrace();
    		} catch (ioexception e) {
    			// todo auto-generated catch block
    			e.printstacktrace();
    		} catch (nosuchproviderexception e) {
    			e.printstacktrace();
    		}
    	}
    	@suppresswarnings("static-access")
    	//文件解密的实现代码 通过文件流
    	public static cipherinputstream decryptedfile(inputstream fis,string skey, string siv){
    			try {
    				//导入支持aes/cbc/pkcs7padding的provider
    				security.addprovider(new bouncycastleprovider());
    				byte[] keyvalue = skey.getbytes();
    					secretkeyspec key= new secretkeyspec(keyvalue,"aes");
    					byte[] ivvalue = siv.getbytes();
    					//fis.read(ivvalue);//获取iv值
    					ivparameterspec iv= new ivparameterspec(ivvalue);
    					cipher cipher = cipher.getinstance("aes/cbc/pkcs7padding","bc");
    					cipher.init(cipher.decrypt_mode, key,iv);
    					cipherinputstream cis= new cipherinputstream(fis, cipher);
    					return cis;
    			} catch (nosuchalgorithmexception e) {
    				e.printstacktrace();
    				return null;
    			} catch (invalidkeyexception e) {
    				e.printstacktrace();
    				return null;
    			} catch (invalidalgorithmparameterexception e) {
    				e.printstacktrace();
    				return null;
    			} catch (nosuchpaddingexception e) {
    				e.printstacktrace();
    				return null;
    			} catch (nosuchproviderexception e) {
    				e.printstacktrace();
    				return null;
    			}
    	}
    	@suppresswarnings("static-access")
    	//文件解密的实现代码
    	public static void decryptedfile2(string encryptedfilename,string decryptedfilename, string skey, string siv){
    		try {
    			//导入支持aes/cbc/pkcs7padding的provider
    			security.addprovider(new bouncycastleprovider());
    			fileinputstream fis = new fileinputstream(encryptedfilename);
    			fileoutputstream fos = new fileoutputstream(decryptedfilename);
    			base64decoder decoder = new base64decoder();
    			//byte[] fileidentifier=new byte[15];
    			//byte[] keyvalue=new byte[16];
    			//string skey= "12345678123456781234567812345678";
    			byte[] keyvalue = skey.getbytes();
    			//fis.read(keyvalue);//读记录的文件加密密码的消息摘要
    			//fis.read(fileidentifier);
    			//system.out.println("file==" new string(fileidentifier,"utf-8"));
    			//if(new string (fileidentifier).equals("myfileencryptor")){
    			secretkeyspec key= new secretkeyspec(keyvalue,"aes");
    			//byte[] ivvalue= new byte[16];
    			//string siv = "1234567812345678";
    			byte[] ivvalue = siv.getbytes();
    			//fis.read(ivvalue);//获取iv值
    			ivparameterspec iv= new ivparameterspec(ivvalue);
    			cipher cipher = cipher.getinstance("aes/cbc/pkcs7padding","bc");
    			cipher.init(cipher.decrypt_mode, key,iv);
    			cipherinputstream cis= new cipherinputstream(fis, cipher);
    			byte[] buffer=new byte[1024];
    			int n=0;
    			while((n=cis.read(buffer))!=-1){
    				fos.write(buffer,0,n);
    			}
    			cis.close();
    			fos.close();
    			//joptionpane.showmessagedialog(null, "解密成功");
    			//}else{
    			//joptionpane.showmessagedialog(null, "文件不是我加密的,爱找谁着谁去");
    			//}
    		} catch (ioexception e) {
    			e.printstacktrace();
    		} catch (nosuchalgorithmexception e) {
    			e.printstacktrace();
    		} catch (invalidkeyexception e) {
    			e.printstacktrace();
    		} catch (invalidalgorithmparameterexception e) {
    			e.printstacktrace();
    		} catch (nosuchpaddingexception e) {
    			e.printstacktrace();
    		} catch (nosuchproviderexception e) {
    			e.printstacktrace();
    		}
    	}
    }

    md5加密

    package com.z.custom;
    import org.apache.commons.codec.digest.digestutils;
    import java.math.biginteger;
    import java.security.messagedigest;
    /**
     * md5通用类
     *
     */
    public class md5util {
        public static string getmd5(string str) {
            try {
                // 生成一个md5加密计算摘要
                messagedigest md = messagedigest.getinstance("md5");
                // 计算md5函数
                md.update(str.getbytes());
                // digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
                // biginteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
                string md5=new biginteger(1, md.digest()).tostring(16);
                //biginteger会把0省略掉,需补全至32位
                return fillmd5(md5);
            } catch (exception e) {
                throw new runtimeexception("md5加密错误:" e.getmessage(),e);
            }
        }
        public static string fillmd5(string md5){
            return md5.length()==32?md5:fillmd5("0" md5);
        }
        /**
         * md5方法
         *
         * @param text 明文
         * @param key 密钥
         * @return 密文
         * @throws exception
         */
        public static string md5(string text, string key) throws exception {
            //加密后的字符串
            string encodestr=digestutils.md5hex(text   key);
            system.out.println("md5加密后的字符串为:encodestr=" encodestr);
            return encodestr;
        }
        /**
         * md5验证方法
         *
         * @param text 明文
         * @param key 密钥
         * @param md5 密文
         * @return true/false
         * @throws exception
         */
        public static boolean verify( string text, string key, string md5) throws exception {
            //根据传入的密钥进行验证
            string md5text = md5(text, key);
            if(md5text.equalsignorecase(md5))
            {
                system.out.println("md5验证通过");
                return true;
            }
            return false;
        }
        public static void main(string[] args) throws exception{
            string str = "lee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81glee81g";
            system.out.println("md5:" getmd5(str));
            system.out.println("length:" getmd5(str).length());
        }
    }

    搭建自定义工程

    以上所用到的java类不包含在平台源码中,需要以自定义工程的方式注入到平台中进行使用,搭建自定义工程及开发参考教程:


    网站地图