| @@ -1,14 +1,20 @@ | |||||
| package com.simple.config; | package com.simple.config; | ||||
| import com.alibaba.fastjson.serializer.SerializeConfig; | |||||
| import com.alibaba.fastjson.serializer.ToStringSerializer; | |||||
| import com.alibaba.fastjson.support.config.FastJsonConfig; | |||||
| import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | import com.simple.interceptor.AuthorizationInterceptor; | ||||
| import com.simple.resolver.LoginUserHandlerMethodArgumentResolver; | import com.simple.resolver.LoginUserHandlerMethodArgumentResolver; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.http.converter.HttpMessageConverter; | |||||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||||
| import java.math.BigInteger; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| @@ -44,4 +50,19 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { | |||||
| //registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/"); | //registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/"); | ||||
| } | } | ||||
| @Override | |||||
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | |||||
| FastJsonHttpMessageConverter fastConverter = | |||||
| new FastJsonHttpMessageConverter(); | |||||
| FastJsonConfig fastJsonConfig = new FastJsonConfig(); | |||||
| SerializeConfig serializeConfig = SerializeConfig.globalInstance; | |||||
| serializeConfig.put(BigInteger.class, ToStringSerializer.instance); | |||||
| serializeConfig.put(Long.class, ToStringSerializer.instance); | |||||
| serializeConfig.put(Long.TYPE, ToStringSerializer.instance); | |||||
| fastJsonConfig.setSerializeConfig(serializeConfig); | |||||
| fastConverter.setFastJsonConfig(fastJsonConfig); | |||||
| converters.add(fastConverter); | |||||
| } | |||||
| } | } | ||||
| @@ -88,4 +88,17 @@ public class BaseController { | |||||
| service.setWxMaConfig(config); | service.setWxMaConfig(config); | ||||
| return service; | return service; | ||||
| } | } | ||||
| public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { | |||||
| WxMaInMemoryConfig config = new WxMaInMemoryConfig(); | |||||
| config.setAppid(appinfo.getAppId()); | |||||
| config.setSecret(appinfo.getSecret()); | |||||
| config.setToken(appinfo.getToken()); | |||||
| config.setAesKey(appinfo.getAesKey()); | |||||
| config.setMsgDataFormat(appinfo.getMsgDataFormat()); | |||||
| WxMaService service = new WxMaServiceImpl(); | |||||
| service.setWxMaConfig(config); | |||||
| return service; | |||||
| } | |||||
| } | } | ||||
| @@ -19,11 +19,11 @@ import io.swagger.annotations.ApiOperation; | |||||
| @RequestMapping("wxCoupon") | @RequestMapping("wxCoupon") | ||||
| public class WxCouponController extends BaseController | public class WxCouponController extends BaseController | ||||
| { | { | ||||
| private Logger logger = Logger.getLogger(WxCouponController.class); | |||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | private WxCouponService wxCouponService; | ||||
| private Logger logger = Logger.getLogger(WxCouponController.class); | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("wxCouponOrder") | |||||
| @RequestMapping("/api/couponOrder") | |||||
| @Api(description="核销和用户卡券查询接口") | @Api(description="核销和用户卡券查询接口") | ||||
| public class WxCouponOrderController extends BaseController | public class WxCouponOrderController extends BaseController | ||||
| { | { | ||||
| @@ -88,7 +88,16 @@ public class WxCouponOrderController extends BaseController | |||||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | logger.error("couponOrderId参数不正确: " + paramMap.toString()); | ||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId参数不正确"); | return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId参数不正确"); | ||||
| } | } | ||||
| return wxCouponOrderService.verify(couponOrderId, getUser().getId()); | |||||
| try { | |||||
| ResultData rd = wxCouponOrderService.verify(couponOrderId, getUser().getId()); | |||||
| return rd; | |||||
| } 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.VERIFY_ERROR, e.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @ApiOperation(value = "退券接口", notes = "{\"couponOrderId\":\"string\"}") | @ApiOperation(value = "退券接口", notes = "{\"couponOrderId\":\"string\"}") | ||||
| @@ -104,10 +113,18 @@ public class WxCouponOrderController extends BaseController | |||||
| try { | try { | ||||
| couponOrderId = Long.valueOf(couponOrderIdStr); | couponOrderId = Long.valueOf(couponOrderIdStr); | ||||
| } catch (NumberFormatException e) { | } catch (NumberFormatException e) { | ||||
| couponOrderId = 0L; | |||||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | logger.error("couponOrderId参数不正确: " + paramMap.toString()); | ||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId参数不正确"); | return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId参数不正确"); | ||||
| } | } | ||||
| return wxCouponOrderService.refund(couponOrderId, getUser().getId()); | |||||
| try { | |||||
| ResultData rd = wxCouponOrderService.refund(couponOrderId, getUser().getId()); | |||||
| return rd; | |||||
| } 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, e.getMessage()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -108,6 +108,13 @@ public enum ErrorCode{ | |||||
| APP_ID_NOT_FOUND(12020, "APPID没找到"), | APP_ID_NOT_FOUND(12020, "APPID没找到"), | ||||
| MCH_INFO_NOT_FOUND(12021, "商户信息没找到"), | MCH_INFO_NOT_FOUND(12021, "商户信息没找到"), | ||||
| MCH_INFO_NOT_EQUAL(12022, "商户信息不对应"), | MCH_INFO_NOT_EQUAL(12022, "商户信息不对应"), | ||||
| API_KEY_NOT_FOUND(12023, "支付密钥未配置"), | |||||
| CERT_PATH_NOT_FOUND(12024, "双向证书未配置"), | |||||
| /** | |||||
| * 核销 | |||||
| */ | |||||
| VERIFY_ERROR(12050, "核销异常") | |||||
| ; | ; | ||||
| @@ -103,7 +103,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| } | } | ||||
| if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode())) { | if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode())) { | ||||
| logger.error("已经核销过的券: couponOrder-" + couponOrderId); | logger.error("已经核销过的券: couponOrder-" + couponOrderId); | ||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_USED); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); | |||||
| } | } | ||||
| try { | try { | ||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | ||||
| @@ -23,6 +23,7 @@ import com.simple.service.WxRefundOrderService; | |||||
| import com.simple.utils.BeanUtils; | import com.simple.utils.BeanUtils; | ||||
| import com.simple.utils.Utility; | import com.simple.utils.Utility; | ||||
| import com.simple.utils.XmlUtil; | import com.simple.utils.XmlUtil; | ||||
| import org.apache.commons.lang.StringUtils; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| @@ -210,6 +211,15 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| @Override | @Override | ||||
| public ResultData createRefundOrder(WxAppinfo appInfo, WxRefundOrder record, EnumPayWay payWay) { | public ResultData createRefundOrder(WxAppinfo appInfo, WxRefundOrder record, EnumPayWay payWay) { | ||||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | |||||
| if (StringUtils.isBlank(payAccount.getApiKey())) { | |||||
| logger.error("支付密钥为空"); | |||||
| throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND.getCode(), "支付密钥为空,请联系商城管理员"); | |||||
| } | |||||
| if (StringUtils.isBlank(payAccount.getCertPath())) { | |||||
| logger.error("证书路径为空"); | |||||
| throw new MallinkException(ErrorCode.CERT_PATH_NOT_FOUND.getCode(), "证书路径为空,请联系商城管理员"); | |||||
| } | |||||
| // check 是否有退款订单 | // check 是否有退款订单 | ||||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(record); | List<WxRefundOrder> list = wxRefundOrderMapper.findList(record); | ||||
| if (list.size() > 0) { | if (list.size() > 0) { | ||||
| @@ -246,8 +256,6 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| throw new MallinkException(ErrorCode.REFUND_PAY_ORDER_IS_ZERO); | throw new MallinkException(ErrorCode.REFUND_PAY_ORDER_IS_ZERO); | ||||
| } | } | ||||
| // TODO check 可退券???? | |||||
| // 创建退款订单 | // 创建退款订单 | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| Long id = idWorker.nextId(); | Long id = idWorker.nextId(); | ||||
| @@ -274,8 +282,6 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | throw new MallinkException(ErrorCode.DB_FAIL); | ||||
| } | } | ||||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | |||||
| // 退款申请 | // 退款申请 | ||||
| String noncestr = Utility.generate32UUID(); | String noncestr = Utility.generate32UUID(); | ||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | ||||