Commit 644a8841 authored by ysongq's avatar ysongq

commit

parent 436ffdf8
......@@ -16,65 +16,63 @@ import com.aliyuncs.profile.IClientProfile;
* @Version:
*/
public class SMSUtils {
public static final String VALIDATE_CODE = "SMS_198677589";//发送短信验证码 验证码签名, 改成你的
public static final String ORDER_NOTICE = "SMS_159771588";//成功通知, 通知类的模板(需要通用的签名)
private static final String SIGN_NAEM = "ysongq商城";// 短信的签名
private static final String PARAMETER_NAME="code"; // 短信模板内容中的参数名
private static final String ACCESS_KEY="LTAI4GAnKS1Gj2NwDepvyBuB"; //AccessKey ID
private static final String SECRET_KEY="BIHOQP6muPtCz9YzrSQpSj0dJjZIET"; //AccessKey Secret
public static final String VALIDATE_CODE = "SMS_205878938";//发送短信验证码模板编码 模版CODE
public static final String ORDER_NOTICE = "SMS_159771588";//体检预约成功通知
private static final String SIGN_NAEM = "万家数据商城";// 短信的签名
private static final String PARAMETER_NAME="code";
private static final String ACCESS_KEY="LTAI4GKPoTkrT6n2fSV7ePEG"; //你的AccessKey ID
private static final String SECRET_KEY="k8HcW3TxZzGxAetEpyDInZehip9MAE"; //你的AccessKey Secret
public static void main(String[] args) throws ClientException {
SMSUtils.sendShortMessage("VALIDATE_CODE","18279617424","666666");
SMSUtils.sendShortMessage(VALIDATE_CODE,"19979232865","55555555");
}
/**
* 发送短信
* @param templateCode 验证码的模板code
* @param phoneNumbers 接收的手机号码
* @param param 验证码
*
* @param templateCode
* @param phoneNumbers
* @param param
* @throws ClientException
*/
public static void sendShortMessage(String templateCode,String phoneNumbers,String param) throws ClientException {
//设置超时时间-可自行调整
public static void sendShortMessage(String templateCode,String phoneNumbers,String param) throws ClientException{
// 设置超时时间-可自行调整
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化ascClient需要的几个参数
final String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)
final String domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改)
//替换成你的AK
final String accessKeyId = ACCESS_KEY;//你的accessKeyId,参考本文档步骤2
final String accessKeySecret = SECRET_KEY;//你的accessKeySecret,参考本文档步骤2
//初始化ascClient,暂时不支持多region(请勿修改)
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId,
accessKeySecret);
// 初始化ascClient需要的几个参数
final String product = "Dysmsapi";// 短信API产品名称(短信产品名固定,无需修改)
final String domain = "dysmsapi.aliyuncs.com";// 短信API产品域名(接口地址固定,无需修改)
// 替换成你的AK
final String accessKeyId = "LTAIak3CfAehK7cE";// 你的accessKeyId,参考本文档步骤2
final String accessKeySecret = "zsykwhTIFa48f8fFdU06GOKjHWHel4";// 你的accessKeySecret,参考本文档步骤2
// 初始化ascClient,暂时不支持多region(请勿修改)
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESS_KEY, SECRET_KEY);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象
// 组装请求对象
SendSmsRequest request = new SendSmsRequest();
//使用post提交
// 使用post提交
request.setMethod(MethodType.POST);
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为国际区号+号码,如“85200000000”
request.setPhoneNumbers("1500000000");
//必填:短信签名-可在短信控制台中找到
request.setSignName("云通信");
//必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版
request.setTemplateCode("SMS_1000000");
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
//友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
//参考:request.setTemplateParam("{\"变量1\":\"值1\",\"变量2\":\"值2\",\"变量3\":\"值3\"}")
request.setTemplateParam("{\"name\":\"Tom\", \"code\":\"123\"}");
//可选-上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段)
//request.setSmsUpExtendCode("90997");
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
request.setOutId("yourOutId");
//请求失败这里会抛ClientException异常
// 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
request.setPhoneNumbers(phoneNumbers);
// 必填:短信签名-可在短信控制台中找到
request.setSignName(SIGN_NAEM);
// 必填:短信模板-可在短信控制台中找到
request.setTemplateCode(templateCode);
// 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
// 友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
//request.setTemplateParam("{\"code\":\""+param+"\"}");
request.setTemplateParam(String.format("{\"%s\":\"%s\"}",PARAMETER_NAME,param));
// 可选-上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段)
// request.setSmsUpExtendCode("90997");
// 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
// request.setOutId("yourOutId");
// 请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
//请求成功
if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
// 请求成功
System.out.println("请求成功");
}else{
System.out.println(sendSmsResponse.getMessage());
}
}
}
......@@ -9,6 +9,6 @@ package com.jz.common.utils;
public class StatusCode {
public static final int OK = 200; // 成功
public static final int ERROR = 201; // 失败
public static final int LOGINERROR = 30002; // 用户名或密码错误
public static final int ACCESSERROR = 30003; // 权限不足
public static final int LOGINERROR = 301; // 用户名或密码错误
public static final int ACCESSERROR = 302; // 权限不足
}
......@@ -10,6 +10,7 @@ import com.jz.dm.mall.moduls.controller.customer.bean.CustomerDto;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.dm.mall.moduls.service.MallCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -28,7 +29,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/customer")
@Api(tags = "商城登陆api")
@Api(tags = "商城登陆--controller")
public class LoginController {
/**
* 服务对象
......@@ -76,13 +77,14 @@ public class LoginController {
/**
* 手机获取验证码
*
* @param paramMap
* @param
* @return
*/
@PostMapping(value = "/getCode")
public Result loginCheck(@RequestParam(required = true) Map<String, String> paramMap) {
@ApiOperation("通过手机号码获取验证码")
public Result loginCheck(@RequestParam(value = "telephone") String telephone,
@RequestParam(value = "validateCode")String validateCode) {
// 获取手机号码
String telephone = paramMap.get("telephone");
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 获取redis中key对应的值
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
......@@ -90,7 +92,7 @@ public class LoginController {
return new Result(false, "请重新获取验证码!", StatusCode.ERROR);
}
// 判断验证码是否一致
if (!codeInRedis.equals(paramMap.get("validateCode"))) {
if (!codeInRedis.equals(validateCode)) {
return new Result(false, "验证码不正确!", StatusCode.ERROR);
}
// 删除redis的验证码
......@@ -109,13 +111,13 @@ public class LoginController {
@ApiOperation(value = "手机号码校验接口", notes = "手机号码是否已注册")
public Result phoneCheck(@RequestParam("telephone") String telephone) {
if (telephone == null) {
return new Result(false, "请重新输入手机号!");
return new Result(false, "请重新输入手机号!",StatusCode.ERROR);
}
MallCustomer mallCustomer = mallCustomerService.selectByPhone(telephone);
if (mallCustomer != null) {
return new Result(false, "手机号码已注册!");
return new Result(false, "手机号码已注册!", StatusCode.ERROR);
}
return new Result(true, "手机号码未注册!");
return new Result(true, "手机号码未注册!", StatusCode.OK);
}
......@@ -136,7 +138,7 @@ public class LoginController {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(telephone);
if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(telephone)) {
return new Result(false, "手机号相同");
return new Result(false, "手机号相同", StatusCode.ERROR);
}
}
}
......@@ -144,9 +146,9 @@ public class LoginController {
CustomerDto mallCustomer = mallCustomerService.selectByAccount(username, request);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username)) {
return new Result(false, "用户名相同!");
return new Result(false, "用户名相同!", StatusCode.ERROR);
}
}
return new Result(true, "用户名不同!");
return new Result(true, "用户名不同!", StatusCode.OK);
}
}
......@@ -34,7 +34,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/mallCustomer")
@Api(tags = "商城用户api")
@Api(tags = "商城用户--controller")
public class MallCustomerController extends BaseController {
/**
* 服务对象
......@@ -61,7 +61,7 @@ public class MallCustomerController extends BaseController {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(telephone);
if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(telephone)) {
return new Result(false, "手机号相同");
return new Result(false, "手机号相同", StatusCode.ERROR);
}
}
}
......@@ -69,7 +69,7 @@ public class MallCustomerController extends BaseController {
CustomerDto mallCustomer = mallCustomerService.selectByAccount(username, request);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username)) {
return new Result(false, "用户名相同");
return new Result(false, "用户名相同", StatusCode.ERROR);
}
}
mallCustomerService.saveCustomer(paramMap);
......@@ -95,12 +95,12 @@ public class MallCustomerController extends BaseController {
return new Result(true, "获取用户信息成功!", StatusCode.OK, user);
}catch (Exception e) {
e.printStackTrace();
return new Result(false, "获取用户信息失败");
return new Result(false, "获取用户信息失败", StatusCode.ERROR);
}
}
@PostMapping(value = "/updatePassword")
@ApiModelProperty(value = "密码修改")
@ApiOperation(value = "密码修改")
public Result updatePassword(@RequestParam(value = "oldPassWard") String oldPassword,
@RequestParam(value = "newPassword")String newPassword,HttpServletRequest request) throws Exception {
// 获取用户信息
......@@ -110,8 +110,8 @@ public class MallCustomerController extends BaseController {
// 修改密码
Long customerId = mallCustomer.getCustomerId();
mallCustomerService.updatePassword(customerId, newPassword);
return new Result(true, "密码修改成功");
return new Result(true, "密码修改成功", StatusCode.OK);
}
return new Result(false, "密码修改失败");
return new Result(false, "密码修改失败", StatusCode.ERROR);
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ import reactor.core.publisher.Mono;
**/
@RestController
@RequestMapping("/personalUser")
@Api(tags = "用户信息controller")
@Api(tags = "用户信息--controller")
public class PersonalUserController {
@Autowired
......
......@@ -4,8 +4,11 @@ import com.aliyuncs.exceptions.ClientException;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.utils.Result;
import com.jz.common.utils.SMSUtils;
import com.jz.common.utils.StatusCode;
import com.jz.common.utils.ValidateCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
......@@ -24,7 +27,7 @@ import java.util.concurrent.TimeUnit;
*/
@RestController
@RequestMapping("/validateCode")
@Api(tags = "短信发送api")
@Api(tags = "短信发送--controller")
public class ValidateCodeController {
@Autowired
......@@ -36,13 +39,14 @@ public class ValidateCodeController {
* @return
*/
@PostMapping(value = "/sendForLogin")
@ApiOperation(value = "注册时发送的验证码")
public Result sendForLogin(String telephone) {
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 通过手机号从redis获取验证码
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (!StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "验证码已发送,请注意查收!");
return new Result(false, "验证码已发送,请注意查收!", StatusCode.ERROR);
}else {
// 生成验证码
String code = ValidateCodeUtils.generateValidateCode(6) + "";
......@@ -51,11 +55,11 @@ public class ValidateCodeController {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!");
return new Result(false, "验证码发送失败!", StatusCode.ERROR);
}
// 存入redis, 有效期为5分钟
redisTemplate.opsForValue().set(key,code,5, TimeUnit.MINUTES);
return new Result(true, "验证码发送成功!");
return new Result(true, "验证码发送成功!", StatusCode.OK);
}
}
......@@ -66,13 +70,14 @@ public class ValidateCodeController {
* @return
*/
@PostMapping("/send4Code")
@ApiOperation(value = "修改密码发送验证码")
public Result send4Code(String telephone) {
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 通过手机号从redis获取验证码
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (!StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "验证码已发送,请注意查收!");
return new Result(false, "验证码已发送,请注意查收!", StatusCode.ERROR);
} else {
// 生成验证码
String code = ValidateCodeUtils.generateValidateCode(6) + "";
......@@ -81,11 +86,11 @@ public class ValidateCodeController {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!");
return new Result(false, "验证码发送失败!", StatusCode.ERROR);
}
// 存入redis, 有效期为5分钟
redisTemplate.opsForValue().set(key, code, 5, TimeUnit.MINUTES);
return new Result(true, "验证码发送成功!");
return new Result(true, "验证码发送成功!", StatusCode.OK);
}
}
}
......@@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("dataGoodsApi")
@Api("api商品详情")
@Api(tags = "商品详情--controller")
public class DataGoodsApiController extends BaseController {
/**
* 服务对象
......@@ -44,6 +44,6 @@ public class DataGoodsApiController extends BaseController {
DataGoodsApiDto dataGoodsApi = tDataGoodsApiService.selectById(id);
return new Result<DataGoodsApiDto>(true, "查询商品详情成功!", StatusCode.OK, dataGoodsApi);
}
return new Result<>(false, "查询商品详情失败!");
return new Result<>(false, "查询商品详情失败!",StatusCode.ERROR);
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import com.jz.dm.mall.moduls.controller.goods.bean.request.DataGoodsListRequest;
import com.jz.dm.mall.moduls.controller.goods.bean.request.DataGoodsRequest;
import com.jz.dm.mall.moduls.entity.DataGoods;
import com.jz.dm.mall.moduls.service.DataGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -26,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
*/
@RestController
@RequestMapping("dataGoods")
@Api(tags = "数据商品--controller")
public class DataGoodsController extends BaseController {
/**
* 服务对象
......
......@@ -22,7 +22,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("mallHotRecommendGoods")
@Api(tags = "热门商品api")
@Api(tags = "热门商品--controller")
public class MallHotRecommendGoodsController extends BaseController {
/**
* 服务对象
......
......@@ -25,7 +25,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/order")
@Api(tags = "订单管理")
@Api(tags = "订单管理--controller")
public class OrderController {
/**
* 服务对象
......
......@@ -41,6 +41,6 @@ public class DataGoodsApiController extends BaseController {
DataGoodsApiDto dataGoodsApi = tDataGoodsApiService.selectById(id);
return new Result<DataGoodsApiDto>(true, "查询商品详情成功!", StatusCode.OK, dataGoodsApi);
}
return new Result<>(false, "查询商品详情失败!");
return new Result<>(false, "查询商品详情失败!", StatusCode.ERROR);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment