ccjgmwz há 4 anos atrás
pai
commit
69ce16994a

+ 3 - 3
pom.xml

@@ -185,6 +185,9 @@
                 <env>local</env>
             </properties>
 
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
         </profile>
         <profile>
             <id>dev</id>
@@ -203,9 +206,6 @@
             <properties>
                 <env>prod</env>
             </properties>
-            <activation>
-                <activeByDefault>true</activeByDefault>
-            </activation>
         </profile>
     </profiles>
     <build>

+ 30 - 0
winsea-haixin-platform-backend/src/main/java/com/yh/saas/platform/config/SMSConfigYlyy.java

@@ -0,0 +1,30 @@
+package com.yh.saas.platform.config;
+
+
+import com.yh.saas.plugin.yiliangyiyun.util.AliyunSMSClient;
+import com.yh.saas.plugin.yiliangyiyun.util.MockSMSClient;
+import com.yh.saas.plugin.yiliangyiyun.util.SMSClientYlyy;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created by rize on 2019/7/2.
+ */
+@Configuration
+public class SMSConfigYlyy {
+
+    @Value("${sms.enable}")
+    private String enable;
+
+    @Bean
+    public SMSClientYlyy smsClientYlyy() {
+        if ("aliyun".equals(enable)) {
+            return new AliyunSMSClient();
+        } else if ("mock".equals(enable)) {
+            return new MockSMSClient();
+        } else {
+            return new MockSMSClient();
+        }
+    }
+}

+ 11 - 8
winsea-haixin-platform-backend/src/main/resources/application.yml

@@ -42,6 +42,7 @@ auth:
     - /system/query/getComanyMgrUrl
     - /saas/**/*
     - /ws/**/*
+    - /commonUser/*
   expire-in: 36000
   login-url: /login.html
   logout-url: /auth/api/logout
@@ -170,15 +171,17 @@ oss:
     timeout: 30000
 pc-url: http://yilaingyiyun.com
 
+### 阿里云短信配置 ###
 sms:
-  gateway:
-    access-id: yinghaikeji
-    access-key: yinghai2013
-    action-url: //sms.webchinese.cn/web_api/SMS/
-    url: http://utf8.api.smschinese.cn
-  template:
-    veri-code=\u9a8c\u8bc1\u7801\uff1a\u007b\u0030\u007d\uff0c\u007b\u0031\u007d\u5206\u949f\u5185\u6709\u6548\uff0c\u5982\u975e\u672c\u4eba\u64cd\u4f5c\uff0c\u8bf7\u5ffd\u7565\u6b64\u4fe1\u606f\u3002:
-
+  aliyun:
+    accessId: LTAI4G9c14PgKvM23WZ9zrpc
+    accessKey: FpClTp4OVrRRtHEfi3lBOWUoLxKieW
+    signature: 易粮易运
+    register-template-id: SMS_202415307
+    bind-phone-template-id: SMS_202415307
+    reset-password-template-id: SMS_202415307
+    admin-login-template-id: SMS_202415307
+  enable: aliyun
 sys:
   client-flag: B
 

+ 11 - 15
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/CommonUserServiceImpl.java

@@ -9,13 +9,9 @@ import com.yh.saas.plugin.yiliangyiyun.exception.AppServiceException;
 import com.yh.saas.plugin.yiliangyiyun.exception.ExceptionDefinition;
 import com.yh.saas.plugin.yiliangyiyun.exception.ServiceException;
 import com.yh.saas.plugin.yiliangyiyun.mapper.CommonUserMapper;
-import com.yh.saas.plugin.yiliangyiyun.util.SMSClient;
-import com.yh.saas.plugin.yiliangyiyun.util.SMSResult;
+import com.yh.saas.plugin.yiliangyiyun.util.*;
 import com.yh.saas.plugin.yiliangyiyun.service.ICommonUserService;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
-import com.yh.saas.plugin.yiliangyiyun.util.Const;
-import com.yh.saas.plugin.yiliangyiyun.util.GeneratorUtil;
-import com.yh.saas.plugin.yiliangyiyun.util.MD5Util;
 import org.apache.commons.codec.digest.Md5Crypt;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,8 +37,8 @@ public class CommonUserServiceImpl extends ServiceImpl<CommonUserMapper, CommonU
     @Autowired
     private CacheComponent cacheComponent;
 
-//    @Autowired
-//    private SMSClient smsClient;
+    @Autowired
+    private SMSClientYlyy smsClient;
 
     @Autowired
     private CommonUserMapper commonUserMapper;
@@ -106,15 +102,15 @@ public class CommonUserServiceImpl extends ServiceImpl<CommonUserMapper, CommonU
      */
     @Override
     public String sendVerifyCode(String phone) throws ServiceException {
-//        String verifyCode = GeneratorUtil.genSixVerifyCode();
-//        System.out.println("verifyCode:"+verifyCode);
-//        SMSResult res = smsClient.sendRegisterVerify(phone, verifyCode);
-//        if (res.isSucc()) {
-//            cacheComponent.putRaw(VERIFY_CODE_PREFIX + phone, verifyCode, 300);
+        String verifyCode = GeneratorUtil.genSixVerifyCode();
+        System.out.println("verifyCode:"+verifyCode);
+        SMSResult res = smsClient.sendRegisterVerify(phone, verifyCode);
+        if (res.isSucc()) {
+            cacheComponent.putRaw(VERIFY_CODE_PREFIX + phone, verifyCode, 300);
             return "ok";
-//        } else {
-//            throw new AppServiceException(res.getMsg(), ExceptionDefinition.USER_SEND_VERIFY_FAILED.getCode());
-//        }
+        } else {
+            throw new AppServiceException(res.getMsg(), ExceptionDefinition.USER_SEND_VERIFY_FAILED.getCode());
+        }
 
     }
 

+ 1 - 1
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/AliyunSMSClient.java

@@ -19,7 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
 /**
  * Created by rize on 2019/8/1.
  */
-public class AliyunSMSClient implements SMSClient, InitializingBean {
+public class AliyunSMSClient implements SMSClientYlyy, InitializingBean {
 
     @Value("${sms.aliyun.accessId}")
     private String accessId;

+ 1 - 1
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/MockSMSClient.java

@@ -11,7 +11,7 @@ import org.slf4j.LoggerFactory;
  * Date: 2019/11/17
  * Time: 15:50
  */
-public class MockSMSClient implements SMSClient {
+public class MockSMSClient implements SMSClientYlyy {
 
     private static Logger logger = LoggerFactory.getLogger(MockSMSClient.class);
 

+ 0 - 82
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/QCloudSMSClient.java

@@ -1,82 +0,0 @@
-package com.yh.saas.plugin.yiliangyiyun.util;
-
-import com.github.qcloudsms.SmsSingleSender;
-import com.github.qcloudsms.SmsSingleSenderResult;
-import com.yh.saas.plugin.yiliangyiyun.exception.ExceptionDefinition;
-import com.yh.saas.plugin.yiliangyiyun.exception.ServiceException;
-import com.yh.saas.plugin.yiliangyiyun.exception.ThirdPartServiceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Value;
-
-/**
- * Created by rize on 2019/7/1.
- */
-public class QCloudSMSClient implements SMSClient, InitializingBean {
-
-    private SmsSingleSender sender;
-
-    @Value("${sms.qcloud.app-id}")
-    private Integer appid;
-    @Value("${sms.qcloud.app-key}")
-    private String appkey;
-    @Value("${sms.qcloud.register-template-id}")
-    private Integer registerTemplateId;
-    @Value("${sms.qcloud.bind-phone-template-id}")
-    private Integer bindPhoneTemplateId;
-    @Value("${sms.qcloud.reset-password-template-id}")
-    private Integer resetPasswordTemplateId;
-    @Value("${sms.qcloud.admin-login-template-id}")
-    private Integer adminLoginTemplateId;
-    @Value("${sms.qcloud.sign}")
-    private String sign;
-
-    private static Logger logger = LoggerFactory.getLogger(QCloudSMSClient.class);
-
-    @Override
-    public void afterPropertiesSet() throws Exception {
-        sender = new SmsSingleSender(appid, appkey);
-    }
-
-    public SMSResult sendMsg(String phone, int templateId, String ...params) throws ServiceException {
-        try {
-            SmsSingleSenderResult smsSingleSenderResult = sender.sendWithParam("86", phone, templateId, params, this.sign, "", "");
-            if (smsSingleSenderResult.result == 0) {
-                SMSResult smsResult = new SMSResult();
-                smsResult.setSucc(true);
-                smsResult.setMsg("成功");
-                return smsResult;
-            } else {
-                logger.info("[腾讯短信发送] 回复与预期不一致 result=" + smsSingleSenderResult.result + ";errMsg=" + smsSingleSenderResult.errMsg);
-                throw new ThirdPartServiceException(smsSingleSenderResult.errMsg, smsSingleSenderResult.result);
-            }
-        } catch (ServiceException e) {
-            throw e;
-        } catch (Exception e) {
-            logger.error("[腾讯短信发送] 异常", e);
-            throw new ThirdPartServiceException("腾讯云短信发送未知异常", ExceptionDefinition.THIRD_PART_SERVICE_EXCEPTION.getCode());
-        }
-    }
-
-
-    @Override
-    public SMSResult sendRegisterVerify(String phone, String verifyCode) throws ServiceException {
-        return sendMsg(phone, registerTemplateId, verifyCode);
-    }
-
-    @Override
-    public SMSResult sendBindPhoneVerify(String phone, String verifyCode) throws ServiceException {
-        return sendMsg(phone, registerTemplateId, verifyCode);
-    }
-
-    @Override
-    public SMSResult sendResetPasswordVerify(String phone, String verifyCode) throws ServiceException {
-        return sendMsg(phone, registerTemplateId, verifyCode);
-    }
-
-    @Override
-    public SMSResult sendAdminLoginVerify(String phone, String verifyCode) throws ServiceException {
-        return sendMsg(phone, adminLoginTemplateId,verifyCode);
-    }
-}

+ 1 - 1
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/SMSClient.java → winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/SMSClientYlyy.java

@@ -5,7 +5,7 @@ import com.yh.saas.plugin.yiliangyiyun.exception.ServiceException;
 /**
  * Created by rize on 2019/7/1.
  */
-public interface SMSClient {
+public interface SMSClientYlyy {
 
     SMSResult sendRegisterVerify(String phone, String verifyCode) throws ServiceException;