微信扫付款码扫不出来码可以在另外一部手机上登录

微信号在新手机上登录,需要扫二维码或好友的验证码,怎么回事了?
按时间排序
在不我的微信室几年前的,我前两天才把它解封回来,可是现在登录需要好友辅助认证或者扫二微码登录,因为好久不用了,没办法好友认证
在新手机上需要验证 按照操作就可以了 也可以朋友帮忙验证。
您可以邀请优质答主更快回答您的问题
擅长领域:&&&&
在手机数码分类下共有90175个回答
擅长领域:&&
在手机数码分类下共有20904个回答
擅长领域:&&&&
在手机数码分类下共有15012个回答
擅长领域:
在手机数码分类下共有10925个回答
yuanzhangtongxue
擅长领域:
在手机数码分类下共有7603个回答
擅长领域:&&&&
在手机数码分类下共有7314个回答
加载更多答主
主屏尺寸5.5英寸
电池容量2850mAh
主屏分辨率像素
电池类型不可拆卸式电池
后置摄像头1300万像素
CPU频率2.0GHz
前置摄像头1600万像素
CPU类型联发科 MT6755
1719人的综合分
性能配置8.1
外观手感8.9
拍照效果8.9
屏幕效果8.1
感谢您为社区的和谐贡献力量请选择举报类型
经过核实后将会做出处理感谢您为社区和谐做出贡献
确定要取消此次报名,退出该活动?扫码登录是如何实现的? - 简书
扫码登录是如何实现的?
网页版微信刚推出时,无数人被它的登录方式惊艳了一下,不需要输入用户名密码,打开手机微信扫一扫,便自动登录。从原理上讲,二维码只能是一段文本的编码,如何用它实现快捷登录的呢?
打开网页版微信,可以看到如下的页面:
微信扫码界面
如果你用我查查、支付宝、新浪微博等软件扫码二维码,你会发现此二维码解析出来是如下的网址:
https://login.weixin.qq.com/l/obsbQ-Dzag==
接下来详细介绍一下扫码登录具体的每个步骤:
扫码登录完整流程
①:用户 A 访问微信网页版,微信服务器为这个会话生成一个全局唯一的 ID,上面的 URL 中 obsbQ-Dzag== 就是这个 ID,此时系统并不知道访问者是谁。
②:用户A打开自己的手机微信并扫描这个二维码,并提示用户是否确认登录。
③:手机上的微信是登录状态,用户点击确认登录后,手机上的微信客户端将微信账号和这个扫描得到的 ID 一起提交到服务器
④:服务器将这个 ID 和用户 A 的微信号绑定在一起,并通知网页版微信,这个 ID 对应的微信号为用户 A,网页版微信加载用户 A 的微信信息,至此,扫码登录全部流程完成
扫码登录看起来神奇,主要是因为微信 APP 扫自家的码会做一些普通二维码软件不会做的额外的操作,那就是将当前已登录的微信和扫出来的 ID 提交到微信服务器,类似的应用还有扫码支付、扫码加公众号等功能,关于二维码在产品设计中的应用,推荐另一篇文章:《》。
我的公众号:PMCraft,每周推送产品相关原创文章,欢迎关注。
公众号 PMCraft
微博商业产品经理
用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金Cover 有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? ... Android 获取 View 宽高的常用正确方式,避免为零 - 掘金相信有很多朋友...
用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? ... Android 获取 View 宽高的常用正确方式,避免为零 - 掘金 相信有很多...
作者:YUNNUO CHENG & RALUCA BUDIU @NNGroup | 翻译:张维钢、朱玲 ,校审:Junliang 摘要:与美国相比,在中国扫描二维码和摇一摇成为了有效沟通线上线下的交流方式,并且应用广泛。 图为中国“绝味鸭脖”在地铁车厢做的小吃广告上附带的二...
Android程序员面试宝典 自定义控件 一分钟实现贴纸功能 一分钟实现TextView高亮 一分钟实现新手引导页 一分钟实现ViewPager卡片 一分钟实现轮播图 一分钟实现GridView拖拽 一分钟实现底部导航栏 一分钟实现底部FragmentTabhost 一分钟...
最近在做一个扫码登录功能,为此我还在网上搜了一下关于微信的扫描登录的实现方式。当这个功能完成了后,我决定将整个实现思路整理出来,方便自己以后查看也方便其他有类似需求的程序猿些。 要实现扫码登录我们需要解决两个问题: 1.在没有输入用户名及密码的情况下,如何解决权限安全问题?...
送孩子上学时,替孩子背书包,已经成了许多家长的习惯,而让父母为自己背书包,也成了许多孩子的习惯,然而这并不是一个好习惯,甚至,并不是一件无足轻重的小事。 昨天和家长一起学习了——你以为自己只是在替孩子背书包?其实你无形中在替他背负人生!作为家长的我们看完以后都有很大的...
在你的生命中 可有这样一段时光 没有利益纷争 没有金钱纠葛 没有勾心斗角 初时的我们 有的只是 在学习的闲暇 偶尔嘻戏吵闹 偶尔相爱相撕 情窦初开的我们 有着自己暗恋的人 却从未点破 只想保留这份纯真的友谊 到永远 今晚初中同学建了一个微信群,不禁联想到许多,道不尽的同学情...
我再一次不耐烦的接起了这个来自于河南南阳的打错的号码。我已经数不清这是第几次打错了,一遍一遍的,隔不久打来一次,我一遍遍重复打错了打错了,对方依旧乐此不彼。
第一次打错是在我们学院的系迎新晚会上,正看的欢畅,手机一阵震动,接起来便是晦涩难懂的河南方言。耳里是听不懂...
最近,工作慢慢步入正轨,4个团队开始竞争。虽说自己是独立的一家公司,但还是依附于另一家公司在成长。同时,也有两个和我们一样的创业公司在竞争。这样的性质和模式和我之前预期的差很多。没有办法按照自己的节奏来走。很多事情都是来了之后再去面对,所以在竞争上就没有了优势。加上自己没办...
第二天,锦和我一起坐车去学校。 先到学院的接待处报道,然后到西联交费。全校的学生都在这里缴费,队伍的长度比方特节假日的队伍还长的多。 锦先回寝室去了。我背着包一直在排队。 排了一个多小时,终于到了队伍中间。锦发短信问我进度如何,我说还没轮到我。过一会儿,锦拿着一瓶绿茶和一瓶...微信扫码登录
时间: 12:40:11
&&&& 阅读:496
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&一、微信官方参考文档地址:
首先你需要在微信开放平台申请一个微信网站应用,获取
AppID:aaaaaaaaabbcc
AppSecret: sfasfsafsafsafsads
二、jsp页面代码
&%@ page pageEncoding="UTF-8"%&
&%@ page contentType="text/ charset=UTF-8"%&
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
&%@ page session="true"%&
&!DOCTYPE html&
&meta http-equiv="Content-Type" content="text/ charset=utf-8"&&/meta&
&link href="&%=request.getContextPath()%&/css/cas.css" rel="stylesheet" type="text/css"&&/link&
&link href="/css/newsTextStyle.css" type="text/css" rel="stylesheet" /&
&link href="/css/login.css" type="text/css" rel="stylesheet" /&
&script type="text/javascript" src="js/jquery-1.4.2.min.js"&&/script&
&script type="text/javascript" src="js/wxLogin.js"&&/script&
&script type="text/javascript" src="js/popup_layer.js"&&/script&
&style type="text/css"&
height:350px;
.ccidlogin {
background: url(images/loginccid.jpg) no-repeat center top;
width: 1200px;
height: 620px;
position: relative;
margin: 0 auto;
.red-line {
position: absolute;
top: 273px;
left: 0px;
display: block;
background: url(images/renline_04.gif) repeat-x left top;
height: 81px;
width: 100%;
z-index: 0;
.ccidlogintext1 {
position: absolute; top:280px;
right: 130px;
.ccidlogintext2 {
top: 244px;
top: 241px\9;
*top: 238px;
.ccidlogintext1 input,.ccidlogintext2 input {
margin-left: 200px;
width: 200px;
height: 22px;
.ccid-jinr {
position: relative;
top: 265px;
*top: 261px;
left: 740px;
width: 220px;
height: 31px;
.ccid-btn {
background: url(images/buttonn.gif) no-repeat 0 0;
width: 91px;
height: 31px;
color: #fff;
font-weight: bold;
float: left;
border: none;
display: block;
margin-right: 15px;
cursor: pointer;
font-size: 12px;
position: absolute;
top: 160px;
right: 124px;
position: absolute;
top: 410px;
right: 560px;
height: 100px;
width: 543px;
line-height: 20px;
.TabCon3 {
position: absolute;
top: 370px;
right: 124px;
width: 420px;
height: 180px;
line-height: 20px;
#TabCon1 {
width: 420px;
height: 180px;
border-left: 0px solid;
border-bottom: 0px solid;
border-right: 0px solid;
#TabCon2 {
width: 420px;
height: 180px;
border-left: 0px solid;
border-bottom: 0px solid;
border-right: 0px solid;
#TabCon3 {
width: 420px;
height: 180px;
border-left: 0px solid;
border-bottom: 0px solid;
border-right: 0px solid;
#TabCon4 {
width: 420px;
height: 180px;
line-height: 180px;
text-align: center;
border-left: 0px solid;
border-bottom: 0px solid;
border-right: 0px solid;
width: 100%;
height: 29px;
line-height: 29px;
background-image: url(images/news_bghover1.png);
cursor: pointer;
background-repeat: no-repeat;
width: 100%;
height: 29px;
line-height: 29px;
background-image: url(images/news_bghover2.png);
background-repeat: no-repeat;
cursor: pointer;
width: 100%;
height: 29px;
line-height: 29px;
background-image: url(images/news_bghover3.png);
background-repeat: no-repeat;
float:left;
cursor: pointer;
width: 100%;
height: 29px;
line-height: 29px;
background-image: url(images/news_bghover3.png);/*background-image: url(images/news_bghover4.png)*/
background-repeat: no-repeat;
float:left;
cursor: pointer;
width: 96px;
height: 29px;
line-height: 29px;
float: left;
text-align: center;
cursor: pointer;
color: #FFF;
width: 96px;
height: 29px;
line-height: 29px;
float: left;
text-align: center;
cursor: pointer;
color: #000;
width: 96px;
height: 29px;
line-height: 29px;
float: left;
text-align: center;
cursor: pointer;
color: #000;
width: 96px;
height: 29px;
line-height: 29px;
float: left;
text-align: center;
cursor: pointer;
color: #000;
.tabInput {
line-height: normal;
width: 100%;
display: inline-block;
margin-bottom: 10px;
.tab_label {
float: left;
width: 30%;
text-align: right;
height: 24px;
line-height: 24px;
/*底部链接*/
#footer-link{
width: 50px;
height: 10px;
float:right;
font-color:red;
/* 仿淘宝登陆页面style.css */
*{margin: 0;padding: 0;}
input{padding: 0;margin: 0;}
body{font-family: "Microsoft YaHei";}
.clear{clear: both;}
/* .login-box-warp{background-color: #border: 1px solid #width: 350height: 390position:margin-left: 61%;top: 188} */
.login-box-warp{background-color: #ffffff;border: 1px solid #dddddd;width: 430px;height: 430px;position: relative;margin-left: 54%;top: 110px;}
.login-tip{width: 300px;height: auto;position: absolute;top: 0;right: 0;}
.login-switch{width: 52px;height: 52px;line-height: 52px;text-align: center;float: right;}
.login-switch img{vertical-align: middle;}
.pop-tip{border: 1px solid #f3d995;background-color: #fefcee;width: 143px;height: 28px;float: right;margin-right: 10px;margin-top: 8px;position: relative;}
.pop-arrow{position: absolute;z-index: 10;top: 8px;right: 0;}
.pop-arrow em{position: absolute;top: 0;left: 1px;overflow: hidden;width: 0;height: 0;border-style: solid;border-color: rgba(255,255,255,0);border-left-color: #f3d995;border-width: 6px 0 6px 6px;}
.pop-arrow span{position: absolute;top: 0;left: 0;overflow: hidden;width: 0;height: 0;border-style: solid;border-color: rgba(255,255,255,0);border-left-color: #fefcee;border-width: 6px 0 6px 6px;}
.pop-content{width: 100%;height: 28px;text-align: center;line-height: 22px;font-size: 12px;font-weight: 400;color: #df9c1f;}
.pop-content img,.pop-content span{vertical-align: middle;padding: 0 2px}
/* .login-content{width: 300height:margin: 40px 25px 10px 25position:z-index: 20;} */
.login-content{width: 300px;height: auto;margin: 60px 65px 10px 65px;position: absolute;z-index: 20;}
.login-content-weixin{width: 300px;height: auto;margin: 20px 65px 10px 65px;position: absolute;z-index: 20;}
.login-title{padding-bottom: 8px;font-size: 16px;font-weight: 700;color: #3c3c3c;}
.login-msg{border: 1px solid #ffb4a8;width: 294px;height: 20px;line-height: 15px;padding: 3px;background-color: #fef2f2;}
.login-msg img{padding-left: 3px;vertical-align: middle;}
.login-msg span{font-size: 12px;color: #6c6c6c;vertical-align: middle;}
.login-msg span a{font-size: 12px;color: #f40;text-decoration: none;}
.login-msg span a:hover{cursor: pointer;}
.qrcode-img{width: 125px;height: 125px;margin: 30px auto 20px auto;}
.qrcode-desc{width: 100%;height: 50px;line-height: 50px;text-align: center;font-size: 12px;color: #9c9c9c;}
.qrcode-desc img,.qrcode-desc span{vertical-align: middle;padding: 0 2px;}
.qrcode-desc .mobile_weixin{color: #f40;}
.field{border: 1px solid #dddddd;width: 300px;height: 40px;}
.yzm{width: 300px;}
.yzm .yzm_button{float: right;border-width: 0;width: 70px;height: 30px;margin-top: 25px;font-size: 16px;color: #fff;display: block;background-color: #ff4400;}
.send_button{float: right;;width: 80px;height: 30px;border-width: 0;background-color: #ff4400;color: #ffffff;font-size: 14px;border-radius: 5px;margin-top: 25px;display: block;}
.username_field{margin-top: 15px;}
.password_field{margin-top: 20px;}
.yzm_field{width: 200px;margin-top: 20px;float: left;}
.field label{width: 40px;height: 40px;display: block;float: left;}
.field input{border-width: 0;width: 240px;height: 40px;padding-left: 15px;font-size: 14px;display: block;float: left;outline: medium;}
.login_submit{width: 300px;height: 40px;margin-top: 20px;}
.login_submit button[type="submit"]{border-width: 0;background-color: #f40;color: #fff;width: 300px;height: 40px;line-height: 40px;text-align: center;font-size: 16px;font-weight: 700;border-radius: 3px;}
.login_submit button[type="submit"]:hover{cursor: pointer;}
.login_submit button[type="button"]{border-width: 0;background-color: #f40;color: #fff;width: 300px;height: 40px;line-height: 40px;text-align: center;font-size: 16px;font-weight: 700;border-radius: 3px;}
.login_submit button[type="button"]:hover{cursor: pointer;}
#bindWechat{border-width: 0;background-color: #f40;color: #fff;width: 300px;height: 40px;line-height: 40px;text-align: center;font-size: 16px;font-weight: 700;border-radius: 3px;}
#bindWechat:hover{cursor: pointer;}
.login-links{width: 300px;height: 20px;margin: auto;text-align: right;position: absolute;bottom: 20px;right: 20px;}
.login-links a{text-decoration: none;padding-right: 15px;color: #6c6c6c;font-size: 12px;}
.login-links a:hover{color: #f40;}
String yan1 = (String) ((HttpServletRequest) request).getSession().getAttribute("flag1");
String yan2 = (String) ((HttpServletRequest) request).getSession().getAttribute("flag0");
String yan3 = (String) ((HttpServletRequest) request).getSession().getAttribute("flag3");
String yan4 = (String) ((HttpServletRequest) request).getSession().getAttribute("flag4");
if (yan1 == null) {
yan1 = "";
if (yan2 == null) {
yan2 = "";
if (yan4 == null) {
yan4 = "";
((HttpServletRequest) request).getSession().removeAttribute("timeTemp");
//int wait = Integer.parseInt(waitime);
//错误次数
String count =
(String)((HttpServletRequest) request).getSession().getAttribute("count");
//int count = Integer.parseInt(((HttpServletRequest) request).getSession().getAttribute("count").toString());
if (count == null || count == "") {
count = "<span style="background-color: #f5f5f5; color: #";
int errorcount = Integer.parseInt(count);
//int errorcount =
&script language="javascript"&
//--------------微信参数----------------------
//var appid="wxfc13be7";//测试版
//var weiChatUrl = "eip.ccidit.com";
var appid="wxf952746adb0bbb46";//正式版
var weiChatUrl = "oa.ccidgroup.com";
//--------------微信参数----------------------
$(function(){
$("#login_pwd,#login_pwd1").click(function(){
$("#mima").css("display","block");
$("#saoma").css("display","none");
$("#weixin").css("display","none");
$("#login_mm").click(function(){
$("#saoma").css("display","block");
$("#mima").css("display","none");
$("#weixin").css("display","none");
//生成二维码
setTimeout(function(){
var obj = new WxLogin({
id:"login_container",
appid: appid,
scope: "snsapi_login",
redirect_uri: encodeURI("http://"+weiChatUrl+"/weChatLogin_get_Code.action?param=true_noname_2_noyanzhengma_true"),
state: "<span style="background-color: #f5f5f5; color: #d6be0abe#wechat_redirect",
style: "",
href: "http://oa.ccidgroup.com/css/weChat.css"
},<span style="background-color: #f5f5f5; color: #);
var isbindWechat = "false";
var username = "noname";
var password = "nopassword";
//微信绑定生成二维码前需要填写用户名密码
function mybindWechat(){
isbindWechat = "true";
username = $.trim($("#weixinusername").val());
password = $.trim($("#weixinpassword").val());
if(username != "" && password != ""){
geterweimatobing(username,password);
$("#saoma").css("display","block");
$("#mima").css("display","none");
$("#weixin").css("display","none");
alert("请输入用户名密码");
//验证用户名和密码的正确性
function checkNameAndPass(){
var name = $.trim($("#weixinusername").val());
var pass = $.trim($("#weixinpassword").val());
if(username != "" && password != ""){
var URL = "http://"+weiChatUrl+"/weChatLogin_mycheckNameAndPass.action?param=true_loginByPhone&name="+name+"&pass="+
type: ‘post‘,
//dataType: ‘json‘,
timeout: <span style="background-color: #f5f5f5; color: #000,
success: function (data) {
if($.trim(data)=="true"){
mybindWechat();
alert("用户名密码不匹配");
fail: function (err) {
console.log(err)
alert("请输入用户名密码");
//跳转输入绑定微信页面
function bingdWeChatBefore(){
$("#saoma").css("display","none");
$("#mima").css("display","none");
$("#weixin").css("display","block");
//返回密码登录
function returnMima(){
$("#saoma").css("display","none");
$("#mima").css("display","block");
$("#weixin").css("display","none");
//动态生成二维码(扫码绑定)
function geterweimatobing(username,password){
var param = "true_"+username+"_"+password+"_noyanzhengma_"+isbindW
setTimeout(function(){
var obj = new WxLogin({
id:"login_container",
appid: appid,
scope: "snsapi_login",
redirect_uri: encodeURI("http://"+weiChatUrl+"/weChatLogin_get_Code.action?param="+param),
state: "<span style="background-color: #f5f5f5; color: #d6be0abe#wechat_redirect",
style: "",
href: "http://"+weiChatUrl+"/css/weChat.css"
},<span style="background-color: #f5f5f5; color: #);
isbindWechat = "false";
//动态生成二维码(扫码登录)
function geterweimatologin(){
var username = "noname";
var password = "nopassword";
var param = "true_"+username+"_"+password+"_noyanzhengma_"+isbindW
setTimeout(function(){
var obj = new WxLogin({
id:"login_container",
appid: appid,
scope: "snsapi_login",
redirect_uri: encodeURI("http://"+weiChatUrl+"/weChatLogin_get_Code.action?param="+param),
state: "<span style="background-color: #f5f5f5; color: #d6be0abe#wechat_redirect",
style: "",
href: "http://"+weiChatUrl+"/css/weChat.css"
},<span style="background-color: #f5f5f5; color: #);
isbindWechat = "false";
//var cTime = 100;
var count = ‘&%=count%&‘;
function test() {
if (cTime &= <span style="background-color: #f5f5f5; color: #) {
//TimeClose();
function TimeClose() {
window.setTimeout(‘TimeClose()‘, <span style="background-color: #f5f5f5; color: #00);
if (cTime &= <span style="background-color: #f5f5f5; color: #) {
this.ShowTime.innerHTML = "&input type=‘submit‘ class=‘ccid-btn‘ value=‘登录‘ style=‘float:display:‘ &&/input&" + "&input type=‘reset‘
class=‘ccid-btn‘ value=‘重置‘ style=‘float:display:‘ &&/input&";
if (Div(cTime, <span style="background-color: #f5f5f5; color: #) & <span style="background-color: #f5f5f5; color: #) {
if (cTime % <span style="background-color: #f5f5f5; color: # === <span style="background-color: #f5f5f5; color: #) {
this.ShowTime.innerHTML = "您累计输入密码错误" + count + "次,倒计时" + Div(cTime, <span style="background-color: #f5f5f5; color: #) + "分钟可以重新登录";
this.ShowTime.innerHTML = "您累计输入密码错误" + count + "次,倒计时" + Div(cTime, <span style="background-color: #f5f5f5; color: #) + "分钟" + (cTime % <span style="background-color: #f5f5f5; color: #) + "秒可以重新登录";
this.ShowTime.innerHTML = "您累计输入密码错误" + count + "次,倒计时" + (cTime % <span style="background-color: #f5f5f5; color: #) + "秒可以重新登录";
//两个数整除运算
function Div(n1, n2) {
var rslt = n1 / n2; //除
if (rslt &= <span style="background-color: #f5f5f5; color: #) {
rslt = Math.floor(rslt); //返回值为小于等于其数值参数的最大整数值。
rslt = Math.ceil(rslt); //返回值为大于等于其数字参数的最小整数。
function ale() {
var ua = navigator.userAgent.toLowerCase();
var IeValue = ua.indexOf("msie");
if (ua.substring(IeValue + <span style="background-color: #f5f5f5; color: #, IeValue + <span style="background-color: #f5f5f5; color: #) & <span style="background-color: #f5f5f5; color: # && ua.substring(IeValue + <span style="background-color: #f5f5f5; color: #, IeValue + <span style="background-color: #f5f5f5; color: #) & <span style="background-color: #f5f5f5; color: #)
alert(" 目前业务系统V1.02只支持IE9及以上版本和火狐浏览器V36及以上版本 。\n 您当前浏览器版本:IE" + ua.substring(IeValue + <span style="background-color: #f5f5f5; color: #, IeValue + <span style="background-color: #f5f5f5; color: #) + ",请更换浏览器。");
function fromCCIDIT(){
var url = "/baseServer?servicename=extLogin&sysId=CCIDIT";
window.location.href=
function fromRKXOA(){
var url = "/baseServer?servicename=extLogin&sysId=RKXOA";
window.location.href=
//获取验证码
function mysend_yzm(){
var mobilePhone = $.trim($("#mobilephone").val());
if(!(/^1[3]{9}/.test(mobilePhone)))
alert("请输入有效的手机号码!");
return false;
showWaitTime();
url: "http://"+weiChatUrl+"/weChatLogin_getPhoneCode.action?param=true_loginByPhone&mobilePhone="+mobilePhone,
type: ‘get‘,
//dataType: ‘json‘,
timeout: <span style="background-color: #f5f5f5; color: #000,
success: function (data) {
console.log(data);
//if($.trim(data)=="success"){
//showWaitTime();
fail: function (err) {
console.log(err)
var WaitTime =<span style="background-color: #f5f5f5; color: #;
//显示等待时间
function showWaitTime(){
cce = setTimeout(function() {
showWaitTime();
}, <span style="background-color: #f5f5f5; color: #00);
if(WaitTime&<span style="background-color: #f5f5f5; color: #){
WaitTime = WaitTime-<span style="background-color: #f5f5f5; color: #;
$("#send_yzm").html(WaitTime+"s");
document.getElementById("send_yzm").disabled=true;
window.clearTimeout(cce);
WaitTime = <span style="background-color: #f5f5f5; color: #;
$("#send_yzm").html("发送验证码");
document.getElementById("send_yzm").disabled=false;
//手机验证码登录
function loginByPhone(){
var mobilePhone = $("#mobilephone").val();
var phoneCode = $("#mobileyzm").val();
var send_yzm = $("#send_yzm").html();
if(mobilePhone!="" && phoneCode !=""){
if(send_yzm == "发送验证码"){
alert("验证码无效,请重新验证");
url: "http://"+weiChatUrl+"/weChatLogin_loginByPhone.action?param=true_loginByPhone&mobilePhone="+mobilePhone+"&phoneCode="+phoneCode,
type: ‘get‘,
//dataType: ‘json‘,
timeout: <span style="background-color: #f5f5f5; color: #000,
success: function (data) {
var Data = $.trim(data);
if(Data == "noThisPhone"){
alert("请输入注册手机号!");
}else if(Data == "error"){
alert("登录失败!");
}else if(Data == "noThisCode"){
alert("手机验证码错误!");
window.location.href="frameworkMgt_sysIndex.action";
fail: function (err) {
console.log(err)
alert("请先验证您的手机号");
&body style="background-color:# position: z-index:99; overflow:" onload="test()"&
&form id="fm1" class="fm-v clearfix" method="post" action="/login"&
&input type="hidden"
id="waitime"& &input type="hidden" value="&%=count%&" id="count"&
&div class="red-line"&&/div&
&div class="ccidlogin"&
&div class="tab4" style="padding-top: 20 font-size: 14 color:
&div style="font-size: 14 color:
#000000;"&
其他登录: &!--&a href="Demo-B/index.jsp"&&img src="images/login-icon.gif" style="width:50height:20"&
&img src="images/logobj_02.gif" style="width:50height:20"&
&span style="width:10"&|&/span&--&
&a href="/account?action=sparkLogin"&统一身份认证登录
&font style="font-weight:"&温馨提示:&/font&
&br/&目前系统只支持火狐和IE9及以上版本的浏览器,推荐使用火狐浏览器。
(&a href="http://download.firefox.com.cn/releases-sha2/full/45.0/zh-CN/Firefox-full-latest.exe"&下载火狐桌面浏览器&/a&)
(&a href="http://219.141.211.80:8963/OurIMServer/00/apk/EIP.apk"&下载安卓手机客户端&/a&)
(&a href="http://hxtime.com/e/ios.html"&下载苹果手机客户端&/a&)
&br/&技术支持:项浩鹏
&nbsp 电话:
&!-- 仿淘宝登陆页面html --&
&div class="login-box-warp"&
&!--微信扫码登录--&
&div id="saoma" style="display: none"&
&div class="login-tip"&
&div class="login-switch"&
&img id="login_pwd" src="images/login-1/diannao.png"&
&!-- &div class="pop-tip"&
&div class="pop-arrow"&
&span&&/span&
&div class="pop-content"&
&img src="images/login-1/anquan.png"&
&span&密码登录在这里&/span&
&/div& --&
&div class="clear"&&/div&
&div class="login-content-weixin"&
&div class="login-title"&手机扫码,安全登录&/div& --&
&div id="login_container"&
&!-- &img src="images/login-1/erweima1.png" width="125" height="125"& --&
&div class="qrcode-desc"&
&img src="images/login-1/saoyisao.png"&
&span&打开&a class="mobile_weixin"& 手机微信 &/a&扫一扫登录&/span&
&/div& --&
&div class="login-links"&
&a id="login_pwd1" href="#"&密码登录&/a&
&!--用户名密码登录--&
&div id="mima"&
&div class="login-tip"&
&div class="login-switch" onclick="geterweimatologin()"&
&img id="login_mm" src="images/login-1/erweima.png"&
&div class="pop-tip"&
&div class="pop-arrow"&
&span&&/span&
&div class="pop-content"&
&img src="images/login-1/anquan.png"&
&span&微信登录更快捷&/span&
&div class="clear"&&/div&
&div class="login-content"&
&div id="login_title_div" class="login-title"&密码登录&/div&
if(yan1!="" || yan2 !="" || yan4 !=""){
&div class="login-msg" style=""&
&img src="images/login/warning.png"&
&span id="warning_msg"&&%=yan1%&&%=yan2%&&%=yan4%&&/span&
&div class="login_form"&
if (errorcount &<span style="background-color: #f5f5f5; color: #) {
&div id="username_div" class="field username_field"&
&label for="username"&&img src="images/login-1/user.png" width="40" height="40"&&/label&
&input id="username" type="text" name="username" placeholder="会员名/邮箱/手机号" required="required"&
&div id="password_div" class="field password_field"&
&label for="password"&&img src="images/login-1/pwd.png" width="40" height="40"&&/label&
&input id="password" type="password" name="password" required="required"&
((HttpServletRequest) request).getSession().setAttribute("flag0",
if (<span style="background-color: #f5f5f5; color: #&= errorcount && errorcount &<span style="background-color: #f5f5f5; color: #) {
&div id="yzm_div" class="yzm"&
&div class="field yzm_field"&
&label for="yzm"&&img src="images/login-1/pwd.png" width="40" height="40"&&/label&
&input id="yanzhengma" type="text" name="yanzhengma" style="width: 130px"
required="required"&
&img class="yzm_button" src="&%=request.getContextPath()%&yanzhengma.jsp"&&/img&
&div class="clear"&&/div&
((HttpServletRequest) request).getSession().setAttribute("flag1","");
if (<span style="background-color: #f5f5f5; color: #&=errorcount) {
((HttpServletRequest) request).getSession().setAttribute("logunRandomNum","");
&div id="mobilephone_div" class="field username_field" &
&label for="mobilephone"&&img src="images/login-1/pwd.png" width="40" height="40"&&/label&
&input id="mobilephone" type="text" name="mobilephone" placeholder="手机号"&
&div id="mobileyzm_div" class="yzm"
&div class="field yzm_field"&
&label for="mobileyzm"&&img src="images/login-1/pwd.png" width="40" height="40"&&/label&
&input id="mobileyzm" type="text" name="mobileyzm" style="width: 130px" &
&button id="send_yzm" class="send_button" type="button" onclick="mysend_yzm()"&发送验证码&/button&
&div class="clear"&&/div&
if (errorcount&<span style="background-color: #f5f5f5; color: #) {
&div class="login_submit"&
&button id="login-button" type="submit"&登 录&/button&
if (errorcount&=<span style="background-color: #f5f5f5; color: #) {
&div class="login_submit"&
&button id="login-button" type="button" onclick="loginByPhone()"&手机登录&/button&
&!-- &div class="login-links"&
&a href=""&忘记密码&/a&
&/div& --&
&div class="login-links" &
&a id="weixinbd" onclick="bingdWeChatBefore()"&绑定微信&/a&
&!--微信绑定登录--&
&div id="weixin" style="display: none"&
&div class="login-tip"&
&div class="login-switch" onclick="returnMima()"&
&img id="login_mm" src="images/login-1/diannao.png"&
&div class="clear"&&/div&
&div class="login-content"&
&div id="login_title_div" class="login-title"&微信绑定&/div&
if(yan1!="" || yan2 !="" || yan4 !=""){
&div class="login-msg" style=""&
&img src="images/login/warning.png"&
&span id="warning_msg"&&%=yan1%&&%=yan2%&&%=yan4%&&/span&
&div class="login_form"&
&div id="username_div" class="field username_field"&
&label for="username"&&img src="images/login-1/user.png" width="40" height="40"&&/label&
&input id="weixinusername" type="text" name="weixinusername" placeholder="会员名/邮箱/手机号" &
&div id="password_div" class="field password_field"&
&label for="password"&&img src="images/login-1/pwd.png" width="40" height="40"&&/label&
&input id="weixinpassword" type="password" name="password" &
&div class="login_submit"&
type="button" onclick="checkNameAndPass()"&下 一 步&/button&
&!-- &div class="login-links"&
&a href=""&忘记密码&/a&
&/div& --&
&div class="login-links" &
&a onclick="returnMima()"&返回&/a&
if ("true".equals(yan3)) {
&div class="TabCon3"&
&span style="color: red"&对不起,您当前不具有外网登录权限.&/span&
&!-- &br/&请您访问内网地址: &a href="http://172.16.80.23"&http://192.168.80.30&/a& --&
&input type="hidden" name="loginTemp" value="login"&&/input& &input type="hidden" name="_eventId" value="submit"&&/input&
&div id="sidebar"&
&div id="list-languages"&&/div&
&script type="text/javascript"&
function login() {
var username = document.getElementById(‘username‘).
var upwd = document.getElementById(‘password‘).
if (username === ‘‘ || upwd === ‘‘) {
alert(‘请输入正确的用户名、密码‘);
document.forms[<span style="background-color: #f5f5f5; color: #].action = "/login";
document.forms[<span style="background-color: #f5f5f5; color: #].submit();
&script type="text/javascript"&
var loginstr = document.forms[<span style="background-color: #f5f5f5; color: #].
function setTab03Syn(i) {
selectTab03Syn(i);
function selectTab03Syn(i) {
switch (i) {
case <span style="background-color: #f5f5f5; color: #:
document.forms[<span style="background-color: #f5f5f5; color: #].action =
document.getElementById("TabCon1").style.display = "block";
document.getElementById("TabCon2").style.display = "none";
document.getElementById("TabCon3").style.display = "none";
document.getElementById("TabCon4").style.display = "none";
document.getElementById("font1").style.color = "#ffffff";
document.getElementById("font2").style.color = "#000000";
document.getElementById("font3").style.color = "#000000";
document.getElementById("font4").style.color = "#000000";
case <span style="background-color: #f5f5f5; color: #:
document.forms[<span style="background-color: #f5f5f5; color: #].action = "sLoginServlet";
document.getElementById("TabCon1").style.display = "none";
document.getElementById("TabCon3").style.display = "none";
document.getElementById("TabCon4").style.display = "none";
document.getElementById("TabCon2").style.display = "block";
document.getElementById("font1").style.color = "#000000";
document.getElementById("font3").style.color = "#000000";
document.getElementById("font4").style.color = "#000000";
document.getElementById("font2").style.color = "#ffffff";
case <span style="background-color: #f5f5f5; color: #:
document.forms[<span style="background-color: #f5f5f5; color: #].action = "sLoginServlet";
document.getElementById("TabCon1").style.display = "none";
document.getElementById("TabCon2").style.display = "none";
document.getElementById("TabCon4").style.display = "none";
document.getElementById("TabCon3").style.display = "block";
document.getElementById("font1").style.color = "#000000";
document.getElementById("font2").style.color = "#000000";
document.getElementById("font4").style.color = "#000000";
document.getElementById("font3").style.color = "#ffffff";
case <span style="background-color: #f5f5f5; color: #:
document.forms[<span style="background-color: #f5f5f5; color: #].action = "sLoginServlet";
document.getElementById("TabCon1").style.display = "none";
document.getElementById("TabCon2").style.display = "none";
document.getElementById("TabCon3").style.display = "none";
document.getElementById("TabCon4").style.display = "block";
document.getElementById("font1").style.color = "#000000";
document.getElementById("font2").style.color = "#000000";
document.getElementById("font3").style.color = "#000000";
document.getElementById("font4").style.color = "red";
$(document).ready(function () {
var t9 = new PopupLayer({
trigger: "#ele9",
popupBlk: "#blk9",
closeBtn: "#close9",
useOverlay: true,
useFx: true,
offsets: {
x: <span style="background-color: #f5f5f5; color: #,
y: - <span style="background-color: #f5f5f5; color: #
t9.doEffects = function (way) {
if (way == "open") {
this.popupLayer.css({opacity: <span style="background-color: #f5f5f5; color: #.3}).show(<span style="background-color: #f5f5f5; color: #0, function () {
this.popupLayer.animate({
left: ($(document).width() - this.popupLayer.width()) / <span style="background-color: #f5f5f5; color: #,
top: (document.documentElement.clientHeight - this.popupLayer.height()) / <span style="background-color: #f5f5f5; color: # + $(document).scrollTop(),
opacity: <span style="background-color: #f5f5f5; color: #.8
}, <span style="background-color: #f5f5f5; color: #0, function () {
this.popupLayer.css("opacity", <span style="background-color: #f5f5f5; color: #)
}.binding(this));
}.binding(this));
this.popupLayer.animate({
left: this.trigger.offset().left,
top: this.trigger.offset().top,
opacity: <span style="background-color: #f5f5f5; color: #.1
}, {duration: <span style="background-color: #f5f5f5; color: #0, complete: function () {
this.popupLayer.css("opacity", <span style="background-color: #f5f5f5; color: #);
this.popupLayer.hide();
}.binding(this)});
$(‘#ele9‘).click();
上面的代码比较乱,其实有关微信的代码只有以下这些:
1、导入微信二维码支持js(本例中,把此js下载放到本地了)
&script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"&&/script&
2、在body中写一个div用来显示二维码:
&div id="login_container"&&/div&
3、在js中调用以下方法来生成二维码
var appid="aaaaaaaaaaaaaaabbbbcc";//微信应用提供的appid
var weiChatUrl = "oa.ccidgroup.com";
//动态生成二维码(扫码登录)
function geterweimatologin(){
var username = "noname";
var password = "nopassword";
var param = "true_"+username+"_"+password+"_noyanzhengma_"+isbindW
setTimeout(function(){
var obj = new WxLogin({
id:"login_container",
appid: appid,
scope: "snsapi_login",
redirect_uri: encodeURI("http://"+weiChatUrl+"/weChatLogin_get_Code.action?param="+param),
state: "3d6be0abe#wechat_redirect",
style: "",
href: "http://"+weiChatUrl+"/css/weChat.css"
isbindWechat = "false";
三、java后台代码
package com.ccidit.features.weChatLogin.
import net.sf.json.JSONA
import net.sf.json.JSONO
import org.apache.commons.httpclient.HttpC
import org.apache.commons.httpclient.HttpE
import org.apache.commons.httpclient.HttpM
import org.apache.commons.httpclient.methods.PostM
import org.apache.struts2.ServletActionC
import com.ccidit.core.cas.CCIDCAS;
import com.ccidit.core.common.jdbc.dao.util.JDBCT
import com.ccidit.core.util.sendSms.SingletonC
import com.ccidit.features.po.UserLogM
import com.ccidit.platform.sdk.C
import com.common.core.base.BaseA
import com.common.core.util.Md5U
import java.io.BufferedR
import java.io.IOE
import java.io.InputStreamR
import java.io.PrintW
import java.io.UnsupportedEncodingE
import java.net.HttpURLC
import java.net.MalformedURLE
import java.net.URL;
import java.sql.C
import java.sql.ResultS
import java.sql.S
import java.sql.T
import java.text.SimpleDateF
import java.util.D
import java.util.HashM
import java.util.M
import java.util.regex.M
import java.util.regex.P
import javax.net.ssl.HttpsURLC
import javax.servlet.ServletR
import javax.servlet.ServletR
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpS
* 微信登录
* @author gaoyipeng
public class WeChatLoginAction
extends BaseAction {
String appid = "aaaaaaaaaabbbbccc";
String secret = "asdfasdfasddfsadfasdf";
String [] stringA
private static Map&String, UserLogMessage& userList = new HashMap&String, UserLogMessage&(); // 登录错误的用户Map集合
private static String userN
private Map&String,Object& resultM
public Map&String, Object& getResultMap() {
return resultM
public void setResultMap(Map&String, Object& resultMap) {
this.resultMap = resultM
* 请求CODE
* @throws IOException
public String get_Code() throws IOException {
HttpServletRequest req = ServletActionContext.getRequest();
HttpServletResponse resp = ServletActionContext.getResponse();
String param = req.getParameter("param");
stringArr= param.split("_");
String weChatLogin = stringArr[0];
String username = stringArr[1];
String password = stringArr[2];
String yanzhengma = stringArr[3];
String code = req.getParameter("code");
String state = req.getParameter("state");
String get_Userinfo =get_Access_Token(req,resp,code, state);
if(get_Userinfo.equals("true")){
return "openFirstPage";
}else if(get_Userinfo.equals("noNameAndPass")){
((HttpServletRequest) req).getSession().setAttribute("flag0", "该账号未绑定微信");
req.setAttribute("yz", "该账号未绑定微信");
return "noNameAndPass";
return "openFirstPage";
//return "get_Code";
* 通过code获取access_token
* @throws IOException
public String get_Access_Token(HttpServletRequest req,HttpServletResponse resp,String code, String state) throws IOException {
String send_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" +
appid + "&secret=" + secret + "&code=" + code +
"&grant_type=authorization_code";
URL myURL = null;
myURL = new URL(send_url);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
// 创建HttpsURLConnection对象,并设置其SSLSocketFactory对象
HttpsURLConnection httpsConn = null;
httpsConn = (HttpsURLConnection) myURL.openConnection();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
// 取得该连接的输入流,以读取响应内容
InputStreamReader insr = null;
insr = new InputStreamReader(httpsConn.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// 读取服务器的响应内容并显示
int respInt = 0;
respInt = insr.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
String result = "";
while (respInt != -1) {
//System.out.print((char) respInt);
result += (char) respI
respInt = insr.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JSONObject jsStr = JSONObject.fromObject(result);
int a= result.indexOf("errcode");
//redirectTo(req, resp, 0);
return "error";
String access_token = jsStr.getString("access_token");
String openid = jsStr.getString("openid");
String get_Userinfo = get_Userinfo(req,resp,access_token,openid);
return get_U
* 获取用户基本信息
* @throws IOException
public String get_Userinfo(HttpServletRequest req,HttpServletResponse resp,String access_token,String openid) throws IOException{
String openFirstPage="false";
String send_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" +
access_token + "&openid=" +
StringBuilder sb = new StringBuilder(send_url);
HttpMethod method = new PostMethod(sb.toString());
HttpClient httpclient = new HttpClient();
httpclient.executeMethod(method);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
String result = null;
result = new String(method.getResponseBody(), "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JSONObject jsStr = JSONObject.fromObject(result);
String unionid = jsStr.getString("unionid");
String headimgurl = jsStr.getString("headimgurl");
String nickname = jsStr.getString("nickname");
String checkisbingwechat = checkIsBingWeChat(unionid);//判断用户是否已经绑定微信
if(!checkisbingwechat.equals("false")){
if(moniLogin(req,resp,checkisbingwechat,stringArr[2],"noyanzheng")){
//saveLoginLog(checkisbingwechat);//添加微信登陆日志
bindWeChat(unionid,headimgurl,nickname,checkisbingwechat);//此处执行此绑定方法,只是为了更新头像
openFirstPage = "true";
}else{//绑定微信
String checklogin="";
if(!stringArr[1].equals("noname")){//是否有用户名
checklogin = checkLogin(req,resp,stringArr[1],stringArr[2],stringArr[3]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if(checklogin.equals("true")){
if(moniLogin(req,resp,stringArr[1],stringArr[2],stringArr[3])){
//saveLoginLog(stringArr[1]);//添加微信登陆日志
if(stringArr[4].equals("true")){//是否绑定,是
if(bindWeChat(unionid,headimgurl,nickname,stringArr[1])){
openFirstPage = "true";
openFirstPage = "true";
openFirstPage = "noNameAndPass";
((HttpServletRequest) req).getSession().setAttribute("unionid",unionid);
((HttpServletRequest) req).getSession().setAttribute("headimgurl",headimgurl);
((HttpServletRequest) req).getSession().setAttribute("nickname",nickname);
openFirstPage = "noNameAndPass";
return openFirstP
* 如果已经绑定微信则登录
public Boolean moniLogin(HttpServletRequest request,HttpServletResponse response,String username,String password,String yanzhengma){
//HttpServletRequest request = ServletActionContext.getRequest();
//HttpServletResponse response = ServletActionContext.getResponse();
CCIDCAS.checkLogin(request, response, username, password, yanzhengma,4);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return true;
* 判断用户是否已经 绑定微信,已经绑定返回绑定CName
public String checkIsBingWeChat(String unionid){
//此处通过用户名,密码查询数据库对应人员unionid是否存在,存在即已经绑定微信,否则,未绑定
//String sql = "select CName from Base_User where ID = (select baseuser_id from base_user_system where system_loginname=‘"+unionid+"‘)";
String sql = "select CName from Base_User where Unionid=‘"+unionid+"‘";
Connection conn = JDBCTools.getConnection();
Statement stmt = null;
ResultSet rs = null;
String DBunionName="false";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
//System.out.println("没有绑定");
while (rs.next()) {
DBunionName = rs.getString("CName");
//System.out.println("绑定了");
} catch (Exception e) {
e.printStackTrace();
} finally {
JDBCTools.release(conn, stmt, rs);
return DBunionN
* 绑定微信
public static boolean bindWeChat(String unionid,String headimgurl,String nickname,String username){
/*String sql= "INSERT INTO base_user_system (id, baseuser_id,_baseuser_name,system_name,system_loginname, binding_time, nickname, headimgurl)"+
"(select ‘"+id+"‘,id,‘"+"weChat‘,‘"+username+"‘,‘"+unionid+"‘,‘"+binding_time+"‘,‘"+nickname+"‘,‘"+headimgurl+"‘ from Base_User where CName=‘"+username+"‘)";*/
String sql= "update Base_User set Unionid=‘"+unionid+"‘,HeadImgUrl=‘"+headimgurl+"‘,HeadImgOrder=‘2‘ where CName=‘"+username+"‘";
Connection conn = JDBCTools.getConnection();
Statement stmt = null;
int rs = 0;
boolean hasuser = false;
stmt = conn.createStatement();
rs = stmt.executeUpdate(sql);
hasuser = true;
} catch (Exception e) {
e.printStackTrace();
hasuser = false;
* 登录前的一些验证
public String checkLogin(ServletRequest request, ServletResponse response, String uname, String upass, String yanzhengma) throws IOException {
boolean isloginT // 是否已登录标识
upass = Md5Utils.md5(upass);
isloginTem = isLoginVal(uname, upass);// 判断用户录入的用户名和密码是否匹配
if (isloginTem) { // 如果用户名和密码匹配,则判断验证码是否正确,和执行登录间隔机制
String yan = (String) ((HttpServletRequest) request).getSession().getAttribute("rand");
if (true) { // 如果验证码正确
return "true";
} else {// 如果验证码错误,怎返回登录页面
((HttpServletRequest) request).getSession().setAttribute("flag1", "验证码输入错误");
request.setAttribute("yz", "验证码输入错误");
redirectTo(request, response, 0);
return "false";
} else {// 如果用户名与密码不匹配
((HttpServletRequest) request).getSession().setAttribute("flag0", "账号或密码错误");
request.setAttribute("yz", "账号或密码错误");
redirectTo(request, response, 0); // 返回登录页面
return "false";
* 根据参数跳转页面
* @param request
* @param response
* @param jumpType 0为登陆页面 ;1为用户请求的页面;3用IP方式请求登录页面;4用户信息页面
* @throws IOException
public static void redirectTo(ServletRequest request, ServletResponse response, int jumpType) throws IOException {
HttpServletRequest rq = (HttpServletRequest)
HttpServletResponse rp = (HttpServletResponse)
String redirectURL = getFullUrl(request, jumpType);
String h5 = request.getParameter("h5");
String yz = (String) rq.getAttribute("yz");
//request.setAttribute("userName", "123");
//String userName = (String) request.getAttribute("userName");
if("/h5".equals(h5)){
jumpType=6;
switch (jumpType) {
redirectURL += "&userName="+userName+"&yz="+
rp.sendRedirect(redirectURL);
rp.sendRedirect(redirectURL);
redirectURL = Client.getProperties("ythIP") + "/casLoginView.jsp?loginTemp=tologin";
rp.sendRedirect(redirectURL);
redirectURL = "http://127.0.0.1/sUserInfo.jsp";
rp.sendRedirect(redirectURL);
redirectURL = Client.getProperties("h5login") ;
rp.sendRedirect(redirectURL);
redirectURL = Client.getProperties("h5login") ;
rp.sendRedirect(redirectURL);
redirectURL = Client.getProperties("mobileURL") ;
rp.sendRedirect(redirectURL);
redirectURL = Client.getProperties("mobileURLCSIP") ;
rp.sendRedirect(redirectURL);
* 得到请求的完全路径,包括参数
* @param i 0为登陆页面 ;1为用户请求路径; 2为只获取ServerN
* @param request
* @return 返回用请求的URL路径
public static String getFullUrl(ServletRequest request, int i) {
StringBuilder url = new StringBuilder();
String scheme = request.getScheme();
String sname = request.getServerName();
String name = Client.getProperties(sname); //根据server Name 查找登录地址
String serverName =
if(name.contains(",")){
serverName = name.substring(0, name.indexOf(","));
String serverName =
Client.getProperties("ythurl");
int port = request.getServerPort();
if (port & 0) {
port = 80; // Work around java.net.URL bug
//url.append(scheme);
//url.append("://");
//url.append(request.getServerName());
url.append(serverName);
if ((scheme.equals("http") && (port != 80)) || (scheme.equals("https") && (port != 443))) {
url.append(‘:‘);
url.append(port);
// url.append(((HttpServletRequest) request).getRequestURI());
String queryString = ((HttpServletRequest) request).getQueryString();
if (i == 0) {
url.append(name.substring(name.indexOf(",") + 1));
String requestURI = ((HttpServletRequest) request).getRequestURI();
if ("/login".equals(requestURI) || i == 2) {
return url.toString();
url.append(requestURI);
if (queryString != null) {
url.append(‘?‘).append(queryString);
return url.toString();
* 根据用户名密码验证登陆
* @param uname
* @param upass
* @return "true"用户名密码正确 ; "false"密码错误
public static boolean isLoginVal(String uname, String upass) {
boolean isloginTemp = false;
if (uname != null && upass != null) {
Matcher matcher = Pattern.compile("^[0-9a-zA-Z_-]+$").matcher(uname);
if (matcher.find()) { // 用户名中,是否有特殊字符
isloginTemp = queryUser(uname, upass);
userName =
isloginTemp = false;// 如果用户名中包含特殊字符,则返回false
return isloginT
* 验证用户名密码的匹配性
public void mycheckNameAndPass() {
HttpServletRequest request = ServletActionContext.getRequest();
String uname = request.getParameter("name");
String upass = Md5Utils.md5(request.getParameter("pass"));
boolean isloginTemp = false;
if (uname != null && upass != null) {
Matcher matcher = Pattern.compile("^[0-9a-zA-Z_-]+$").matcher(uname);
if (matcher.find()) { // 用户名中,是否有特殊字符
isloginTemp = queryUser(uname, upass);
userName =
isloginTemp = false;// 如果用户名中包含特殊字符,则返回false
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.println(isloginTemp);
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
* 执行验证登陆查询
* @param CName
* @param Password
public static boolean queryUser(String CName, String Password) {
String sql = "select password from YTH.Base_User where CName = ‘" + CName + "‘ and IsValid = ‘1‘";
Connection conn = JDBCTools.getConnection();
Statement stmt = null;
ResultSet rs = null;
boolean hasuser = false;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {// 如果查到用户的密码,则与输入密码比对,如果相符则返回true,否则返回false
passwd = rs.getString("password");
if (Password.equals(passwd)) {
hasuser = true;
} catch (Exception e) {
e.printStackTrace();
hasuser = false;
} finally {
JDBCTools.release(conn, stmt, rs);
* 通过手机号登录
public void loginByPhone(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String mobilePhone = request.getParameter("mobilePhone");
String sql = "select CName from YTH.Base_User where MobilePhone = ‘" + mobilePhone + "‘ and IsValid = ‘1‘";
//String sql = "select CName from YTH.Base_User where MobilePhone = ‘‘ and IsValid = ‘1‘";
String phoneCode = request.getParameter("phoneCode");
Boolean VerificationCode = VerificationCode(request,phoneCode);
Connection conn = JDBCTools.getConnection();
Statement stmt = null;
ResultSet rs = null;
String openFirstPage = "";
// 获取登录时间
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String logtime = format.format(date);
Timestamp create = Timestamp.valueOf(logtime); // 将字符的时间转换成时间对象
PrintWriter out = null;
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
HttpSession session = request.getSession();
int count1 = Integer.parseInt(session.getAttribute("count").toString());
JSONObject cell = new JSONObject();
if(!VerificationCode){//!VerificationCode
request.getSession().setAttribute("count", String.valueOf(count1));
cell.put("result", "noThisCode");
cell.put("count", String.valueOf(count1));
out.println(cell);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
CName = rs.getString("CName");
if(CName == null){
request.getSession().setAttribute("count", String.valueOf(count1));
cell.put("result", "noThisPhone");
cell.put("count", String.valueOf(count1));
out.println(cell);
//System.out.println("手机号对应人员为:"+CName);
request.getSession().removeAttribute("count");//.setAttribute("count", "");
phoneMoniLogin(request,response,CName, create, "noyanzheng");
cell.put("result", "success");
cell.put("count", String.valueOf(count1));
out.println(cell);
request.getSession().setAttribute("count", String.valueOf(count1));
cell.put("result", "noThisPhone");
cell.put("count", String.valueOf(count1));
out.println(cell);
} catch (Exception e) {
e.printStackTrace();
} finally {
out.flush();
out.close();
JDBCTools.release(conn, stmt, rs);
* 手机号模拟登录
public Boolean phoneMoniLogin(HttpServletRequest request,HttpServletResponse response,String username,Timestamp create,String yanzhengma){
//HttpServletRequest request = ServletActionContext.getRequest();
//HttpServletResponse response = ServletActionContext.getResponse();
//HttpSession session = ((HttpServletRequest) request).getSession(true);
CCIDCAS.checkLogin(request, response, username, "noupass", "noyanzheng",4);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return true;
* 判断手机验证码是否正确
public Boolean VerificationCode(HttpServletRequest request,String phoneCode){
//System.out.println((((HttpServletRequest) request).getSession().getAttribute("loginRandomNum")));
HttpSession session = request.getSession();
//System.out.println(session.getAttribute("loginRandomNum").toString());
if(session.getAttribute("loginRandomNum")!=null){
if(session.getAttribute("loginRandomNum").toString().equals(phoneCode)){
return true;
request.getSession().setAttribute("flag4", "手机验证码输入错误");
return false;
return false;
* 获取手机验证码
public void getPhoneCode(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String mobilePhone = request.getParameter("mobilePhone");
int i=SingletonClient.getClient().registEx("565560");
int randomNum = (int)((Math.random()*9+1)*100000);
HttpSession session = request.getSession();
session.setAttribute("loginRandomNum", randomNum);
//((HttpServletRequest) request).getSession().setAttribute("loginRandomNum", randomNum);
int a = SingletonClient.getClient().sendSMS(new String[] { mobilePhone },"您的登录验证码为:"+randomNum+",请在一分钟内登录【EIP综合业务管理平台】",3);
double b=0;
b = SingletonClient.getClient().getBalance();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
/*System.out.println("短信发送结果:"+a);
System.out.println("查询余额返回结果:"+b);*/
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.println("success");
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
* 绑定微信
public void bangDingWeChat(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String name = request.getParameter("name");
String unionid = (String) ((HttpServletRequest) request).getSession().getAttribute("unionid");
String headimgurl = (String) ((HttpServletRequest) request).getSession().getAttribute("headimgurl");
String nickname = (String) ((HttpServletRequest) request).getSession().getAttribute("nickname");
String sql= "update Base_User set Unionid=‘"+unionid+"‘,HeadImgUrl=‘"+headimgurl+"‘,HeadImgOrder=‘2‘ where CName=‘"+name+"‘";
Connection conn = JDBCTools.getConnection();
Statement stmt = null;
int rs = 0;
boolean hasuser = false;
// 获取登录时间
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String logtime = format.format(date);
Timestamp create = Timestamp.valueOf(logtime); // 将字符的时间转换成时间对象
stmt = conn.createStatement();
rs = stmt.executeUpdate(sql);
if(moniLogin(request,response,name,"nopass","noyanzheng")){
//saveLoginLog(name);//添加微信登陆日志
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.println("success");
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
hasuser = false;
((HttpServletRequest) request).getSession().removeAttribute("unionid");
((HttpServletRequest) request).getSession().removeAttribute("headimgurl");
((HttpServletRequest) request).getSession().removeAttribute("nickname");
* 同步头像
public void SynchronousWeChat(){
String requestUrl = "http://wechat.ccidgroup.com/_vti_bin/EmployeesService.svc/GetEmployeesByDeptId/1";
HttpURLConnection con = null;
String result = null;
URL url = new URL(requestUrl);
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setConnectTimeout(10000);
con.setReadTimeout(2000);
con.setDoOutput(false); // post改为true
con.setDoInput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "text/plain");
con.connect();
int code = con.getResponseCode();
if (code == 200) {
// 读取返回内容
StringBuffer buffer = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(
con.getInputStream(), "UTF-8"));
while ((temp = br.readLine()) != null) {
buffer.append(temp);
buffer.append("\n");
result = buffer.toString().trim();
JSONArray AllArray = JSONArray.fromObject(result);
for(int i=0;i&AllArray.length();i++){
JSONObject obj = AllArray.getJSONObject(i);
// "update Base_User set HeadImgUrl=‘HeadImgUrl‘,HeadImgOrder=‘2‘ where MobilePhone=‘‘ and (HeadImgOrder&1 or HeadImgOrder is null or HeadImgOrder=‘‘)
String sql= "update Base_User set HeadImgUrl=‘"+obj.get("photoUrl")+"‘,HeadImgOrder=‘3‘ where (HeadImgOrder&2 or HeadImgOrder is null or HeadImgOrder=‘‘)
and MobilePhone=‘"+obj.get("mobile")+"‘";
Connection conn = JDBCTools.getConnection();
Statement stmt = null;
int rs = 0;
stmt = conn.createStatement();
rs = stmt.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.println("success");
out.flush();
out.close();
BufferedReader br = new BufferedReader(new InputStreamReader(
con.getErrorStream(), "UTF-8"));
StringBuffer buffer = new StringBuffer();
while ((temp = br.readLine()) != null) {
buffer.append(temp);
buffer.append("\n");
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.println("failure");
out.flush();
out.close();
} catch (Exception e) {
} finally {
con.disconnect();
&四、效果展示
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文地址:http://www.cnblogs.com/Garnett-Boy/p/7047873.html
&&国之画&&&& &&&&chrome插件&&
版权所有 京ICP备号-2
迷上了代码!

我要回帖

更多关于 微信扫付款码扫不出来 的文章

 

随机推荐