diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java
index b6440f39..a35d771b 100644
--- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java
+++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java
@@ -3,15 +3,14 @@ package org.linlinjava.litemall.admin.web;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
-import org.linlinjava.litemall.core.notify.LitemallNotifyService;
-import org.linlinjava.litemall.core.notify.util.ConfigUtil;
+import org.linlinjava.litemall.core.notify.NotifyService;
+import org.linlinjava.litemall.core.notify.NotifyType;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.LitemallOrderGoodsService;
import org.linlinjava.litemall.db.service.LitemallOrderService;
import org.linlinjava.litemall.db.service.LitemallProductService;
import org.linlinjava.litemall.db.service.LitemallUserService;
-import org.linlinjava.litemall.db.util.OrderHandleOption;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +45,7 @@ public class AdminOrderController {
private LitemallUserService userService;
@Autowired
- private LitemallNotifyService litemallNotifyService;
+ private NotifyService notifyService;
@GetMapping("/list")
public Object list(@LoginAdmin Integer adminId,
@@ -153,7 +152,7 @@ public class AdminOrderController {
* 注意订单号只发后6位
*
*/
- litemallNotifyService.notifySMSTemplate(order.getMobile(), ConfigUtil.NotifyType.REFUND, new String[]{order.getOrderSn().substring(8, 14)});
+ notifyService.notifySmsTemplate(order.getMobile(), NotifyType.REFUND, new String[]{order.getOrderSn().substring(8, 14)});
txManager.commit(status);
@@ -207,7 +206,7 @@ public class AdminOrderController {
* 您的订单已经发货,快递公司 {1},快递单 {2} ,请注意查收
*
*/
- litemallNotifyService.notifySMSTemplate(order.getMobile(), ConfigUtil.NotifyType.SHIP, new String[]{shipChannel, shipSn});
+ notifyService.notifySmsTemplate(order.getMobile(), NotifyType.SHIP, new String[]{shipChannel, shipSn});
return ResponseUtil.ok();
}
diff --git a/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/AdminConfigTest.java b/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/AdminConfigTest.java
index 32ee2b4b..7520e8c7 100644
--- a/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/AdminConfigTest.java
+++ b/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/AdminConfigTest.java
@@ -18,7 +18,7 @@ public class AdminConfigTest {
@Test
public void test() {
// 测试获取application-core.yml配置信息
- System.out.println(environment.getProperty("express.appId"));
+ System.out.println(environment.getProperty("litemall.express.appId"));
// 测试获取application-db.yml配置信息
System.out.println(environment.getProperty("spring.datasource.druid.url"));
// 测试获取application-admin.yml配置信息
diff --git a/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java b/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java
index 0d355a94..8587ab94 100644
--- a/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java
+++ b/litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java
@@ -18,7 +18,7 @@ public class AllinoneConfigTest {
@Test
public void test() {
// 测试获取application-core.yml配置信息
- System.out.println(environment.getProperty("express.appId"));
+ System.out.println(environment.getProperty("litemall.express.appId"));
// 测试获取application-db.yml配置信息
System.out.println(environment.getProperty("spring.datasource.druid.url"));
// 测试获取application-wx.yml配置信息
diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java
index 4e5b96c5..1f1b7656 100644
--- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java
+++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java
@@ -1,12 +1,11 @@
package org.linlinjava.litemall.core.express;
-import org.linlinjava.litemall.core.express.config.ExpressConfig;
+import org.linlinjava.litemall.core.express.config.ExpressProperties;
import org.linlinjava.litemall.core.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Base64Utils;
-import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.HashMap;
@@ -17,13 +16,19 @@ import java.util.Map;
*
* 3831775044640 韵达快递(YD)
*/
-@Service
public class ExpressService {
//请求url
private String ReqURL = "http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx";
- @Autowired
- ExpressConfig config;
+ private ExpressProperties properties;
+
+ public ExpressProperties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(ExpressProperties properties) {
+ this.properties = properties;
+ }
/**
* 获取物流供应商名
@@ -32,7 +37,7 @@ public class ExpressService {
* @return
*/
public String getVendorName(String vendooCode) {
- for (Map item : config.getVendors()) {
+ for (Map item : properties.getVendors()) {
if (item.get("code").equals(vendooCode))
return item.get("name");
}
@@ -45,13 +50,17 @@ public class ExpressService {
* @throws Exception
*/
public String getOrderTracesByJson(String expCode, String expNo) throws Exception {
+ if(!properties.isEnable()){
+ return null;
+ }
+
String requestData = "{'OrderCode':'','ShipperCode':'" + expCode + "','LogisticCode':'" + expNo + "'}";
Map params = new HashMap();
params.put("RequestData", URLEncoder.encode(requestData, "UTF-8"));
- params.put("EBusinessID", config.getAppId());
+ params.put("EBusinessID", properties.getAppId());
params.put("RequestType", "1002");
- String dataSign = encrypt(requestData, config.getAppKey(), "UTF-8");
+ String dataSign = encrypt(requestData, properties.getAppKey(), "UTF-8");
params.put("DataSign", URLEncoder.encode(dataSign, "UTF-8"));
params.put("DataType", "2");
diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java
new file mode 100644
index 00000000..0e3f3319
--- /dev/null
+++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java
@@ -0,0 +1,31 @@
+package org.linlinjava.litemall.core.express.config;
+
+import com.github.qcloudsms.SmsSingleSender;
+import org.linlinjava.litemall.core.express.ExpressService;
+import org.linlinjava.litemall.core.notify.NotifyService;
+import org.linlinjava.litemall.core.notify.TencentSmsSender;
+import org.linlinjava.litemall.core.notify.WxTemplateSender;
+import org.linlinjava.litemall.core.notify.config.NotifyProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+
+@Configuration
+@EnableConfigurationProperties(ExpressProperties.class)
+public class ExpressAutoConfiguration {
+
+ private final ExpressProperties properties;
+
+ public ExpressAutoConfiguration(ExpressProperties properties) {
+ this.properties = properties;
+ }
+
+ @Bean
+ public ExpressService expressService(){
+ ExpressService expressService = new ExpressService();
+ expressService.setProperties(properties);
+ return expressService;
+ }
+
+}
diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressConfig.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java
similarity index 70%
rename from litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressConfig.java
rename to litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java
index 281f3e33..84479440 100644
--- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressConfig.java
+++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java
@@ -1,19 +1,23 @@
package org.linlinjava.litemall.core.express.config;
-import org.linlinjava.litemall.core.util.YmlPropertyFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-@Component
-@Configuration
-@ConfigurationProperties(prefix = "express")
-public class ExpressConfig {
+@ConfigurationProperties(prefix = "litemall.express")
+public class ExpressProperties {
+ private boolean enable;
+
+ public boolean isEnable() {
+ return enable;
+ }
+
+ public void setEnable(boolean enable) {
+ this.enable = enable;
+ }
+
private String appId;
private String appKey;
diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/LitemallNotifyService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/LitemallNotifyService.java
deleted file mode 100644
index 41fd32c7..00000000
--- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/LitemallNotifyService.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package org.linlinjava.litemall.core.notify;
-
-import org.linlinjava.litemall.core.notify.util.ConfigUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-
-/**
- * Litemall商城通知服务类
- */
-@Service("litemallNotifyService")
-public class LitemallNotifyService {
- @Autowired
- private MailSendService mailSendService;
- @Autowired
- private SMSSendService smsSendService;
- @Autowired
- private WXTemplateSendService wxTemplateSendService;
-
- @Async
- public void notifySMSMessage(String phoneNumber, String message) {
- if (!smsSendService.config.isEnable())
- return;
-
- smsSendService.sendSMS(phoneNumber, message);
- }
-
- /**
- * 微信模版消息通知
- * @param token 通过wxMAService获取token或者通过url请求token
- * @param touser 接收者openId
- * @param formId 表单ID或者 prepayId
- * @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
- * @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
- */
- @Async
- public void notifyWXTemplate(String token,String touser, String formId, ConfigUtil.NotifyType notifyType, String[] params) {
- if (!wxTemplateSendService.config.isEnable())
- return;
-
- String templateId = ConfigUtil.getTemplateId(notifyType, wxTemplateSendService.config.getTemplate());
-
- if (templateId != "")
- wxTemplateSendService.sendWechatMsg(token,touser, templateId, formId, "", "", params);
- }
-
- /**
- * 短信模版通知
- *
- * @param phoneNumber 接收通知的电话号码
- * @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
- * @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
- */
- @Async
- public void notifySMSTemplate(String phoneNumber, ConfigUtil.NotifyType notifyType, String[] params) {
- if (!smsSendService.config.isEnable())
- return;
-
- int templateId = Integer.parseInt(ConfigUtil.getTemplateId(notifyType, smsSendService.config.getTemplate()));
-
- if (templateId != -1)
- smsSendService.sendSMSWithTemplate(phoneNumber, templateId, params);
- }
-
- /**
- * 短信模版通知
- *
- * @param phoneNumber 接收通知的电话号码
- * @param templateId 模板ID
- * @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
- */
- @Async
- public void notifySMSTemplate(String phoneNumber, int templateId, String[] params) {
- if (!smsSendService.config.isEnable())
- return;
-
- smsSendService.sendSMSWithTemplate(phoneNumber, templateId, params);
- }
-
- /**
- * 发送邮件通知,接收者在spring.mail.sendto中指定
- *
- * @param setSubject 邮件标题
- * @param setText 邮件内容
- */
- @Async
- public void notifyMailMessage(String setSubject, String setText) {
- if (!mailSendService.config.isEnable())
- return;
-
- mailSendService.sendEmail(setSubject, setText);
- }
-}
diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/MailSendService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/MailSendService.java
deleted file mode 100644
index 6966dbda..00000000
--- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/MailSendService.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.linlinjava.litemall.core.notify;
-
-import org.linlinjava.litemall.core.notify.config.MailNotifyConfig;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.mail.javamail.JavaMailSenderImpl;
-import org.springframework.mail.javamail.MimeMessageHelper;
-import org.springframework.stereotype.Service;
-
-import javax.mail.internet.MimeMessage;
-
-@Service("mailSendService")
-class MailSendService {
- @Autowired
- MailNotifyConfig config;
-
- private JavaMailSenderImpl mailSender;
-
- private JavaMailSenderImpl getMailSender() {
- if (mailSender == null) {
- mailSender = new JavaMailSenderImpl();
- mailSender.setHost(config.getHost());
- mailSender.setUsername(config.getUsername());
- mailSender.setPassword(config.getPassword());
- }
-
- return mailSender;
- }
-
- /**
- * 发送邮件通知
- *
- * @param setSubject 邮件标题
- * @param setText 邮件内容
- */
- public void sendEmail(String setSubject, String setText) {
- try {
- final MimeMessage mimeMessage = getMailSender().createMimeMessage();
- final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
-
- message.setFrom(config.getUsername());
- message.setTo(config.getSendto());
- message.setSubject(setSubject);
- message.setText(setText);
- getMailSender().send(mimeMessage);
-
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-}
diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java
new file mode 100644
index 00000000..f78360c6
--- /dev/null
+++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java
@@ -0,0 +1,160 @@
+package org.linlinjava.litemall.core.notify;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mail.MailSender;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.scheduling.annotation.Async;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 商城通知服务类
+ */
+public class NotifyService {
+ private MailSender mailSender;
+ private String sendFrom;
+ private String sendTo;
+
+ private SmsSender smsSender;
+ private List