fix(商城): 添加支付宝支付

master
waynaqua 3 years ago
parent d94a943656
commit 6f9d04bda9

@ -12,6 +12,7 @@ import com.wayn.common.core.service.shop.IColumnGoodsRelationService;
import com.wayn.common.core.service.shop.IColumnService;
import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.util.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,6 +24,7 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RestController
@RequestMapping("shop/column")
public class ColumnController extends BaseController {
@ -45,7 +47,7 @@ public class ColumnController extends BaseController {
try {
BeanUtils.copyProperties(columnVO, item);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
Integer count = iColumnGoodsRelationService.getGoodsNum(item.getId());
columnVO.setGoodsNum(count);

@ -1,11 +1,13 @@
package com.wayn.common.task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
@Slf4j
@Component
public class TaskService {
private final DelayQueue<Task> delayQueue = new DelayQueue<>();
@ -19,7 +21,7 @@ public class TaskService {
Task task = delayQueue.take();
task.run();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
}
});

@ -2,6 +2,7 @@ package com.wayn.common.util;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wayn.common.base.entity.BaseEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
@ -12,109 +13,111 @@ import java.util.Map;
/**
*
*/
@Slf4j
public class ParameterUtil {
private static final String BASE_ENTITY = "BaseEntity";
private static final ThreadLocal<QueryWrapper> entityWrapperThreadLocal = new ThreadLocal<>();
private static final String BASE_ENTITY = "BaseEntity";
private static final ThreadLocal<QueryWrapper> entityWrapperThreadLocal = new ThreadLocal<>();
/**
* wrapper
*
* @param <T>
*/
public static <T> void setWrapper() {
QueryWrapper<T> wrapper = new QueryWrapper<>();
String startTime = ServletUtils.getParameter("startTime");
String endTime = ServletUtils.getParameter("endTime");
ServletUtils.setParameter("startTime", startTime);
ServletUtils.setParameter("endTime", endTime);
wrapper.ge(StringUtils.isNotEmpty(startTime), "createTime", startTime + " 00:00:00");
wrapper.le(StringUtils.isNotEmpty(endTime), "createTime", endTime + " 23:59:59");
entityWrapperThreadLocal.set(wrapper);
}
/**
* wrapper
*
* @param <T>
*/
public static <T> void setWrapper() {
QueryWrapper<T> wrapper = new QueryWrapper<>();
String startTime = ServletUtils.getParameter("startTime");
String endTime = ServletUtils.getParameter("endTime");
ServletUtils.setParameter("startTime", startTime);
ServletUtils.setParameter("endTime", endTime);
wrapper.ge(StringUtils.isNotEmpty(startTime), "createTime", startTime + " 00:00:00");
wrapper.le(StringUtils.isNotEmpty(endTime), "createTime", endTime + " 23:59:59");
entityWrapperThreadLocal.set(wrapper);
}
/**
* baseEntity
*
* @param baseEntity
* @param <T>
*/
public static <T> void set(BaseEntity baseEntity) {
Map<String, String[]> allParameter = ServletUtils.getAllParameter();
allParameter.forEach((String k, String[] v) -> {
if (StringUtils.containsIgnoreCase(k, "startTime")) {
String startTime = ServletUtils.getParameter(k);
if (StringUtils.isNotEmpty(startTime)) {
startTime = startTime + " 00:00:00";
Class<? extends BaseEntity> aClass = baseEntity.getClass();
if (StringUtils.equalsIgnoreCase("startTime", k)) {
Class<?> superclass = aClass.getSuperclass();
while (!BASE_ENTITY.equals(superclass.getSimpleName())) {
superclass = superclass.getSuperclass();
}
try {
Method declaredMethod = superclass.getDeclaredMethod("set" + StringUtils.capitalize(k),
String.class);
declaredMethod.setAccessible(true);
declaredMethod.invoke(baseEntity, startTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return;
}
Field[] declaredFields = aClass.getDeclaredFields();
for (Field declaredField : declaredFields) {
if (StringUtils.containsIgnoreCase(declaredField.getName(), "startTime")) {
try {
Method method = aClass.getDeclaredMethod(
"set" + StringUtils.capitalize(declaredField.getName()), String.class);
method.setAccessible(true);
method.invoke(baseEntity, startTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
} else if (StringUtils.containsIgnoreCase(k, "endTime")) {
String endTime = ServletUtils.getParameter(k);
if (StringUtils.isNotEmpty(endTime)) {
endTime = endTime + " 23:59:59";
Class<? extends BaseEntity> aClass = baseEntity.getClass();
if (StringUtils.equalsIgnoreCase("endTime", k)) {
Class<?> superclass = aClass.getSuperclass();
while (!BASE_ENTITY.equals(superclass.getSimpleName())) {
superclass = superclass.getSuperclass();
}
try {
Method declaredMethod = superclass.getDeclaredMethod("set" + StringUtils.capitalize(k),
String.class);
declaredMethod.setAccessible(true);
declaredMethod.invoke(baseEntity, endTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return;
}
Field[] declaredFields = aClass.getDeclaredFields();
for (Field declaredField : declaredFields) {
if (StringUtils.containsIgnoreCase(declaredField.getName(), "endTime")) {
try {
Method method = aClass.getMethod(
"set" + StringUtils.capitalize(declaredField.getName()), String.class);
method.setAccessible(true);
method.invoke(baseEntity, endTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
});
}
/**
* baseEntity
*
* @param baseEntity
* @param <T>
*/
public static <T> void set(BaseEntity baseEntity) {
Map<String, String[]> allParameter = ServletUtils.getAllParameter();
allParameter.forEach((String k, String[] v) -> {
if (StringUtils.containsIgnoreCase(k, "startTime")) {
String startTime = ServletUtils.getParameter(k);
if (StringUtils.isNotEmpty(startTime)) {
startTime = startTime + " 00:00:00";
Class<? extends BaseEntity> aClass = baseEntity.getClass();
if (StringUtils.equalsIgnoreCase("startTime", k)) {
Class<?> superclass = aClass.getSuperclass();
while (!BASE_ENTITY.equals(superclass.getSimpleName())) {
superclass = superclass.getSuperclass();
}
try {
Method declaredMethod = superclass.getDeclaredMethod("set" + StringUtils.capitalize(k),
String.class);
declaredMethod.setAccessible(true);
declaredMethod.invoke(baseEntity, startTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.error(e.getMessage(), e);
}
return;
}
Field[] declaredFields = aClass.getDeclaredFields();
for (Field declaredField : declaredFields) {
if (StringUtils.containsIgnoreCase(declaredField.getName(), "startTime")) {
try {
Method method = aClass.getDeclaredMethod(
"set" + StringUtils.capitalize(declaredField.getName()), String.class);
method.setAccessible(true);
method.invoke(baseEntity, startTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.error(e.getMessage(), e);
}
}
}
}
} else if (StringUtils.containsIgnoreCase(k, "endTime")) {
String endTime = ServletUtils.getParameter(k);
if (StringUtils.isNotEmpty(endTime)) {
endTime = endTime + " 23:59:59";
Class<? extends BaseEntity> aClass = baseEntity.getClass();
if (StringUtils.equalsIgnoreCase("endTime", k)) {
Class<?> superclass = aClass.getSuperclass();
while (!BASE_ENTITY.equals(superclass.getSimpleName())) {
superclass = superclass.getSuperclass();
}
try {
Method declaredMethod = superclass.getDeclaredMethod("set" + StringUtils.capitalize(k),
String.class);
declaredMethod.setAccessible(true);
declaredMethod.invoke(baseEntity, endTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.error(e.getMessage(), e);
}
return;
}
Field[] declaredFields = aClass.getDeclaredFields();
for (Field declaredField : declaredFields) {
if (StringUtils.containsIgnoreCase(declaredField.getName(), "endTime")) {
try {
Method method = aClass.getMethod(
"set" + StringUtils.capitalize(declaredField.getName()), String.class);
method.setAccessible(true);
method.invoke(baseEntity, endTime);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.error(e.getMessage(), e);
}
}
}
}
}
});
}
public static <T> QueryWrapper get() {
return entityWrapperThreadLocal.get();
}
public static <T> QueryWrapper get() {
return entityWrapperThreadLocal.get();
}
}

@ -1,6 +1,7 @@
package com.wayn.common.util.file;
import com.wayn.common.util.security.Md5Utils;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
@ -12,6 +13,7 @@ import java.text.DecimalFormat;
*
* @author ruoyi
*/
@Slf4j
public class FileUtils extends org.apache.commons.io.FileUtils {
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
@ -150,7 +152,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
try {
if (!((temp = br.readLine()) != null)) break;
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
content.append(temp);
}

@ -1,6 +1,7 @@
package com.wayn.common.util.http;
import com.wayn.common.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@ -12,10 +13,9 @@ import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;
@Slf4j
public class HttpUtil {
private static final Logger logger = Logger.getLogger("HttpUtil");
/**
* JS
*
@ -73,7 +73,7 @@ public class HttpUtil {
out.print(tip);
out.flush();
} catch (IOException e) {
logger.severe(e.toString());
log.error(e.toString());
}
}
@ -157,8 +157,7 @@ public class HttpUtil {
try {
retStr.append(URLEncoder.encode(retUrl, Constants.UTF_ENCODING));
} catch (UnsupportedEncodingException e) {
logger.severe("encodeRetURL error." + url);
e.printStackTrace();
log.error("encodeRetURL error." + url);
}
if (data != null) {
@ -187,8 +186,7 @@ public class HttpUtil {
try {
retUrl = URLDecoder.decode(url, Constants.UTF_ENCODING);
} catch (UnsupportedEncodingException e) {
logger.severe("encodeRetURL error." + url);
e.printStackTrace();
log.error("encodeRetURL error." + url);
}
return retUrl;
@ -230,8 +228,7 @@ public class HttpUtil {
try {
response.sendRedirect(location);
} catch (IOException e) {
logger.severe("sendRedirect location:" + location);
e.printStackTrace();
log.error("sendRedirect location:" + location);
}
}
@ -312,4 +309,4 @@ public class HttpUtil {
}
return value;
}
}
}

@ -62,7 +62,7 @@ public class ElasticDocument {
return false;
}
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
return true;
}

@ -10,7 +10,7 @@ public class BufferedInputFile {
try (BufferedReader reader = new BufferedReader(new FileReader("E:/data.txt"))) {
System.out.println(reader.lines().collect(Collectors.joining("\n")));
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
}

@ -14,9 +14,9 @@ public class FileRead {
System.out.println(new String(arr,0 ,len));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
}

@ -12,9 +12,9 @@ public class TestEOF {
System.out.write(in.readByte());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
System.out.println(1000== 1000);
Integer i1 = 1000;

@ -1,18 +1,22 @@
package com.wayn.mobile.api.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.JsonObject;
import com.wayn.common.base.controller.BaseController;
import com.wayn.common.core.domain.shop.Order;
import com.wayn.common.core.domain.vo.OrderVO;
import com.wayn.common.util.R;
import com.wayn.mobile.api.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@RestController
@RequestMapping("order")
public class OrderController extends BaseController {
@ -63,9 +67,16 @@ public class OrderController extends BaseController {
return iOrderService.h5pay(orderVO.getOrderSn(), orderVO.getPayType(), request);
}
@PostMapping("payNotify")
public R payNotify(HttpServletRequest request, HttpServletResponse response) {
return iOrderService.payNotify(request, response);
@PostMapping("wxPayNotify")
public R wxPayNotify(HttpServletRequest request, HttpServletResponse response) {
log.info("微信paySuccess通知数据记录req{}", JSONObject.toJSONString(request.getParameterMap()));
return iOrderService.wxPayNotify(request, response);
}
@PostMapping("aliPayNotify")
public R aliPayNotify(Integer payType, String orderNo) {
log.info("支付宝paySuccess通知数据记录orderNo: {}, payType{}", orderNo, payType);
return iOrderService.aliPayNotify(request, response);
}
@GetMapping("searchResult/{orderSn}")

@ -44,7 +44,7 @@ public interface IOrderService extends IService<Order> {
* @param request
* @return r
*/
R h5pay(String orderSn, Integer payType, HttpServletRequest request) throws UnsupportedEncodingException;
R h5pay(String orderSn, Integer payType, HttpServletRequest request);
/**
*
@ -57,7 +57,7 @@ public interface IOrderService extends IService<Order> {
* @param request
* @return r
*/
R prepay(String orderSn, Integer payType, HttpServletRequest request) throws UnsupportedEncodingException;
R prepay(String orderSn, Integer payType, HttpServletRequest request);
/**
*
@ -75,7 +75,9 @@ public interface IOrderService extends IService<Order> {
* @param response
* @return r
*/
R payNotify(HttpServletRequest request, HttpServletResponse response);
R wxPayNotify(HttpServletRequest request, HttpServletResponse response);
R aliPayNotify(HttpServletRequest request, HttpServletResponse response);
/**
*

@ -129,7 +129,7 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
jsonObject.put("tag", "热品");
}
} catch (IntrospectionException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
}
array.add(jsonObject);
}

@ -6,12 +6,14 @@ import com.wayn.common.core.domain.shop.GoodsProduct;
import com.wayn.common.core.service.shop.*;
import com.wayn.common.util.R;
import com.wayn.mobile.api.service.IGoodsDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.*;
@Slf4j
@Service
public class GoodsDetailServiceImpl implements IGoodsDetailService {
@ -52,7 +54,7 @@ public class GoodsDetailServiceImpl implements IGoodsDetailService {
success.add("productList", productTask.get());
success.add("attributes", attrTask.get());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
log.error(e.getMessage(), e);;
} finally {
poolExecutor.shutdown();
}

@ -13,6 +13,7 @@ import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.util.R;
import com.wayn.data.redis.manager.RedisCache;
import com.wayn.mobile.api.service.IHomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
@ -21,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
@Slf4j
@Service
public class IHomeServiceImpl implements IHomeService {
@ -79,7 +81,7 @@ public class IHomeServiceImpl implements IHomeService {
success.add("hotGoodsList", hotGoodsTask.get());
redisCache.setCacheObject(INDEX_DATA, success, 10, TimeUnit.MINUTES);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
} finally {
threadPoolTaskExecutor.shutdown();
}

@ -5,6 +5,7 @@ import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -43,6 +44,7 @@ import com.wayn.mobile.api.service.IOrderService;
import com.wayn.mobile.api.task.OrderUnpaidTask;
import com.wayn.mobile.api.util.OrderSnGenUtil;
import com.wayn.mobile.framework.security.util.MobileSecurityUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
@ -364,7 +366,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
@Override
@Transactional(rollbackFor = Exception.class)
public R prepay(String orderSn, Integer payType, HttpServletRequest request) throws UnsupportedEncodingException {
public R prepay(String orderSn, Integer payType, HttpServletRequest request) {
// 获取订单详情
Order order = getOne(new QueryWrapper<Order>().eq("order_sn", orderSn));
String checkMsg = checkOrderOperator(order);
@ -399,7 +401,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
result = wxPayService.createOrder(orderRequest);
return R.success().add("result", result);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
;
return R.error("订单不能支付");
}
}
@ -407,9 +410,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
@Override
@Transactional(rollbackFor = Exception.class)
public R h5pay(String orderSn, Integer payType, HttpServletRequest request) throws UnsupportedEncodingException {
public R h5pay(String orderSn, Integer payType, HttpServletRequest request) {
// 获取订单详情
Order order = getOne(new QueryWrapper<Order>().eq("order_sn", orderSn));
Long userId = order.getUserId();
String checkMsg = checkOrderOperator(order);
if (!SysConstants.STRING_TRUE.equals(checkMsg)) {
return R.error(checkMsg);
@ -443,13 +447,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
return R.error("订单不能支付");
}
case ALI:
request.setCharacterEncoding(Constants.UTF_ENCODING);
// 初始化
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig.getGateway(), alipayConfig.getAppId(),
alipayConfig.getRsaPrivateKey(), alipayConfig.getFormat(), alipayConfig.getCharset(), alipayConfig.getAlipayPublicKey(),
alipayConfig.getSigntype());
// 创建API对应的request
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
// 创建API对应的request使用手机网站支付request
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
// 在公共参数中设置回跳和通知地址
String url = WaynConfig.getMobileUrl() + request.getContextPath();
alipayRequest.setReturnUrl(url + "/returnOrders/" + orderSn + "/" + userId);
@ -470,7 +473,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
// 选填
// 商品描述,可空
String body = "商品描述";
alipayRequest.setBizContent("{" + "\"out_trade_no\":\"" + out_trade_no + "\"," + "\"product_code\":\""
+ product_code + "\"," + "\"total_amount\":\"" + total_amount + "\"," + "\"subject\":\"" + subject
+ "\"," + "\"body\":\"" + body + "\"}");
@ -481,7 +483,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
form = alipayClient.pageExecute(alipayRequest).getBody();//调用SDK生成表单
return R.success().add("form", form);
} catch (AlipayApiException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
;
return R.error("订单不能支付");
}
case ALI_TEST:
@ -511,12 +514,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
}
@Override
public R payNotify(HttpServletRequest request, HttpServletResponse response) {
public R wxPayNotify(HttpServletRequest request, HttpServletResponse response) {
String xmlResult;
try {
xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
;
return R.error(WxPayNotifyResponse.fail(e.getMessage()));
}
@ -529,7 +533,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
throw new WxPayException("微信通知支付失败!");
}
} catch (WxPayException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
;
return R.error(WxPayNotifyResponse.fail(e.getMessage()));
}
@ -575,6 +580,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
return R.error(WxPayNotifyResponse.success("处理成功!"));
}
@Override
public R aliPayNotify(HttpServletRequest request, HttpServletResponse response) {
return null;
}
@Override
public R searchResult(String orderSn) {
Order order = getOne(new QueryWrapper<Order>().eq("order_sn", orderSn));

Loading…
Cancel
Save