Web系统
创建newbies-shopp-web项目
Maven相关依赖
<!-- 引入freemarker包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
在resources创建templates
新建index.ftl页面 内容
杨改革,微信:Yang_Gaige, www.newbies.com,欢迎你!
application.yml配置文件
server:
port: 80
# context-path: /web
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: message
启动方式
@EnableEurekaClient
@SpringBootApplication
public class WebApp {
public static void main(String[] args) {
SpringApplication.run(WebApp.class, args);
}
}
注册功能
Maven依赖
<dependency>
<groupId>com.newbies</groupId>
<artifactId>newbies-shopp-api-member</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>com.newbies</groupId>
<artifactId>newbies-shopp-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
使用fegin调用会员服务
@Component
@FeignClient(value = "member")
public interface MemberServiceFegin extends MemberService {
}
注册控制层
@Controller
public class RegisterController {
@Autowired
private MemberServiceFegin memberServiceFegin;
private static final String LOGIN = "login";
private static final String REGISTER = "register";
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String register() {
return REGISTER;
}
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(UserEntity user, HttpServletRequest reqest) {
// 1.调用会员服务注册
ResponseBase regUser = memberServiceFegin.regUser(user);
if (!regUser.getRtnCode().equals(Constants.HTTP_RES_CODE_200)) {
reqest.setAttribute("error", regUser.getMsg());
return REGISTER;
}
// 2.注册成功,跳转到登录页面
return LOGIN;
}
}
注册页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>云EC电商系统-欢迎注册会员</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" href="/view/default/css/common.css" />
<link rel="stylesheet" href="/view/default/css/loginregister.css" />
<link rel="stylesheet" href="/view/default/css/valifrom.css" />
</head>
<style>
.form-box .input-box {
overflow: visible;
}
</style>
<body>
<div class="ny-header">
<div class="nb">
<div class="logo">
<a href="../index.html"><img src="static/images/logo.png" alt="" /></a>
<span>· 欢迎注册</span>
</div>
<div class="right">
<span>我已经注册,马上</span> <a href="login.html" class="blue">登录 ></a>
</div>
</div>
</div>
<div class="nb">
<div class="ny-body ny-register">
<div class="left">
<div class="form-box">
<form action="/register" method="post">
<div class="input-box input-box1 onfocusstyle user-word">
<label for="username" class="icon-user"></label> <input
type="text" name="username" id="username" value=""
placeholder="用户名" maxlength="20" autocomplete="off" />
<div class="Validform_checktip formtip">
<span class="i-tip"><i></i><label>支持中文、字母、数字、“-”“_”的组合</label></span>
</div>
</div>
<div class="input-box input-box1 onfocusstyle user-word">
<label for="username" class="icon-user"></label> <input
type="text" name="email" id="email" value=""
placeholder="邮 箱" maxlength="20" autocomplete="off" />
</div>
<div class="input-box onfocusstyle position-input p-w">
<label class="icon-phone" for="mobile"></label> <input
type="text" id="mobile" value="" placeholder="手机号码"
maxlength="11" autocomplete="off" />
<div class="Validform_checktip formtip">
<span class=""><i></i><label></label></span>
</div>
</div>
<div class="input-box onfocusstyle pass-w">
<label class="icon-setpassw" for="password"></label> <input
type="password" name="password" id="password" value=""
placeholder="请输入密码" maxlength="20" min="8" autocomplete="off" />
<div class="Validform_checktip formtip">
<span class="i-tip"><i></i><label>建议使用字母、数字和符号两种及以上的组合,6-20个字符</label></span>
</div>
</div>
<div class="input-box onfocusstyle position-input pass-w2">
<label class="icon-setpassw" for="repassword"></label> <input
type="password" name="repassword" id="repassword" value=""
placeholder="请再次输入密码" maxlength="20" />
<div class="Validform_checktip formtip">
<span class=""><i></i><label></label></span>
</div>
</div>
<div class="check onfocusstyle" style="position: relative;">
<input type="checkbox" nullmsg="请阅读并选择" name="agree" id="agree"
value="1" /> <label for="agree">我已阅读并同意</label> <a
href="javascript:void(0);" class="blue" id="rule">《云EC电商系统用户协议》</a>
<div class="Validform_checktip formtip" style="top: 0px;">
<span class=""><i></i><label></label></span>
</div>
</div>
<div class="input-box sub-box">
<input type="submit" id="reg" value="注册" />
</div>
</form>
</div>
</div>
<div class="right">
<div class="hezuo oauth">
<!--<h4>如果您已注册,请<a href="login.html" class="blue">直接登录</a></h4>
<p style="border-top: dashed 1px #ddd;margin: 15px auto; "></p>-->
<h4>合作网站帐号登录:</h4>
<ul>
<li><a href="/plugin.html?mod=oauth&c=wx" class="wx">微信</a></li>
<li><a href="/plugin.html?mod=oauth&c=qq" class="qq">QQ</a></li>
</ul>
</div>
</div>
</div>
<div class="ny-footer">
<div class="link">
<a href="/">首页</a> | <a href="/n-help.html">关于我们</a> | <a
href="/n-help.html">联系我们</a> | <a href="/timespike.html">限时抢购</a> |
<a href="/user.html">会员中心</a> | <a href="/n-help.html">帮助中心</a>
</div>
<div class="copyright">
<p>
<p>
Copy@2017 <a href="http://www.yunec.cn/" target="_blank">云EC电商系统</a>
<a href="http://www.yunec.cn/" target="_blank">www.yunec.cn</a> All
Rights Reserved 粤ICP备16042138号-1
</p>
</p>
</div>
</div>
</div>
<div class="pass-rule">
<div class="pass-rule-box">
<div class="rule-title">
<h3>用户协议</h3>
<a href="javascript:void(0);" class="btn-close"></a>
<div class="rule-nr">
<h4
style="white-space: normal; margin: 0px; padding: 0px; color: #333333; font-size: 14px; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; line-height: 20px; background-color: #FFFFFF;">
云EC用户注册协议aaaaaaaaaaaaaa</h4>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
本协议是您与云EC网站(简称"本站",网址:www.yunec.cn)所有者(以下简称为"云EC")之间就云EC网站服务等相关事宜所订立的契约,请您仔细阅读本注册协议,您点击"同意并继续"按钮后,本协议即构成对双方有约束力的法律文件。
</p>
<h5
style="white-space: normal; margin: 10px 0px; padding: 0px; color: #333333; font-size: 14px; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; line-height: 20px; background-color: #FFFFFF;">
第1条 本站服务条款的确认和接纳</h5>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">1.1</strong>本站的各项电子服务的所有权和运作权归云EC所有。用户同意所有注册协议条款并完成注册程序,才能成为本站的正式用户。用户确认:本协议条款是处理双方权利义务的契约,始终有效,法律另有强制性规定或双方另有特别约定的,依其规定。
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">1.2</strong>用户点击同意本协议的,即视为用户确认自己具有享受本站服务、下单购物等相应的权利能力和行为能力,能够独立承担法律责任。
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">1.3</strong>如果您在18周岁以下,您只能在父母或监护人的监护参与下才能使用本站。
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">1.4</strong>云EC保留在*大陆地区法施行之法律允许的范围内独自决定拒绝服务、关闭用户账户、清除或编辑内容或取消订单的权利。
</p>
<h5
style="white-space: normal; margin: 10px 0px; padding: 0px; color: #333333; font-size: 14px; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; line-height: 20px; background-color: #FFFFFF;">
第2条 本站服务</h5>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">2.1</strong>云EC通过互联网依法为用户提供互联网信息等服务,用户在完全同意本协议及本站规定的情况下,方有权使用本站的相关服务。
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">2.2</strong>用户必须自行准备如下设备和承担如下开支:(1)上网设备,包括并不限于电脑或者其他上网终端、调制解调器及其他必备的上网装置;(2)上网开支,包括并不限于网络接入费、上网设备租用费、手机流量费等。
</p>
<h5
style="white-space: normal; margin: 10px 0px; padding: 0px; color: #333333; font-size: 14px; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; line-height: 20px; background-color: #FFFFFF;">
第3条 用户信息</h5>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">3.1</strong>用户应自行诚信向本站提供注册资料,用户同意其提供的注册资料真实、准确、完整、合法有效,用户注册资料如有变动的,应及时更新其注册资料。如果用户提供的注册资料不合法、不真实、不准确、不详尽的,用户需承担因此引起的相应责任及后果,并且云EC保留终止用户使用云EC各项服务的权利。
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="margin: 0px; padding: 0px;">3.2</strong>用户在本站进行浏览、下单购物等活动时,涉及用户真实姓名/名称、通信地址、联系电话、电子邮箱等隐私信息的,本站将予以严格保密,除非得到用户的授权或法律另有规定,本站不会向外界披露用户隐私信息。
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<br />
</p>
<p
style="margin-top: 0px; margin-bottom: 0px; white-space: normal; padding: 0px; color: #666666; font-family: 'Microsoft YaHei', 'Hiragino Sans GB'; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<h4
style="box-sizing: border-box; margin: 0px; padding: 0px; font-weight: normal; font-size: 14px; color: #333333; text-align: justify; white-space: normal; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; line-height: 20px; background-color: #FFFFFF;">
云EC用户注册协议aaaaaaaaaaaaaa</h4>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
本协议是您与云EC网站(简称"本站",网址:www.yunec.cn)所有者(以下简称为"云EC")之间就云EC网站服务等相关事宜所订立的契约,请您仔细阅读本注册协议,您点击"同意并继续"按钮后,本协议即构成对双方有约束力的法律文件。
</p>
<h5
style="box-sizing: border-box; margin: 10px 0px; padding: 0px; font-weight: normal; font-size: 14px; color: #333333; text-align: justify; white-space: normal; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; line-height: 20px; background-color: #FFFFFF;">
第1条 本站服务条款的确认和接纳</h5>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">1.1</strong>本站的各项电子服务的所有权和运作权归云EC所有。用户同意所有注册协议条款并完成注册程序,才能成为本站的正式用户。用户确认:本协议条款是处理双方权利义务的契约,始终有效,法律另有强制性规定或双方另有特别约定的,依其规定。
</p>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">1.2</strong>用户点击同意本协议的,即视为用户确认自己具有享受本站服务、下单购物等相应的权利能力和行为能力,能够独立承担法律责任。
</p>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">1.3</strong>如果您在18周岁以下,您只能在父母或监护人的监护参与下才能使用本站。
</p>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">1.4</strong>云EC保留在*大陆地区法施行之法律允许的范围内独自决定拒绝服务、关闭用户账户、清除或编辑内容或取消订单的权利。
</p>
<h5
style="box-sizing: border-box; margin: 10px 0px; padding: 0px; font-weight: normal; font-size: 14px; color: #333333; text-align: justify; white-space: normal; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; line-height: 20px; background-color: #FFFFFF;">
第2条 本站服务</h5>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">2.1</strong>云EC通过互联网依法为用户提供互联网信息等服务,用户在完全同意本协议及本站规定的情况下,方有权使用本站的相关服务。
</p>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">2.2</strong>用户必须自行准备如下设备和承担如下开支:(1)上网设备,包括并不限于电脑或者其他上网终端、调制解调器及其他必备的上网装置;(2)上网开支,包括并不限于网络接入费、上网设备租用费、手机流量费等。
</p>
<h5
style="box-sizing: border-box; margin: 10px 0px; padding: 0px; font-weight: normal; font-size: 14px; color: #333333; text-align: justify; white-space: normal; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; line-height: 20px; background-color: #FFFFFF;">
第3条 用户信息</h5>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">3.1</strong>用户应自行诚信向本站提供注册资料,用户同意其提供的注册资料真实、准确、完整、合法有效,用户注册资料如有变动的,应及时更新其注册资料。如果用户提供的注册资料不合法、不真实、不准确、不详尽的,用户需承担因此引起的相应责任及后果,并且云EC保留终止用户使用云EC各项服务的权利。
</p>
<p
style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; padding: 0px; text-align: justify; white-space: normal; color: #666666; font-family: & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; quot; font-size: 14px; line-height: 20px; background-color: #FFFFFF;">
<strong style="box-sizing: border-box; margin: 0px; padding: 0px;">3.2</strong>用户在本站进行浏览、下单购物等活动时,涉及用户真实姓名/名称、通信地址、联系电话、电子邮箱等隐私信息的,本站将予以严格保密,除非得到用户的授权或法律另有规定,本站不会向外界披露用户隐私信息。
</p>
</p>
<div>
<br />
</div>
</div>
</div>
</div>
</div>
<div id="mask"></div>
<script src="/view/default/js/jquery-1.9.1.min.js"
type="text/javascript"></script>
<script src="/view/default/js/main.js" type="text/javascript"></script>
<script src="/view/default/js/users.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
});
</script>
<p style="display: none;"></p>
</body>
</html>
登录功能
登录控制层
@Controller
public class LoginController {
private static final String LOGIN = "login";
private static final String INDEX = "redirect:/";
@Autowired
private MemberServiceFegin memberServiceFegin;
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login() {
return LOGIN;
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(UserEntity userEntity, HttpServletRequest reqest, HttpServletResponse response) {
// 1.调用登录接口
ResponseBase login = memberServiceFegin.login(userEntity);
if (!login.getRtnCode().equals(Constants.HTTP_RES_CODE_200)) {
reqest.setAttribute("error", "账号或密码错误!");
return LOGIN;
}
// 2.登录成功,获取token信息
LinkedHashMap linkedHashMap = (LinkedHashMap) login.getData();
String memberToken = (String) linkedHashMap.get("memberToken");
if (StringUtils.isEmpty(memberToken)) {
reqest.setAttribute("error", "token已经失效!");
return LOGIN;
}
// 3.将token存放在cookie中
CookieUtil.addCookie(response, Constants.MEMBER_TOKEN_KEY, memberToken, Constants.MEMBER_TOKEN_COOKIE);
return INDEX;
}
}
登录页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SpringCloud-欢迎登录</title>
<link rel="stylesheet" href="/view/default/css/common.css" />
<link rel="stylesheet" href="/view/default/css/loginregister.css" />
<link rel="stylesheet" href="/view/default/css/valifrom.css" />
<style>
.form-box .input-box {
overflow: hidden;
}
</style>
</head>
<body
onkeypress="if(event.keyCode==13){document.getElementById('login').click();return false;}">
<div class="ny-header">
<div class="nb">
<div class="logo">
<a href="/index.html"><img src="view/default/images/logo.png"
alt="" style="width: 200px; height: 60px" /></a>
</div>
<div class="right login-right">
<span>您好!欢迎光临云EC电商系统 !</span> <a href="/n-help.html">帮助中心</a>
</div>
</div>
</div>
<div class="nb">
<div class="ny-body ny-zsy">
<div class="left">
<img src="/view/default/images/login-pic.jpg" alt="" />
</div>
<div class="right">
<div class="form-box">
<form action="login" method="post">
<h3>SpringCloud电商系统用户登录</h3>
<div class="bind">
<a href="register" class="blue">注册账号</a>
</div>
<div class="input-box input-box1 onfocusstyle user-word">
<label for="loginname" class="icon-user"></label> <input
type="text" name="username" id="loginname" value=""
placeholder="用户名/手机号码" class="position-input" maxlength="20"
datatype="*" autocomplete="off" />
<div class="Validform_checktip formtip">
<span class=""><i></i><label></label></span>
</div>
</div>
<div class="input-box onfocusstyle passw-word">
<label for="passw" class="icon-passw"></label> <input
type="password" name="password" id="passw" value=""
placeholder="密码" class="position-input" maxlength="20"
datatype="*" autocomplete="off" />
<div class="Validform_checktip formtip">
<span class=""><i></i><label></label></span>
</div>
</div>
<div class="input-box onfocusstyle yanm-div"
style="display: none;">
<label for="authcode" class="icon-passw"></label> <input
type="text" maxlength="4" name="authcode" id="authcode" value=""
placeholder="验证码" class="position-input" nullmsg="请输入验证码!"
datatype="*" onclick="showvode();" /> <img id="mx"
style="cursor: pointer;" src="" alt="看不清?点击更换另一个验证码" border="1"
onClick="refreshimage(this)" title="看不清?点击更换另一个验证码">
<div class="Validform_checktip formtip">
<span class=""><i></i><label></label></span>
</div>
</div>
<div class="check">
<span class="mh-checkbox checkbox-stylemh"><input
type="checkbox" id="autologin" value="1" class="zdlogin-btn"
checked="checked" /></span> <label for="autologin">自动登录</label>
<a href="findpwd.html" target="_blank">忘记密码?</a>
</div>
<div class="input-box sub-box">
<input type="submit" id="login" value="登录" /> <#if error ?? > <span
style="color: red; font-size: 18px;"> ${error} </span> </#if>
</div>
</form>
<div class="hezuo oauth">
<h4>合作网站帐号登录</h4>
<ul>
<li><a href="/plugin.html?mod=oauth&c=wx" class="wx">微信</a></li>
<li><a href="/plugin.html?mod=oauth&c=qq" class="qq">QQ</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="ny-footer">
<div class="link">
<a href="/" target="_blank">首页</a>| <a href="/n-help.html">关于我们</a>
| <a href="/n-help.html">联系我们</a> | <a href="/timespike.html">限时抢购</a>
| <a href="/user.html">会员中心</a> | <a href="/n-help.html">帮助中心</a>
</div>
<div class="copyright">
<p>
<p>
Copy@2017 <a href="http://www.yunec.cn/" target="_blank">云EC电商系统</a>
<a href="http://www.yunec.cn/" target="_blank">www.yunec.cn</a> All
Rights Reserved 粤ICP备16042138号-1
</p>
</p>
</div>
</div>
</div>
<script src="/view/default/js/jquery-1.9.1.min.js"
type="text/javascript"></script>
<script src="/view/default/js/main.js" type="text/javascript"></script>
<script src="/view/default/js/users.js" type="text/javascript"></script>
<script>
$(function() {
loadLayer();
});
var return_url = '';
$(".hezuo li:last-child").css("margin-right", 0);
$(".position-input").focus(function() {
$(this).parent(".onfocusstyle").css({
"border-color" : "#abcdef"
}).siblings().css({
"border-color" : "#dedede"
});
});
$(".position-input").blur(function() {
$(this).parent(".onfocusstyle").css({
"border-color" : "#dedede"
}).siblings().css({
"border-color" : "#dedede"
});
});
$(".mh-checkbox").on("click", function() {
if ($(this).hasClass("checkbox-stylemh")) {
$(this).removeClass("checkbox-stylemh");
$(".zdlogin-btn").attr("checked", false);
} else {
$(this).addClass("checkbox-stylemh");
$(".zdlogin-btn").attr("checked", true);
}
});
if ((navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent
.indexOf('MSIE 10') == -1)
&& (navigator.userAgent.indexOf('Opera') < 0)) {
var a = navigator.userAgent;
$(".passw-word").append("<span>密码</span>");
$(".user-word").append("<span>用户名</span>");
$("#passw,#loginname").blur(function() {
if ($("#passw").val() == "") {
$(".passw-word").append("<span>密码</span>");
}
});
$("#loginname")
.blur(
function() {
$(".user-word")
.append(
$("#loginname").val() == "" ? "<span>用户名</span>"
: "");
});
$("#passw").focus(function() {
$(".passw-word span").remove();
});
$("#loginname").focus(function() {
$(".user-word span").remove();
});
}
function refreshimage(clickidimg) {
clickidimg.src = '/vcode-M.html' + '?' + Date.parse(new Date());
}
function showvode() {
document.getElementById('mx').style.display = 'block';
}
document.getElementById('mx').src = '/vcode-M.html' + '?'
+ Date.parse(new Date());
function refreshimage(clickidimg) {
clickidimg.src = clickidimg.src + '?' + Date.parse(new Date());
}
</script>
<p style="display: none;"></p>
</body>
</html>
QQ授权
java对接QQ登录
QQ授权步骤
1.生成授权连接,需要配置回调地址
https://graph.qq.com/oauth2.0/authorize?response_type=code&
client_id=101420900&redirect_uri=http://127.0.0.1/qqLoginCallback&
state=1234656
2.通过授权码换取assessToken
https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&
client_id=101420900&client_secret=bd56a336f6ac49a65005595c2a41201a&code=F732DD04857AD75AA3AEC7A09B5
45500&redirect_uri=http://127.0.0.1/qqLoginCallback
3.使用assessToken换取openid
https://graph.qq.com/oauth2.0/me?access_token=D08A024B0AAD7DD0F279BF8D0EDC8D1A
4.使用openid和assessToken获取用户信息
https://graph.qq.com/user/get_user_info?
access_token=D08A024B0AAD7DD0F279BF8D0EDC8D1A&
oauth_consumer_key=101420900&
openid=0C4D91D8B0F80BF0C3E9D295DCA362B7
将Sdk4J.jar打包到maven本地仓库或私服中
mvn install:install-file -Dfile=F:/Sdk4J.jar -DgroupId=com.sdk4j -DartifactId=sdk4j -Dversion=1.0 -Dpackaging=jar
maven依赖
<dependency>
<groupId>com.sdk4j</groupId>
<artifactId>sdk4j</artifactId>
<version>1.0</version>
</dependency>
将QQ授权配置文件
修改信息app_ID、app_KEY、redirect_URI
封装跳转QQ登录地址
/**
* 跳转到QQ授权地址
* @param request
* @return
* @throws QQConnectException
*/
@RequestMapping("/locaQQLogin")
public String locaQQLogin(HttpServletRequest request) throws QQConnectException {
String authorizeURL = new Oauth().getAuthorizeURL(request);
return "redirect:"+authorizeURL;
}
封装QQ授权回调地址
@RequestMapping("/qqLoginCallback")
public String qqLoginCallback(HttpServletRequest request, HttpServletResponse response, HttpSession httpSession)
throws QQConnectException {
AccessToken accessTokenObj = new Oauth().getAccessTokenByRequest(request);
if (accessTokenObj == null) {
request.setAttribute("error", "qq授权失败!");
return ERROR;
}
String accessToken = accessTokenObj.getAccessToken();
if (StringUtils.isEmpty(accessToken)) {
request.setAttribute("error", "qq授权失败!");
return ERROR;
}
// 获取openid
OpenID openIdObj = new OpenID(accessToken);
String userOpenID = openIdObj.getUserOpenID();
ResponseBase openIdUser = memberServiceFegin.findByOpenIdUser(userOpenID);
// 用戶沒有关联QQ账号
if (openIdUser.getRtnCode().equals(Constants.HTTP_RES_CODE_201)) {
// 跳转到管理账号
httpSession.setAttribute("qqOpenid", userOpenID);
return RELATION;
}
// 如果用户关联账号 直接登录
LinkedHashMap dataMap = (LinkedHashMap) openIdUser.getData();
return cookieLogin(request, response, dataMap);
}
会员服务新增两个接口
使用openid查询用户信息
public ResponseBase findByOpenIdUser(@RequestParam("openId") String openId) {
if (StringUtils.isEmpty(openId)) {
return setResultError("openId不能为空!");
}
UserEntity userEntity = memberDao.findByOpenIdUser(openId);
if (userEntity == null) {
return setResultErrorCode(Constants.HTTP_RES_CODE_201, "用户未授权QQ登录.");
}
Integer userId = userEntity.getId();
JSONObject jsonObject = setUserRedis(userId);
return setResultSuccess(jsonObject);
}
openid关联userId
public ResponseBase qqLoginOpenId(@RequestBody UserEntity user) {
// 1.验证参数
String username = user.getUsername();
if (StringUtils.isEmpty(username)) {
return setResultError("用戶名称不能为空!");
}
String password = user.getPassword();
if (StringUtils.isEmpty(password)) {
return setResultError("密码不能为空!");
}
// 2.数据库查找账号密码是否正确
String newPassWrod = MD5Util.MD5(password);
UserEntity userEntity = memberDao.login(username, newPassWrod);
if (userEntity == null) {
return setResultError("账号或者密码不能正确");
}
// 3. 关联userid
String openid = user.getOpenid();
Integer userId = userEntity.getId();
memberDao.updateUser(openid, userId);
JSONObject jsonObject = setUserRedis(userId);
return setResultSuccess(jsonObject);
}