Merge remote-tracking branch 'origin/master'
commit
d432ae703c
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.config.util;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author A3385
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CodeEntity implements Serializable {
|
||||
|
||||
|
||||
private String phone;
|
||||
|
||||
private String code;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.config.util;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author A3385
|
||||
*/
|
||||
|
||||
public class MsgUtil {
|
||||
//取code
|
||||
@Cacheable(key = "#phone",value = "bbb")
|
||||
public String getCacheCode(String phone){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//把当前注解的返回值装进去 //存code
|
||||
@CachePut(key = "#codeEntity.phone",value = "bbb")
|
||||
public String saveCacheCode(CodeEntity codeEntity){
|
||||
return codeEntity.getCode();
|
||||
}
|
||||
|
||||
public static void sendMsg(String phone, String code){
|
||||
String result = null;
|
||||
String host = "https://gyyyx1.market.alicloudapi.com";
|
||||
String path = "/sms/smsSend";
|
||||
String method = "POST";
|
||||
String appcode = "033359549f644a32858017cd76df3f88";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
querys.put("mobile", phone);
|
||||
querys.put("param", "**code**:"+code+",**minute**:5");
|
||||
|
||||
//smsSignId(短信前缀)和templateId(短信模板),可登录国阳云控制台自助申请。参考文档:http://help.guoyangyun.com/Problem/Qm.html
|
||||
|
||||
querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
|
||||
querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
|
||||
|
||||
try {
|
||||
/**
|
||||
* 重要提示如下:
|
||||
* HttpUtils请从\r\n\t \t* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java\r\n\t \t* 下载
|
||||
*
|
||||
* 相应的依赖请参照
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||
*/
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
// System.out.println(response.toString());
|
||||
//获取response的body
|
||||
result = EntityUtils.toString(response.getEntity());
|
||||
System.out.println(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -92,4 +92,18 @@ public class PaymentController {
|
|||
return SfUtil.query(standingRes);
|
||||
}
|
||||
|
||||
//TODO 发送验证码
|
||||
@PostMapping("/sendCode/{phonenumber}")
|
||||
public Result<String> sendCode(@PathVariable("phonenumber")String phonenumber){
|
||||
return Result.success(null,userService.sendCode(phonenumber));
|
||||
}
|
||||
|
||||
|
||||
//TODO 验证验证码
|
||||
@PostMapping("/checkCode/{phonenumber}/{code}")
|
||||
public Result<String> checkCode(@PathVariable("phonenumber")String phonenumber,@PathVariable("code")String code){
|
||||
return Result.success(null,userService.checkCode(phonenumber,code));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -155,4 +155,9 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
public int addRecords(PaymentParam paymentParam);
|
||||
|
||||
List<PaymentParam> selectPaymentParamList(PaymentParam paymentParam);
|
||||
|
||||
|
||||
|
||||
SysUser findByPhone(String phonenumber);
|
||||
|
||||
}
|
||||
|
|
|
@ -239,4 +239,9 @@ public interface SysUserService extends IService<SysUser> {
|
|||
public int addRecords(PaymentParam paymentParam);
|
||||
|
||||
List<PaymentParam> selectPaymentParamList(PaymentParam paymentParam);
|
||||
|
||||
|
||||
String sendCode(String phonenumber);
|
||||
|
||||
String checkCode(String phonenumber, String code);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
|
@ -7,6 +8,7 @@ import com.alipay.api.request.AlipayTradePagePayRequest;
|
|||
import com.alipay.api.response.AlipayTradePagePayResponse;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.constant.UserConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
|
@ -17,6 +19,7 @@ import com.muyu.common.system.domain.PaymentParam;
|
|||
import com.muyu.common.system.domain.SysRole;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.config.AlipayConfig;
|
||||
import com.muyu.config.util.MsgUtil;
|
||||
import com.muyu.system.domain.SysPost;
|
||||
import com.muyu.system.domain.SysUserPost;
|
||||
import com.muyu.system.domain.SysUserRole;
|
||||
|
@ -28,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -36,6 +40,7 @@ import java.math.BigDecimal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.muyu.config.AlipayConfig.*;
|
||||
|
@ -551,6 +556,36 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public String sendCode(String phonenumber) {
|
||||
SysUser byPhone = userMapper.findByPhone(phonenumber);
|
||||
if(byPhone == null){
|
||||
throw new RuntimeException("手机号不存在");
|
||||
}
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
System.out.println(code);
|
||||
redisTemplate.opsForValue().set(phonenumber,code,5, TimeUnit.MINUTES);
|
||||
MsgUtil.sendMsg(phonenumber,code);
|
||||
return "发送成功";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String checkCode(String phonenumber, String code) {
|
||||
if(redisTemplate.hasKey(phonenumber)){
|
||||
String s = redisTemplate.opsForValue().get(phonenumber);
|
||||
if(s.equals(code)){
|
||||
return Result.success().getMsg();
|
||||
}else{
|
||||
throw new RuntimeException("验证码错误");
|
||||
}
|
||||
}else{
|
||||
throw new RuntimeException("验证码已过期");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -199,6 +199,10 @@
|
|||
from pay_ment_param
|
||||
</select>
|
||||
|
||||
<select id="findByPhone" resultType="com.muyu.common.system.domain.SysUser">
|
||||
select phonenumber from sys_user where phonenumber = #{phone}
|
||||
</select>
|
||||
|
||||
|
||||
<update id="addUserMoney">
|
||||
update sys_user set user_balance = user_balance + #{userBalance} where user_id = #{userId}
|
||||
|
|
Loading…
Reference in New Issue