发表于: 2017-11-25 23:47:41
2 695
今天做的事情:
要将短信接口的demo项目里的jar包放在自己的项目中,必须在maven仓库指定位置, 在网上查了教程,使用一下命令:
mvn install:install-file -Dfile=d:\jar包\ZIP包\CCP_REST_SMS_DEMO_JAVA_v2.6r\demo\lib\CCP_REST_SMS_SDK_JAVA_v2.6.3r.jar -DgroupId=com.google.code -DartifactId=SMSdemo -Dversion=2.6.3 -Dpackaging=jar
Dfile指定了位置 , DgroupId 指定了名称 , Dversion 指定版本。
将短信接口集成到自己项目中,这一天,干的也就这点事,实名点赞姚远师兄,在最重要的时候,站了出来。
在一个测试test里面。测试成功
ApplicationContext context=new ClassPathXmlApplicationContext("classpath:Spring.xml");
SMS sms = (SMS) context.getBean("sms");
sms.sendMessage("13083899038","1212");
使用ApplicationContext来加载配置文件。
手机已收到信息。
接下来可以做一个注册,
晚上抓紧做的页面,虽然简陋,但是最重要的是逻辑。用户名可以判断一下是否唯一,密码两次判断是否一样,头像的话,因为七牛云还没搞好,所以先放放。邮箱验证的话,放在注册之后,登录时做,一般的网站流程也是这样的。
controller层:
@RequestMapping(value = "/checkPhone",method = RequestMethod.GET)
public void checkPhone(String phone, Model model,HttpServletResponse response){
int i = (int)((Math.random()*9+1)*100000);
logger.info("phone 为 :"+phone+"\t随机数为"+i);
sms.sendMessage("phone","i");
// model.addAttribute("msg","1");
try {
response.getWriter().print(1);
} catch (IOException e) {
e.printStackTrace();
}
}
jsp页面。
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.8.2.min.js"></script>
<script>
$(function(){
});
function cheockpwd() {
var password = $("[name=password]").val();
var pwd = $(".pwd").val();
// var password = $(".password").val();
// var pwd = $(".pwd").val();
if(password == pwd){
document.getElementById("tishi").innerHTML="<font color='green'>两次密码相同</font>";
document.getElementById("submit").disabled= false;
}else{
document.getElementById("tishi").innerHTML="<font color='red'>两次密码不相同</font>";
document.getElementById("submit").disabled= true;
}
}
function getStatus() {
var phone = $("[name=phone]").val();
alert(phone);
if(phone!=null){
$.ajax({
url:"checkPhone",
type:"get",
data:{"phone":phone},
success:function (msg) {
if(msg==1){
document.getElementById("sc").innerHTML="<font color='green'>验证码发送成功</font>";
document.getElementById("submit").disabled= false;
}else{
document.getElementById("sc").innerHTML="<font color='red'>验证码发送失败</font>";
document.getElementById("submit").disabled= true;
}
}
})
}
}
</script>
<head>
<title>报名注册页面</title>
</head>
<body>
<form method="post" action="<%=request.getContextPath()%>/a/user">
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td>用户名</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="text" class="password" name="password"></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="text" class="pwd" onblur="cheockpwd()"><span id="tishi"></span></td>
</tr>
<tr>
<td>头像</td>
<td><input type="text" name="headpicture"></td>
</tr>
<tr>
<td>手机号</td>
<td>
<input type="text" name="phone">
<input type="button" onclick="getStatus()" value="获取验证码"></td>
</td>
</tr>
<tr>
<td>验证码</td>
<td><input type="text" id="status"> <span id="sc"></span></td>
</tr>
<tr>
<td>邮箱</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td colspan="2">
<input type="button" id="submit" value="注册" onclick="tj()">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
遇到的问题:
看第三方文档真的是很晕啊。。。没有姚远师兄帮忙集成一下短信接口到项目中,我一天都算是没干事,快挂了。晚上抓紧敲了这些,没有白费时间,时间关系,先提交。
收获:
稍微可以做出一点东西,对第三方接口也有了解,先用,再熟悉。继续加油。
评论