Giter Site home page Giter Site logo

sailing's Introduction

验证码服务使用指南

1 部署验证码服务

1.1 基础环境

​ Java 1.8+

1.2 安装Redis

验证码服务使用了Redis存储生成的信息,所以需要先安装Redis。确认6379端口未被占用

  1. 下载安装包:https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.zip

  2. 解压安装,将下载的Redis-x64-3.2.100.zip 解压到某个地址

  3. 启动Redis:打开一个cmd窗口,使用cd命令切换到上边的解压目录

    cd C:\work\Redis-x64-3.2.100
    redis-server.exe redis.windows.conf
  4. 测试:再打开一个cmd窗口,启动Redis客户端

    cd C:\work\Redis-x64-3.2.100
    redis-cli.exe -h 127.0.0.1 -p 6379
    

    设置键值对:

    set key abc
    

    取出键值对:

    get key
    

1.3 部署验证码服务

1.3.1 下载源码
git clone https://github.com/fightingape/sailing.git
1.3.2 使用idea打开项目
1.3.3 注册腾讯云短信服务

本服务中的短信发送使用了腾讯云短信服务,需要注册腾讯云开通短信服务:

https://cloud.tencent.com/product/isms/getting-started

  1. 开通短信服务成功后,获取 SDKAppID 和 AppKey** 云短信应用 SDKAppIDAppKey 可在 短信控制台 的应用信息里获取。如您尚未添加应用,请登录 短信控制台 添加应用。

  2. 申请签名并确认审核通过 一个完整的短信由短信签名短信正文内容两部分组成,短信签名需申请和审核,签名可在 短信控制台的相应服务模块【内容配置】中进行申请,详细申请操作请参见 创建签名。发送国际短信时,允许不携带签名。

  3. 申请模板并确认审核通过 短信或语音正文内容模板需申请和审核,模板可在 短信控制台 的相应服务模块【内容配置】中进行申请,详细申请操作请参见 创建正文模板

1.3.4 配置短信参数
  1. 打开项目中sailing/src/main/resources/application.yml

  2. 将腾讯云短信服务获取到参数做如下配置:

    sms:
      qcloud:
        appId: 14000000
        appKey: 36ff7sd14d0d2342344cdf335cc25052
        templateId: 234323
        sign: 签名
1.3.5 控制台获取验证码

如果暂时没有申请到腾讯云短信服务,可以临时将验证码输出到控制台。

修改sailing/src/main/java/cn/itcast/sailing/handler/SmsNumberVerificationHandler.java

	@Override
	String confusion(Map<String, Object> payload, String key, String code) {
		String mobile = String.valueOf(payload.get("mobile"));

		// 使用腾讯云发送短信
		//smsService.send(mobile, code, getEffectiveTime());

		// 测试使用,在控制台输出验证码
		smsService.sendOnConsole(mobile, code, getEffectiveTime());
		return null;
	}
1.3.6 启动服务
Tomcat started on port(s): 56085 (http) with context path '/sailing'
Started SailingBootstrap in 3.224 seconds (JVM running for 4.01)
Completed initialization in 7 ms

在控制台查看验证码:

INFO [http-nio-56085-exec-1][QCloudSmsService.java:37] - 给手机号17717815555发送验证码:575184

sailing's People

Contributors

fightingape avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sailing's Issues

无法连接redis

各位有遇到无法连接redis的问题吗?yaml文件修改了redis密码还是提示连接失败。
org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379
at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:86)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1085)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1065)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:865)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:340)
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132)
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95)
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:82)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:211)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:256)
at cn.itcast.sailing.common.cache.RedisCache.set(RedisCache.java:44)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.