重构目标:将bos_fore项目中的CustomerAction作为短信消息生产者,将消息发给ActiveMQ,创建一个单独的SMS项目,作为短信息的消费者,从ActiveMQ获取短信消息,调用第三方接口完成短信发送。
CustomerAction完整代码:

@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class CustomerAction extends BaseAction<Customer> {@Autowired@Qualifier("jmsQueueTemplate")private JmsTemplate jmsTemplate;@Action(value = "customer_sendSms")public String sendSms() throws IOException {// 手机号保存在Customer对象// 生成短信验证码String randomCode = RandomStringUtils.randomNumeric(4);// 将短信验证码 保存到sessionServletActionContext.getRequest().getSession().setAttribute(model.getTelephone(), randomCode);System.out.println("生成手机验证码为:" + randomCode);// 编辑短信内容final String msg = "尊敬的用户您好,本次获取的验证码为:" + randomCode+ ",服务电话:4007654321";// 调用MQ服务,发送一条消息jmsTemplate.send("bos_sms", new MessageCreator() {@Overridepublic Message createMessage(Session session) throws JMSException {MapMessage mapMessage = session.createMapMessage();mapMessage.setString("telephone", model.getTelephone());mapMessage.setString("msg", msg);return mapMessage;}});return NONE;}// 属性驱动private String checkcode;public void setCheckcode(String checkcode) {this.checkcode = checkcode;}@Autowiredprivate RedisTemplate<String, String> redisTemplate;@Action(value = "customer_regist", results = {@Result(name = "success", type = "redirect", location = "signup-success.html"),@Result(name = "input", type = "redirect", location = "signup.html") })public String regist() {// 先校验短信验证码,如果不通过,调回注册页面// 从session获取 之前生成验证码String checkcodeSession = (String) ServletActionContext.getRequest().getSession().getAttribute(model.getTelephone());if (checkcodeSession == null || !checkcodeSession.equals(checkcode)) {System.out.println("短信验证码错误...");// 短信验证码错误return INPUT;}// 调用webService 连接CRM 保存客户信息WebClient.create("http://localhost:9002/crm_management/services"+ "/customerService/customer").type(MediaType.APPLICATION_JSON).post(model);System.out.println("客户注册成功...");// 发送一封激活邮件// 生成激活码String activecode = RandomStringUtils.randomNumeric(32);// 将激活码保存到redis,设置24小时失效redisTemplate.opsForValue().set(model.getTelephone(), activecode, 24,TimeUnit.HOURS);// 调用MailUtils发送激活邮件String content = "尊敬的客户您好,请于24小时内,进行邮箱账户的绑定,点击下面地址完成绑定:<br/><a href='"+ MailUtils.activeUrl + "?telephone=" + model.getTelephone()+ "&activecode=" + activecode + "'>速运快递邮箱绑定地址</a>";MailUtils.sendMail("速运快递激活邮件", content, model.getEmail());return SUCCESS;}// 属性驱动private String activecode;public void setActivecode(String activecode) {this.activecode = activecode;}@Action("customer_activeMail")public String activeMail() throws IOException {ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");// 判断激活码是否有效String activecodeRedis = redisTemplate.opsForValue().get(model.getTelephone());if (activecodeRedis == null || !activecodeRedis.equals(activecodeRedis)) {// 激活码无效ServletActionContext.getResponse().getWriter().println("激活码无效,请登录系统,重新绑定邮箱!");} else {// 激活码有效// 防止重复绑定// 调用CRM webService 查询客户信息,判断是否已经绑定Customer customer = WebClient.create("http://localhost:9002/crm_management/services"+ "/customerService/customer/telephone/"+ model.getTelephone()).accept(MediaType.APPLICATION_JSON).get(Customer.class);if (customer.getType() == null || customer.getType() != 1) {// 没有绑定,进行绑定WebClient.create("http://localhost:9002/crm_management/services"+ "/customerService/customer/updatetype/"+ model.getTelephone()).get();ServletActionContext.getResponse().getWriter().println("邮箱绑定成功!");} else {// 已经绑定过ServletActionContext.getResponse().getWriter().println("邮箱已经绑定过,无需重复绑定!");}// 删除redis的激活码redisTemplate.delete(model.getTelephone());}return NONE;}}

spring的配置文件applicationContext-mq.xml完整代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:task="http://www.springframework.org/schema/task"xmlns:amq="http://activemq.apache.org/schema/core"xmlns:jms="http://www.springframework.org/schema/jms"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsdhttp://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsdhttp://www.springframework.org/schema/jmshttp://www.springframework.org/schema/jms/spring-jms.xsdhttp://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd "><!-- ActiveMQ 连接工厂 --><!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供--><!-- 如果连接网络:tcp://ip:61616;未连接网络:tcp://localhost:61616 以及用户名,密码--><amq:connectionFactory id="amqConnectionFactory"brokerURL="tcp://localhost:61616" userName="admin" password="admin"  /><!-- Spring Caching连接工厂 --><!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->  <bean id="mqConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"><!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->  <property name="targetConnectionFactory" ref="amqConnectionFactory"></property><!-- 同上,同理 --><!-- <constructor-arg ref="amqConnectionFactory" /> --><!-- Session缓存数量 --><property name="sessionCacheSize" value="100" /></bean><!-- Spring JmsTemplate 的消息生产者 start--><!-- 定义JmsTemplate的Queue类型 --><bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate"><!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->  <constructor-arg ref="mqConnectionFactory" /><!-- 非pub/sub模型(发布/订阅),即队列模式 --><property name="pubSubDomain" value="false" /></bean><!-- 定义JmsTemplate的Topic类型 --><bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate"><!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->  <constructor-arg ref="mqConnectionFactory" /><!-- pub/sub模型(发布/订阅) --><property name="pubSubDomain" value="true" /></bean><!--Spring JmsTemplate 的消息生产者 end-->
</beans>

maven的pom文件完整代码:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>cn.niwotaxuexiba.maven</groupId><artifactId>common_parent</artifactId><version>0.0.1-SNAPSHOT</version></parent>  <artifactId>bos_fore</artifactId><packaging>war</packaging><name>bos_fore</name><description>物流前端系统</description><build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId><version>1.1</version><configuration><port>9003</port></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build><dependencies><dependency><groupId>cn.niwotaxuexiba.maven</groupId><artifactId>crm_domain</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies>
</project>

重构客户注册-基于ActiveMQ实现短信验证码生产者相关推荐

  1. 某注册页面存在手机短信验证码绕过

    某注册页面存在手机短信验证码绕过的情况 关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭关闭 ...

  2. 基于redis的短信验证码服务开发

    基于redis的短信验证码服务开发 目前可以提供的验证码服务平台有很多,这里选择阿里大于短信验证码服务平台,里面有10元体验卷可以免费试用,不多说上代码.写代码之前需要去阿里大于平台申请验证码服务,同 ...

  3. 快速集成APP注册页面免费获取短信验证码功能

    前言: 最近这段时间都忙着优化自己的个人项目,好久没来总结分享了,今天就抽空跟大家分享一下快速集成APP注册页面免费获取短信验证码功能吧. 一.使用第三方短信SDK前期准备: 在这里我是使用了第三方免 ...

  4. 使用activeMQ发送短信验证码

    package cn.itcast.bos.web.action; /*** 1.获取用户电话号码,生成4位数的验证(随机数),保存到session中,用吉信通发送验证码给客户* 2.客户点击注册,获 ...

  5. 注册简单流程及短信验证码的发送

    一.书写前端页面并前端验证 1.对于注册页面进行排版布局 <label class="control-label">手机号:</label><inpu ...

  6. android 短信注册,Android注冊短信验证码功能

    一.短信验证的效果是通过使用聚合数据的SDK实现的 ,效果例如以下: 二.依据前一段时间的博客中输了怎么注冊! 注冊之后找到个人中心找到申请一个应用就可以! 四.调用SDK 第一步:创建并配置proj ...

  7. SpringBoot基于Session实现短信验证码登录

  8. 注册app短信验证平台_免费的短信验证码平台弊端竟然这么多!

    现如今人们为了工作和生活方便,就注册了大量的网站/app账号,而短信验证码就成为了验证用户身份必不可少的方式,尤其在涉及到付款行为中,手机短信验证成为"必经之路",成为了保证用户安 ...

  9. JAVA怎么对接第三方短信平台?短信验证码完整API文档

    验证码短信平台的应用场景,一般包括用户注册.登陆账号.忘记密码.登录异常.支付确认等. 一.用户注册 通常我们会在注册时会用到短信验证码,即用户在网站或软件上注册账号时,企业需要通过验证码确认用户身份 ...

最新文章

  1. spring boot配置druid
  2. 数据结构源码笔记(C语言):哈希表的相关运算算法
  3. SAP Spartacus里cx-carousel的实现
  4. 09(maven+SSH)网上商城项目实战之使用jersey实现应用服务器和图片服务器分离...
  5. php Closure 类型
  6. 在传统行业做数字化转型之最终篇
  7. 【计算机网络】周知端口号列表
  8. 专业即时通讯工具的SEO人生发力
  9. Python库:Pyinstaller库、pip工具、pip指定安装源和版本
  10. tcga数据下载_TCGA数据下载-GDC
  11. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第3节 两种获取Stream流的方式_4_Stream流的特点_只能使用一次...
  12. python可以跨平台吗_python是跨平台的么
  13. python教材分析_初中信息技术_初识Python教学设计学情分析教材分析课后反思
  14. 产品-Axure9英文版,轮播图效果
  15. 使用无人机倾斜摄影测量技术采集某县城区地理信息数据并生成实景三维模型的案例
  16. 京东青龙面板撸豆_搭建环境流程
  17. cartographer探秘第三章之对比实验
  18. 证券运维外包第3个月工作总结
  19. Cannot attach the file 'C:\Users\raye\Documents\(LocalDB)\MSSQLLocalDB.mdf' as database 'D:\DIY\DMS-
  20. 用户、配额管理 、 云主机类型管理 、 镜像管理 、 网络管理 、 安全和实例管理 、 计算节点扩容案例

热门文章

  1. 建议收藏!最新的(2019年)电子/计算机领域SCI期刊影响因子大全
  2. 全国人工智能大赛 AI+4K HDR赛项 冠军团队方案分享
  3. 模型提效的另一条路:数据增强
  4. 易创课堂上海站干货回顾
  5. Android之获取手机上的图片和视频缩略图thumbnails
  6. AC自动机模板(摘自刘汝佳紫书,无指针)
  7. fresco xml配置属性不起作用
  8. Android官方开发文档Training系列课程中文版:构建第一款安卓应用之入门指南
  9. 百度全面开放HTTPS之我见
  10. session多服务器共享的方案梳理