xiongzhu 1 سال پیش
والد
کامیت
4accfd8c21

+ 2 - 2
src/main/java/com/izouma/zhirongip/config/Constants.java

@@ -11,7 +11,7 @@ public interface Constants {
 
 
     String DEFAULT_AVATAR = "https://zhumj.oss-cn-hangzhou.aliyuncs.com/image/user.jpg";
     String DEFAULT_AVATAR = "https://zhumj.oss-cn-hangzhou.aliyuncs.com/image/user.jpg";
 
 
-    String SMS_SIGN_NAME = "走马信息";
+    String SMS_SIGN_NAME = "泰州军融知产";
 
 
-    String SMS_TEMPLATE_CODE_GENERIC = "SMS_175485688";
+    String SMS_TEMPLATE_CODE_GENERIC = "SMS_465720048";
 }
 }

+ 31 - 30
src/main/java/com/izouma/zhirongip/service/sms/AliSmsService.java

@@ -1,5 +1,6 @@
 package com.izouma.zhirongip.service.sms;
 package com.izouma.zhirongip.service.sms;
 
 
+
 import com.aliyuncs.CommonRequest;
 import com.aliyuncs.CommonRequest;
 import com.aliyuncs.CommonResponse;
 import com.aliyuncs.CommonResponse;
 import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.DefaultAcsClient;
@@ -11,19 +12,16 @@ import com.izouma.zhirongip.config.Constants;
 import com.izouma.zhirongip.domain.SmsRecord;
 import com.izouma.zhirongip.domain.SmsRecord;
 import com.izouma.zhirongip.exception.BusinessException;
 import com.izouma.zhirongip.exception.BusinessException;
 import com.izouma.zhirongip.repo.SmsRecordRepo;
 import com.izouma.zhirongip.repo.SmsRecordRepo;
-import com.mascloud.sdkclient.Client;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang.RandomStringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.configurationprocessor.json.JSONException;
 import org.springframework.boot.configurationprocessor.json.JSONException;
 import org.springframework.boot.configurationprocessor.json.JSONObject;
 import org.springframework.boot.configurationprocessor.json.JSONObject;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import javax.annotation.PostConstruct;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.time.ZoneOffset;
-import java.util.UUID;
 
 
 @Service
 @Service
 @Slf4j
 @Slf4j
@@ -35,45 +33,49 @@ public class AliSmsService implements SmsService {
     @Autowired
     @Autowired
     private SmsRecordRepo smsRecordRepo;
     private SmsRecordRepo smsRecordRepo;
 
 
-    private Client client;
-
-    @PostConstruct
-    public void init() {
-        client = Client.getInstance();
-        boolean success = client.login("http://112.35.4.197:15000", "sms", "2wsx@WSX", "江苏移动信息系统集成有限公司(政企)");
-        if (!success) {
-            log.error("sms login failed");
-        }
-    }
-
     @Override
     @Override
     public String sendVerify(String phone) {
     public String sendVerify(String phone) {
         smsRecordRepo.findLastByPhoneAndExpiresAtAfterAndExpiredFalse(phone, LocalDateTime.now()).ifPresent(record -> {
         smsRecordRepo.findLastByPhoneAndExpiresAtAfterAndExpiredFalse(phone, LocalDateTime.now()).ifPresent(record -> {
             if (record.getCreatedAt().plusMinutes(1L).isAfter(LocalDateTime.now())) {
             if (record.getCreatedAt().plusMinutes(1L).isAfter(LocalDateTime.now())) {
-                long sec = record.getCreatedAt().plusMinutes(1L).toInstant(ZoneOffset.UTC)
-                                 .getEpochSecond() - LocalDateTime.now().toInstant(ZoneOffset.UTC).getEpochSecond() + 1;
+                long sec = record.getCreatedAt().plusMinutes(1L).toInstant(ZoneOffset.UTC).getEpochSecond() - LocalDateTime.now().toInstant(ZoneOffset.UTC).getEpochSecond() + 1;
                 throw new BusinessException("请" + sec + "秒后再试");
                 throw new BusinessException("请" + sec + "秒后再试");
             }
             }
         });
         });
 
 
         String code = RandomStringUtils.randomNumeric(4);
         String code = RandomStringUtils.randomNumeric(4);
+        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
+        IAcsClient client = new DefaultAcsClient(profile);
 
 
+        CommonRequest request = new CommonRequest();
+        request.setMethod(MethodType.POST);
+        request.setDomain("dysmsapi.aliyuncs.com");
+        request.setVersion("2017-05-25");
+        request.setAction("SendSms");
+        request.putQueryParameter("PhoneNumbers", phone);
+        request.putQueryParameter("SignName", Constants.SMS_SIGN_NAME);
+        request.putQueryParameter("TemplateCode", Constants.SMS_TEMPLATE_CODE_GENERIC);
+        request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
         try {
         try {
-            int rtCode = client.sendTSMS(new String[]{phone}, "2c7838661d09499a9d8e045cbd44ecd5",
-                    new String[]{code}, "", 5, "ubfdvkj65", UUID.randomUUID().toString());
-            log.info("send sms response {}", rtCode);
-
+            CommonResponse response = client.getCommonResponse(request);
+            if (response.getHttpStatus() != 200) {
+                throw new BusinessException("发送失败,请稍后再试", response.getHttpStatus() + "," + response.getData());
+            }
+            log.info("send sms response {}", response.getData());
+            JSONObject jsonObject = new JSONObject(response.getData());
+            if (!"ok".equalsIgnoreCase(jsonObject.getString("Code"))) {
+                throw new BusinessException("发送失败,请稍后再试", jsonObject.getString("Message"));
+            }
             smsRecordRepo.expire(phone);
             smsRecordRepo.expire(phone);
             String sessionId = RandomStringUtils.randomAlphabetic(10);
             String sessionId = RandomStringUtils.randomAlphabetic(10);
             smsRecordRepo.save(SmsRecord.builder()
             smsRecordRepo.save(SmsRecord.builder()
-                                        .sessionId(sessionId)
-                                        .phone(phone)
-                                        .code(code)
-                                        .expiresAt(LocalDateTime.now().plusMinutes(5))
-                                        .expired(false)
-                                        .build());
+                    .sessionId(sessionId)
+                    .phone(phone)
+                    .code(code)
+                    .expiresAt(LocalDateTime.now().plusMinutes(5))
+                    .expired(false)
+                    .build());
             return sessionId;
             return sessionId;
-        } catch (Exception e) {
+        } catch (ClientException | JSONException e) {
             e.printStackTrace();
             e.printStackTrace();
             throw new BusinessException("发送失败,请稍后再试", e.getMessage());
             throw new BusinessException("发送失败,请稍后再试", e.getMessage());
         }
         }
@@ -81,8 +83,7 @@ public class AliSmsService implements SmsService {
 
 
     @Override
     @Override
     public void verify(String phone, String code) throws SmsVerifyException {
     public void verify(String phone, String code) throws SmsVerifyException {
-        SmsRecord smsRecord = smsRecordRepo.findLastByPhoneAndExpiresAtAfterAndExpiredFalse(phone, LocalDateTime.now())
-                                           .orElseThrow(new SmsVerifyException("验证码错误"));
+        SmsRecord smsRecord = smsRecordRepo.findLastByPhoneAndExpiresAtAfterAndExpiredFalse(phone, LocalDateTime.now()).orElseThrow(new SmsVerifyException("验证码错误"));
         if (!smsRecord.getCode().equalsIgnoreCase(code)) {
         if (!smsRecord.getCode().equalsIgnoreCase(code)) {
             throw new BusinessException("验证码错误");
             throw new BusinessException("验证码错误");
         }
         }

+ 9 - 9
src/main/resources/application.yaml

@@ -72,16 +72,16 @@ wx:
         notifyUrl: http://zhirongip.izouma.com/wx/payNotify
         notifyUrl: http://zhirongip.izouma.com/wx/payNotify
         refundNotifyUrl: http://zhirongip.izouma.com/wx/refundNotify
         refundNotifyUrl: http://zhirongip.izouma.com/wx/refundNotify
 storage:
 storage:
-    provider: eos
+    provider: aliyun
     local_path: /var/www/upload/
     local_path: /var/www/upload/
 aliyun:
 aliyun:
-    access-key-id: PXzJyah5rZfWHIIH
-    access-key-secret: e1MS6j0wypXJrw8CM0hObZu8qKbfah
+    access-key-id: LTAI5tBhTJmZfMx64Nqr9WTr
+    access-key-secret: KcMqcOJD5lstXEbL3kbC9lNNeIPvfH
     oss-end-point: oss-cn-hangzhou.aliyuncs.com
     oss-end-point: oss-cn-hangzhou.aliyuncs.com
-    oss-bucket-name: baixiaip
-    oss-domain: https://baixiaip.oss-cn-hangzhou.aliyuncs.com
+    oss-bucket-name: zhirongipp
+    oss-domain: https://zhirongipp.oss-cn-hangzhou.aliyuncs.com
 general:
 general:
-    host: http://baixiaip.izouma.com
+    host: http://tzip.izouma.com
 ---
 ---
 
 
 spring:
 spring:
@@ -92,6 +92,6 @@ spring:
 spring:
 spring:
     profiles: prod
     profiles: prod
     datasource:
     datasource:
-        url: jdbc:mysql://100.113.204.123/yzip?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
-        username: yzip
-        password: w@xaZLAk%M4@*J
+        url: jdbc:mysql://rm-bp1521ow0hyrqce19.mysql.rds.aliyuncs.com/tzip?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
+        username: root
+        password: Jrq&2!h^4rs#pF

+ 2 - 2
src/main/resources/logback-spring.xml

@@ -55,7 +55,7 @@
             <encoder>
             <encoder>
                 <pattern>${FILE_LOG_PATTERN}</pattern>
                 <pattern>${FILE_LOG_PATTERN}</pattern>
             </encoder>
             </encoder>
-            <file>/var/www/yzip/app.log</file>
+            <file>/var/www/tzip/app.log</file>
             <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
             <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                 <fileNamePattern>app.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
                 <fileNamePattern>app.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
                 <maxFileSize>10MB</maxFileSize>
                 <maxFileSize>10MB</maxFileSize>
@@ -78,7 +78,7 @@
             <encoder>
             <encoder>
                 <pattern>${FILE_LOG_PATTERN}</pattern>
                 <pattern>${FILE_LOG_PATTERN}</pattern>
             </encoder>
             </encoder>
-            <file>/var/www/yzip/app.log</file>
+            <file>/var/www/tzip/app.log</file>
             <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
             <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                 <fileNamePattern>app.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
                 <fileNamePattern>app.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
                 <maxFileSize>10MB</maxFileSize>
                 <maxFileSize>10MB</maxFileSize>