| @@ -0,0 +1,24 @@ | |||
| package com.simple.config; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| @Component | |||
| @ConfigurationProperties(prefix = "pay") | |||
| public class PayProperty { | |||
| /** | |||
| * 真实支付 | |||
| */ | |||
| private boolean real; | |||
| public boolean isReal() { | |||
| return real; | |||
| } | |||
| public void setReal(boolean real) { | |||
| this.real = real; | |||
| } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package com.simple.config; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| @Component | |||
| @ConfigurationProperties(prefix = "pay") | |||
| public class PayProperty { | |||
| /** | |||
| * 真实支付 | |||
| */ | |||
| private boolean real; | |||
| public boolean isReal() { | |||
| return real; | |||
| } | |||
| public void setReal(boolean real) { | |||
| this.real = real; | |||
| } | |||
| } | |||
| @@ -4,8 +4,8 @@ import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ErrorCode; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.config.PayProperty; | |||
| import com.simple.domain.po.*; | |||
| import com.simple.enums.EnumCouponOrderStatus; | |||
| import com.simple.enums.EnumPayStatus; | |||
| import com.simple.enums.EnumPayWay; | |||
| import com.simple.exception.MallinkException; | |||
| @@ -27,6 +27,9 @@ import java.util.Map; | |||
| public class WxRefundOrderController extends BaseController { | |||
| private Logger logger = Logger.getLogger(WxRefundOrderController.class); | |||
| @Autowired | |||
| private PayProperty payProperty; | |||
| @Autowired | |||
| private WxCouponOrderService wxCouponOrderService; | |||
| @@ -100,7 +103,7 @@ public class WxRefundOrderController extends BaseController { | |||
| WxMerchantBUser bUser = getUser(); | |||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | |||
| try { | |||
| wxRefundOrderService.createRefundOrder(appinfo, refundOrderQ, payOrder, EnumPayWay.PAY_WAY_WEAPP); | |||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, refundOrderQ, payOrder, EnumPayWay.PAY_WAY_WEAPP); | |||
| return new ResultData(); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -1,12 +1,14 @@ | |||
| package com.simple.pay; | |||
| package com.simple.config; | |||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| @Component | |||
| @ConfigurationProperties(prefix = "pay") | |||
| public class PayProperty { | |||
| /** | |||
| @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| @RestController | |||
| @RequestMapping("wxMsgValidationcode") | |||
| @RequestMapping("/api/wxMsgValidationcode") | |||
| @Api(description="短信验证相关接口") | |||
| public class WxMsgValidationcodeController extends BaseController { | |||
| private Logger logger = Logger.getLogger(WxMsgValidationcodeController.class); | |||
| @@ -3,6 +3,7 @@ package com.simple.controller; | |||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||
| import com.simple.annotation.AuthIgnore; | |||
| import com.simple.common.ErrorCode; | |||
| import com.simple.config.PayProperty; | |||
| import com.simple.domain.po.WxAppinfo; | |||
| import com.simple.domain.po.WxCUser; | |||
| import com.simple.enums.EnumPayStatus; | |||
| @@ -39,6 +40,9 @@ public class WxPayOrderController extends BaseController { | |||
| private Logger logger = Logger.getLogger(WxPayOrderController.class); | |||
| @Autowired | |||
| private PayProperty payProperty; | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @@ -66,7 +70,7 @@ public class WxPayOrderController extends BaseController { | |||
| try { | |||
| record.setIp(IPUtil.getIpAddr(request)); | |||
| return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| return wxPayOrderService.createPayOrder(payProperty.isReal(), appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -1,94 +0,0 @@ | |||
| package com.simple.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ErrorCode; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxAppinfo; | |||
| import com.simple.domain.po.WxCUser; | |||
| import com.simple.domain.po.WxMerchantBUser; | |||
| import com.simple.domain.po.WxRefundOrder; | |||
| import com.simple.enums.EnumPayWay; | |||
| import com.simple.exception.MallinkException; | |||
| import com.simple.service.WxRefundOrderService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/refund") | |||
| public class WxRefundOrderController extends BaseController | |||
| { | |||
| private Logger logger = Logger.getLogger(WxRefundOrderController.class); | |||
| @Autowired | |||
| private WxRefundOrderService wxRefundOrderService; | |||
| @ApiOperation(value = "发起退款", notes = "{\"orderId\":,\"string\", \"payOrderId\":\"string\"}") | |||
| @PostMapping("/create") | |||
| public ResultData create(@RequestBody Map<String, String> paramMap) { | |||
| logger.info("/api/refund/create" + paramMap.toString()); | |||
| //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| String payOrderIdStr = paramMap.get("payOrderId"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.error("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(payOrderIdStr)) { | |||
| logger.error("payOrderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payOrderId不能为空"); | |||
| } | |||
| Long orderId = 0L; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error("orderId参数不正确: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||
| } | |||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||
| refundOrder.setPayOrderNo(payOrderIdStr); | |||
| refundOrder.setOrderId(orderId); | |||
| WxCUser cUser = getUser(); | |||
| WxAppinfo appinfo = getAppInfo(cUser.getAppId()); | |||
| try { | |||
| wxRefundOrderService.createRefundOrder(appinfo, refundOrder, EnumPayWay.PAY_WAY_WEAPP); | |||
| return new ResultData(); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR); | |||
| } | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||
| public ResultData list(@ModelAttribute WxRefundOrder wxRefundOrder,Integer pageNum, Integer pageSize) { | |||
| if (null == wxRefundOrder) wxRefundOrder = new WxRefundOrder(); | |||
| final PageInfo<WxRefundOrder> page = wxRefundOrderService.listAsPage(wxRefundOrder, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("根据id查询接口") | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxRefundOrderService.getById(id)); | |||
| } | |||
| } | |||
| @@ -18,7 +18,7 @@ public interface WxPayOrderService { | |||
| * @param payWay | |||
| * @return | |||
| */ | |||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||
| ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||
| /** | |||
| * 异步通知 | |||
| @@ -12,13 +12,14 @@ public interface WxRefundOrderService { | |||
| /** | |||
| * 创建退款订单 | |||
| * @param isReal | |||
| * @param appInfo | |||
| * @param record 退款订单请求 | |||
| * @param payOrder 支付订单 | |||
| * @param payWay | |||
| * @return | |||
| */ | |||
| ResultData createRefundOrder(WxAppinfo appInfo, WxRefundOrder record, WxPayOrder payOrder, EnumPayWay payWay); | |||
| ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, WxRefundOrder record, WxPayOrder payOrder, EnumPayWay payWay); | |||
| /** | |||
| * 退款订单查询 | |||
| @@ -10,7 +10,6 @@ import com.simple.domain.vo.OrderVo; | |||
| import com.simple.enums.*; | |||
| import com.simple.exception.MallinkException; | |||
| import com.simple.mapper.*; | |||
| import com.simple.pay.PayProperty; | |||
| import com.simple.service.WxOrderService; | |||
| import com.simple.utils.RedisLock; | |||
| import org.apache.log4j.Logger; | |||
| @@ -28,7 +27,6 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @Autowired | |||
| WxAppinfoMapper wxAppinfoMapper; | |||
| @@ -17,7 +17,6 @@ import com.simple.enums.EnumPayType; | |||
| import com.simple.enums.EnumPayWay; | |||
| import com.simple.exception.MallinkException; | |||
| import com.simple.mapper.*; | |||
| import com.simple.pay.PayProperty; | |||
| import com.simple.pay.WxPay; | |||
| import com.simple.pay.WxPayOrderP; | |||
| import com.simple.pay.WxPayment; | |||
| @@ -38,8 +37,6 @@ import org.springframework.transaction.annotation.Transactional; | |||
| public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| private Logger logger = Logger.getLogger(getClass()); | |||
| @Autowired | |||
| PayProperty payProperty; | |||
| @Autowired | |||
| WxAppinfoMapper wxAppinfoMapper; | |||
| @@ -76,7 +73,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| "\"NOT_UTF8\":{\"detail\":\"编码格式错误\",\"reason\":\"未使用指定编码格式\",\"resolution\":\"请使用UTF-8编码格式\"}}"); | |||
| @Override | |||
| public ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||
| public ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| try { | |||
| @@ -125,7 +122,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | |||
| if (payProperty.isReal()) { | |||
| if (isReal) { | |||
| // 统一下单 | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||
| @@ -11,16 +11,13 @@ import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.*; | |||
| import com.simple.enums.EnumOrderStatus; | |||
| import com.simple.enums.EnumPayStatus; | |||
| import com.simple.enums.EnumPayWay; | |||
| import com.simple.enums.EnumRefundStatus; | |||
| import com.simple.exception.MallinkException; | |||
| import com.simple.mapper.*; | |||
| import com.simple.pay.PayProperty; | |||
| import com.simple.pay.WxPay; | |||
| import com.simple.pay.WxPayment; | |||
| import com.simple.pay.WxRefundOrderP; | |||
| import com.simple.service.WxCouponVerifyService; | |||
| import com.simple.service.WxOrderService; | |||
| import com.simple.service.WxRefundOrderService; | |||
| import com.simple.utils.BeanUtils; | |||
| @@ -38,9 +35,6 @@ import org.springframework.transaction.annotation.Transactional; | |||
| public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| private Logger logger = Logger.getLogger(getClass()); | |||
| @Autowired | |||
| PayProperty payProperty; | |||
| @Autowired | |||
| WxAppinfoMapper wxAppinfoMapper; | |||
| @@ -219,7 +213,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| "}"); | |||
| @Override | |||
| public ResultData createRefundOrder(WxAppinfo appInfo, WxRefundOrder record, WxPayOrder payOrder, EnumPayWay payWay) { | |||
| public ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, WxRefundOrder record, WxPayOrder payOrder, EnumPayWay payWay) { | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | |||
| if (StringUtils.isBlank(payAccount.getApiKey())) { | |||
| logger.error("支付密钥为空"); | |||
| @@ -276,7 +270,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| wxRefundOrderP.setTotal_fee(record.getTotalFee()); | |||
| wxRefundOrderP.setRefund_fee(record.getRefundFee()); | |||
| if (payProperty.isReal()) { | |||
| if (isReal) { | |||
| Map signMap = new HashMap(); | |||
| try { | |||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||