<#import "/ftl/spring.ftl" as spring/> <@mdp.mdp_index_common/> <@mdp.mdp_index_top/>
应用开发接入示例
安全客户端调用

a. 找到相关资源,点击“为新应用申请资源”

b. 填写应用注册信息,保存并提交审核

c. 审核通过后,开发者会收到站内信,同时,可以去查看并下载相关资源

d. 将文档中所给资源(调用代码)应用至新应用的代码中

        //调用安全客户端
        private void startVpn() {
                ComponentName componetName = new ComponentName(  
                //这个是另外一个应用程序的包名  
                "com.xdja.safeclient",  
                //这个参数是要启动的Activity  
                "com.xdja.safeclient.StartVpnActivity");  
                        
                try {  
                    Intent intent = new Intent(); 
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setComponent(componetName);  
                    startActivity(intent);              
                } catch (Exception e) {  
                    e.printStackTrace();         
                }  
            }

        // 连接安全客户端
        VPNSocket vpnCS = new VPNSocket("127.0.0.1", 3001);
        int nres = vpnCS.connect();

        long ctime = System.currentTimeMillis();

        while (nres != 0) {
            if (System.currentTimeMillis() - ctime > 60000) {
                return "连接vpn服务失败!";
            }               
            nres = vpnCS.connect();
            try {
                Thread.sleep(1000);
            } catch (Exception ex) {
                
            }
        }

        String state = "";
        // 根据安全客户端返回结果判断安全客户端是否启动成功或者超时
        // 启动成功后,可以往127.0.0.1发送登陆消息
        ctime = System.currentTimeMillis();
        while (!state.startsWith("OK 100")) {
            try {
                Thread.sleep(1000);
            } catch (Exception ex) {
                
            }
            if (System.currentTimeMillis() - ctime > 60000) {
                return "vpn连接建立超时";
            }
            vpnCS.sendData("GETSTATUS");
            vpnstatelen = vpnCS.recvData(vpnstate);
            if (vpnstatelen < 0) {
                continue;
            }
            state = new String(vpnstate, 0, vpnstatelen);
        }
        return "vpn安全认证成功";
        }
        //关闭安全客户端
        Intent intent = new Intent();
        intent.setAction("com.xdja.safeclient.action.STOP_SERVICE");
        sendBroadcast(intent);
                            

e. 找到已审核、未发布的应用,点击“应用修改”,进入应用详情页,上传调试好的APK包,提交审核

f. 管理员审核通过后点击发布,应用上线

统一认证集成

a. 找到统一认证资源,点击“为现有应用申请资源”,跳转至申请页面,输入应用名称,提交审核

b. 审核通过后,下载相关附件并使用业务资源

        public static final String CONTENT_URI = "content://com.xdja.app.pj";
        /**
        * 返回代码
        */
        public static final String RESULT_CODE = "resultCode";
        /**
        * 返回信息
        */
        public static final String RESULT_MESSAGE = "message";
        /**
        * 票据信息
        */
        public static final String BILLSTR = "billStr";
            /**
             * 从统一认证中取票据
             * @param context 句柄
             * @return 票据信息
             */
            public static String getBill(Context context){
                ContentResolver resolver = context.getContentResolver();
                Uri uri = Uri.parse(CONTENT_URI+"/"+context.getPackageName());
                Cursor query = resolver.query(uri, null, null, null, null);
                String billString = null;
                if(query !=null){
                    query.moveToFirst();
                if("0".equals(query.getString(query.getColumnIndex(RESULT_CODE)))){
                        billString = query.getString(query
                        .getColumnIndex(BILLSTR));
                    }else {
                        code = query.getString(query.getColumnIndex(RESULT_CODE));
                    message=query.getString(query.getColumnIndex(RESULT_MESSAGE));
                    }
                    query.close();
                }
                return billString;
            }

        /**
         * 统一认证广播接收器
         */
        public class AuthorizeReceiver extends BroadcastReceiver{
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                context = arg0;
                if(arg1.getAction().equals(arg0.getPackageName())){
                    getData(context);
            }
        }

        服务程序示例:
        public class HttpRequestUtil {
            private static final Logger log=LoggerFactory.getLogger(HttpRequestUtil.class);

            public String post(String urlStr,String param){
                String sTotalString = "";  
                URL url;
                try {
                    url = new URL(urlStr);
                    URLConnection URLconnection = url.openConnection();  
                    //URLconnection.setDoInput(true);
                    URLconnection.setDoOutput(true);
                    HttpURLConnection httpConnection = (HttpURLConnection)URLconnection;  
                    httpConnection.setRequestMethod("POST");
                    OutputStreamWriter out=new OutputStreamWriter(httpConnection.getOutputStream(),"UTF-8");
                    out.write(param);
                    out.flush();
                    out.close();
                    int responseCode = httpConnection.getResponseCode();  
                    if (responseCode == HttpURLConnection.HTTP_OK) {  
                        System.err.println("成功");
                        InputStream urlStream = httpConnection.getInputStream();  
                        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlStream,
                            "UTF-8"));  
                        String sCurrentLine = "";  
                        
                        while ((sCurrentLine = bufferedReader.readLine()) != null) {  
                            sTotalString += sCurrentLine+"\n";  
                        }  
                        System.out.println(sTotalString);
                    }else{
                        System.err.println("失败");
                     }
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return sTotalString;
            }
            
        public static void main(String[] args) throws UnsupportedEncodingException {
        //此处地址可为接入网地址也可为内网地址,需要在资源处查看
            String ip=" http://192.168.22.193:10000/7b7d881e379641809fbdfff29a34de39";
            HttpRequestUtil httpRequestUtil=new HttpRequestUtil();
            String param="strToken=加密票据";
            httpRequestUtil.post(url, param);   
            }
        }
                            

c. 在“我的应用”中找到已发布的应用,点击“应用升级”,上传调试好的APK包,保存并提交审核

d. 管理员审核通过后点击发布,新应用上线

应用升级集成

a. 应用检测版本

            /**
             *  
             * 下载升级信息任务
             * 
             */
            private class CheckVerTask extends AsyncTask<String, Integer, String> {
                private ProgressDialog pDialog = null;

                protected void onPreExecute() {
                    pDialog = new ProgressDialog(context1);
                    // pDialog.setProgressStyle(1);
                    pDialog.setTitle("连接中");
                    pDialog.setMessage("正在检测版本,请稍候");
                    pDialog.setCancelable(false);
                    pDialog.show();
                }

                protected void onPostExecute(String obj) {
                    //
                    pDialog.dismiss();// 关闭进度对话框

                    String result = obj;
                    if (result != null) {// 申请验证或下载升级信息失败
                        // 没有版本更新
                        if (result.indexOf("无升级版本") != -1) {
                            uplisten1.handerResult("-5");
                        } else uplisten1.handerResult("-2");

                    } else { // 申请验证和下载升级信息成功
                        File file = new File(lfileDir + "/update_s.xml");
                        File temfile = new File(lfileDir + "/update_temp.xml");
                        //解析升级配置信息
                        boolean res = ParseConfigInfo("update_s.xml");
                        if (res == false) {
                            // 删除update_s.xml文件
                            file.delete();
                            uplisten1.handerResult("-2");// 解析update_s.xml失败
                            Log.i("check version info", "解析update_s.xml失败");
                            return;
                        }
                        if (updatetag.equals("0")) {
                            doNewVersionUpdate(); // 提示版本升级
                        } else {
                            GetFileTask getfiletask = new GetFileTask();
                            getfiletask.execute();
                        }
                    }
                }
                
                protected String doInBackground(String... params) {
                    CreateVersionInfo(context1, lfileDir + "/ClientVer.xml");// 生成客服端文件
                    // 解析文件
                    ParseVersionInfo(lfileDir + "/ClientVer.xml");
                        nres = ParseConfirmInfo(result);
                        switch (nres) {
                        case 0:
                            result = sl.recvData();
                            if (result == null) {
                                return "接收升级配置信息超时";
                            } else {
                                Log.i("result", "result1:::"+new String(result));
                                // 解决断点续传停止后,跨版本无法升级问题
                                new File(lfileDir + "/update_temp.xml").delete();
                                if (new File(lfileDir + "/update_s.xml").exists()) {
                                    UpdateFunc.WriteFile(lfileDir + "/update_temp.xml",
                                            result, false);
                                } else {
                                    UpdateFunc.WriteFile(lfileDir + "/update_s.xml",
                                            result, false);// 把升级配置信息写入本地文件update_s.xml
                                }

                            }
                            break;
                        case 1:
                            return "无升级版本";
                        case 2:
                            return "当前终端无配置信息";
                        case 3:
                            return "查询升级配置失败";
                        case 4:
                            return "升级配置文件不存在";
                        case -1:
                            return "无法解析升级确认信息";
                        }
                }
                return null;
            }

                            

b. 文件下载

        GetFileTask getfiletask = new GetFileTask();
        getfiletask.execute();
                            

c. 升级服务调用

        /**
         * 
         * 调用升级程序入口
         * 
         * @return
         * 
         */
        public static void updateStartFrame(Context context, String fileDir,
                UpdateListener uplisten) {
                    
            uplisten1 = uplisten;
            context1 = context;
            lfileDir = fileDir;
            AutoUpdate g = new AutoUpdate();
            CheckVerTask checktask = g.new CheckVerTask();
            checktask.execute();

        }
                            

d. 应用调用升级接口

        //文件下载路径
        private String lfileDir = "/data/data/" +UserCache.packageName + "/files";
        /**
         * 添加升级信息进行版本升级
         */
        com.xdja.autoupdate.AutoUpdate.updateStartFrame(Login.this, lfileDir, Login.this);
                            
<@mdp.mdp_index_bottom/>