zero 1 年間 前
コミット
1f1949cc18

+ 11 - 0
pom.xml

@@ -263,6 +263,17 @@
             <version>2.0</version>
         </dependency>
 
+        <!-- 短信接口 -->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-core</artifactId>
+            <version>4.5.16</version>
+        </dependency>
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
+            <version>1.1.0</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 3 - 2
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -23,6 +23,7 @@ import com.example.xiaoshiweixinback.entity.vo.person.PersonVO;
 import com.example.xiaoshiweixinback.mapper.PersonMapper;
 import com.example.xiaoshiweixinback.okhttp.RequestManager;
 import com.example.xiaoshiweixinback.okhttp.ResponseManager;
+import com.example.xiaoshiweixinback.service.common.SmsService;
 import org.apache.commons.codec.binary.Base64;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -50,7 +51,7 @@ public class LoginService {
     private RedisService redisService;
 
     @Autowired
-    private RedisUtil redisUtil;
+    private SmsService smsService;
 
     @Autowired
     private PersonMapper personMapper;
@@ -207,7 +208,7 @@ public class LoginService {
             redisService. set(AppCacheKeyUtil.getLoginMessageCode(vo.getPhoneNum()), random);
             redisService.expire(AppCacheKeyUtil.getLoginMessageCode(vo.getPhoneNum()), CacheTTLEnum.FIVE_MINUTE);
             //发送短信
-//        smsService.sendMessage(vo.getPhoneNo(), random);
+            smsService.sendMessage(vo.getPhoneNum(), random);
             flag = true;
         }
         return flag;

+ 45 - 0
src/main/java/com/example/xiaoshiweixinback/service/common/SmsService.java

@@ -0,0 +1,45 @@
+package com.example.xiaoshiweixinback.service.common;
+
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.profile.DefaultProfile;
+import com.google.gson.Gson;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SmsService {
+
+    @Value("${SMS.regionId}")
+    private String regionId;
+
+    @Value("${SMS.accessKeyId}")
+    private String accessKeyId;
+
+    @Value("${SMS.secret}")
+    private String secret;
+
+    public void sendMessage(String phoneNum,String random){
+
+        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
+        IAcsClient client = new DefaultAcsClient(profile);
+        SendSmsRequest request = new SendSmsRequest();
+//        String templateParam = "{\"code\":\"" + random + "\",\"message\":\"" + "为您的登陆验证码" + "\",\"validTime\":\"" + "5分钟" + "\"}";
+        String templateParam = "{\"code\":\"" + random + "\"}";
+        request.setPhoneNumbers(phoneNum);//接收短信的手机号码
+        request.setSignName("小世数字科技");//短信签名名称
+        request.setTemplateCode("SMS_296725687");//短信模板CODE
+        request.setTemplateParam(templateParam);//短信模板变量对应的实际值
+        try {
+            SendSmsResponse response = client.getAcsResponse(request);
+            System.out.println(new Gson().toJson(response));
+        } catch (ClientException e) {
+            System.out.println("ErrCode:" + e.getErrCode());
+            System.out.println("ErrMsg:" + e.getErrMsg());
+            System.out.println("RequestId:" + e.getRequestId());
+        }
+    }
+}

+ 7 - 0
src/main/resources/application-dev.yml

@@ -69,6 +69,13 @@ PASUrl: http://localhost:8877
 FMSUrl: http://localhost:8801
 FileSource: 1
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-dev1.yml

@@ -69,6 +69,13 @@ PASUrl: http://localhost:8877
 FMSUrl: http://localhost:8801
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-prodNetIn.yml

@@ -35,6 +35,13 @@ RMSUrl: http://localhost:8872
 FMSUrl: http://localhost:8801
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-prodNetOut.yml

@@ -33,6 +33,13 @@ RMSUrl: http://localhost:8872
 FMSUrl: http://localhost:8801
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-testNetIn.yml

@@ -69,6 +69,13 @@ PASUrl: http://localhost:8880
 FMSUrl: http://localhost:8885
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-testNetOut.yml

@@ -25,6 +25,13 @@ spring:
         exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
 authorUrl: http://localhost:8871
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application.yml

@@ -47,6 +47,13 @@ mybatis-plus:
   mapper-locations: classpath:mapper/*.xml
 queueName: emailProd.queue
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 5 - 1
src/test/java/com/example/xiaoshiweixinback/XiaoshiWeixinbackApplicationTests.java

@@ -1,6 +1,7 @@
 package com.example.xiaoshiweixinback;
 
 import com.example.xiaoshiweixinback.entity.dto.person.PersonPhoneDTO;
+import com.example.xiaoshiweixinback.entity.dto.person.SendCodeDTO;
 import com.example.xiaoshiweixinback.service.LoginService;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +27,9 @@ class XiaoshiWeixinbackApplicationTests {
         dto.setPhoneNum("123456789");
         Map<String, String> map = loginService.verifyCode(dto);
         System.out.println(map);
-
+//        SendCodeDTO dto = new SendCodeDTO();
+//        dto.setPhoneNum("15705220533");
+//        boolean send = loginService.send(dto);
+//        System.out.println(send);
     }
 }