فهرست منبع

采美豆开通会员发短信

zhijiezhao 3 سال پیش
والد
کامیت
5656fa8546

+ 5 - 0
pom.xml

@@ -30,6 +30,11 @@
     </dependencyManagement>
 
     <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+        </dependency>
+
         <dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-web</artifactId>

+ 2 - 0
src/main/java/com/caimei365/user/UserApplication.java

@@ -3,6 +3,7 @@ package com.caimei365.user;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
 
 
 /**
@@ -15,6 +16,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 
 @EnableDiscoveryClient
 @SpringBootApplication
+@EnableFeignClients(basePackages = {"com.caimei365.user.feign"})
 public class UserApplication {
 
     public static void main(String[] args) {

+ 26 - 0
src/main/java/com/caimei365/user/feign/ToolsFeign.java

@@ -0,0 +1,26 @@
+package com.caimei365.user.feign;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/9/8
+ */
+@FeignClient("CAIMEI365-CLOUD-TOOLS")
+public interface ToolsFeign {
+    /**
+     * 请求发短信接口
+     *
+     * @param mobile  手机号
+     * @param content 内容
+     * @return str
+     */
+    @PostMapping("/tools/sms/send")
+    String getSendSms(@RequestParam String mobile, @RequestParam String content);
+
+}

+ 6 - 1
src/main/java/com/caimei365/user/mapper/SuperVipMapper.java

@@ -132,5 +132,10 @@ public interface SuperVipMapper {
      */
     SuperVipPo findEndTime(Integer userId);
 
-
+    /**
+     * 找手机号发短信
+     * @param userId
+     * @return
+     */
+    String findMobile(Integer userId);
 }

+ 34 - 0
src/main/java/com/caimei365/user/service/impl/RegisterServiceImpl.java

@@ -3,6 +3,7 @@ package com.caimei365.user.service.impl;
 import com.caimei365.user.components.CommonService;
 import com.caimei365.user.components.RedisService;
 import com.caimei365.user.components.WeChatService;
+import com.caimei365.user.feign.ToolsFeign;
 import com.caimei365.user.mapper.*;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.dto.*;
@@ -51,6 +52,8 @@ public class RegisterServiceImpl implements RegisterService {
     private RegisterMapper registerMapper;
     @Resource
     private SellerMapper sellerMapper;
+    @Resource
+    private ToolsFeign smsFeign;
 
     /**
      * 检查账号可以注册
@@ -1007,6 +1010,7 @@ public class RegisterServiceImpl implements RegisterService {
      * @param beginTime
      */
     private void beanPay(Integer userId, Integer packageId, Date beginTime, Integer repayFlag) {
+        String message = "";
         //1.user表扣豆子
         Double price = vipMapper.findUserPackage(packageId);
         Integer userBeans = vipMapper.findUserBeans(userId);
@@ -1035,6 +1039,16 @@ public class RegisterServiceImpl implements RegisterService {
             vipMapper.addVip(superVip);
             //购买记录表加数据
             setHistory(superVip);
+            //发短信
+            message = "【采美365】恭喜您成功开通采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。";
+            String mobile = vipMapper.findMobile(userId);
+            if (mobile != null && mobile != "") {
+                try {
+                    smsFeign.getSendSms(mobile, message);
+                } catch (Exception e) {
+                    log.error("短信发送异常"+e);
+                }
+            }
         } else if (repayFlag == 1) {
             //有效期内续费
             SuperVipPo superVip = vipMapper.findSuperVip(userId);
@@ -1050,6 +1064,16 @@ public class RegisterServiceImpl implements RegisterService {
             vipMapper.updateVip(superVip);
             //购买记录表加数据
             setHistory(superVip);
+            //发短信
+            message="【采美365】恭喜您成功续费采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。";
+            String mobile = vipMapper.findMobile(userId);
+            if (mobile != null && mobile != "") {
+                try {
+                    smsFeign.getSendSms(mobile, message);
+                } catch (Exception e) {
+                    log.error("短信发送异常"+e);
+                }
+            }
         } else if (repayFlag == -1) {
             //过期续费
             SuperVipPo superVip = vipMapper.findSuperVip(userId);
@@ -1068,6 +1092,16 @@ public class RegisterServiceImpl implements RegisterService {
             vipMapper.updateVip(superVip);
             //购买记录表加数据
             setHistory(superVip);
+            //发短信
+            message="【采美365】恭喜您成功续费采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。";
+            String mobile = vipMapper.findMobile(userId);
+            if (mobile != null && mobile != "") {
+                try {
+                    smsFeign.getSendSms(mobile, message);
+                } catch (Exception e) {
+                    log.error("短信发送异常"+e);
+                }
+            }
         }
         log.info(userId + "消费采美豆" + l + "会员到期时间至" + cal.getTime());
     }

+ 4 - 0
src/main/resources/mapper/SuperVipMapper.xml

@@ -134,5 +134,9 @@
           AND useTime = #{useTime}
     </select>
 
+    <select id="findMobile" resultType="java.lang.String">
+        select bindMobile from user where userID=#{userId}
+    </select>
+
 
 </mapper>

+ 10 - 6
src/test/java/com/caimei365/user/UserApplicationTests.java

@@ -1,5 +1,6 @@
 package com.caimei365.user;
 
+import com.caimei365.user.feign.ToolsFeign;
 import com.caimei365.user.mapper.SuperVipMapper;
 import com.caimei365.user.model.po.SuperVipPo;
 import com.caimei365.user.utils.AliyunSmsUtil;
@@ -21,16 +22,19 @@ class UserApplicationTests {
         boolean b = ValidateUtil.validateEmail("182126@qq.com");
         System.out.println(b);
     }*/
+    @Resource
+    private ToolsFeign feign;
 
-    //    @Test
-//    void sms(){
-//        String mobile = "15814011616";
+
+    @Test
+    void sms(){
+        String mobile = "15827317748";
 //        String randomCode = CodeUtil.generateCodeInt(6);
 //        String name ="dsfsd";
-//        //AliyunSmsUtil.sendSms(mobile, 6, "{name:"+ mobile +",content:"+ randomCode +"}");
+        //AliyunSmsUtil.sendSms(mobile, 6, "{name:"+ mobile +",content:"+ randomCode +"}");
 //        AliyunSmsUtil.sendSms(mobile, 11, "{name:\""+ name +"\",code:" + randomCode + "}");
-//
-//    }
+        feign.getSendSms(mobile,"恭喜您成功开通采美平台超级会员,为期1个月,快戳采美网站链接www.caimei365.com或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯!");
+    }
 //    @Test
 //    public static void main(String[] args) {
 //        Calendar cal = Calendar.getInstance();