起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4574|回复: 6

手机客户端源代码部署及增加验证码

[复制链接]

11

主题

1134

帖子

1261

积分

金牌会员

Rank: 6Rank: 6

积分
1261
QQ
发表于 2014-4-1 16:17:08 | 显示全部楼层 |阅读模式
本例实现的功能是取消andriod客户端登陆时加载的对话框(如图)
QQ图片20140401155844.jpg
1.将手机客户端源代码文件夹下的androidSource.zip解压,导入到Eclipse中(andriod开发环境自己搭,支持2.3以上版本)
2.右击justepLib 选择 Build Path -> Use as Source folder
3.右击项目名 选择 Build Path -> Configure Build Path...   把justepAppBridge.jar包remove了
QQ截图20140401161110.png

4.将src/com.justep.mobile/PortalActivity.java 中的 160行 302行的代码注释掉
  1. spinnerStart("", getResources().getString(R.string.loadingTip));
复制代码
5.注释掉以后项目会报错(右击项目名选Andriod Tools ->Clear lint Markers) 这个错误只要改动代码就会出现 出现后用括号中的方法clear就行 要不运行不了
6.将手机连接电脑开启usb调试模式(可以百度下)  用真机测试  不要使用虚拟机
7.右击项目 选择Run as  -> andriod application  运行
QQ截图20140401162554.png

8.将bin/androidApp.apk 拷贝到model/Mobile UI/portal中改名为x5.apk替换原来的
远程的联系方法QQ2025089647。添加好友时,需要填写论坛账号
发远程时同时也发一下帖子的地址,方便了解要

11

主题

1134

帖子

1261

积分

金牌会员

Rank: 6Rank: 6

积分
1261
QQ
 楼主| 发表于 2014-4-1 16:46:15 | 显示全部楼层
给手机客户端加验证码

1.新建validate.j文件(/mobileUI/portal/validate.j)生成验证码的代码
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.image.BufferedImage;
  5. import java.io.IOException;
  6. import java.io.Writer;
  7. import java.util.Random;

  8. import javax.imageio.ImageIO;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.servlet.http.HttpSession;


  13. public class Validate extends com.justep.ui.impl.JProcessorImpl  {
  14.         @Override
  15.         public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  16.                 response.setHeader("Cache-Control","no-cache");
  17.                 int width=60,height=25;
  18.                 BufferedImage image=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  19.                 Graphics g=image.getGraphics();
  20.                 g.setColor(new Color(200,200,200));
  21.                 g.fillRect(0,0, width, height);
  22.                 Random random=new Random();
  23.                 int randNum=random.nextInt(8999)+1000;
  24.                 String randStr=String.valueOf(randNum);
  25.                 HttpSession session=request.getSession();
  26.                 session.setAttribute("randStr",randStr);
  27.                 g.setColor(Color.black);
  28.                 g.setFont(new Font("",Font.PLAIN,20));
  29.                 g.drawString(randStr, 10, 17);
  30.                 for(int i=0;i<100;i++){
  31.                         int x=random.nextInt(width);
  32.                         int y=random.nextInt(height);
  33.                         g.drawOval(x, y, 1, 1);
  34.                 }
  35.                 ImageIO.write(image, "JPEG", response.getOutputStream());
  36.         }
  37. }
复制代码
2.新建validateServlet.j文件(/mobileUI/portal/validateServlet.j) 验证验证码代码
  1. import java.io.IOException;
  2. import java.io.PrintWriter;

  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;


  6. public class ValidateServlet extends com.justep.ui.impl.JProcessorImpl  {
  7.         public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  8.                 int flag=1;
  9.                 String verification_code=request.getParameter("verification_code");
  10.                 String code=(String) request.getSession().getAttribute("randStr");
  11.                 if(verification_code.trim().equals(code)){
  12.                         flag=0;
  13.                 }else{
  14.                         flag=1;
  15.                 }
  16.         response.setCharacterEncoding("UTF-8");
  17.         PrintWriter out = response.getWriter();
  18.         out.print(flag);
  19.         }
  20. }
复制代码
3.将mobileUI/portal/driectLogin.w 源码替换为如下代码:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <html xmlns="http://www.w3.org/1999/xhtml" sys-param="false">
  3.         <head>
  4.                 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5.                 <title>X5 协同管理系统</title>
  6.                 <link rel="stylesheet" type="text/css" href="/UI/portal/x5/css/style.default.css" media="screen" title="defaultTheme"/>
  7.             <script type="text/javascript" src="/mobileUI/portal/system/js/jquery/jquery.js"></script>
  8.             <script type="text/javascript" src="/mobileUI/portal/system/js/md5.js"></script>
  9.             <script type="text/javascript" src="/mobileUI/portal/system/js/portal.js"></script>
  10.                 <script type="text/javascript">
  11.                 <![CDATA[
  12.                                 (function($){
  13.                             $.getUrlParam = function(name)
  14.                             {
  15.                                 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  16.                                 var r = window.location.search.substr(1).match(reg);
  17.                                 if (r!=null) return unescape(r[2]); return '';
  18.                             }
  19.                         })(jQuery);
  20.                         jQuery(function(){
  21.                                 $("#login_button").click(function(event){
  22.                                         login();
  23.                                 });       
  24.                                 $("#validate").click(function(event){
  25.                                         this.src = this.src.replace("\?(.)*", '') + "?" + Math.random();
  26.                                 });               
  27.                         });
  28.                         login=function(){
  29.                                 var verification_code=$.trim($("#verification_code").val());
  30.                                 if(verification_code==""){
  31.                                         $("#hint_label").text("请输入验证码!").show();
  32.                                 }else{
  33.                                         $.ajax({
  34.                                                 async: false,
  35.                                                 type: 'POST',
  36.                                                 data:{
  37.                                                         verification_code:verification_code
  38.                                                 },
  39.                                                 url:'/x5/mobileUI/portal/validateServlet.j',
  40.                                                 error:function(error,status,text){
  41.                                                         alert("调用失败"+text);
  42.                                                 },
  43.                                                 success:function(result){
  44.                                                         if(result==0){
  45.                                                                 var password = "${request.query.password?first}";
  46.                                                                 var username = "${request.query.username?first}";
  47.                                                                 justep.mobile.Portal.baseUrl = "${baseUrl}";
  48.                                                                 var isIOS = $.getUrlParam('isIOS');
  49.                                                                 justep.mobile.Portal.isIOS = isIOS;
  50.                                                                 var result = justep.mobile.Portal.login(username, password, true, true);
  51.                                                         }else{
  52.                                                                 $("#hint_label").text("验证码输入错误").show();
  53.                                                                 $("#verification_code").val("");
  54.                                                         }
  55.                                                 }
  56.                                         });
  57.                                 }
  58.                         }
  59.                         ]]>
  60.                 </script>
  61.                 <style type="text/css">
  62.                         html, body {
  63.                             height: 100%;
  64.                     }
  65.            
  66.                     body{
  67.                             margin: 0;
  68.                             padding: 0;
  69.                             line-height: normal;
  70.                             font-family: 宋体, arial;
  71.                                 background: -webkit-gradient(linear, left top, left bottom, from(#D2E8F7), to(#fff));
  72.                     }
  73.                         #verification_code{
  74.                                 width:200px;
  75.                                 height:30px;
  76.                         }
  77.                         #login_button{
  78.                                 width:120px;
  79.                                 height:40px;
  80.                         }
  81.                 </style>
  82.         </head>   
  83.         <body onmousewheel="">
  84.                 <table border="0" align="center">
  85.                         <tr>
  86.                                 <td>
  87.                                         <div id="hint_label" style="color:red"></div>
  88.                                 </td>
  89.                         </tr>
  90.                         <tr align="center">
  91.                                 <td>验证码</td>
  92.                         </tr>
  93.                         <tr>
  94.                                 <td>
  95.                                         <input type="text" id="verification_code" value=""></input>
  96.                                 </td>
  97.                         </tr>
  98.                         <tr align="center">
  99.                                 <td>
  100.                                         <img id="validate" src="validate.j" title="换一张" style="height:30px;width:100px;cursor:pointer;cursor:hand;"></img>
  101.                                 </td>
  102.                         </tr>
  103.                         <tr>
  104.                                 <td align="center">
  105.                                         <button id="login_button" onclick="return false;">登录</button>
  106.                                 </td>
  107.                         </tr>
  108.                 </table>
  109.         </body>
  110. </html>
复制代码
4.效果如下:
wifi0s0-1041999898S40401-164303.jpg


远程的联系方法QQ2025089647。添加好友时,需要填写论坛账号
发远程时同时也发一下帖子的地址,方便了解要

14

主题

74

帖子

124

积分

初级会员

Rank: 2

积分
124
QQ
发表于 2014-4-2 08:51:02 | 显示全部楼层
项目中没有这个justepLib文件夹,是这么回事?
QQ图片20140402084543.jpg

11

主题

1134

帖子

1261

积分

金牌会员

Rank: 6Rank: 6

积分
1261
QQ
 楼主| 发表于 2014-4-2 09:29:29 | 显示全部楼层
一九四七 发表于 2014-4-2 08:51
项目中没有这个justepLib文件夹,是这么回事?

用5.2.7预览版中的手机客户端源码
远程的联系方法QQ2025089647。添加好友时,需要填写论坛账号
发远程时同时也发一下帖子的地址,方便了解要

14

主题

74

帖子

124

积分

初级会员

Rank: 2

积分
124
QQ
发表于 2014-4-2 09:32:24 | 显示全部楼层
song_ning_ning 发表于 2014-4-2 09:29
用5.2.7预览版中的手机客户端源码

楼主您能给我分享一个手机源码吗?感谢了

11

主题

1134

帖子

1261

积分

金牌会员

Rank: 6Rank: 6

积分
1261
QQ
 楼主| 发表于 2014-4-2 09:46:02 | 显示全部楼层
一九四七 发表于 2014-4-2 09:32
楼主您能给我分享一个手机源码吗?感谢了

论坛有限制  上传不了   http://www.justep.com/downloads.html下载吧
远程的联系方法QQ2025089647。添加好友时,需要填写论坛账号
发远程时同时也发一下帖子的地址,方便了解要

14

主题

74

帖子

124

积分

初级会员

Rank: 2

积分
124
QQ
发表于 2014-4-2 10:08:08 | 显示全部楼层
song_ning_ning 发表于 2014-4-2 09:46
论坛有限制  上传不了   http://www.justep.com/downloads.html下载吧

谢谢!
高级模式
B Color Image Link Quote Code Smilies

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-4-18 22:05 , Processed in 0.082527 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表