qmj 2 долоо хоног өмнө
parent
commit
1cad6f961a

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/app/user/InfoUserController.java

@@ -488,7 +488,8 @@ public class InfoUserController extends BaseController {
         String authcode = "1" + RandomStringUtils.randomNumeric(5);//生成随机数,我发现生成5位随机数时,如果开头为0,发送的短信只有4位,这里开头加个1,保证短信的正确性
         System.out.println("验证码:" + authcode);
         jedis.set(phone.trim().replaceAll("\\+", ""), authcode);//将验证码存入缓存
-        sms.getcode(phone, authcode);//发送短息
+//        sms.getcode(phone, authcode);//发送短息
+        sms.getTwCode(phone,authcode);
         return success(MessageUtils.message("no.sms.send.success"));
     }
 

+ 35 - 43
ruoyi-system/src/main/java/com/ruoyi/system/utils/MobileSMS.java

@@ -2,11 +2,10 @@ package com.ruoyi.system.utils;
 
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 
 import java.nio.charset.StandardCharsets;
-import java.util.Collections;
+import java.util.Base64;
 
 public class MobileSMS {
     public void getcode(String phone,String code){
@@ -24,48 +23,41 @@ public class MobileSMS {
     }
 
     /**
-     * 发送短信提醒(EngageLab)
-     * 文档:https://www.engagelab.com/zh_CN/docs/NEWSMS/REST-API/API-SMS-Sending
+     * 发送 OTP 验证码(EngageLab OTP API)
+     * 参考:https://otp.api.engagelab.cc/v1/messages
+     *
      * @param phone 手机号(含国家码,如 +8613700000000)
-     * @param code  验证码/短信内容变量
+     * @param code  验证码
      */
-    public void getTwCode(String phone, String code)
-    {
-        // EngageLab 短信发送地址
-        String url = "https://smsapi.engagelab.com/v1/messages";
-
-        // TODO 根据实际控制台配置替换为自己的 key / secret / 模板 ID
-        String devKey = "d6kk5d4ao9hcpovohsl0";
-        String devSecret = "t7bhxkdype5p6facdna4ehja";
-        String templateId = "tw_foodie_user_register";
-
-        // Basic 认证头:Authorization: Basic base64(dev_key:dev_secret)
-        String auth = devKey + ":" + devSecret;
-        String base64Auth = java.util.Base64.getEncoder()
-                .encodeToString(auth.getBytes(StandardCharsets.UTF_8));
-
-        // 组装请求体
-        JSONObject body = new JSONObject();
-        body.put("to", Collections.singletonList(phone));
-
-        JSONObject template = new JSONObject();
-        template.put("id", templateId);
-
-        // 根据你在 EngageLab 模板中定义的变量名赋值
-        JSONObject params = new JSONObject();
-        // 假设模板中有 {{code}} 变量;如果变量名不同,请相应修改 key
-        params.put("code", code);
-
-        template.put("params", params);
-        body.put("template", template);
-
-        String res = HttpRequest.post(url)
-                .header("Authorization", "Basic " + base64Auth)
-                .header("Content-Type", "application/json")
-                .body(JSON.toJSONString(body))
-                .execute()
-                .body();
-
-        System.out.println("发送短信结果:" + res);
+    public void getTwCode(String phone, String code) {
+        try {
+            String apiKey = "d6kk5d4ao9hcpovohsl0";
+            String apiSecret = "t7bhxkdype5p6facdna4ehja";
+            String authString = Base64.getEncoder()
+                    .encodeToString((apiKey + ":" + apiSecret).getBytes(StandardCharsets.UTF_8));
+
+            JSONObject template = new JSONObject();
+            template.put("id", "tw_foodie_code");
+            template.put("language", "default");
+            JSONObject params = new JSONObject();
+            params.put("code", code);
+            template.put("params", params);
+
+            JSONObject body = new JSONObject();
+            body.put("to", phone);
+            body.put("template", template);
+            String bodyString = body.toJSONString();
+
+            String res = HttpRequest.post("https://otp.api.engagelab.cc/v1/codes")
+                    .header("Authorization", "Basic " + authString)
+                    .header("Content-Type", "application/json")
+                    .body(bodyString)
+                    .execute()
+                    .body();
+
+            System.out.println("发送短信结果:" + res);
+        } catch (Exception e) {
+            System.err.println("OTP 发送异常:" + e.getMessage());
+        }
     }
 }

+ 5 - 1
ruoyi-system/target/classes/mapper/system/InfoAddressMapper.xml

@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="name"    column="name"    />
         <result property="phone"    column="phone"    />
         <result property="address"    column="address"    />
+        <result property="addressDetail"    column="address_detail"    />
         <result property="longitude"    column="longitude"    />
         <result property="latitude"    column="latitude"    />
         <result property="country"    column="country"    />
@@ -19,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectInfoAddressVo">
-        select id, user_id, name, phone, address, longitude, latitude, country, province, city, area from info_address
+        select id, user_id, name, phone, address, address_detail, longitude, latitude, country, province, city, area from info_address
     </sql>
 
     <select id="selectInfoAddressList" parameterType="InfoAddress" resultMap="InfoAddressResult">
@@ -48,6 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="name != null and name != ''">name,</if>
             <if test="phone != null and phone != ''">phone,</if>
             <if test="address != null and address != ''">address,</if>
+            <if test="addressDetail != null and addressDetail != ''">address_detail,</if>
             <if test="longitude != null">longitude,</if>
             <if test="latitude != null">latitude,</if>
             <if test="country != null">country,</if>
@@ -60,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="name != null and name != ''">#{name},</if>
             <if test="phone != null and phone != ''">#{phone},</if>
             <if test="address != null and address != ''">#{address},</if>
+            <if test="addressDetail != null and addressDetail != ''">#{addressDetail},</if>
             <if test="longitude != null">#{longitude},</if>
             <if test="latitude != null">#{latitude},</if>
             <if test="country != null">#{country},</if>
@@ -76,6 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="name != null and name != ''">name = #{name},</if>
             <if test="phone != null and phone != ''">phone = #{phone},</if>
             <if test="address != null and address != ''">address = #{address},</if>
+            <if test="addressDetail != null and addressDetail != ''">address_detail = #{addressDetail},</if>
             <if test="longitude != null">longitude = #{longitude},</if>
             <if test="latitude != null">latitude = #{latitude},</if>
             <if test="country != null">country = #{country},</if>