Conflicts: mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.javarelease_toaliyun_real
| @@ -7,6 +7,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxMerchantMapper; | |||
| @@ -56,7 +57,7 @@ public class WxAppinfoController extends BaseController { | |||
| @Override | |||
| public void run() { | |||
| String param = merchant.getWeappScene(); | |||
| ResultData resultData = qrCodeService.uploadQrcode(merchant, 1, pageUrl, param, 0, "", "", "店铺详情"); | |||
| ResultData resultData = qrCodeService.uploadQrcode(merchant, 1, pageUrl, param, 0, "", "", "店铺详情",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String, String> map = (Map) resultData.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -82,7 +83,9 @@ public class WxAppinfoController extends BaseController { | |||
| @Override | |||
| public void run() { | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultData = qrCodeService.uploadQrcode(couponChannel,1,pageUrl,param,0,"","","券"); | |||
| //暂时只有微信二维码,有别的码,需要加字段 | |||
| ResultData resultData = qrCodeService.uploadQrcode(couponChannel,1,pageUrl,param,0,"","","券",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultData.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -125,7 +128,7 @@ public class WxAppinfoController extends BaseController { | |||
| qrCodeService.exportQrcode(request, response, | |||
| getTenantInfo(), type, pageUrl, sceneParam, | |||
| withText, text1, text2, | |||
| name); | |||
| name,EnumPayWay.PAY_WAY_WECHAT); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(Result.ERROR, "下载异常"); | |||
| @@ -12,6 +12,7 @@ import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.domain.vo.WxMerchantTradeDetailVo; | |||
| import com.iformall.domain.vo.WxMerchantTradeVo; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.QrCodeService; | |||
| import com.iformall.service.WxMerchantService; | |||
| import com.iformall.utils.Constant; | |||
| @@ -145,7 +146,9 @@ public class WxMerchantController extends BaseController { | |||
| //加载二维码图片 | |||
| String pageUrl = Constant.mainPageUrl; | |||
| String param = "t:md:"+resultData.data; | |||
| ResultData resultQrCode = qrCodeService.uploadQrcode(wxMerchant,1,pageUrl,param,0,"","","店铺详情"); | |||
| //这里暂时只有微信二维码,后续有别的二维码,再加字段 | |||
| ResultData resultQrCode = qrCodeService.uploadQrcode(wxMerchant,1,pageUrl,param,0,"","","店铺详情",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultQrCode.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -156,7 +159,8 @@ public class WxMerchantController extends BaseController { | |||
| return resultData; | |||
| } | |||
| @ApiOperation("更新商户接口") | |||
| @PostMapping("updateMerchant") | |||
| @SystemControllerLog(description = "商户-更新") | |||
| @@ -172,7 +176,7 @@ public class WxMerchantController extends BaseController { | |||
| public ResultData updateMerchantAccount(@RequestBody WxMerchant wxMerchant) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantAccount"); | |||
| wxMerchant.updateTenantInfo(getTenantInfo()); | |||
| return wxMerchantService.updateMerchantAccount(wxMerchant); | |||
| return wxMerchantService.updateMerchantAccount(wxMerchant,EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| @ApiOperation("更新管理员接口") | |||
| @@ -10,6 +10,7 @@ import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.dto.WxCouponChannelDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| @@ -82,7 +83,9 @@ public class WxCouponChannelController extends BaseController { | |||
| if(couponChannel!=null){ | |||
| String pageUrl = Constant.mainPageUrl; | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(couponChannel,1,pageUrl,param,0,"","","券"); | |||
| //此处只有微信二维码,别的二维码需要加字段 | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(couponChannel,1,pageUrl,param,0,"","","券",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultDataQ.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -6,9 +6,11 @@ import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.vo.WxCouponOrderBVo; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| @@ -93,8 +95,15 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(couponOrderId); | |||
| if (wxCouponOrder == null) { | |||
| logger.error("券ID不存在:" + couponOrderId); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| WxAppinfo appinfoQ = new WxAppinfo(); | |||
| appinfoQ.updateTenantInfo(getTenantInfo()); | |||
| appinfoQ.setPlat(EnumPayWay.getEnum(wxCouponOrder.getPayVendor()).getPlat().getCode()); | |||
| appinfoQ.setType(EnumAppType.B.getCode()); | |||
| PageInfo<WxAppinfo> appinfoPageInfo = wxAppinfoService.listAsPage(appinfoQ, 1, 1); | |||
| if (appinfoPageInfo.getList().size() > 0) { | |||
| @@ -10,6 +10,7 @@ import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||
| import com.iformall.enums.EnumCouponStatus; | |||
| import com.iformall.enums.EnumCouponValidType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.PushLimitService; | |||
| import com.iformall.service.WxCouponPasswordService; | |||
| @@ -127,7 +128,8 @@ public class WxCouponPresentController extends BaseController { | |||
| } | |||
| wxCouponPresent.setCouponName(wxCoupon.getTitle()); | |||
| wxCouponPresentService.add(wxCouponPresent, list, phoneSet); | |||
| //只需要给一端发就可以了。默认给微信小程序发 | |||
| wxCouponPresentService.add(wxCouponPresent, list, phoneSet,EnumPayWay.PAY_WAY_WECHAT); | |||
| return new ResultData(); | |||
| } | |||
| @@ -30,6 +30,16 @@ ADD COLUMN `pay_vendor` SMALLINT(3) NOT NULL DEFAULT 1 COMMENT '订单渠道,Enu | |||
| UPDATE wx_coupon_order o INNER JOIN wx_pay_order po ON po.order_id = o.`id` SET o.pay_vendor = po.pay_vendor; | |||
| ---刷新完之后把DEFAULT 1 去掉 | |||
| ALTER TABLE `wx_card_spend` | |||
| ADD COLUMN `remark` VARCHAR(30) DEFAULT NULL COMMENT '备注'; | |||
| ALTER TABLE `wx_appinfo` | |||
| ADD COLUMN `plat` SMALLINT(3) NOT NULL DEFAULT 1 COMMENT 'app平台 1:微信 2:阿里 3:头条'; | |||
| ALTER TABLE `wx_profit_sharing_receiver` | |||
| ADD COLUMN `plat` SMALLINT(3) NOT NULL DEFAULT 1 COMMENT '平台 1:微信 2:阿里 3:头条'; | |||
| @@ -4,6 +4,7 @@ import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumMsgSend; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxMerchantService; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| @@ -72,7 +73,7 @@ public class WxMerchantController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "账号名称不能为空"); | |||
| } | |||
| wxMerchant.updateTenantInfo(getTenantInfo()); | |||
| return wxMerchantService.updateMerchantAccount(wxMerchant); | |||
| return wxMerchantService.updateMerchantAccount(wxMerchant,EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| @ApiOperation("删除分账账户") | |||
| @@ -11,6 +11,7 @@ import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.enums.EnumCampaignStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.WxCampaignService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import io.swagger.annotations.Api; | |||
| @@ -78,7 +79,7 @@ public class WxCampaignController extends BaseController { | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "sourceId", value = "", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "targetId", value = "", dataType = "Long", paramType = "query", required = true)}) | |||
| public ResultData move(Long sourceId, Long targetId) { | |||
| public ResultData move(Long sourceId, Long targetId,EnumPayWay payWay) { | |||
| WxCampaign source = wxCampaignService.getById(sourceId); | |||
| WxCampaign target = wxCampaignService.getById(targetId); | |||
| if (source == null || target == null) { | |||
| @@ -120,6 +120,7 @@ public class CouponOrderExpiringSchedule { | |||
| WxAppinfo appinfo = new WxAppinfo(); | |||
| appinfo.updateTenantInfo(co); | |||
| //appinfo.setType(EnumAppType.B.getCode()); | |||
| appinfo.setPlat(EnumPayWay.getEnum(co.getPayVendor()).getPlat().getCode()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| @@ -18,10 +18,12 @@ import org.springframework.transaction.annotation.Transactional; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.EnumOrderType; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumRefundStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxAppinfoService; | |||
| @@ -82,6 +84,14 @@ public class OrderExpiringSchedule { | |||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void orderExpireSchedule() { | |||
| for (EnumPayWay payWay: EnumPayWay.values()) { | |||
| if(null != payWay.getPlat()) { | |||
| orderExpireSchedule(payWay); | |||
| } | |||
| } | |||
| } | |||
| private void orderExpireSchedule(EnumPayWay payWay) { | |||
| Map dateMap = new HashMap(); | |||
| Date curDate = new Date(); | |||
| @@ -96,7 +106,7 @@ public class OrderExpiringSchedule { | |||
| List<WxOrder> orderCoupons = wxOrderMapper.findListOfUnpaidOrderByDate(dateMap); | |||
| orderCoupons.stream().forEach( o -> { | |||
| try { | |||
| proxy.orderExpired(o,true); | |||
| proxy.orderExpired(o,true,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("券过期失败" + e.getMessage()); | |||
| } | |||
| @@ -110,7 +120,7 @@ public class OrderExpiringSchedule { | |||
| List<WxOrder> orderPresss = wxOrderMapper.findListOfCompleteUnPaidPressOrderByDate(dateMap); | |||
| orderPresss.stream().forEach( o -> { | |||
| try { | |||
| proxy.orderPressExpired(o, true,true); | |||
| proxy.orderPressExpired(o, true,true,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("砍价券支付过期失败" + e.getMessage()); | |||
| } | |||
| @@ -121,7 +131,7 @@ public class OrderExpiringSchedule { | |||
| orderPresss = wxOrderMapper.findListOfUnpaidPressOrderByDate(dateMap); | |||
| orderPresss.stream().forEach( o -> { | |||
| try { | |||
| proxy.orderPressExpired(o, false,true); | |||
| proxy.orderPressExpired(o, false,true,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("砍价券过期失败" +e.getMessage()); | |||
| } | |||
| @@ -133,7 +143,7 @@ public class OrderExpiringSchedule { | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode()); | |||
| wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { | |||
| try { | |||
| proxy.orderGroupExpired((WxOrder) o,true,true); | |||
| proxy.orderGroupExpired((WxOrder) o,true,true,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("拼团取消失败" + e.getMessage()); | |||
| } | |||
| @@ -145,7 +155,7 @@ public class OrderExpiringSchedule { | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_OVERTIME.getCode()); | |||
| wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { | |||
| try { | |||
| proxy.expiredAndReturnMoney((WxOrder) o,false); | |||
| proxy.expiredAndReturnMoney((WxOrder) o,false,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("拼团过期退款失败" + e.getMessage()); | |||
| } | |||
| @@ -156,8 +166,7 @@ public class OrderExpiringSchedule { | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); | |||
| wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { | |||
| try { | |||
| proxy.orderGroupBreak((WxOrder) o); | |||
| proxy.returnMoney((WxOrder) o); | |||
| proxy.returnMoney((WxOrder) o,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("拼团券下架退款失败" + e.getMessage()); | |||
| } | |||
| @@ -167,7 +176,7 @@ public class OrderExpiringSchedule { | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); | |||
| wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { | |||
| try { | |||
| proxy.expiredAndReturnMoney((WxOrder) o,true); | |||
| proxy.expiredAndReturnMoney((WxOrder) o,true,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("参团失败退款失败" + e.getMessage()); | |||
| } | |||
| @@ -177,7 +186,7 @@ public class OrderExpiringSchedule { | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_SCHEDU_REFUND.getCode()); | |||
| wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { | |||
| try { | |||
| proxy.expiredAndReturnMoney((WxOrder) o,false); | |||
| proxy.expiredAndReturnMoney((WxOrder) o,false,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("参团失败退款失败" + e.getMessage()); | |||
| } | |||
| @@ -186,13 +195,13 @@ public class OrderExpiringSchedule { | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void expiredAndReturnMoney(WxOrder wxOrder,boolean checkRealPay) throws MallinkException, Exception { | |||
| orderGroupExpired(wxOrder,checkRealPay,false); | |||
| returnMoney(wxOrder); | |||
| public void expiredAndReturnMoney(WxOrder wxOrder,boolean checkRealPay,EnumPayWay payWay) throws MallinkException, Exception { | |||
| orderGroupExpired(wxOrder,checkRealPay,false,payWay); | |||
| returnMoney(wxOrder,payWay); | |||
| } | |||
| public boolean wxPaySuccess(WxOrder order,boolean autoReHandle) throws MallinkException, Exception { | |||
| public boolean wxPaySuccess(WxOrder order,boolean autoReHandle,EnumPayWay payWay) throws MallinkException, Exception { | |||
| WxPayOrder payOrderq = new WxPayOrder(); | |||
| payOrderq.setOrderId(order.getId()); | |||
| List<WxPayOrder> payorderlist = wxPayOrderMapper.findList(payOrderq); | |||
| @@ -208,15 +217,16 @@ public class OrderExpiringSchedule { | |||
| if (null == user) { | |||
| return true; | |||
| } | |||
| WxCUser cuUser = new WxCUser(); | |||
| cuUser.updateTenantInfo(order); | |||
| cuUser.setUserId(user.getId()); | |||
| WxCUser cUser = wxCUserMapper.selectOne(new QueryWrapper(cuUser)); | |||
| //找不到用户,问题单,不能删 | |||
| if (null == cUser) { | |||
| return true; | |||
| } | |||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(cUser.getAppId()); | |||
| // WxCUser cuUser = new WxCUser(); | |||
| // cuUser.updateTenantInfo(order); | |||
| // cuUser.setUserId(user.getId()); | |||
| // WxCUser cUser = wxCUserMapper.selectOne(new QueryWrapper(cuUser)); | |||
| // //找不到用户,问题单,不能删 | |||
| // if (null == cUser) { | |||
| // return true; | |||
| // } | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(order, payWay); | |||
| //WxAppinfo appInfo = wxAppinfoService.getByAppId(cUser.getAppId()); | |||
| //找不到appInfo,问题单,不能删 | |||
| if(appInfo == null) { | |||
| return true; | |||
| @@ -241,9 +251,9 @@ public class OrderExpiringSchedule { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderExpired(WxOrder order,boolean checkRealPay) throws MallinkException, Exception { | |||
| public void orderExpired(WxOrder order,boolean checkRealPay,EnumPayWay payWay) throws MallinkException, Exception { | |||
| if (checkRealPay) { | |||
| if (wxPaySuccess(order,true)) { | |||
| if (wxPaySuccess(order,true,payWay)) { | |||
| return; | |||
| } | |||
| } | |||
| @@ -251,7 +261,7 @@ public class OrderExpiringSchedule { | |||
| wxOrderService.stockBack(order); | |||
| // 微信 关单 | |||
| wxOrderService.orderClose(order); | |||
| wxOrderService.orderClose(order,payWay); | |||
| // 订单状态更改 | |||
| WxOrder updateOrder = new WxOrder(); | |||
| @@ -264,9 +274,9 @@ public class OrderExpiringSchedule { | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderPressExpired(WxOrder order, boolean payExpired,boolean checkRealPay) throws MallinkException, Exception { | |||
| public void orderPressExpired(WxOrder order, boolean payExpired,boolean checkRealPay,EnumPayWay payWay) throws MallinkException, Exception { | |||
| if (checkRealPay) { | |||
| if (wxPaySuccess(order,true)) { | |||
| if (wxPaySuccess(order,true,payWay)) { | |||
| return; | |||
| } | |||
| } | |||
| @@ -290,9 +300,9 @@ public class OrderExpiringSchedule { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderGroupExpired(WxOrder order,boolean checkRealPay,boolean stockBack) throws MallinkException, Exception { | |||
| public void orderGroupExpired(WxOrder order,boolean checkRealPay,boolean stockBack,EnumPayWay payWay) throws MallinkException, Exception { | |||
| if (checkRealPay) { | |||
| if (wxPaySuccess(order,true)) { | |||
| if (wxPaySuccess(order,true,payWay)) { | |||
| return; | |||
| } | |||
| } | |||
| @@ -309,20 +319,9 @@ public class OrderExpiringSchedule { | |||
| wxOrderService.stockBack(order); | |||
| } | |||
| // 微信 关单 | |||
| wxOrderService.orderClose(updateOrder); | |||
| wxOrderService.orderClose(updateOrder,payWay); | |||
| logger.info("拼团订单: " + order.getId() + " create at " + order.getCreateDate() + " expired at " + curDate); | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderGroupBreak(WxOrder order) { | |||
| Date curDate = new Date(); | |||
| WxOrder updateOrder = new WxOrder(); | |||
| updateOrder.setId(order.getId()); | |||
| updateOrder.updateTenantInfo(order); | |||
| updateOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_BREAK.getCode()); | |||
| updateOrder.setUpdateDate(curDate); | |||
| wxOrderMapper.updateById(updateOrder); | |||
| } | |||
| /** | |||
| * 回调会再次扣减库存 | |||
| @@ -331,14 +330,37 @@ public class OrderExpiringSchedule { | |||
| * @throws MallinkException | |||
| */ | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void returnMoney(WxOrder order) throws MallinkException, Exception { | |||
| public void returnMoney(WxOrder order,EnumPayWay payWay) throws MallinkException, Exception { | |||
| //支付成功的才退款 | |||
| if (!wxPaySuccess(order,false)) { | |||
| if (!wxPaySuccess(order,false,payWay)) { | |||
| return; | |||
| } | |||
| // 查找支付订单 | |||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||
| payOrderQ.updateTenantInfo(order); | |||
| payOrderQ.setCUserId(order.getCUserId()); | |||
| payOrderQ.setOrderId(order.getId()); | |||
| payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| WxPayOrder payOrder = null; | |||
| List<WxPayOrder> list = wxPayOrderMapper.findList(payOrderQ); | |||
| if (list.size() > 0) { | |||
| if (list.size() > 1) { | |||
| logger.error("TODO: payOrder成功记录应该只有一条????!!!"); | |||
| } | |||
| logger.warn(""); | |||
| payOrder = list.get(0); | |||
| } | |||
| if (payOrder == null) { | |||
| logger.error("支付订单不存在(payOrder不存在)"); | |||
| return ; | |||
| } | |||
| //获取APP信息 | |||
| WxAppinfo appinfo = new WxAppinfo(); | |||
| appinfo.updateTenantInfo(order); | |||
| appinfo.setPlat(EnumPayWay.getEnum(payOrder.getPayVendor()).getPlat().getCode()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| Date limitDate = DateUtils.getTimeAfterDays(360, order.getCreateDate()); | |||
| @@ -22,6 +22,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxUserVisit; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxUserVisitService; | |||
| @@ -44,5 +44,7 @@ public class WxAppinfo extends BaseTenantEntity { | |||
| private Integer groupSupport; | |||
| @io.swagger.annotations.ApiModelProperty(value="是否启用(0:启用,1禁用)",name="enable") | |||
| private Integer enable; | |||
| @io.swagger.annotations.ApiModelProperty(value="app平台 EnumAppPlat ",name="plat") | |||
| private Integer plat; | |||
| } | |||
| @@ -39,6 +39,8 @@ public class WxProfitSharingReceiver extends TenantEntity { | |||
| private Integer status; | |||
| @io.swagger.annotations.ApiModelProperty(value="分账参数,目前为分账比例(单位为万分之一)",name="parameter") | |||
| private String parameter; | |||
| @io.swagger.annotations.ApiModelProperty(value="平台 EnumAppPlat",name="plat") | |||
| private Integer plat; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="分账金额(分)",name="sharingAmount") | |||
| @@ -0,0 +1,29 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * app平台 | |||
| * @author alascor | |||
| */ | |||
| public enum EnumAppPlat { | |||
| WX(1,"微信"),ALI(2,"阿里"),TOUTIAO(3,"头条"); | |||
| EnumAppPlat(Integer code,String name) { | |||
| this.code = code; | |||
| this.name = name; | |||
| } | |||
| private Integer code; | |||
| private String name; | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public void setCode(Integer code) { | |||
| this.code = code; | |||
| } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| } | |||
| @@ -7,7 +7,7 @@ public enum EnumCardSpendFrom { | |||
| // 0:C端小程序扫一扫, 1:POS支付 | |||
| C(0, "小程序支付"), | |||
| C(0, "微信小程序支付"), | |||
| POS(1, "POS支付") | |||
| ; | |||
| @@ -19,6 +19,15 @@ public enum EnumCardSpendFrom { | |||
| } | |||
| return null; | |||
| } | |||
| public static EnumPayWay getPayWay(Integer code) { | |||
| for (EnumPayWay payWay:EnumPayWay.values()) { | |||
| if (null != payWay.getCardSpendFrom() && payWay.getCardSpendFrom().getCode().intValue() == code.intValue() ) { | |||
| return payWay; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| @@ -5,22 +5,22 @@ package com.iformall.enums; | |||
| */ | |||
| public enum EnumPayWay { | |||
| PAY_WAY_WECHAT(1, "微信小程序支付",EnumPayWayType.WX_MINIPAY), | |||
| PAY_WAY_WECHAT_MA(12, "微信小程序B端扫码支付",EnumPayWayType.WX_MINIPAY), | |||
| PAY_WAY_WECHAT_WAP(2, "微信H5",EnumPayWayType.WX_H5PAY), | |||
| PAY_WAY_ALIPAY(3, "支付宝",EnumPayWayType.ALI_MINIPAY), | |||
| PAY_WAY_ALIPAY_WAP(4, "支付宝H5",EnumPayWayType.ALI_H5PAY), | |||
| PAY_WAY_POS_B(10, "POS B端",EnumPayWayType.POS), | |||
| PAY_WAY_POS_NEU(11, "POS 东软",EnumPayWayType.NEU_POS), | |||
| PAY_WAY_NOT_UNPAY_MERCHANT(91, "商户注券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_VERRIFY(92, "核销发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_B_MA(93, "B端扫码支付发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_CAR_STOP(94, "停车发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_SYSTEM_SEND(95, "系统定时发放券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_BATCH_SEND(96, "后台批量发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_TRADE(97, "交易发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_PASSWD(98, "根据卡密兑换卡,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_CREDIT(99, "积分兑换券,无需支付",null) | |||
| PAY_WAY_WECHAT(1, "微信小程序支付",EnumPayWayType.WX_MINIPAY,EnumAppPlat.WX,EnumCardSpendFrom.C), | |||
| PAY_WAY_WECHAT_MA(12, "微信小程序B端扫码支付",EnumPayWayType.WX_MINIPAY,EnumAppPlat.WX,null), | |||
| PAY_WAY_WECHAT_WAP(2, "微信H5",EnumPayWayType.WX_H5PAY,EnumAppPlat.WX,null), | |||
| PAY_WAY_ALIPAY(3, "支付宝",EnumPayWayType.ALI_MINIPAY,EnumAppPlat.ALI,null), | |||
| PAY_WAY_ALIPAY_WAP(4, "支付宝H5",EnumPayWayType.ALI_H5PAY,EnumAppPlat.ALI,null), | |||
| PAY_WAY_POS_B(10, "POS B端",EnumPayWayType.POS,null,null), | |||
| PAY_WAY_POS_NEU(11, "POS 东软",EnumPayWayType.NEU_POS,null,EnumCardSpendFrom.POS), | |||
| PAY_WAY_NOT_UNPAY_MERCHANT(91, "商户注券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_VERRIFY(92, "核销发券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_B_MA(93, "B端扫码支付发券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_CAR_STOP(94, "停车发券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_SYSTEM_SEND(95, "系统定时发放券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_BATCH_SEND(96, "后台批量发券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_TRADE(97, "交易发券,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_PASSWD(98, "根据卡密兑换卡,无需支付",null,null,null), | |||
| PAY_WAY_NOT_UNPAY_CREDIT(99, "积分兑换券,无需支付",null,null,null) | |||
| ; | |||
| public static EnumPayWay getEnum(Integer code) { | |||
| @@ -32,14 +32,19 @@ public enum EnumPayWay { | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| private EnumPayWayType type; | |||
| private EnumAppPlat plat; | |||
| private EnumCardSpendFrom cardSpendFrom; | |||
| EnumPayWay(Integer code, String message,EnumPayWayType type) { | |||
| EnumPayWay(Integer code, String message,EnumPayWayType type,EnumAppPlat plat,EnumCardSpendFrom cardSpendFrom) { | |||
| this.code = code; | |||
| this.message = message; | |||
| this.type = type; | |||
| this.plat = plat; | |||
| this.cardSpendFrom = cardSpendFrom; | |||
| } | |||
| public Integer getCode() { | |||
| @@ -54,6 +59,16 @@ public enum EnumPayWay { | |||
| return type; | |||
| } | |||
| public EnumAppPlat getPlat() { | |||
| return plat; | |||
| } | |||
| public EnumCardSpendFrom getCardSpendFrom() { | |||
| return cardSpendFrom; | |||
| } | |||
| public static enum EnumPayWayType { | |||
| WX_MINIPAY,WX_H5PAY,ALI_MINIPAY,ALI_H5PAY,NEU_POS,POS | |||
| @@ -3,6 +3,7 @@ package com.iformall.service; | |||
| import com.amazonaws.services.s3.model.ObjectMetadata; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| @@ -14,14 +15,14 @@ import java.util.Map; | |||
| @Service | |||
| public interface QrCodeService { | |||
| void downQrCode(TenantEntity tenantEntity, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params) throws MallinkException; | |||
| void downQrCode(TenantEntity tenantEntity, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params,EnumPayWay payWay) throws MallinkException; | |||
| ResultData exportQrcode(HttpServletRequest request, HttpServletResponse response, | |||
| TenantEntity tenantEntity, int type, String pageUrl, String sceneParam, | |||
| int withText, String text1, String text2, | |||
| String name); | |||
| String name,EnumPayWay payWay); | |||
| ResultData uploadQrcode(TenantEntity tenantEntity, int type, String pageUrl, String sceneParam, | |||
| int withText, String text1, String text2, | |||
| String name); | |||
| String name,EnumPayWay payWay); | |||
| ResultData awsUpload(InputStream inputStream, ObjectMetadata metadata, String fileName, TenantEntity tenantEntity); | |||
| } | |||
| @@ -3,6 +3,7 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxActivity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxProjectConfig; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -60,7 +61,7 @@ public interface WxAppinfoService { | |||
| * 获取c端小程序信息 | |||
| * @return | |||
| */ | |||
| WxAppinfo getCAppInfo(TenantEntity tenantEntity); | |||
| WxAppinfo getCAppInfo(TenantEntity tenantEntity,EnumPayWay payWay); | |||
| /** | |||
| * 保存或更新实体 | |||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCampaign; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -6,6 +6,7 @@ import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponPassword; | |||
| import com.iformall.domain.po.WxCouponPresent; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| @@ -18,6 +19,6 @@ public interface WxCouponPresentService { | |||
| WxCouponPresent findById(Long id); | |||
| ResultData add(WxCouponPresent wxCouponPresent, List<WxCouponPassword> list, Set<String> phoneSet); | |||
| ResultData add(WxCouponPresent wxCouponPresent, List<WxCouponPassword> list, Set<String> phoneSet,EnumPayWay payWay); | |||
| } | |||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.domain.po.WxGameActionLog; | |||
| import com.iformall.enums.EnumPayWay; | |||
| public interface WxGameService { | |||
| @@ -10,6 +10,8 @@ import com.iformall.domain.vo.WxMerchantSimpleVo; | |||
| import com.iformall.domain.vo.WxMerchantTradeDetailVo; | |||
| import com.iformall.domain.vo.WxMerchantTradeVo; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| @@ -115,7 +117,7 @@ public interface WxMerchantService { | |||
| ResultData updateMerchant(WxMerchant wxMerchant); | |||
| ResultData updateMerchantAccount(WxMerchant wxMerchant); | |||
| ResultData updateMerchantAccount(WxMerchant wxMerchant,EnumPayWay payWay); | |||
| ResultData updateMerchantAdmin(WxMerchant wxMerchant); | |||
| @@ -112,7 +112,7 @@ public interface WxOrderService { | |||
| /** | |||
| * 订单关单 | |||
| */ | |||
| ResultData orderClose(WxOrder order); | |||
| ResultData orderClose(WxOrder order,EnumPayWay payWay); | |||
| /** | |||
| * 根据Id获得实体 | |||
| @@ -5,6 +5,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import java.util.List; | |||
| @@ -44,11 +45,11 @@ public interface WxProfitSharingReceiverService { | |||
| WxProfitSharingReceiver findReceiver(WxMerchant merchant); | |||
| ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List<WxProfitSharingReceiver> delList); | |||
| ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List<WxProfitSharingReceiver> delList,EnumPayWay payWay); | |||
| ResultData delReceiver(WxProfitSharingReceiver receiver, Integer send); | |||
| ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver); | |||
| ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver,EnumPayWay payWay); | |||
| void sendMsg(String phone, String account, String merchant, String time, Integer modelType, TenantEntity tenantEntity); | |||
| @@ -3,6 +3,7 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxTopic; | |||
| import com.iformall.enums.EnumPayWay; | |||
| public interface WxTopicService { | |||
| @@ -18,11 +18,13 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.config.AwsProperty; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.service.QrCodeService; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.wechat.FmOpenService; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.QRCodeUtils; | |||
| @@ -47,8 +49,6 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| @Autowired | |||
| private WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| private FmOpenService openService; | |||
| @Autowired | |||
| private boolean isFmOpen; | |||
| @Autowired | |||
| private AwsProperty awsProperty; | |||
| @@ -56,6 +56,8 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| private MallResourceService mallResourceService; | |||
| @Autowired | |||
| private String fmUploadDir; | |||
| @Autowired | |||
| private PayServiceFactory payServiceFactory; | |||
| private AmazonS3 s3 = null; | |||
| @@ -126,7 +128,7 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| } | |||
| @Override | |||
| public void downQrCode(TenantEntity tenantEntity, HttpServletRequest request, HttpServletResponse response, Map<String, Object> params) throws MallinkException { | |||
| public void downQrCode(TenantEntity tenantEntity, HttpServletRequest request, HttpServletResponse response, Map<String, Object> params,EnumPayWay payWay) throws MallinkException { | |||
| String name = (String) params.get("name"); | |||
| String pageUrl = (String) params.get("pageUrl"); | |||
| String sceneParam = (String) params.get("sceneParam"); | |||
| @@ -152,7 +154,7 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| exportQrcode(request, response, | |||
| tenantEntity, type, pageUrl, sceneParam, | |||
| withText, text1, text2, | |||
| name); | |||
| name,payWay); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(Result.ERROR, "下载异常"); | |||
| @@ -163,28 +165,10 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| public ResultData exportQrcode(HttpServletRequest request, HttpServletResponse response, | |||
| TenantEntity tenantEntity, int type, String pageUrl, String sceneParam, | |||
| int withText, String text1, String text2, | |||
| String name) { | |||
| String name,EnumPayWay payWay) { | |||
| // type 0 有限二维码, 1 无限制二维码 | |||
| // withText 0 不带字 1. 带下面的字,2 带下面的两行字 | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity); | |||
| boolean autoColor = false; | |||
| boolean isHyaline = true; | |||
| WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); | |||
| WxMaService wxMaService; | |||
| if(isFmOpen) { | |||
| wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); | |||
| } else { | |||
| wxMaService = MaUtil.getWeappService(appinfo); | |||
| } | |||
| String pathStr = ""; | |||
| if (StringUtils.isNotBlank(sceneParam)) { | |||
| pathStr = pageUrl + "?scene="+sceneParam; | |||
| } else { | |||
| pathStr = pageUrl; | |||
| } | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity,payWay); | |||
| String filepath = fmUploadDir; | |||
| String fileName = name + ".png"; | |||
| @@ -197,16 +181,9 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| pDest.mkdirs(); | |||
| } | |||
| try { | |||
| if(type == 0) { | |||
| final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); | |||
| copyFileToDest(withText, text1, text2, destPath1, dest, codeFile); | |||
| org.apache.commons.io.FileUtils.forceDelete(codeFile); | |||
| } else { | |||
| final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); | |||
| copyFileToDest(withText, text1, text2, destPath1, dest, codeFile); | |||
| org.apache.commons.io.FileUtils.forceDelete(codeFile); | |||
| } | |||
| File codeFile = payServiceFactory.getPayAdapterService(payWay.getCode()).getQrcode(appinfo, pageUrl, type, sceneParam); | |||
| copyFileToDest(withText, text1, text2, destPath1, dest, codeFile); | |||
| org.apache.commons.io.FileUtils.forceDelete(codeFile); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| @@ -225,28 +202,10 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| @Override | |||
| public ResultData uploadQrcode(TenantEntity tenantEntity, int type, String pageUrl, String sceneParam, | |||
| int withText, String text1, String text2, | |||
| String name) { | |||
| String name,EnumPayWay payWay) { | |||
| // type 0 有限二维码, 1 无限制二维码 | |||
| // withText 0 不带字 1. 带下面的字,2 带下面的两行字 | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity); | |||
| boolean autoColor = false; | |||
| boolean isHyaline = true; | |||
| WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); | |||
| WxMaService wxMaService; | |||
| if(isFmOpen) { | |||
| wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); | |||
| } else { | |||
| wxMaService = MaUtil.getWeappService(appinfo); | |||
| } | |||
| String pathStr = ""; | |||
| if (StringUtils.isNotBlank(sceneParam)) { | |||
| pathStr = pageUrl + "?scene="+sceneParam; | |||
| } else { | |||
| pathStr = pageUrl; | |||
| } | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity,payWay); | |||
| String filepath = fmUploadDir; | |||
| String fileName = name + ".png"; | |||
| @@ -259,16 +218,9 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| pDest.mkdirs(); | |||
| } | |||
| try { | |||
| if(type == 0) { | |||
| final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); | |||
| copyFileToDest(withText, text1, text2, destPath1, dest, codeFile); | |||
| org.apache.commons.io.FileUtils.forceDelete(codeFile); | |||
| } else { | |||
| final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); | |||
| copyFileToDest(withText, text1, text2, destPath1, dest, codeFile); | |||
| org.apache.commons.io.FileUtils.forceDelete(codeFile); | |||
| } | |||
| File codeFile = payServiceFactory.getPayAdapterService(payWay.getCode()).getQrcode(appinfo, pageUrl, type, sceneParam); | |||
| copyFileToDest(withText, text1, text2, destPath1, dest, codeFile); | |||
| org.apache.commons.io.FileUtils.forceDelete(codeFile); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| @@ -8,6 +8,7 @@ import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxProjectConfig; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import org.slf4j.Logger; | |||
| @@ -25,9 +26,10 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { | |||
| WxAppinfoMapper wxAppinfoMapper; | |||
| @Override | |||
| public WxAppinfo getCAppInfo(TenantEntity tenantEntity) { | |||
| public WxAppinfo getCAppInfo(TenantEntity tenantEntity,EnumPayWay payWay) { | |||
| WxAppinfo appInfo = null; | |||
| WxAppinfo appinfoQ = new WxAppinfo(); | |||
| appinfoQ.setPlat(payWay.getPlat().getCode()); | |||
| appinfoQ.updateTenantInfo(tenantEntity); | |||
| appinfoQ.setType(EnumAppType.C.getCode()); | |||
| List<WxAppinfo> appList = wxAppinfoMapper.selectList(new QueryWrapper(appinfoQ)); | |||
| @@ -271,7 +271,9 @@ public class WxCampaignServiceImpl implements WxCampaignService { | |||
| couponChannel.setId(wxCouponChannel.getId()); | |||
| couponChannel.setType(wxCouponChannel.getType()); | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券"); | |||
| //此处只有微信二维码,如果需要彼得二维码,需要加字段 | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultDataQ.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -292,7 +292,9 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||
| couponChannel.setId(vo.getId()); | |||
| couponChannel.setType(vo.getType()); | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券"); | |||
| //此处只有微信二维码 | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultDataQ.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -626,7 +626,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| WxAppinfo wxAppinfo = wxAppinfoService.getCAppInfo(couponOrder); | |||
| WxAppinfo wxAppinfo = wxAppinfoService.getCAppInfo(couponOrder,EnumPayWay.getEnum(couponOrder.getPayVendor())); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(wxAppinfo.getPayId()); | |||
| Integer subsidyNum = coupon.getSubsidyNum(); | |||
| @@ -54,7 +54,7 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { | |||
| @Async | |||
| @Override | |||
| public ResultData add(WxCouponPresent record, List<WxCouponPassword> list, Set<String> phoneSet) { | |||
| public ResultData add(WxCouponPresent record, List<WxCouponPassword> list, Set<String> phoneSet,EnumPayWay payWay) { | |||
| //添加记录 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| long id = idWorker.nextId(); | |||
| @@ -62,7 +62,7 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { | |||
| record.setSendAmount(phoneSet.size()); | |||
| wxCouponPresentMapper.insert(record); | |||
| //小程序 | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record,payWay); | |||
| String title = record.getCouponName(); | |||
| String name = appInfo.getName(); | |||
| List<WxCouponPassword> tempList = new ArrayList<>(); | |||
| @@ -418,7 +418,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| String phone = user.getPhone(); | |||
| //小程序名称 | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantEntity); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantEntity,EnumPayWay.getEnum(couponOrder.getPayVendor())); | |||
| String appName = appInfo.getName(); | |||
| Map<String, String> msgReplaceMap = new HashMap(); | |||
| msgReplaceMap.put("title", title); | |||
| @@ -16,6 +16,7 @@ import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.enums.EnumCouponStatus; | |||
| import com.iformall.enums.EnumGameStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxCouponOrderMapper; | |||
| @@ -336,7 +337,9 @@ public class WxGameServiceImpl implements WxGameService { | |||
| couponChannel.setId(wxCouponChannel.getId()); | |||
| couponChannel.setType(wxCouponChannel.getType()); | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券"); | |||
| //暂时只有微信二维码,如果有别的二维码,则需要别的字段 | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultDataQ.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -457,7 +457,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| @Override | |||
| public ResultData updateMerchantAccount(WxMerchant wxMerchant) { | |||
| public ResultData updateMerchantAccount(WxMerchant wxMerchant,EnumPayWay payWay) { | |||
| try { | |||
| if (wxMerchant.getId() == null) { | |||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||
| @@ -473,7 +473,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| receiver.setReceiverType(wxMerchant.getAccountTypeValue()); | |||
| receiver.setTrueName(wxMerchant.getAccountName()); | |||
| receiver.setParameter(wxMerchant.getAccountParameter()); | |||
| return wxProfitSharingReceiverService.updateReceiver(wxMerchant, receiver); | |||
| return wxProfitSharingReceiverService.updateReceiver(wxMerchant, receiver,payWay); | |||
| } | |||
| } catch (Exception e) { | |||
| logger.error("db failed: 账户操作失败, e:" + e.getMessage()); | |||
| @@ -67,6 +67,9 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| WxPayOrderMapper wxPayOrderMapper; | |||
| private int updateOrderGroup(WxOrderGroup wxOrderGroup,WxOrder order, WxCoupon wxCoupon) { | |||
| //锁住人数 | |||
| @@ -393,11 +396,9 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| order.setOrderGroupId(group.getId()); | |||
| order.setOrderStatus(group.getStatus()); | |||
| wxOrderMapper.updateStatusByOrderGroupId(order); | |||
| //获取APP信息 | |||
| WxAppinfo appinfo = new WxAppinfo(); | |||
| appinfo.setTenantId(order.getTenantId()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| WxAppinfo appinfo =null; | |||
| //退款流程 | |||
| WxOrder wxOrder = new WxOrder(); | |||
| wxOrder.setTenantId(group.getTenantId()); | |||
| @@ -408,6 +409,37 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| || temp.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode())) { | |||
| boolean has = wxRefundOrderService.hasRefundOrder(order.getId(), EnumRefundStatus.REFUND_SUCCESS.getCode()); | |||
| if (!has) { | |||
| // 查找支付订单 | |||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||
| payOrderQ.updateTenantInfo(wxOrder); | |||
| payOrderQ.setCUserId(wxOrder.getCUserId()); | |||
| payOrderQ.setOrderId(wxOrder.getId()); | |||
| payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| WxPayOrder payOrder = null; | |||
| List<WxPayOrder> payOrderlist = wxPayOrderMapper.findList(payOrderQ); | |||
| if (list.size() > 0) { | |||
| if (list.size() > 1) { | |||
| logger.error("TODO: payOrder成功记录应该只有一条????!!!"); | |||
| } | |||
| logger.warn(""); | |||
| payOrder = payOrderlist.get(0); | |||
| } | |||
| if (payOrder == null) { | |||
| logger.error("支付订单不存在(payOrder不存在)"); | |||
| return ; | |||
| } | |||
| //获取APP信息 | |||
| if (null == appinfo) { | |||
| appinfo = new WxAppinfo(); | |||
| appinfo.setTenantId(order.getTenantId()); | |||
| appinfo.setPlat(EnumPayWay.getEnum(payOrder.getPayVendor()).getPlat().getCode()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| } | |||
| //去库存 | |||
| wxOrderService.stockBack(temp); | |||
| wxRefundOrderService.returnMoney(appinfo, temp.getId()); | |||
| @@ -1629,9 +1629,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * 微信关闭订单 | |||
| */ | |||
| @Override | |||
| public ResultData orderClose(WxOrder order) { | |||
| public ResultData orderClose(WxOrder order,EnumPayWay payWay) { | |||
| // 1. get c appid | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(order); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(order,payWay); | |||
| // 2. get pay order | |||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||
| payOrderQ.updateTenantInfo(order); | |||
| @@ -105,14 +105,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| "\"ORDERNOTEXIST\":{\"detail\":\"此交易订单号不存在\",\"reason\":\"查询系统中不存在此交易订单号\",\"resolution\":\"该API只能查提交支付交易返回成功的订单,请商户检查需要查询的订单号是否正确\"},\n" + | |||
| "\"SYSTEMERROR\":{\"detail\":\"系统错误\t\",\"reason\":\"后台系统返回错误\",\"resolution\":\"系统异常,请再调用发起查询\"}}"); | |||
| JSONObject errorMapClose = JSON.parseObject("{" + | |||
| "\"ORDERPAID\":{\"detail\":\"订单已支付\",\"reason\":\"订单已支付,不能发起关单\",\"resolution\":\"订单已支付,不能发起关单,请当作已支付的正常交易\"}," + | |||
| "\"SYSTEMERROR\":{\"detail\":\"系统错误\",\"reason\":\"系统错误\",\"resolution\":\"系统异常,请重新调用该API\"}," + | |||
| "\"ORDERCLOSED\":{\"detail\":\"订单已关闭\",\"reason\":\"订单已关闭,无法重复关闭\",\"resolution\":\"订单已关闭,无需继续调用\"}," + | |||
| "\"SIGNERROR\":{\"detail\":\"签名错误\",\"reason\":\"参数签名结果不正确\",\"resolution\":\"请检查签名参数和方法是否都符合签名算法要求\"}," + | |||
| "\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + | |||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | |||
| //方法必须为public AopContext.currentProxy() | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| @Override | |||
| @@ -402,7 +394,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| public ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay,PayExtraParam params) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user,payWay); | |||
| if (null == params) { | |||
| params = new PayExtraParam(); | |||
| } | |||
| @@ -529,7 +521,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), "Order not found"); | |||
| } | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record,payWay); | |||
| PayAdapterService payService = payServiceFactory.getPayAdapterService(payWay.getCode()); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| PayQueryAdapterResult apiResult = payService.queryPayStatus(record, order, appInfo, payAccount); | |||
| @@ -595,167 +587,40 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| } | |||
| private String wechatPayOrderClose(WxAppinfo appInfo, WxPayOrder record) { | |||
| // get payAccount | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||
| // 普通商户号模式 | |||
| WxPayOrderQ payOrderC = new WxPayOrderQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderC.setAppid(appInfo.getAppId()); | |||
| payOrderC.setMch_id(payAccount.getMchId()); | |||
| payOrderC.setNonce_str(noncestr); | |||
| payOrderC.setOut_trade_no(record.getPayOrderNo()); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderC); | |||
| payOrderC.setSign(WxPayment.createSign(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderC); | |||
| String response = WxPay.closeOrder(map); | |||
| logger.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } else { | |||
| // 服务商模式 | |||
| WxPayOrderSQ payOrderSC = new WxPayOrderSQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderSC.setAppid(appInfo.getParentAppId()); | |||
| payOrderSC.setSub_appid(appInfo.getAppId()); | |||
| payOrderSC.setMch_id(payAccount.getMchId()); | |||
| payOrderSC.setSub_mch_id(payAccount.getSubMchId()); | |||
| payOrderSC.setNonce_str(noncestr); | |||
| payOrderSC.setOut_trade_no(record.getPayOrderNo()); | |||
| payOrderSC.setSign_type("HMAC-SHA256"); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderSC); | |||
| payOrderSC.setSign(WxPayment.createSignHMAC(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderSC); | |||
| String response = WxPay.closeOrder(map); | |||
| logger.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 微信关闭支付订单 | |||
| */ | |||
| @Override | |||
| public ResultData payOrderClose(WxAppinfo appInfo, WxPayOrder record) { | |||
| try { | |||
| String response = wechatPayOrderClose(appInfo, record); | |||
| logger.info("pay order close, " + record.toString() + ", response: " + response); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_CANCEL.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order 关单:{} 成功", record.getId()); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "支付订单关闭成功", returnMap); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMapClose.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| try { | |||
| PayAdapterResult result = payServiceFactory.getPayAdapterService(record.getPayVendor()).payOrderClose(appInfo, record, payAccount); | |||
| if (result.isSuccess()) { | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_CANCEL.getCode()); | |||
| }else { | |||
| record.setFailReason(result.getMsg()); | |||
| } | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| } catch (RuntimeException e) { | |||
| if (result.isSuccess()) { | |||
| return new ResultData(Result.SUCCESS, "支付订单关闭成功", result.getData()); | |||
| }else { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), result.getMsg(), result.getData()); | |||
| } | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| private String wechatPayOrderReverse(WxAppinfo appInfo, WxPayOrder record) { | |||
| // get payAccount | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||
| // 普通商户号模式 | |||
| WxPayOrderQ payOrderC = new WxPayOrderQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderC.setAppid(appInfo.getAppId()); | |||
| payOrderC.setMch_id(payAccount.getMchId()); | |||
| payOrderC.setNonce_str(noncestr); | |||
| payOrderC.setOut_trade_no(record.getPayOrderNo()); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderC); | |||
| payOrderC.setSign(WxPayment.createSign(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderC); | |||
| String response = WxPay.orderReverse(map, payAccount.getCertPath(), payAccount.getMchId()); | |||
| logger.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } else { | |||
| // 服务商模式 | |||
| WxPayOrderSQ payOrderSC = new WxPayOrderSQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderSC.setAppid(appInfo.getParentAppId()); | |||
| payOrderSC.setSub_appid(appInfo.getAppId()); | |||
| payOrderSC.setMch_id(payAccount.getMchId()); | |||
| payOrderSC.setSub_mch_id(payAccount.getSubMchId()); | |||
| payOrderSC.setNonce_str(noncestr); | |||
| payOrderSC.setOut_trade_no(record.getPayOrderNo()); | |||
| payOrderSC.setSign_type("HMAC-SHA256"); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderSC); | |||
| payOrderSC.setSign(WxPayment.createSignHMAC(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderSC); | |||
| String response = WxPay.orderReverse(map, payAccount.getCertPath(), payAccount.getMchId()); | |||
| logger.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 撤销订单 - 刷卡支付 | |||
| @@ -763,102 +628,77 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| @Override | |||
| public ResultData payOrderReverse(WxPayOrder record) { | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record,EnumPayWay.getEnum(record.getPayVendor())); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| try { | |||
| String response = wechatPayOrderReverse(appInfo, record); | |||
| logger.info("pay order reverse, " + record.toString() + ", response: " + response); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| // 预核销撤回 | |||
| WxPayOrder verifyPayOrder = null; | |||
| WxPayOrder verifyPayOrderQ = new WxPayOrder(); | |||
| verifyPayOrderQ.setPayFrom(EnumOrderFrom.INSIDE.getCode()); | |||
| verifyPayOrderQ.setOrderId(record.getOrderId()); | |||
| verifyPayOrderQ.setCUserId(record.getCUserId()); | |||
| verifyPayOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| try { | |||
| verifyPayOrder = wxPayOrderMapper.selectOne(new QueryWrapper<>(verifyPayOrderQ)); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| if (verifyPayOrder != null) { | |||
| verifyPayOrderQ = new WxPayOrder(); | |||
| verifyPayOrderQ.setId(verifyPayOrder.getId()); | |||
| verifyPayOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); | |||
| verifyPayOrderQ.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(verifyPayOrderQ); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| PosCouponOrderVerify posCouponOrderVerifyQ = new PosCouponOrderVerify(); | |||
| posCouponOrderVerifyQ.setCouponOrderId(verifyPayOrder.getPosPayOrderId()); | |||
| posCouponOrderVerifyQ.setPosOrderId(record.getOrderId()); | |||
| try { | |||
| posCouponOrderVerifyMapper.delete(new UpdateWrapper<>(posCouponOrderVerifyQ)); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| WxCouponOrder updateCouponOrder = new WxCouponOrder(); | |||
| updateCouponOrder.setId(verifyPayOrder.getPosPayOrderId()); | |||
| updateCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| updateCouponOrder.setUpdateDate(new Date()); | |||
| try { | |||
| wxCouponOrderService.saveOrUpdate(updateCouponOrder); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| // 预核销撤回-end | |||
| WxOrder order = new WxOrder(); | |||
| order.setId(record.getOrderId()); | |||
| order.setType(EnumOrderType.MICROPAY.getCode()); | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| order.setUpdateDate(new Date()); | |||
| try { | |||
| wxOrderMapper.updateById(order); | |||
| } catch (Exception e) { | |||
| logger.error("order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "订单撤销成功", returnMap); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMapClose.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| PayAdapterResult result = payServiceFactory.getPayAdapterService(record.getPayVendor()).payOrderReverse(appInfo, record, payAccount); | |||
| if (result.isSuccess()) { | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| // 预核销撤回 | |||
| WxPayOrder verifyPayOrder = null; | |||
| WxPayOrder verifyPayOrderQ = new WxPayOrder(); | |||
| verifyPayOrderQ.setPayFrom(EnumOrderFrom.INSIDE.getCode()); | |||
| verifyPayOrderQ.setOrderId(record.getOrderId()); | |||
| verifyPayOrderQ.setCUserId(record.getCUserId()); | |||
| verifyPayOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| try { | |||
| verifyPayOrder = wxPayOrderMapper.selectOne(new QueryWrapper<>(verifyPayOrderQ)); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| if (verifyPayOrder != null) { | |||
| verifyPayOrderQ = new WxPayOrder(); | |||
| verifyPayOrderQ.setId(verifyPayOrder.getId()); | |||
| verifyPayOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); | |||
| verifyPayOrderQ.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(verifyPayOrderQ); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| PosCouponOrderVerify posCouponOrderVerifyQ = new PosCouponOrderVerify(); | |||
| posCouponOrderVerifyQ.setCouponOrderId(verifyPayOrder.getPosPayOrderId()); | |||
| posCouponOrderVerifyQ.setPosOrderId(record.getOrderId()); | |||
| try { | |||
| posCouponOrderVerifyMapper.delete(new UpdateWrapper<>(posCouponOrderVerifyQ)); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| WxCouponOrder updateCouponOrder = new WxCouponOrder(); | |||
| updateCouponOrder.setId(verifyPayOrder.getPosPayOrderId()); | |||
| updateCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| updateCouponOrder.setUpdateDate(new Date()); | |||
| try { | |||
| wxCouponOrderService.saveOrUpdate(updateCouponOrder); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| // 预核销撤回-end | |||
| WxOrder order = new WxOrder(); | |||
| order.setId(record.getOrderId()); | |||
| order.setType(EnumOrderType.MICROPAY.getCode()); | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| order.setUpdateDate(new Date()); | |||
| try { | |||
| wxOrderMapper.updateById(order); | |||
| } catch (Exception e) { | |||
| logger.error("order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(Result.SUCCESS, result.getMsg(), result.getData()); | |||
| }else { | |||
| record.setFailReason(result.getMsg()); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateById(record); | |||
| @@ -866,8 +706,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), result.getMsg(), result.getData()); | |||
| } | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| @@ -1120,7 +960,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(order); | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(order,payWay); | |||
| if (record.getPayAmount().equals(order.getTotalPayment())) { | |||
| doCouponPayOrder(user, record, order,payWay); | |||
| @@ -1235,7 +1075,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| // 有价券 | |||
| if (EnumPayStatus.PAY_STATUS_FAIL.getCode() == status) { | |||
| // 1. get appinfo | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(order); | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(order,EnumPayWay.getEnum(record.getPayVendor())); | |||
| // 前端支付取消, | |||
| // 回调未返回,主动检查支付订单状态 | |||
| try { | |||
| @@ -1318,19 +1158,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| } | |||
| private WxAppinfo getWxAppinfo(Integer orderType, String tenentId) { | |||
| WxAppinfo appInfo = null; | |||
| WxAppinfo appinfoQ = new WxAppinfo(); | |||
| appinfoQ.setTenantId(tenentId); | |||
| appinfoQ.setType(EnumAppType.C.getCode()); | |||
| List<WxAppinfo> appList = wxAppinfoMapper.selectList(new QueryWrapper(appinfoQ)); | |||
| if (appList.size() > 0) { | |||
| appInfo = appList.get(0); | |||
| } | |||
| return appInfo; | |||
| } | |||
| @Override | |||
| public PageInfo<WxPayOrder> listAsPage(WxPayOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxPayOrderMapper.findList(record)); | |||
| @@ -108,14 +108,11 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| private WxAppinfo getAppinfo(Long cUserId) { | |||
| private WxAppinfo getAppinfo(String tenantId,Integer payWay) { | |||
| WxAppinfo wxAppinfo = new WxAppinfo(); | |||
| WxCUser wxCUser = wxCUserMapper.selectById(cUserId); | |||
| if (wxCUser == null) | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| wxAppinfo.setAppId(wxCUser.getAppId()); | |||
| wxAppinfo.setTenantId(tenantId); | |||
| wxAppinfo.setPlat(EnumPayWay.getEnum(payWay).getPlat().getCode()); | |||
| wxAppinfo.setType(EnumAppType.C.getCode()); | |||
| wxAppinfo = wxAppinfoMapper.selectOne(new QueryWrapper(wxAppinfo)); | |||
| if (wxAppinfo == null) | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| @@ -135,7 +132,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| } | |||
| WxPayOrder payOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId()); | |||
| WxAppinfo appInfo = getAppinfo(payOrder.getCUserId()); | |||
| WxAppinfo appInfo = getAppinfo(payOrder.getTenantId(),payOrder.getPayVendor()); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| List<JSONObject> receivers; | |||
| @@ -251,7 +248,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getCUserId()); | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| //准备分账列表 | |||
| @@ -389,13 +386,13 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId()); | |||
| if (wxPayOrder == null) | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| appInfo = getAppinfo(wxPayOrder.getCUserId()); | |||
| appInfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor()); | |||
| } else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()) | |||
| ||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ | |||
| WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId()); | |||
| if (wxCardSpend == null) | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| appInfo = getAppinfo(wxCardSpend.getOwnerId()); | |||
| appInfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode()); | |||
| } else { | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); | |||
| } | |||
| @@ -527,7 +524,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getCUserId()); | |||
| WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| @@ -26,6 +26,8 @@ import com.iformall.pay.WxPayment; | |||
| import com.iformall.pay.WxProfitSharing; | |||
| import com.iformall.pay.WxProfitSharingReceiverP; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.Utility; | |||
| @@ -65,6 +67,9 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| WxMerchantMapper wxMerchantMapper; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| PayServiceFactory payServiceFactory; | |||
| @Override | |||
| public PageInfo<WxProfitSharingReceiver> listAsPage(WxProfitSharingReceiver record, Integer pageIndex, Integer pageSize) { | |||
| @@ -106,10 +111,11 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| @Override | |||
| public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List<WxProfitSharingReceiver> delList) { | |||
| public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List<WxProfitSharingReceiver> delList,EnumPayWay payWay) { | |||
| WxAppinfo appInfo = new WxAppinfo(); | |||
| appInfo.updateTenantInfo(merchant); | |||
| appInfo.setPlat(EnumPayWay.getEnum(payWay.getCode()).getPlat().getCode()); | |||
| appInfo.setType(EnumAppType.C.getCode()); | |||
| appInfo = wxAppinfoMapper.findList(appInfo).get(0); | |||
| @@ -124,6 +130,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| receiver.setUpdateTime(date); | |||
| receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); | |||
| receiver.setIsUse(EnumProfitSharingUse.APPLY.getCode()); | |||
| receiver.setPlat(payWay.getPlat().getCode()); | |||
| //passed from uplevel | |||
| //receiver.setReceiverAccount(receiverParam.getReceiverAccount()); | |||
| //receiver.setReceiverComments(receiverParam.getReceiverComments()); | |||
| @@ -131,53 +138,11 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| //receiver.setTrueName(receiverParam.getTrueName()); | |||
| //添加分账账户 | |||
| WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); | |||
| if (StringUtils.isNotBlank(appInfo.getParentAppId())) { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); | |||
| } else { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| } | |||
| wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); | |||
| wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); | |||
| JSONObject receiverJSON = new JSONObject(); | |||
| receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| receiverJSON.put("account", receiver.getReceiverAccount()); | |||
| receiverJSON.put("name", receiver.getTrueName()); | |||
| wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); | |||
| String response; | |||
| try { | |||
| wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); | |||
| response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); | |||
| logger.info(response); | |||
| } catch (Exception e) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + e.getMessage()); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED, e.getMessage()); | |||
| ShareAccountResult createResult = payServiceFactory.getPayShareAdapterService(payWay.getCode()).createShareAccount(appInfo, payAccount, receiver); | |||
| if (!createResult.isSuccess()) { | |||
| return new ResultData(createResult.getCode(), createResult.getMsg()); | |||
| } | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| if (!"SUCCESS".equals(return_code)) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("return_msg")); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("return_msg")); | |||
| } | |||
| String result_code = returnMap.get("result_code"); | |||
| if (!"SUCCESS".equals(result_code)) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("err_code_des")); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("err_code_des")); | |||
| } | |||
| if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + "verifyNotifyHMAC"); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage()); | |||
| } | |||
| wxProfitSharingReceiverMapper.insert(receiver); | |||
| //添加成功才删除账户 | |||
| @@ -198,7 +163,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| //添加变更短信 | |||
| sendMsgByType(EnumMsgModel.UPDATE_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode(), merchant.getId(), receiver.getReceiverAccount(), receiver); | |||
| } | |||
| return new ResultData(returnMap); | |||
| return new ResultData(createResult.getData()); | |||
| } | |||
| private void sendMsgByType(Integer type, Long merchantId, String account, TenantEntity tenantEntity) { | |||
| @@ -282,56 +247,10 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| ))) { | |||
| //还有别的商户使用这个账号,不从微信服务器申请删除 | |||
| } else { | |||
| //删除分账账户从微信服务器 | |||
| WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); | |||
| if (StringUtils.isNotBlank(appInfo.getParentAppId())) { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); | |||
| } else { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| } | |||
| wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); | |||
| wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); | |||
| JSONObject receiverJSON = new JSONObject(); | |||
| receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| receiverJSON.put("account", receiver.getReceiverAccount()); | |||
| wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); | |||
| String response; | |||
| try { | |||
| wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); | |||
| response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); | |||
| } catch (Exception e) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED, e.getMessage()); | |||
| } | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| if (!"SUCCESS".equals(return_code)) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg")); | |||
| } | |||
| String result_code = returnMap.get("result_code"); | |||
| if (!"SUCCESS".equals(result_code)) { | |||
| if (returnMap.get("err_code").contains("USER_NOT_EXIST")) { | |||
| receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); | |||
| receiver.setUpdateTime(new Date()); | |||
| wxProfitSharingReceiverMapper.updateById(receiver); | |||
| } | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des")); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des")); | |||
| } | |||
| if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { | |||
| logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC"); | |||
| } | |||
| ShareAccountResult shareResult = payServiceFactory.getPayShareAdapterService(receiver.getPlat()).deleteShareAccount(appInfo, payAccount, receiver); | |||
| if (!shareResult.isSuccess()) { | |||
| return new ResultData(shareResult.getCode(), shareResult.getMsg()); | |||
| } | |||
| } | |||
| receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); | |||
| @@ -347,7 +266,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| } | |||
| @Override | |||
| public ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver) { | |||
| public ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver,EnumPayWay payWay) { | |||
| WxProfitSharingReceiver oldReceiver = new WxProfitSharingReceiver(); | |||
| oldReceiver.updateTenantInfo(merchant); | |||
| @@ -361,7 +280,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||
| oldReceiver = wxProfitSharingReceiverMapper.selectOne(new QueryWrapper(oldReceiver)); | |||
| if (oldReceiver == null) { | |||
| return addReceiver(merchant, receiver, delList); | |||
| return addReceiver(merchant, receiver, delList,payWay); | |||
| } else { | |||
| oldReceiver.setParameter(receiver.getParameter()); | |||
| oldReceiver.setUpdateTime(new Date()); | |||
| @@ -10,6 +10,7 @@ import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxTopic; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumWxTopicStatus; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxCouponMapper; | |||
| @@ -141,7 +142,9 @@ public class WxTopicServiceImpl implements WxTopicService { | |||
| couponChannel.setId(wxCouponChannel.getId()); | |||
| couponChannel.setType(wxCouponChannel.getType()); | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券"); | |||
| //这里暂时只有微信二维码,有其他的码需要加字段 | |||
| ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon,1,pageUrl,param,0,"","","券",EnumPayWay.PAY_WAY_WECHAT); | |||
| Map<String,String> map = (Map)resultDataQ.data; | |||
| if(map!=null && map.get("url") !=null) { | |||
| String url = map.get("url"); | |||
| @@ -1,6 +1,9 @@ | |||
| package com.iformall.service.pay.service.pay; | |||
| import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| @@ -56,4 +59,31 @@ public interface PayAdapterService { | |||
| * @throws Exception | |||
| */ | |||
| public int queryPayStatusCode(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
| /** | |||
| * API关闭订单 | |||
| * @param appInfo | |||
| * @param record | |||
| * @param payAccount | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public PayAdapterResult payOrderClose(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception; | |||
| /** | |||
| * API 订单撤回 | |||
| * @param appInfo | |||
| * @param record | |||
| * @param payAccount | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception; | |||
| /** | |||
| * 获取二维码 | |||
| * @param param | |||
| * @return | |||
| */ | |||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception; | |||
| } | |||
| @@ -1,15 +1,53 @@ | |||
| package com.iformall.service.pay.service.pay.wx; | |||
| import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.PosCouponOrderVerify; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumCouponOrderStatus; | |||
| import com.iformall.enums.EnumOrderFrom; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.EnumOrderType; | |||
| import com.iformall.enums.EnumPayMode; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.pay.WxPay; | |||
| import com.iformall.pay.WxPayOrderQ; | |||
| import com.iformall.pay.WxPayOrderSQ; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.service.QrCodeService; | |||
| import com.iformall.service.helper.WxPayOrderServiceHelper; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.QRCodeUtils; | |||
| import com.iformall.utils.Utility; | |||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||
| import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.open.api.WxOpenService; | |||
| @Slf4j | |||
| public class BaseWxPayAdapterService { | |||
| protected PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| @@ -29,4 +67,196 @@ public class BaseWxPayAdapterService { | |||
| throws Exception { | |||
| return WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| JSONObject errorMapClose = JSON.parseObject("{" + | |||
| "\"ORDERPAID\":{\"detail\":\"订单已支付\",\"reason\":\"订单已支付,不能发起关单\",\"resolution\":\"订单已支付,不能发起关单,请当作已支付的正常交易\"}," + | |||
| "\"SYSTEMERROR\":{\"detail\":\"系统错误\",\"reason\":\"系统错误\",\"resolution\":\"系统异常,请重新调用该API\"}," + | |||
| "\"ORDERCLOSED\":{\"detail\":\"订单已关闭\",\"reason\":\"订单已关闭,无法重复关闭\",\"resolution\":\"订单已关闭,无需继续调用\"}," + | |||
| "\"SIGNERROR\":{\"detail\":\"签名错误\",\"reason\":\"参数签名结果不正确\",\"resolution\":\"请检查签名参数和方法是否都符合签名算法要求\"}," + | |||
| "\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + | |||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | |||
| protected PayAdapterResult closeOrder(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) { | |||
| String response = closeOrderWx(appInfo, record,payAccount); | |||
| log.info("pay order close, " + record.toString() + ", response: " + response); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| return new PayAdapterResult(true, "success", returnMap, null); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMapClose.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| return new PayAdapterResult(false, errMsg, returnMap, null); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| return new PayAdapterResult(false, errMsg, returnMap, null); | |||
| } | |||
| } | |||
| private String closeOrderWx(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) { | |||
| // get payAccount | |||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||
| // 普通商户号模式 | |||
| WxPayOrderQ payOrderC = new WxPayOrderQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderC.setAppid(appInfo.getAppId()); | |||
| payOrderC.setMch_id(payAccount.getMchId()); | |||
| payOrderC.setNonce_str(noncestr); | |||
| payOrderC.setOut_trade_no(record.getPayOrderNo()); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderC); | |||
| payOrderC.setSign(WxPayment.createSign(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderC); | |||
| String response = WxPay.closeOrder(map); | |||
| log.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } else { | |||
| // 服务商模式 | |||
| WxPayOrderSQ payOrderSC = new WxPayOrderSQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderSC.setAppid(appInfo.getParentAppId()); | |||
| payOrderSC.setSub_appid(appInfo.getAppId()); | |||
| payOrderSC.setMch_id(payAccount.getMchId()); | |||
| payOrderSC.setSub_mch_id(payAccount.getSubMchId()); | |||
| payOrderSC.setNonce_str(noncestr); | |||
| payOrderSC.setOut_trade_no(record.getPayOrderNo()); | |||
| payOrderSC.setSign_type("HMAC-SHA256"); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderSC); | |||
| payOrderSC.setSign(WxPayment.createSignHMAC(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderSC); | |||
| String response = WxPay.closeOrder(map); | |||
| log.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| protected PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception { | |||
| String response = payOrderReverseWx(appInfo, record,payAccount); | |||
| log.info("pay order reverse, " + record.toString() + ", response: " + response); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| return new PayAdapterResult(true, "订单撤销成功", returnMap, null); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMapClose.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| return new PayAdapterResult(false, errMsg, returnMap, null); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| return new PayAdapterResult(false, errMsg, returnMap, null); | |||
| } | |||
| } | |||
| private String payOrderReverseWx(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) { | |||
| // get payAccount | |||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||
| // 普通商户号模式 | |||
| WxPayOrderQ payOrderC = new WxPayOrderQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderC.setAppid(appInfo.getAppId()); | |||
| payOrderC.setMch_id(payAccount.getMchId()); | |||
| payOrderC.setNonce_str(noncestr); | |||
| payOrderC.setOut_trade_no(record.getPayOrderNo()); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderC); | |||
| payOrderC.setSign(WxPayment.createSign(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderC); | |||
| String response = WxPay.orderReverse(map, payAccount.getCertPath(), payAccount.getMchId()); | |||
| log.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } else { | |||
| // 服务商模式 | |||
| WxPayOrderSQ payOrderSC = new WxPayOrderSQ(); | |||
| String noncestr = Utility.generate32UUID(); | |||
| payOrderSC.setAppid(appInfo.getParentAppId()); | |||
| payOrderSC.setSub_appid(appInfo.getAppId()); | |||
| payOrderSC.setMch_id(payAccount.getMchId()); | |||
| payOrderSC.setSub_mch_id(payAccount.getSubMchId()); | |||
| payOrderSC.setNonce_str(noncestr); | |||
| payOrderSC.setOut_trade_no(record.getPayOrderNo()); | |||
| payOrderSC.setSign_type("HMAC-SHA256"); | |||
| try { | |||
| Map map = BeanUtils.toStringMap(payOrderSC); | |||
| payOrderSC.setSign(WxPayment.createSignHMAC(map, payAccount.getApiKey())); | |||
| map = BeanUtils.toStringMap(payOrderSC); | |||
| String response = WxPay.orderReverse(map, payAccount.getCertPath(), payAccount.getMchId()); | |||
| log.info("request:" + map.toString() + "\nresponse:" + response); | |||
| return response; | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @Autowired | |||
| WxOpenService openService; | |||
| protected File getQrCode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws WxErrorException { | |||
| boolean isFmOpen = false; | |||
| WxMaService wxMaService; | |||
| if(isFmOpen) { | |||
| wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); | |||
| } else { | |||
| wxMaService = MaUtil.getWeappService(appinfo); | |||
| } | |||
| boolean autoColor = false; | |||
| boolean isHyaline = true; | |||
| WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); | |||
| String pathStr = ""; | |||
| if (StringUtils.isNotBlank(sceneParam)) { | |||
| pathStr = pageUrl + "?scene="+sceneParam; | |||
| } else { | |||
| pathStr = pageUrl; | |||
| } | |||
| if(type == 0) { | |||
| final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); | |||
| return codeFile; | |||
| }else { | |||
| final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); | |||
| return codeFile; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,6 +1,8 @@ | |||
| package com.iformall.service.pay.service.pay.wx.h5; | |||
| import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -41,5 +43,25 @@ public class WxH5PayService extends BaseWxPayAdapterService implements CDriving | |||
| throws Exception { | |||
| return super.queryPayStatusCode(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderClose(WxAppinfo appInfo, WxPayOrder record, WxPayAccount payAccount) | |||
| throws Exception { | |||
| // TODO Auto-generated method stub | |||
| return null; | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record, WxPayAccount payAccount) | |||
| throws Exception { | |||
| // TODO Auto-generated method stub | |||
| return null; | |||
| } | |||
| @Override | |||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception{ | |||
| // TODO Auto-generated method stub | |||
| return null; | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.service.pay.service.pay.wx.miniApp.appPay; | |||
| import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| @@ -251,4 +252,20 @@ public class WxMiniAppPayAdapterService extends BaseWxPayAdapterService implemen | |||
| return super.queryPayStatusCode(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderClose(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception { | |||
| return super.closeOrder(appInfo, record, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.payOrderReverse(appInfo, record, payAccount); | |||
| } | |||
| @Override | |||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception{ | |||
| return super.getQrCode(appinfo, pageUrl, type, sceneParam); | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.service.pay.service.pay.wx.miniApp.maPay; | |||
| import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -31,6 +32,7 @@ import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.Utility; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| @Slf4j | |||
| @@ -246,5 +248,21 @@ public class WxMiniMaPayAdapterService extends BaseWxPayAdapterService implement | |||
| return super.queryPayStatusCode(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderClose(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception { | |||
| return super.closeOrder(appInfo, record, payAccount); | |||
| } | |||
| @Override | |||
| public PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.payOrderReverse(appInfo, record, payAccount); | |||
| } | |||
| @Override | |||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception { | |||
| return super.getQrCode(appinfo, pageUrl, type, sceneParam); | |||
| } | |||
| } | |||
| @@ -6,10 +6,12 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxProfitSharingOrder; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.enums.EnumProfitSharingReceiverType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; | |||
| @@ -62,7 +64,28 @@ public interface PayShareAdapterService { | |||
| */ | |||
| public EnumProfitSharingReceiverType getShareAccount(Integer accountType); | |||
| /** | |||
| * 分账异步通知接收 | |||
| * @param paramMap | |||
| * @param payWay | |||
| * @return | |||
| */ | |||
| public ShareNotifyAdapterResult notify(Map<String, String> paramMap,EnumPayWay payWay); | |||
| /** | |||
| * 调用API 添加分账账户 | |||
| * @param appInfo | |||
| * @param payAccount | |||
| * @param receiver | |||
| */ | |||
| public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver); | |||
| /** | |||
| * 调用API 删除分账账户 | |||
| * @param appInfo | |||
| * @param payAccount | |||
| * @param receiver | |||
| */ | |||
| public ShareAccountResult deleteShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver); | |||
| } | |||
| @@ -0,0 +1,21 @@ | |||
| package com.iformall.service.pay.service.share.entity; | |||
| import java.io.Serializable; | |||
| import lombok.AllArgsConstructor; | |||
| import lombok.Data; | |||
| @Data | |||
| @AllArgsConstructor | |||
| public class ShareAccountResult implements Serializable{ | |||
| private static final long serialVersionUID = -3701322871877301001L; | |||
| private boolean isSuccess; | |||
| private Integer code; | |||
| private String msg; | |||
| private Object data; | |||
| } | |||
| @@ -11,28 +11,35 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.WxProfitSharingOrder; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.enums.EnumMerchantSubsidyType; | |||
| import com.iformall.enums.EnumPayEndFrom; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderStatus; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.enums.EnumProfitSharingReceiverStatus; | |||
| import com.iformall.enums.EnumProfitSharingReceiverType; | |||
| import com.iformall.enums.EnumProfitSharingType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.mapper.WxProfitSharingReceiverMapper; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.pay.WxProfitSharing; | |||
| import com.iformall.pay.WxProfitSharingFinishP; | |||
| import com.iformall.pay.WxProfitSharingP; | |||
| import com.iformall.pay.WxProfitSharingReceiverP; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| @@ -259,4 +266,116 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| return getErrorResult("FAILED"); | |||
| } | |||
| @Override | |||
| public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { | |||
| WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); | |||
| if (StringUtils.isNotBlank(appInfo.getParentAppId())) { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); | |||
| } else { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| } | |||
| wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); | |||
| wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); | |||
| JSONObject receiverJSON = new JSONObject(); | |||
| receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| receiverJSON.put("account", receiver.getReceiverAccount()); | |||
| receiverJSON.put("name", receiver.getTrueName()); | |||
| wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); | |||
| String response; | |||
| try { | |||
| wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); | |||
| response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); | |||
| log.info(response); | |||
| } catch (Exception e) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + e.getMessage()); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), e.getMessage(), null); | |||
| } | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| if (!"SUCCESS".equals(return_code)) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("return_msg")); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("return_msg"), null); | |||
| } | |||
| String result_code = returnMap.get("result_code"); | |||
| if (!"SUCCESS".equals(result_code)) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("err_code_des")); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("err_code_des"), null); | |||
| } | |||
| if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + "verifyNotifyHMAC"); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage(), null); | |||
| } | |||
| return new ShareAccountResult(true, null, "success", returnMap); | |||
| } | |||
| @Autowired | |||
| WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; | |||
| @Override | |||
| public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount, | |||
| WxProfitSharingReceiver receiver) { | |||
| //删除分账账户从微信服务器 | |||
| WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); | |||
| if (StringUtils.isNotBlank(appInfo.getParentAppId())) { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); | |||
| } else { | |||
| wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); | |||
| wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); | |||
| } | |||
| wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); | |||
| wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); | |||
| JSONObject receiverJSON = new JSONObject(); | |||
| receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| receiverJSON.put("account", receiver.getReceiverAccount()); | |||
| wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); | |||
| String response; | |||
| try { | |||
| wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); | |||
| response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); | |||
| } catch (Exception e) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), e.getMessage(), null); | |||
| } | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| if (!"SUCCESS".equals(return_code)) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg"), null); | |||
| } | |||
| String result_code = returnMap.get("result_code"); | |||
| if (!"SUCCESS".equals(result_code)) { | |||
| if (returnMap.get("err_code").contains("USER_NOT_EXIST")) { | |||
| receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); | |||
| receiver.setUpdateTime(new Date()); | |||
| wxProfitSharingReceiverMapper.updateById(receiver); | |||
| } | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des")); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"), null); | |||
| } | |||
| if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { | |||
| log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); | |||
| return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC", null); | |||
| } | |||
| return new ShareAccountResult(true, null, "success", returnMap); | |||
| } | |||
| } | |||
| @@ -9,6 +9,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.wechat.FmOpenService; | |||
| @@ -139,7 +140,7 @@ public class WxAppinfoController extends BaseController { | |||
| String name) { | |||
| // type 0 有限二维码, 1 无限制二维码 | |||
| // withText 0 不带字 1. 带下面的字,2 带下面的两行字 | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity); | |||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantEntity,EnumPayWay.PAY_WAY_WECHAT); | |||
| boolean autoColor = false; | |||
| boolean isHyaline = true; | |||
| WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); | |||
| @@ -8,6 +8,7 @@ import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.WxMerchantService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -118,7 +119,7 @@ public class WxMerchantController extends BaseController { | |||
| public ResultData updateMerchantAccount(@RequestBody WxMerchant wxMerchant) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantAccount"); | |||
| wxMerchant.updateTenantInfo(getTenantInfo()); | |||
| return wxMerchantService.updateMerchantAccount(wxMerchant); | |||
| return wxMerchantService.updateMerchantAccount(wxMerchant,EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| @ApiOperation("更新管理员接口") | |||