Ver Fonte

短信服务商已经切换https://zz.253.com

chao há 3 anos atrás
pai
commit
d6085a7f38

+ 20 - 0
src/main/java/com/caimei365/user/service/RemoteCallService.java

@@ -0,0 +1,20 @@
+package com.caimei365.user.service;
+
+
+/**
+ * 远程调用数据处理
+ *
+ * @author : Charles
+ * @date : 2021/11/08
+ */
+public interface RemoteCallService {
+    /**
+     * 请求发短信接口
+     *
+     * @param markId  短信类型
+     * @param mobile  手机号
+     * @param content 内容
+     * @return
+     */
+    boolean remoteSendSms(int markId, String mobile, String content);
+}

+ 22 - 13
src/main/java/com/caimei365/user/service/impl/BaseServiceImpl.java

@@ -1,21 +1,22 @@
 package com.caimei365.user.service.impl;
 
 import com.caimei365.user.components.CommonService;
+import com.caimei365.user.components.RedisService;
 import com.caimei365.user.mapper.BaseMapper;
 import com.caimei365.user.mapper.LoginMapper;
 import com.caimei365.user.mapper.SuperVipMapper;
 import com.caimei365.user.model.ResponseJson;
-import com.caimei365.user.components.RedisService;
 import com.caimei365.user.model.dto.MobileDto;
 import com.caimei365.user.model.dto.PasswordDto;
 import com.caimei365.user.model.dto.SuperVipDto;
 import com.caimei365.user.model.po.SuperVipPo;
 import com.caimei365.user.model.po.VipPackage;
 import com.caimei365.user.model.po.VipPayHistoryPo;
-import com.caimei365.user.model.vo.*;
+import com.caimei365.user.model.vo.CouponVo;
+import com.caimei365.user.model.vo.UserLoginVo;
 import com.caimei365.user.service.BaseService;
+import com.caimei365.user.service.RemoteCallService;
 import com.caimei365.user.utils.*;
-import com.fasterxml.jackson.annotation.JsonFormat;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
@@ -24,9 +25,10 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -50,7 +52,8 @@ public class BaseServiceImpl implements BaseService {
     private LoginMapper loginMapper;
     @Value("${spring.cloud.config.profile}")
     private String profile;
-
+    @Resource
+    private RemoteCallService remoteCallService;
 
     /**
      * 获取图片验证码
@@ -149,7 +152,8 @@ public class BaseServiceImpl implements BaseService {
                 return ResponseJson.error("该手机号尚未注册");
             }
             // 找回密码
-            sendFlag = isBeta || AliyunSmsUtil.sendSms(mobile, 1, "{code:" + randomCode + "}");
+            String content = "验证码"+randomCode+",您正在尝试修改登录密码,请妥善保管账户信息。";
+            sendFlag = isBeta || remoteCallService.remoteSendSms(0, mobile, content);
             codeTypeTxt = "找回密码";
         } else if (2 == activateCodeType || 3 == activateCodeType) {
             if (null != userId && userId > 0) {
@@ -157,25 +161,29 @@ public class BaseServiceImpl implements BaseService {
             }
             if (2 == activateCodeType) {
                 // 机构用户(自主)注册
-                sendFlag = isBeta || AliyunSmsUtil.sendSms(mobile, 8, "{code:" + randomCode + "}");
+                String content = "欢迎注册采美365网,您的短信验证码为:"+randomCode+",该验证码 5 分钟内有效,请勿泄漏于他人。";
+                sendFlag = isBeta || remoteCallService.remoteSendSms(0, mobile, content);
                 codeTypeTxt = "机构(自主)注册";
             } else if (3 == activateCodeType) {
                 // 供应商(自主)注册
-                sendFlag = isBeta || AliyunSmsUtil.sendSms(mobile, 9, "{code:" + randomCode + "}");
+                String content = "欢迎注册采美365网供应商账号,您的短信验证码为:"+randomCode+",该验证码 5 分钟内有效,请勿泄漏于他人。";
+                sendFlag = isBeta || remoteCallService.remoteSendSms(0, mobile, content);
                 codeTypeTxt = "供应商(自主)注册";
             } else {
                 return ResponseJson.error("参数错误:activateCodeType");
             }
         } else if (4 == activateCodeType) {
             // 您正在更换联系人手机号,您的验证码为:${code}。
-            sendFlag = isBeta || AliyunSmsUtil.sendSms(mobile, 13, "{code:" + randomCode + "}");
+            String content = "验证码"+randomCode+",您正在尝试变更重要信息,请妥善保管账户信息。";
+            sendFlag = isBeta || remoteCallService.remoteSendSms(0, mobile, content);
             codeTypeTxt = "更换联系人(旧手机号验证码)";
         } else if (5 == activateCodeType) {
             if (null != userId && userId > 0) {
                 return ResponseJson.error("该手机号已被使用");
             }
             // 您正在更换联系人手机号,您的验证码为:${code}。
-            sendFlag = isBeta || AliyunSmsUtil.sendSms(mobile, 13, "{code:" + randomCode + "}");
+            String content = "验证码"+randomCode+",您正在尝试变更重要信息,请妥善保管账户信息。";
+            sendFlag = isBeta || remoteCallService.remoteSendSms(0, mobile, content);
             codeTypeTxt = "更换联系人(新手机号验证码)";
         } else {
             return ResponseJson.error("参数错误:activateCodeType");
@@ -255,10 +263,11 @@ public class BaseServiceImpl implements BaseService {
         }
         String userName = baseMapper.getUserNameByUserId(userId);
         // 欢迎成为${name}的运营人员,您的邀请码为${code}。
-        boolean smsFlag = isBeta || AliyunSmsUtil.sendSms(mobile, 11, "{name:" + userName + ",code:" + randomCode + "}");
+        String content = "欢迎成为"+userName+"的运营人员,您的邀请码为"+randomCode+"。您可使用以下两种方式激活您的身份:1. 您可在微信搜索“采美采购商城”小程序,使用邀请码登录并绑定微信;2. 进入“采美采购商城”小程序后,使用邀请码登录并绑定微信。绑定微信后,您可通过微信授权直接登录“采美采购商城”小程序或微信扫码直接登录采美365网站。";
+        boolean smsFlag = isBeta || remoteCallService.remoteSendSms(0, mobile, content);
         if (!smsFlag) {
             // 短信发送失败重试一次
-            smsFlag = AliyunSmsUtil.sendSms(mobile, 11, "{name:\"" + userName + "\",code:" + randomCode + "}");
+            smsFlag = remoteCallService.remoteSendSms(0, mobile, content);
         }
         if (smsFlag) {
             redisService.set("code:" + mobile, randomCode, 1800L);

+ 6 - 3
src/main/java/com/caimei365/user/service/impl/HeHeServiceImpl.java

@@ -9,7 +9,7 @@ import com.caimei365.user.model.po.CmHeHeUserPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.vo.HeHeUserVo;
 import com.caimei365.user.service.HeHeService;
-import com.caimei365.user.utils.AliyunSmsUtil;
+import com.caimei365.user.service.RemoteCallService;
 import com.caimei365.user.utils.CodeUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -40,6 +40,8 @@ public class HeHeServiceImpl implements HeHeService {
     private RedisService redisService;
     @Value("${spring.cloud.config.profile}")
     private String active;
+    @Resource
+    private RemoteCallService remoteCallService;
 
     @Override
     public ResponseJson<HeHeUserVo> authorization(String code, HttpHeaders headers) {
@@ -108,10 +110,11 @@ public class HeHeServiceImpl implements HeHeService {
     @Override
     public ResponseJson<String> sendVerificationCode(String mobile) {
         String randomCode = CodeUtil.generateCodeInt(6);
-        boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 7, "{code:" + randomCode + "}");
+        String content = "您“呵呵商城”小程序的验证码为:"+randomCode+",验证码 5 分钟内有效。";
+        boolean smsFlag = remoteCallService.remoteSendSms(0, mobile, content);
         if (!smsFlag) {
             // 短信发送失败重试一次
-            AliyunSmsUtil.sendSms(mobile, 7, "{code:" + randomCode + "}");
+            remoteCallService.remoteSendSms(0, mobile, content);
         }
         log.info("呵呵商城注册验证码:" + randomCode);
         redisService.set("heCode:" + mobile, randomCode, 300L);

+ 9 - 3
src/main/java/com/caimei365/user/service/impl/OperationServiceImpl.java

@@ -8,7 +8,7 @@ import com.caimei365.user.model.po.OperationPo;
 import com.caimei365.user.model.vo.OperationVo;
 import com.caimei365.user.model.vo.PaginationVo;
 import com.caimei365.user.service.OperationService;
-import com.caimei365.user.utils.AliyunSmsUtil;
+import com.caimei365.user.service.RemoteCallService;
 import com.caimei365.user.utils.CodeUtil;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
@@ -34,6 +34,8 @@ public class OperationServiceImpl implements OperationService {
     private CommonService commonService;
     @Resource
     private OperationMapper operationMapper;
+    @Resource
+    private RemoteCallService remoteCallService;
 
     /**
      * 添加运营人员
@@ -78,7 +80,9 @@ public class OperationServiceImpl implements OperationService {
             }
             String mobile = operationDto.getMobile();
             if (StringUtils.isNotEmpty(mobile)) {
-                AliyunSmsUtil.sendSms(mobile, 11, "{name:\""+ name +"\",code:" + invitationCode + "}");
+                // 欢迎成为${name}的运营人员,您的邀请码为${code}。
+                String content = "欢迎成为"+name+"的运营人员,您的邀请码为"+invitationCode+"。您可使用以下两种方式激活您的身份:1. 您可在微信搜索“采美采购商城”小程序,使用邀请码登录并绑定微信;2. 进入“采美采购商城”小程序后,使用邀请码登录并绑定微信。绑定微信后,您可通过微信授权直接登录“采美采购商城”小程序或微信扫码直接登录采美365网站。";
+                remoteCallService.remoteSendSms(0, mobile, content);
                 log.info("欢迎成为"+ name +"的运营人员,您的邀请码为:" + invitationCode);
             }
         }
@@ -133,7 +137,9 @@ public class OperationServiceImpl implements OperationService {
             }
             String mobile = operation.getMobile();
             if (StringUtils.isNotEmpty(mobile)) {
-                AliyunSmsUtil.sendSms(mobile, 11, "{name:\""+ name +"\",code:" + invitationCode + "}");
+                // 欢迎成为${name}的运营人员,您更新的邀请码为${code}。
+                String content = "欢迎成为"+name+"的运营人员,您的邀请码为"+invitationCode+"。您可使用以下两种方式激活您的身份:1. 您可在微信搜索“采美采购商城”小程序,使用邀请码登录并绑定微信;2. 进入“采美采购商城”小程序后,使用邀请码登录并绑定微信。绑定微信后,您可通过微信授权直接登录“采美采购商城”小程序或微信扫码直接登录采美365网站。";
+                remoteCallService.remoteSendSms(0, mobile, content);
                 log.info("欢迎成为"+ name +"的运营人员,您更新的邀请码为:" + invitationCode);
             }
             flag = operationMapper.updateOperation(operation);

+ 51 - 59
src/main/java/com/caimei365/user/service/impl/RegisterServiceImpl.java

@@ -1,6 +1,5 @@
 package com.caimei365.user.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
 import com.caimei365.user.components.CommonService;
 import com.caimei365.user.components.RedisService;
 import com.caimei365.user.components.WeChatService;
@@ -11,8 +10,11 @@ import com.caimei365.user.model.dto.*;
 import com.caimei365.user.model.po.*;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.RegisterService;
-import com.caimei365.user.utils.*;
-
+import com.caimei365.user.service.RemoteCallService;
+import com.caimei365.user.utils.CodeUtil;
+import com.caimei365.user.utils.Md5Util;
+import com.caimei365.user.utils.RandomCodeGenerator;
+import com.caimei365.user.utils.ValidateUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
@@ -21,13 +23,11 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Map;
 
 /**
  * Description
@@ -59,6 +59,8 @@ public class RegisterServiceImpl implements RegisterService {
     private ToolsFeign smsFeign;
     @Resource
     private MessagePushMapper messagePushMapper;
+    @Resource
+    private RemoteCallService remoteCallService;
 
     /**
      * 检查账号可以注册
@@ -213,10 +215,11 @@ public class RegisterServiceImpl implements RegisterService {
         user.setClubId(club.getClubId());
         registerMapper.updateUserClubId(user.getUserId(), club.getClubId());
         // 注册成功短信
-        boolean smsFlag = AliyunSmsUtil.sendSms(clubRegisterDto.getBindMobile(), 10, "{name:" + clubRegisterDto.getBindMobile() + "}");
+        String content = "注册成功!您可以通过手机号"+clubRegisterDto.getBindMobile()+"登录。";
+        boolean smsFlag = remoteCallService.remoteSendSms(0, clubRegisterDto.getBindMobile(), content);
         if (!smsFlag) {
             // 短信发送失败重试一次
-            AliyunSmsUtil.sendSms(clubRegisterDto.getBindMobile(), 10, "{name:" + clubRegisterDto.getBindMobile() + "}");
+            remoteCallService.remoteSendSms(0, clubRegisterDto.getBindMobile(), content);
         }
         /*
             绑定微信,成为机构运营人员
@@ -661,10 +664,11 @@ public class RegisterServiceImpl implements RegisterService {
             logTxt = String.format(logTxt, "普通机构", mobile, initPassword);
         }
         // 发送短信
-        boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 6, "{name:" + mobile + ",content:" + randomCode + "}");
+        String content = "欢迎成为采美机构用户,您的登录账号为:"+mobile+",初始密码为:cm"+randomCode+",您可使用该账号密码登录采美365网和“采美采购商城”小程序。";
+        boolean smsFlag = remoteCallService.remoteSendSms(0, mobile, content);
         if (!smsFlag) {
             // 短信发送失败重试一次
-            AliyunSmsUtil.sendSms(mobile, 6, "{name:" + mobile + ",content:" + randomCode + "}");
+            remoteCallService.remoteSendSms(0, mobile, content);
         }
         // 打印短信内容
         log.info(logTxt);
@@ -1108,11 +1112,7 @@ public class RegisterServiceImpl implements RegisterService {
             message = "恭喜您成功开通采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com/t/" + shortLink + "或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。退订回T";
             String mobile = vipMapper.findMobile(userId);
             if (mobile != null && mobile != "") {
-                try {
-                    sendSms(2, mobile, message);
-                } catch (Exception e) {
-                    log.error("短信发送异常" + e);
-                }
+                remoteCallService.remoteSendSms(2, mobile, message);
             }
         } else if (repayFlag == 1) {
             //有效期内续费
@@ -1137,11 +1137,7 @@ public class RegisterServiceImpl implements RegisterService {
             message = "恭喜您成功续费采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www-b.caimei365.com/t/" + shortLink + "或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。退订回T";
             String mobile = vipMapper.findMobile(userId);
             if (mobile != null && mobile != "") {
-                try {
-                    sendSms(2, mobile, message);
-                } catch (Exception e) {
-                    log.error("短信发送异常" + e);
-                }
+                remoteCallService.remoteSendSms(2, mobile, message);
             }
         } else if (repayFlag == -1) {
             //过期续费
@@ -1169,11 +1165,7 @@ public class RegisterServiceImpl implements RegisterService {
             message = "恭喜您成功续费采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com/t/" + shortLink + "或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。退订回T";
             String mobile = vipMapper.findMobile(userId);
             if (mobile != null && mobile != "") {
-                try {
-                    sendSms(2, mobile, message);
-                } catch (Exception e) {
-                    log.error("短信发送异常" + e);
-                }
+                remoteCallService.remoteSendSms(2, mobile, message);
             }
         }
         log.info(userId + "消费采美豆" + multiply + "会员到期时间至" + cal.getTime());
@@ -1201,38 +1193,38 @@ public class RegisterServiceImpl implements RegisterService {
         vipMapper.addPayHistory(payHistory);
     }
 
-    public boolean sendSms(int markId, String mobile, String message) {
-        AtomicBoolean returnValue = new AtomicBoolean(false);
-        try {
-            //测试环境手机号允许发短信
-            List<String> list = new ArrayList<>();
-            list.add("15917362709");
-            list.add("15814011616");
-            list.add("13100721916");
-            list.add("15113936829");
-            list.add("15827317748");
-            if ("prod".equals(profile) || list.contains(mobile)) {
-                if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
-                    String regex = "^(1[3-9]\\d{9}$)";
-                    Pattern pattern = Pattern.compile(regex);
-                    Matcher matcher = pattern.matcher(mobile);
-                    if (matcher.matches()) {
-                        // 调用 ToolsFeign 发送短信
-                        String jsonStr = smsFeign.getSendSms(mobile, message);
-                        JSONObject parseObject = JSONObject.parseObject(jsonStr);
-                        if (0 == parseObject.getInteger("code")) {
-                            // 保存短信发送条数+count
-                            messagePushMapper.updateSmsSendCount(markId, 1);
-                            returnValue.set(true);
-                        }
-                    }
-                }
-            }
-        } catch (Exception e) {
-            log.error("短信推送异常:", e);
-        }
-        return returnValue.get();
-    }
+//    public boolean sendSms(int markId, String mobile, String message) {
+//        AtomicBoolean returnValue = new AtomicBoolean(false);
+//        try {
+//            //测试环境手机号允许发短信
+//            List<String> list = new ArrayList<>();
+//            list.add("15917362709");
+//            list.add("15814011616");
+//            list.add("13100721916");
+//            list.add("15113936829");
+//            list.add("15827317748");
+//            if ("prod".equals(profile) || list.contains(mobile)) {
+//                if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
+//                    String regex = "^(1[3-9]\\d{9}$)";
+//                    Pattern pattern = Pattern.compile(regex);
+//                    Matcher matcher = pattern.matcher(mobile);
+//                    if (matcher.matches()) {
+//                        // 调用 ToolsFeign 发送短信
+//                        String jsonStr = smsFeign.getSendSms(mobile, message);
+//                        JSONObject parseObject = JSONObject.parseObject(jsonStr);
+//                        if (0 == parseObject.getInteger("code")) {
+//                            // 保存短信发送条数+count
+//                            messagePushMapper.updateSmsSendCount(markId, 1);
+//                            returnValue.set(true);
+//                        }
+//                    }
+//                }
+//            }
+//        } catch (Exception e) {
+//            log.error("短信推送异常:", e);
+//        }
+//        return returnValue.get();
+//    }
 
     private static String strs(String str) {
         if (str.indexOf(".") > 0) {

+ 76 - 0
src/main/java/com/caimei365/user/service/impl/RemoteCallServiceImpl.java

@@ -0,0 +1,76 @@
+package com.caimei365.user.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.caimei365.user.feign.ToolsFeign;
+import com.caimei365.user.mapper.MessagePushMapper;
+import com.caimei365.user.service.RemoteCallService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 远程调用数据处理
+ *
+ * @author : Charles
+ * @date : 2021/7/15
+ */
+@Slf4j
+@Service
+public class RemoteCallServiceImpl implements RemoteCallService {
+    @Value("${spring.cloud.config.profile}")
+    private String profile;
+    @Resource
+    private ToolsFeign toolsFeign;
+    @Resource
+    private MessagePushMapper messagePushMapper;
+    /**
+     * 请求发短信接口
+     *
+     * @param markId  跳转类型
+     * @param mobile  手机号
+     * @param content 内容
+     */
+    @Override
+    public boolean remoteSendSms(int markId, String mobile, String content) {
+        AtomicBoolean returnValue = new AtomicBoolean(false);
+        try {
+            //测试环境手机号允许发短信
+            List<String> list = new ArrayList<>();
+            list.add("15917362709");
+            list.add("15814011616");
+            list.add("13100721916");
+            list.add("15113936829");
+            if ("prod".equals(profile) || list.contains(mobile)) {
+                if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
+                    String regex = "^(1[3-9]\\d{9}$)";
+                    Pattern pattern = Pattern.compile(regex);
+                    Matcher matcher = pattern.matcher(mobile);
+                    if (matcher.matches()) {
+                        // 调用 ToolsFeign 发送短信
+                        String jsonStr = toolsFeign.getSendSms(mobile, content);
+                        JSONObject parseObject = JSONObject.parseObject(jsonStr);
+                        if (0 == parseObject.getInteger("code")){
+                            if (markId > 0 ) {
+                                // 保存短信发送条数+count
+                                messagePushMapper.updateSmsSendCount(markId, 1);
+                            }
+                            returnValue.set(true);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("短信推送异常:", e);
+        }
+        return returnValue.get();
+    }
+
+}

+ 1 - 0
src/main/java/com/caimei365/user/utils/AliyunSmsUtil.java

@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 
 /**
  * 阿里云短信Sms
+ * 【短信服务商已经切换https://zz.253.com/】
  *
  * @author : Charles
  * @date : 2021/3/5