Parcourir la source

识别地址信息 短信发送

zxf il y a 8 heures
Parent
commit
30f2fbab0e

+ 7 - 1
jd-logistics-modules/jd-logistics-system/pom.xml

@@ -46,7 +46,13 @@
             <groupId>com.mysql</groupId>
             <artifactId>mysql-connector-j</artifactId>
         </dependency>
-        
+
+
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+        </dependency>
         <!-- RuoYi Common DataSource -->
         <dependency>
             <groupId>com.ruoyi</groupId>

+ 17 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/config/GemaiyunSmsConfig.java

@@ -0,0 +1,17 @@
+package com.ruoyi.logistics.config;
+
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "sms.gemaiyun")
+public class GemaiyunSmsConfig {
+    private String accessKey;
+    private String accessSecret;
+    private String sign;
+    private String templateId;
+    private String url;
+}

+ 2 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/config/KD100ExpressConfig.java

@@ -2,10 +2,12 @@ package com.ruoyi.logistics.config;
 
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Component;
 
 @Data
 @Component
+@RefreshScope
 @ConfigurationProperties(prefix = "kd100.express")
 public class KD100ExpressConfig {
     /**

+ 1 - 1
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/domain/BizWaybillCostDetails.java

@@ -85,7 +85,7 @@ public class BizWaybillCostDetails extends BaseEntity
     @Excel(name = "产品类型")
     private String productCode;
     /** 经手人 */
-    @Excel(name = "经手人")
+   // @Excel(name = "经手人")
     private String userName;
 
     @Excel(name = "调账类型")

+ 49 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/util/GemaiyunSmsUtil.java

@@ -0,0 +1,49 @@
+package com.ruoyi.logistics.util;
+
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+
+import java.net.URLEncoder;
+
+public class GemaiyunSmsUtil {
+    /**
+     * 发送歌麦云短信
+     */
+    public static String sendSms(String apiUrl,
+                                 String accesskey,
+                                 String secret,
+                                 String sign,
+                                 String templateId,
+                                 String mobile,
+                                 String content) throws Exception {
+
+        HttpClient httpClient = new HttpClient();
+        PostMethod postMethod = new PostMethod(apiUrl);
+
+        postMethod.getParams().setContentCharset("UTF-8");
+        postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+                new DefaultHttpMethodRetryHandler());
+
+        // 封装参数
+        NameValuePair[] data = {
+                new NameValuePair("accesskey", accesskey),
+                new NameValuePair("secret", secret),
+                new NameValuePair("sign", sign),
+                new NameValuePair("templateId", templateId),
+                new NameValuePair("mobile", mobile),
+                new NameValuePair("content", URLEncoder.encode(content, "utf-8"))
+        };
+
+        postMethod.setRequestBody(data);
+        postMethod.setRequestHeader("Connection", "close");
+
+        int statusCode = httpClient.executeMethod(postMethod);
+        String result = postMethod.getResponseBodyAsString();
+
+        postMethod.releaseConnection();
+        return "statusCode:" + statusCode + ", body:" + result;
+    }
+}

+ 61 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/util/PasswordUtils.java

@@ -0,0 +1,61 @@
+package com.ruoyi.logistics.util;
+
+
+import java.security.SecureRandom;
+
+/**
+ * 密码生成工具类
+ * 生成 8 位高强度随机密码:默认包含 大写字母+小写字母+数字
+ */
+public class PasswordUtils {
+
+    // 字符池:大写字母
+    private static final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    // 字符池:小写字母
+    private static final String LOWER = "abcdefghijklmnopqrstuvwxyz";
+    // 字符池:数字
+    private static final String DIGITS = "0123456789";
+    // 字符池:特殊符号(可选)
+    private static final String SPECIAL = "!@#$%^&*_+-=?";
+
+    // 安全随机数(比 Random 更安全)
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    /**
+     * 生成 8 位随机密码(大小写+数字,最常用)
+     */
+    public static String generate8Password() {
+        // 组合字符池
+        String allChars = UPPER + LOWER + DIGITS;
+        return generateRandomPassword(8, allChars);
+    }
+
+    /**
+     * 生成 8 位随机密码(包含特殊符号,强度更高)
+     */
+    public static String generate8PasswordWithSpecial() {
+        String allChars = UPPER + LOWER + DIGITS + SPECIAL;
+        return generateRandomPassword(8, allChars);
+    }
+
+    /**
+     * 通用密码生成方法
+     * @param length 密码长度
+     * @param chars 字符池
+     * @return 随机密码
+     */
+    private static String generateRandomPassword(int length, String chars) {
+        if (length <= 0 || chars.isEmpty()) {
+            throw new IllegalArgumentException("参数不合法");
+        }
+
+        StringBuilder password = new StringBuilder(length);
+        for (int i = 0; i < length; i++) {
+            int index = RANDOM.nextInt(chars.length());
+            password.append(chars.charAt(index));
+        }
+        return password.toString();
+    }
+
+
+}

+ 42 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -4,6 +4,10 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
+
+import com.ruoyi.logistics.config.GemaiyunSmsConfig;
+import com.ruoyi.logistics.util.GemaiyunSmsUtil;
+import com.ruoyi.logistics.util.PasswordUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -65,6 +69,9 @@ public class SysUserServiceImpl implements ISysUserService
     @Autowired
     protected Validator validator;
 
+    @Autowired
+    private GemaiyunSmsConfig smsConfig;
+
     /**
      * 根据条件分页查询用户列表
      * 
@@ -266,9 +273,43 @@ public class SysUserServiceImpl implements ISysUserService
         insertUserPost(user);
         // 新增用户与角色管理
         insertUserRole(user);
+
+        String password=PasswordUtils.generate8PasswordWithSpecial();
+        user.setPassword(password);
+        if(rows>0){
+            sendCreateUserSms(user);
+        }
+
         return rows;
     }
 
+
+
+    private void sendCreateUserSms(SysUser user) {
+        try {
+            // ✅ 局部变量,每个请求独立,安全!
+            StringBuilder sb = new StringBuilder();
+            sb.append(user.getNickName()).append("##")
+                    .append(user.getPassword());
+            String content = sb.toString();
+            // 调用短信接口
+            String result = GemaiyunSmsUtil.sendSms(
+                    smsConfig.getUrl(),
+                    smsConfig.getAccessKey(),
+                    smsConfig.getAccessSecret(),
+                    smsConfig.getSign(),
+                    smsConfig.getTemplateId(),
+                    user.getPhonenumber(),
+                    content
+            );
+            System.out.println(result);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
     /**
      * 注册用户信息
      * 
@@ -362,6 +403,7 @@ public class SysUserServiceImpl implements ISysUserService
      */
     @Override
     public int resetPwd(SysUser user)
+
     {
         return userMapper.updateUser(user);
     }

+ 1 - 1
jd-logistics-ui-v3/src/views/logistics/monthSummary/costList.vue

@@ -32,7 +32,7 @@
           <span>月结</span>
         </template>
       </el-table-column>
-      <el-table-column label="费用(元)" align="center" prop="rateAmount" />
+      <el-table-column label="费用(元)" align="center" prop="rateAmount" />aaaaa
       <el-table-column label="经手人" align="center" prop="userName" />
       <el-table-column label="增值费用" align="center" prop="feeItemName" />
 <!--      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>-->