Commit 2ad061a7 authored by Junling Bu's avatar Junling Bu
Browse files

chore[litemall-core, litemall-wx-api]:调整代码

parent 03b48600
package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import javax.mail.internet.MimeMessage;
public class MailUtils {
private static final Log logger = LogFactory.getLog(MailUtils.class);
private static MailUtils mailUtils;
private JavaMailSenderImpl mailSender;
// TODO 邮箱相关后置后续应移到数据库,在后台配置完成,暂时先完成功能
// 通知邮件送达地址
private static final String SEND_TO = "ex@qq.com";
private MailUtils() {
mailSender = new JavaMailSenderImpl();
// 配置发送邮箱设置,请按照自己邮箱填写
mailSender.setHost("smtp.exmail.qq.com");
mailSender.setUsername("ex@ex.com.cn");
mailSender.setPassword("ex");
mailSender.setDefaultEncoding("UTF-8");
}
public static MailUtils getMailUtils() {
if (mailUtils == null)
mailUtils = new MailUtils();
return mailUtils;
}
public boolean sendEmail(String setSubject, String setText) {
try {
final MimeMessage mimeMessage = mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setFrom(mailSender.getUsername());
message.setTo(SEND_TO);
message.setSubject(setSubject);
message.setText(setText);
mailSender.send(mimeMessage);
return true;
} catch (Exception ex) {
logger.error("通知邮件发送出错" + ex.getMessage());
return false;
}
}
}
#\u90AE\u4EF6\u53D1\u9001\u914D\u7F6E
# 邮件发送配置
sprint.mail.enable=false
spring.mail.host=smtp.exmail.qq.com
spring.mail.username=ex@ex.com.cn
spring.mail.password=
spring.mail.password=xxxxxx
spring.mail.sendto=ex@qq.com
#\u77ED\u4FE1\u53D1\u9001\u914D\u7F6E
# 短信发送配置
spring.sms.enable=false
spring.sms.appid=
spring.sms.appkey=
spring.sms.sign=
spring.sms.appid=111111
spring.sms.appkey=xxxxxx
spring.sms.sign=xxxxxx
#\u77ED\u4FE1\u6A21\u7248\u6D88\u606F\u914D\u7F6E\uFF0C\u8BF7\u5728\u817E\u8BAF\u77ED\u4FE1\u5E73\u53F0\u914D\u7F6E\u597D\u5404\u4E2A\u901A\u77E5\u6D88\u606F\u7684\u6A21\u7248\uFF0C\u7136\u540E\u5C06\u6A21\u7248ID\u4E00\u4E00\u8D4B\u503C,LitemallNotifyService,NotifyType\u679A\u4E3E\u4E2D\u4E0E\u8FD9\u91CC\u4E00\u4E00\u5BF9\u5E94
spring.sms.template.pay.complated=156349
spring.sms.template.verificationcode=156433
# 短信模板消息配置
# 请在腾讯短信平台配置通知消息模板,然后模板ID这里参数
# 请参考LitemallNotifyService.notifySMSTemplate
spring.sms.template.pay.complated=111111
spring.sms.template.verificationcode=111111
#\u53D1\u9001\u7EBF\u7A0B\u6C60\u914D\u7F6E
# 发送线程池配置
spring.notify.corePoolSize=5
spring.notify.maxPoolSize=100
spring.notify.queueCapacity=50
\ No newline at end of file
......@@ -293,7 +293,7 @@ public class WxOrderController {
// 根据订单商品总价计算运费,满88则免运费,否则8元;
BigDecimal freightPrice = new BigDecimal(0.00);
if (checkedGoodsPrice.compareTo(new BigDecimal(88.00)) < 0) {
freightPrice = new BigDecimal(0.00);
freightPrice = new BigDecimal(8.00);
}
// 可以使用的其他钱,例如用户积分
......@@ -488,16 +488,12 @@ public class WxOrderController {
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
orderRequest.setOutTradeNo(order.getOrderSn());
orderRequest.setOpenid(openid);
// TODO 更有意义的显示名称
orderRequest.setBody("订单:" + order.getOrderSn());
// 元转成分
Integer fee = 0;
// 这里演示仅支付1分
// 实际项目取消下面两行注释
BigDecimal actualPrice = order.getActualPrice();
fee = actualPrice.multiply(new BigDecimal(100)).intValue();
orderRequest.setTotalFee(fee);
// TODO 用户IP地址
orderRequest.setSpbillCreateIp(IpUtil.getIpAddr(request));
result = wxPayService.createOrder(orderRequest);
......@@ -546,7 +542,6 @@ public class WxOrderController {
}
// 检查支付订单金额
// TODO 这里1分钱需要改成实际订单金额
if (!totalFee.equals(order.getActualPrice().toString())) {
throw new Exception(order.getOrderSn() + " : 支付金额不符合 totalFee=" + totalFee);
}
......@@ -557,6 +552,7 @@ public class WxOrderController {
orderService.updateById(order);
//TODO 发送邮件和短信通知,这里采用异步发送
// 订单支付成功以后,会发送短信给用户,以及发送邮件给管理员
litemallNotifyService.notifyMailMessage("订单通知", order.toString());
litemallNotifyService.notifySMSTemplate(order.getMobile(), new String[]{""}, NotifyUtils.NotifyType.PAY_COMPLATED);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment