上海杨浦OA整合安全认证客户端

1.添加文件证书

通过数据线将手机连接到电脑,在手机存储根目录下新建文件夹并命名为koal_cert,将证书命名为filecert.pfx,然后把证书拷贝至koal_cert文件夹。

2.按照图片两步,添加aidl文件和认证客户端。

11.png

3.添加登录YpLoginAction

package com.epoint.yangpu.action;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;

import com.epoint.frame.action.FrmLockPatternAction;
import com.epoint.frame.action.FrmTaskDealFlow;
import com.epoint.frame.core.app.BaseActivity;
import com.epoint.frame.core.controls.EpointToast;
import com.epoint.frame.core.task.BaseRequestor;
import com.epoint.frame.core.utils.PhoneUtil;
import com.epoint.frame.core.utils.ToastUtil;
import com.epoint.mobileoa.action.MOABaseAction;
import com.epoint.mobileoa.action.MOALoginAction;
import com.epoint.mobileoa.actys.MOAMainActivity;
import com.epoint.yangpu.utils.Config;
import com.epoint.yangpu.task.YP_CheckLoginTask;
import com.epoint.yangpu.utils.SSLUtils;
import com.google.gson.JsonObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import koal.ssl.IAutoService;


/**
 * 登录的方法集合
 * Created by a1278 on 17/1/19.
 */
public class YpLoginAction extends MOABaseAction implements Config {

    public static IAutoService autoService = null;

    private ServiceConnection serviceConnection = null;

    private ServiceMon srvMonitor = null;

    private String idCard;

    // 判断服务是否启动成功标志
    private int isKoalStart;

    public YpLoginAction(BaseActivity _activity) {
        super(_activity);

        //检查安全认证客户端是否安装
        if (!SSLUtils.checkApkExist(_activity, sslName)) {
            SSLUtils.installSSLAPK(_activity);
        } else {
            bindKoalService();
        }
    }

    public void bindKoalService() {
        // 广播接收器,用来监听SSL服务发出的广播
        srvMonitor = new ServiceMon();
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_INTENT_STARTSERVER_INPROC);
        filter.addAction(ACTION_INTENT_STARTSERVER_SUCCESS);
        filter.addAction(ACTION_INTENT_STARTSERVER_FAILURE);
        filter.addAction(ACTION_INTENT_DOWNLOADCFG_SUCCESS);
        filter.addAction(ACTION_INTENT_STOPSERVER_SUCCESS);
        filter.addAction(ACTION_INTENT_UPGRADE);
        filter.addAction(ACTION_INTENT_NETWORK_CONNECTED);
        filter.addAction(ACTION_INTENT_NETWORK_DISCONNECTED);
        filter.addAction(ACTION_INTENT_CHECKAPPS_SUCCESS);
        filter.addAction(ACTION_INTENT_CHECKAPPS_FAILURE);
        activity.registerReceiver(srvMonitor, filter);

        serviceConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                autoService = IAutoService.Stub.asInterface(service);
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                autoService = null;
            }
        };
        // 绑定SSL服务
        Intent mIntent = new Intent();
        mIntent.setAction(KOAL_SERVICE);
        Intent eintent = new Intent(SSLUtils.getExplicitIntent(activity,mIntent));
        activity.startService(eintent);
        activity.bindService(eintent, serviceConnection, activity.BIND_AUTO_CREATE);
    }



    /*
 * SSL广播接收器 为防止接收器的阻塞,最好将耗时的操作放入handle中完成
 */
    private class ServiceMon extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            String data = intent.getStringExtra(ACTION_INTENT_DATA);
            if (intent.getAction().equals(ACTION_INTENT_STARTSERVER_INPROC)) {
                handleMessage(handler, MSG_SHOWLOG, data);
            } else if (intent.getAction().equals(
                    ACTION_INTENT_STARTSERVER_SUCCESS)) {
                handleMessage(handler, MSG_SHOWLOG, "启动服务成功!");
                isKoalStart = 1;
                getCerInfo();
            } else if (intent.getAction().equals(
                    ACTION_INTENT_STARTSERVER_FAILURE)) {
                handleMessage(handler, MSG_SHOWLOG, "启动服务失败!");
                handlerErrToast("无法登录,请检查证书密码后重试!");
            } else if (intent.getAction().equals(
                    ACTION_INTENT_DOWNLOADCFG_SUCCESS)) {
                handleMessage(handler, MSG_SHOWLOG, "下载策略成功!");
            } else if (intent.getAction().equals(
                    ACTION_INTENT_STOPSERVER_SUCCESS)) {
                handleMessage(handler, MSG_SHOWLOG, "停止服务成功!");
            } else if (intent.getAction().equals(ACTION_INTENT_UPGRADE)) {
                handleMessage(handler, MSG_UPGRADE, data);
            } else if (intent.getAction().equals(
                    ACTION_INTENT_NETWORK_CONNECTED)) {
                handleMessage(handler, MSG_SHOWLOG, "网络已链接");
            } else if (intent.getAction().equals(
                    ACTION_INTENT_NETWORK_DISCONNECTED)) {
                handleMessage(handler, MSG_SHOWLOG, "网络已断开");
            } else if (intent.getAction().equals(
                    ACTION_INTENT_CHECKAPPS_SUCCESS)) {
                handleMessage(handler, MSG_SHOWLOG, "后台应用服务检测成功:" + data);
            } else if (intent.getAction().equals(
                    ACTION_INTENT_CHECKAPPS_FAILURE)) {
                handleMessage(handler, MSG_SHOWLOG, "后台应用服务检测失败:" + data);
            }

        }
    }

    private void handleMessage(Handler h, int msgID, String data) {
        Message msg = new Message();
        msg.what = msgID;
        Bundle bundle = new Bundle();
        bundle.putString(MSG_KEY, data);
        msg.setData(bundle);
        handler.sendMessage(msg);
    }

    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            String data = msg.getData().getString(MSG_KEY);

            switch (msg.what) {
                case MSG_SHOWLOG: // 向Log控件输出数据
                    Log.i("KOAL", data);
                    break;
                case MSG_UPGRADE: // 弹出对话框,询问是否升级
                    new AlertDialog.Builder(activity)
                            .setTitle("自动升级")
                            .setMessage("最新版本:" + data + ",是否立即升级?")
                            .setCancelable(true)
                            .setPositiveButton("立即升级",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface arg0,
                                                            int arg1) {
                                            try {
                                                autoService.upgrade();
                                            } catch (RemoteException e) {

                                            }
                                        }
                                    })
                            .setNegativeButton("取消",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface arg0,
                                                            int arg1) {

                                        }
                                    }).show();
                    break;
                case LOGINTASK:
                    YP_CheckLoginTask task = new YP_CheckLoginTask();
                    task.identityId = idCard;
                    task.identifyFlag = "1";
                    task.refreshHandler = new LoginRefresh();
                    task.start();
                    break;
                case 1003:
                    try {
                        Thread.sleep(2000);
                        if (autoService == null) {
                            throw new Exception();
                        }

                        String idblock = autoService.getCertInfo(3);
                        String[] info2part = idblock.split(",");
                        String sfzblock = info2part[4];
                        String identUlt = sfzblock.split("=")[1];
                        if (identUlt.length() == 0) {
                            throw new Exception();
                        } else {
                            final String id = identUlt.toLowerCase()
                                    .replace(" ", "").replace("sf", "");
                            getIdCard(id);
                            System.out.println(id);
                            Message msg1=new Message();
                            msg1.what = LOGINTASK;
                            sendMessage(msg1);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        handlerErrToast("证书信息读取失败!");
                        System.out.println("异常是:" + e);

                    }
                    break;
                default:
                    break;
            }
        };
    };

    public void getCerInfo() {
        Message msg = new Message();
        msg.what = 1003;
        handler.sendMessage(msg);
    }

    class LoginRefresh implements BaseRequestor.RefreshHandler {

        @Override
        public void refresh(final Object obj) {
            activity.hideLoading();
            new FrmTaskDealFlow(activity, (JsonObject) obj, new FrmTaskDealFlow.BusinessOperation() {

                @Override
                public void deal() {

                    MOALoginAction.setUserInfo(obj, "","");

                    Intent intent = new Intent(activity, MOAMainActivity.class);
                    activity.startActivity(intent);
                    activity.finish();

                    //清除手势密码
                    FrmLockPatternAction.cleanLockPattern();

                    // 去掉通知图标
                    PhoneUtil.cancelAllNotify(activity);
                }
            }, null, new FrmTaskDealFlow.NetErrorOperation() {
                @Override
                public void deal() {

                    EpointToast.showShort(activity, "网络请求超时");


                }
            }, new FrmTaskDealFlow.ServerErrorOperation() {
                @Override
                public void deal() {

                    EpointToast.showShort(activity, "服务器请求失败");

                }
            }).dealFlow();
        }
    }


    public void handlerErrToast(final String msg) {
        handler.post(new Runnable() {

            @Override
            public void run() {
                ToastUtil.toastShort(activity,msg);
            }
        });

    }

    public String getIdCard(String id) {
        idCard = id;
        return idCard;
    }

    /**
     * 取消ssl服务
     * 页面destory的时候取消
     */
    public void unregisterReceiver(){
        // 取消绑定SSL服务
        activity.unregisterReceiver(srvMonitor);
        activity.unbindService(serviceConnection);
    }

    /**
     * 登录
     */
    public void loginZH(final String cerPin) {

        new Thread(new Runnable() {

            @Override
            public void run() {
                // // TODO Auto-generated method stub
                try {

                    if (autoService == null) {
                        Thread.sleep(2000);
                        loginZH(cerPin);
                    }
                    if (!autoService.isStarted()) {

                        autoService.setServerAddr(serverUri, serverPort);
                        autoService.setPin(cerPin, false);
                        autoService.start();

                    } else {
                        getCerInfo();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }

}

4.增加YP_CheckLoginTask文件

package com.epoint.yangpu.task;

import com.epoint.frame.core.String.StringHelp;
import com.epoint.frame.core.app.AppUtil;
import com.epoint.frame.core.db.service.FrmDBService;
import com.epoint.frame.core.net.WebServiceUtilDAL;
import com.epoint.frame.core.security.MDUtil;
import com.epoint.frame.core.task.BaseRequestor;
import com.epoint.frame.core.utils.PhoneUtil;
import com.epoint.mobileoa.action.MOACommonAction;
import com.epoint.mobileoa.action.MOAConfigKeys;
import com.epoint.mobileoa.model.MOAPlatformLoginModel;
import com.epoint.mobileoa.utils.MOABaseInfo;
import com.google.gson.JsonObject;

/**
 * Created by liyachun on 15/6/18.
 */
public class YP_CheckLoginTask extends BaseRequestor {

    public String loginId;

    public String psw;

    public String identityId;

    public String identifyFlag;

    @Override
    public Object execute() {

        if (MOABaseInfo.needPlatform()) {
            return checkPlatform();
        } else {
            return checkLogin();
        }
    }

    private Object checkPlatform() {

        String deviceId = MOABaseInfo.getAppDeviceId();

        String userType = MOABaseInfo.getUserType();

        String interfaceFlag = MOABaseInfo.getInterfaceFlag();

        String appguid = MOABaseInfo.getAppGuid();

        String method = "checkLoginInfo";

        String url = MOABaseInfo.getPlatformWebservice();

        String namespace = "http://server.service.axis2";

        WebServiceUtilDAL ws = new WebServiceUtilDAL(url, method, namespace);

        ws.addProperty("IMEI", deviceId);

        ws.addProperty("LoginId", "admin");

        ws.addProperty("MobileVersion", MOABaseInfo.getMobileVersion());

        ws.addProperty("InterfaceFlag", interfaceFlag);

        ws.addProperty("appguid", appguid);

        ws.addProperty("userType", userType);

        ws.addProperty("VersionName", MOABaseInfo.getAppVersionInfo());

        String bs = ws.start();

        boolean isRequestOK = !StringHelp.getXMLAtt(bs, "EpointDataBody").equals("");

        if (isRequestOK) {

            MOAPlatformLoginModel model = new MOAPlatformLoginModel();

            String ReturnInfo = StringHelp.getAttOut(bs, "ReturnInfo");

            model.Status = StringHelp.getXMLAtt(ReturnInfo, "Status");

            model.Description = StringHelp.getXMLAtt(ReturnInfo, "Description");

            if (model.Status.toLowerCase().equals("true")) {

                String UserArea = StringHelp.getXMLAtt(bs, "UserArea");

                model.BusinessWebServiceUrl = StringHelp.getXMLAtt(UserArea, "BusinessWebServiceUrl");

                model.needHandwrite = StringHelp.getXMLAtt(UserArea, "needHandwrite");

                model.mqttServer = StringHelp.getXMLAtt(UserArea, "mqttServer");

                //保存信息
                String handWriteValue = model.needHandwrite.toLowerCase().equals("true") ? "1" : "0";

                FrmDBService.setConfigValue(MOAConfigKeys.WriteSign, handWriteValue);

                FrmDBService.setConfigValue(MOAConfigKeys.MQTT_URI, model.mqttServer);

                FrmDBService.setConfigValue(MOAConfigKeys.Interface_Address, model.BusinessWebServiceUrl);

                Object bsJson = checkLogin();

                if (bsJson == null) {
                    return null;
                } else {
                    return bsJson;
                }

            } else {
                return createPlatformMessageJson(model.Description);
            }
        }

        return null;
    }

    private JsonObject createPlatformMessageJson(String message) {

        JsonObject jsonObject = new JsonObject();

        JsonObject ReturnInfoJson = new JsonObject();
        ReturnInfoJson.addProperty("Code", "1");
        ReturnInfoJson.addProperty("Description", "");

        jsonObject.add("ReturnInfo", ReturnInfoJson);

        JsonObject BusinessInfoJson = new JsonObject();
        BusinessInfoJson.addProperty("Code", "0");
        BusinessInfoJson.addProperty("Description", message);
        jsonObject.add("BusinessInfo", BusinessInfoJson);
        return jsonObject;
    }

    /**
     * "LoginID": "登录名",
     "Password": "登录密码",
     "loginType": "登录类型(1用户名密码认证,2身份证+标识认证)",
     "identityId": "身份证",
     "identifyFlag": "标识",
     "OSVersion": "",
     "SoftwareVersion": "",
     "manufacturer": ""

     * @return
     */
    private Object checkLogin() {
        JsonObject paras = new JsonObject();
        paras.addProperty("LoginID", "");
        paras.addProperty("Password","");
        paras.addProperty("loginType", "2");
        paras.addProperty("identityId",identityId);
        paras.addProperty("identifyFlag", identifyFlag);
        paras.addProperty("OSVersion", "");
        paras.addProperty("SoftwareVersion", "");
        paras.addProperty("manufacturer", "");
        JsonObject bs = MOACommonAction.request(paras, "LoginV2_V6",MOABaseInfo.GETGXHURL());
        return bs;
    }
}

5.登录页面添加部分

A.在登录页面中引入YpLoginAction
action = new YpLoginAction(this);
B.在登录按钮的点击事件中实现登录接口
 showLoading();
 action.loginZH(etPassword.getText().toString());
C.在页面销毁的时候注销广播
@Override
protected void onDestroy() {
     super.onDestroy();
     action.unregisterReceiver();
}

6.运行app测试

7.资源下载

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,277评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,689评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,624评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,356评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,402评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,292评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,135评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,992评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,429评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,636评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,785评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,492评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,092评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,723评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,858评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,891评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,713评论 2 354

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,654评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,105评论 25 707
  • vsftpd.conf 部分:文件格式(5)索引 返回主要内容 名称 vsftpd.conf - vsftpd的配...
    张龙象阅读 2,283评论 0 1
  • 唐代诗人自我推销的人太多了,比如说,李庆西《禅外禅》一书转引宋代尤袤《全唐诗话》中这么一个故事:唐初的诗人陈子昂刚...
    吹过山头的清风徐徐阅读 981评论 0 0
  • 青生病了,上吐下泻,还发烧。 想来是昨天竹筏漂流受凉了,没穿雨披,寒气内袭所致。 一向结实的他,仗着身板儿硬实,梗...
    陌生如我阅读 99评论 0 0