Search in sources :

Example 6 with R

use of com.github.liuweijw.commons.base.R in project fw-cloud-framework by liuweijw.

the class WxSendRedpackServiceImpl method sendRedpack.

@Override
public R<Map<String, Object>> sendRedpack(PaySendRedpack paySendRedpack, WxPaySendRedpackRequest sendRedpackRequest) {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    // 设置会出现签名加密返回
    returnMap.put(PayConstant.RETURN_PARAM_RETCODE, PayConstant.RETURN_VALUE_SUCCESS);
    returnMap.put("return_code", PayConstant.RETURN_VALUE_FAIL);
    returnMap.put("return_msg", "请求出现异常!");
    boolean isCommonRedPack = paySendRedpack.getRedPackType().intValue() == 0;
    String resKey = paySendRedpack.getResKey();
    String logPrefix = isCommonRedPack ? "【发放普通红包】" : "【发放裂变红包】";
    try {
        log.info(logPrefix + "请求:" + sendRedpackRequest.toString());
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(paySendRedpack.getWxPayConfig());
        WxPaySendRedpackResult paySendRedpackResult = wxPayService.sendRedpack(sendRedpackRequest);
        paySendRedpack.setReturnCode(paySendRedpackResult.getReturnCode());
        paySendRedpack.setReturnMsg(paySendRedpackResult.getReturnMsg());
        paySendRedpack.setResultCode(paySendRedpackResult.getResultCode());
        paySendRedpack.setErrCode(paySendRedpackResult.getErrCode());
        paySendRedpack.setErrCodeDes(paySendRedpackResult.getErrCodeDes());
        // 订单流水号
        returnMap.put("send_order_id", paySendRedpack.getSendOrderId());
        // 订单编号
        returnMap.put("mch_order_no", paySendRedpack.getMchOrderNo());
        returnMap.put("return_code", paySendRedpackResult.getReturnCode());
        returnMap.put("return_msg", paySendRedpackResult.getReturnMsg());
        returnMap.put("result_code", paySendRedpackResult.getResultCode());
        returnMap.put("err_code", paySendRedpackResult.getErrCode());
        returnMap.put("err_code_des", paySendRedpackResult.getErrCodeDes());
        if (PayConstant.RETURN_VALUE_SUCCESS.equals(paySendRedpackResult.getReturnCode()) && PayConstant.RETURN_VALUE_SUCCESS.equals(paySendRedpackResult.getResultCode())) {
            paySendRedpack.setWxTotalAmount(paySendRedpackResult.getTotalAmount());
            paySendRedpack.setSendListid(paySendRedpackResult.getSendListid());
            paySendRedpack.setSendTime(paySendRedpackResult.getSendTime());
            returnMap.put("total_amount", paySendRedpackResult.getTotalAmount());
            returnMap.put("send_listid", paySendRedpackResult.getSendListid());
            returnMap.put("send_time", paySendRedpackResult.getSendTime());
            log.info(logPrefix + "响应:" + JSON.toJSONString(returnMap));
            log.info(logPrefix + "结果:" + PayConstant.RETURN_VALUE_SUCCESS);
        } else {
            log.info(logPrefix + "响应:" + JSON.toJSONString(returnMap));
            log.info(logPrefix + "结果:" + PayConstant.RETURN_VALUE_FAIL);
        }
        // 保存 发送明细数据入库
        paySendRedpackRepository.saveAndFlush(paySendRedpack);
        return new R<Map<String, Object>>().data(PayUtil.makeRetData(returnMap, resKey)).success();
    } catch (WxPayException e) {
        e.printStackTrace();
        return new R<Map<String, Object>>().data(PayUtil.makeRetData(returnMap, resKey)).failure(logPrefix + "请求异常:" + e.toString());
    }
}
Also used : WxPayService(com.github.binarywang.wxpay.service.WxPayService) WxPaySendRedpackResult(com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult) R(com.github.liuweijw.commons.base.R) HashMap(java.util.HashMap) WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) WxPayException(com.github.binarywang.wxpay.exception.WxPayException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with R

use of com.github.liuweijw.commons.base.R in project fw-cloud-framework by liuweijw.

the class WxUnifiedOrderServiceImpl method doWxUnifiedOrderRequest.

@Override
public R<Map<String, Object>> doWxUnifiedOrderRequest(String tradeType, PayOrder payOrder, Map<String, String> params) {
    try {
        String logPrefix = "【微信支付统一下单】";
        if (null == payOrder || null == params || StringHelper.isBlank(tradeType) || StringHelper.isBlank(params.get("resKey")) || StringHelper.isBlank(params.get("channelParam")))
            return new R<Map<String, Object>>().data(PayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001)).failure();
        String resKey = params.get("resKey");
        WxPayConfig wxPayConfig = WxPayUtil.getWxPayConfig(params.get("channelParam"), tradeType, wxPayProperties.getCertRootPath(), wxPayProperties.getNotifyUrl());
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxPayConfig);
        WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = buildUnifiedOrderRequest(payOrder, wxPayConfig);
        String payOrderId = payOrder.getPayOrderId();
        WxPayUnifiedOrderResult wxPayUnifiedOrderResult = null;
        try {
            wxPayUnifiedOrderResult = wxPayService.unifiedOrder(wxPayUnifiedOrderRequest);
            log.info("{} >>> 下单成功", logPrefix);
            Map<String, Object> map = PayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
            map.put("payOrderId", payOrderId);
            map.put("prepayId", wxPayUnifiedOrderResult.getPrepayId());
            boolean result = payOrderService.updatePayOrderStatus4Paying(payOrderId, wxPayUnifiedOrderResult.getPrepayId());
            log.info("更新第三方支付订单号:payOrderId={},prepayId={},result={}", payOrderId, wxPayUnifiedOrderResult.getPrepayId(), result);
            switch(tradeType) {
                case PayConstant.WxConstant.TRADE_TYPE_NATIVE:
                    {
                        // 二维码支付链接
                        map.put("codeUrl", wxPayUnifiedOrderResult.getCodeURL());
                        break;
                    }
                case PayConstant.WxConstant.TRADE_TYPE_APP:
                    {
                        Map<String, String> payInfo = new HashMap<>();
                        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
                        String nonceStr = String.valueOf(System.currentTimeMillis());
                        // APP支付绑定的是微信开放平台上的账号,APPID为开放平台上绑定APP后发放的参数
                        String appId = wxPayConfig.getAppId();
                        Map<String, String> configMap = new HashMap<>();
                        // 此map用于参与调起sdk支付的二次签名,格式全小写,timestamp只能是10位,格式固定,切勿修改
                        String partnerId = wxPayConfig.getMchId();
                        configMap.put("prepayid", wxPayUnifiedOrderResult.getPrepayId());
                        configMap.put("partnerid", partnerId);
                        String packageValue = "Sign=WXPay";
                        configMap.put("package", packageValue);
                        configMap.put("timestamp", timestamp);
                        configMap.put("noncestr", nonceStr);
                        configMap.put("appid", appId);
                        // 此map用于客户端与微信服务器交互
                        payInfo.put("sign", SignUtils.createSign(configMap, null, wxPayConfig.getMchKey(), new String[0]));
                        payInfo.put("prepayId", wxPayUnifiedOrderResult.getPrepayId());
                        payInfo.put("partnerId", partnerId);
                        payInfo.put("appId", appId);
                        payInfo.put("packageValue", packageValue);
                        payInfo.put("timeStamp", timestamp);
                        payInfo.put("nonceStr", nonceStr);
                        map.put("payParams", payInfo);
                        break;
                    }
                case PayConstant.WxConstant.TRADE_TYPE_JSPAI:
                    {
                        Map<String, String> payInfo = new HashMap<>();
                        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
                        String nonceStr = String.valueOf(System.currentTimeMillis());
                        payInfo.put("appId", wxPayUnifiedOrderResult.getAppid());
                        // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                        payInfo.put("timeStamp", timestamp);
                        payInfo.put("nonceStr", nonceStr);
                        payInfo.put("package", "prepay_id=" + wxPayUnifiedOrderResult.getPrepayId());
                        payInfo.put("signType", WxPayConstants.SignType.MD5);
                        payInfo.put("paySign", SignUtils.createSign(payInfo, null, wxPayConfig.getMchKey(), new String[0]));
                        map.put("payParams", payInfo);
                        break;
                    }
                case PayConstant.WxConstant.TRADE_TYPE_MWEB:
                    {
                        // h5支付链接地址
                        map.put("payUrl", wxPayUnifiedOrderResult.getMwebUrl());
                        break;
                    }
            }
            return new R<Map<String, Object>>().data(PayUtil.makeRetData(map, resKey)).success();
        } catch (WxPayException e) {
            log.error(e + "下单失败");
            // 出现业务错误
            log.info("{}下单返回失败", logPrefix);
            log.info("err_code:{}", e.getErrCode());
            log.info("err_code_des:{}", e.getErrCodeDes());
            return new R<Map<String, Object>>().data(PayUtil.makeRetData(PayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_FAIL, "0111", "调用微信支付失败," + e.getErrCode() + ":" + e.getErrCodeDes()), resKey)).failure();
        }
    } catch (Exception e) {
        log.error("微信支付统一下单异常" + e);
        return new R<Map<String, Object>>().data(PayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001)).failure();
    }
}
Also used : WxPayUnifiedOrderResult(com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult) WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) WxPayException(com.github.binarywang.wxpay.exception.WxPayException) WxPayUnifiedOrderRequest(com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest) WxPayException(com.github.binarywang.wxpay.exception.WxPayException) WxPayService(com.github.binarywang.wxpay.service.WxPayService) R(com.github.liuweijw.commons.base.R) WxPayConfig(com.github.binarywang.wxpay.config.WxPayConfig) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with R

use of com.github.liuweijw.commons.base.R in project fw-cloud-framework by liuweijw.

the class RoleController method add.

@ApiOperation(value = "新增", notes = "角色", produces = "application/json")
@ApiImplicitParam(name = "role", value = "", required = true, dataType = "Role")
@RequestMapping(value = "/add", method = RequestMethod.POST)
@PrePermissions(value = Functional.ADD)
public R<Boolean> add(HttpServletRequest request, @RequestBody Role role) {
    if (null == role)
        return new R<Boolean>().failure("角色信息为空");
    // 检测权限编码是否存在
    Role exRole = roleService.findRoleByCode(role.getRoleCode());
    if (null != exRole)
        return new R<Boolean>().failure("权限编码已经存在!").data(false);
    if (null == role.getDeptId())
        return new R<Boolean>().failure("请选择角色所属部门");
    role.setCreateTime(new Date());
    role.setUpdateTime(new Date());
    role.setStatu(0);
    Role updateObj = roleService.saveRoleAndDept(role);
    return new R<Boolean>().data(null != updateObj);
}
Also used : Role(com.github.liuweijw.business.admin.domain.Role) R(com.github.liuweijw.commons.base.R) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) PrePermissions(com.github.liuweijw.business.commons.web.aop.PrePermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with R

use of com.github.liuweijw.commons.base.R in project fw-cloud-framework by liuweijw.

the class MenuController method add.

@RequestMapping(value = "/add", method = RequestMethod.POST)
@PrePermissions(value = Functional.ADD)
public R<Boolean> add(HttpServletRequest request, @RequestBody Menu menu) {
    if (null == menu)
        return new R<Boolean>().failure("菜单信息为空");
    if (null == menu.getPid())
        return new R<Boolean>().failure("请选择菜单再点击进行新增");
    menu.setCreateTime(new Date());
    menu.setUpdateTime(new Date());
    menu.setStatu(0);
    Menu menuObj = menuService.saveOrUpdate(menu);
    return new R<Boolean>().data(null != menuObj);
}
Also used : R(com.github.liuweijw.commons.base.R) Menu(com.github.liuweijw.business.admin.domain.Menu) Date(java.util.Date) PrePermissions(com.github.liuweijw.business.commons.web.aop.PrePermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with R

use of com.github.liuweijw.commons.base.R in project fw-cloud-framework by liuweijw.

the class MenuController method upd.

@RequestMapping(value = "/upd", method = RequestMethod.POST)
@PrePermissions(value = Functional.UPD)
public R<Boolean> upd(HttpServletRequest request, @RequestBody Menu menu) {
    if (null == menu)
        return new R<Boolean>().failure("菜单信息为空");
    if (null == menu.getPid() || null == menu.getMenuId())
        return new R<Boolean>().failure("请选择菜单再点击进行修改");
    menu.setCreateTime(new Date());
    menu.setUpdateTime(new Date());
    menu.setStatu(0);
    Menu menuObj = menuService.saveOrUpdate(menu);
    return new R<Boolean>().data(null != menuObj);
}
Also used : R(com.github.liuweijw.commons.base.R) Menu(com.github.liuweijw.business.admin.domain.Menu) Date(java.util.Date) PrePermissions(com.github.liuweijw.business.commons.web.aop.PrePermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

R (com.github.liuweijw.commons.base.R)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 PrePermissions (com.github.liuweijw.business.commons.web.aop.PrePermissions)8 Date (java.util.Date)6 JSONObject (com.alibaba.fastjson.JSONObject)5 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3 WxPayConfig (com.github.binarywang.wxpay.config.WxPayConfig)2 WxPayException (com.github.binarywang.wxpay.exception.WxPayException)2 WxPayService (com.github.binarywang.wxpay.service.WxPayService)2 WxPayServiceImpl (com.github.binarywang.wxpay.service.impl.WxPayServiceImpl)2 Dept (com.github.liuweijw.business.admin.domain.Dept)2 Menu (com.github.liuweijw.business.admin.domain.Menu)2 Role (com.github.liuweijw.business.admin.domain.Role)2 PayChannel (com.github.liuweijw.business.pay.domain.PayChannel)2 PayMchInfo (com.github.liuweijw.business.pay.domain.PayMchInfo)2 AlipayClient (com.alipay.api.AlipayClient)1 DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)1