use of com.github.liuweijw.business.pay.domain.PayMchInfo in project fw-cloud-framework by liuweijw.
the class PaySendRedpackController method validateSendRedpackReqParams.
private R<Boolean> validateSendRedpackReqParams(PaySendRedpackReqBean sendRedpackReqBean, PaySendRedpack paySendRedpack, WxPaySendRedpackRequestBuilder wxPaySendRedpackRequestBuilder) {
if (null == sendRedpackReqBean)
return new R<Boolean>().data(false).failure("请求[/pay/order/sendRedpack]参数不能为空!");
// 是否是发放普通
boolean isCommonRedPack = sendRedpackReqBean.getRedPackType().intValue() == 0;
String preFix = isCommonRedPack ? "【发放普通红包】" : "【发放裂变红包】";
// 商户id
String mchId = sendRedpackReqBean.getMchId();
if (StringHelper.isBlank(mchId))
return new R<Boolean>().data(false).failure(preFix + "商户ID不存在!");
// 商户订单号
String mchOrderNo = sendRedpackReqBean.getMchOrderNo();
if (StringHelper.isBlank(mchOrderNo))
return new R<Boolean>().data(false).failure(preFix + "商户订单号不存在!");
// 渠道ID
String channelId = sendRedpackReqBean.getChannelId();
if (StringHelper.isBlank(channelId))
return new R<Boolean>().data(false).failure(preFix + "渠道ID不存在!");
// 红包发放总金额(单位分)
Integer amount = sendRedpackReqBean.getTotalAmount();
if (null == amount || amount <= 0)
return new R<Boolean>().data(false).failure(preFix + "红包发放总金额(单位分)不正确!");
if (amount < 100 || amount > 20000)
return new R<Boolean>().data(false).failure(preFix + "每个红包的平均金额必须在1.00元到200.00元之间!");
// 红包发放总人数
Integer totalNum = sendRedpackReqBean.getTotalNum();
if (null == totalNum || totalNum <= 0)
return new R<Boolean>().data(false).failure(preFix + "红包发放总人数设置不正确!");
// 红包祝福语
String wishing = sendRedpackReqBean.getWishing();
if (StringHelper.isBlank(wishing))
return new R<Boolean>().data(false).failure(preFix + "红包祝福语未设置!");
// ip
String ip = sendRedpackReqBean.getIp();
if (StringHelper.isBlank(ip))
return new R<Boolean>().data(false).failure(preFix + "请求IP地址不正确!");
// 活动名称
String actName = sendRedpackReqBean.getActName();
if (StringHelper.isBlank(actName))
return new R<Boolean>().data(false).failure(preFix + "活动名称未设置!");
// 备注
String remark = sendRedpackReqBean.getRemark();
if (StringHelper.isBlank(remark))
return new R<Boolean>().data(false).failure(preFix + "备注信息未设置!");
// 场景id
String sceneId = sendRedpackReqBean.getSceneId();
if (StringHelper.isBlank(sceneId) || !checkSceneId(sceneId))
return new R<Boolean>().data(false).failure(preFix + "场景id不正确!");
// 签名信息
String sign = sendRedpackReqBean.getSign();
if (StringHelper.isBlank(sign))
return new R<Boolean>().data(false).failure(preFix + "未签名!");
// 查询商户信息
PayMchInfo mchInfo = mchInfoService.findMchInfoByMchId(mchId);
if (null == mchInfo)
return new R<Boolean>().data(false).failure(preFix + "商户信息不存在!");
if (mchInfo.getStatu().intValue() != 1)
return new R<Boolean>().data(false).failure(preFix + "商户信息已失效!");
if (StringHelper.isBlank(mchInfo.getReqKey()))
return new R<Boolean>().data(false).failure(preFix + "商户请求私钥未设置!");
// 查询商户对应的支付渠道
PayChannel payChannel = payChannelService.findPayChannel(channelId, mchId);
if (null == payChannel)
return new R<Boolean>().data(false).failure(preFix + "商户渠道[channelId=" + channelId + ",mchId=" + mchId + "]信息不存在!");
if (payChannel.getStatu().intValue() != 1)
return new R<Boolean>().data(false).failure(preFix + "商户渠道[channelId=" + channelId + ",mchId=" + mchId + "]信息已经失效!");
WxPayConfig wxPayConfig = WxPayUtil.getWxPayConfig(payChannel.getParam(), null, wxPayProperties.getCertRootPath(), wxPayProperties.getNotifyUrl());
if (null == wxPayConfig)
return new R<Boolean>().data(false).failure(preFix + "商户渠道[channelId=" + channelId + ",mchId=" + mchId + "]信息param设置不正确!");
// 验证签名数据
boolean verifyFlag = PayUtil.verifyPaySign((JSONObject) JSON.toJSON(sendRedpackReqBean), mchInfo.getReqKey());
if (!verifyFlag)
return new R<Boolean>().data(false).failure(preFix + "验证签名失败!");
paySendRedpack.setSendOrderId(SequenceUtils.getInstance().generateBizSeqNo("SRP"));
paySendRedpack.setWxPayConfig(wxPayConfig);
paySendRedpack.setResKey(mchInfo.getResKey());
paySendRedpack.setRedPackType(isCommonRedPack ? 0 : 1);
paySendRedpack.setChannelId(channelId);
// 商户订单号
paySendRedpack.setMchOrderNo(mchOrderNo);
// 商户号
paySendRedpack.setMchId(wxPayConfig.getMchId());
paySendRedpack.setOpenId(sendRedpackReqBean.getOpenId());
// 付款金额
paySendRedpack.setTotalAmount(sendRedpackReqBean.getTotalAmount());
// 红包发放总人数
paySendRedpack.setTotalNum(sendRedpackReqBean.getTotalNum());
if (!isCommonRedPack) {
// 红包金额设置方式 裂变红包才进行设置
paySendRedpack.setAmtType("ALL_RAND");
} else {
paySendRedpack.setAmtType(null);
}
// 红包祝福语
paySendRedpack.setWishing(sendRedpackReqBean.getWishing());
paySendRedpack.setIp(ip);
// 活动名称
paySendRedpack.setActName(sendRedpackReqBean.getActName());
// 备注
paySendRedpack.setRemark(sendRedpackReqBean.getRemark());
// 场景id
paySendRedpack.setSceneId(sceneId);
if (!PublicHelper.isEmpty(sendRedpackReqBean.getRiskInfo()))
// 活动信息
paySendRedpack.setRiskInfo(sendRedpackReqBean.getRiskInfo());
if (!PublicHelper.isEmpty(sendRedpackReqBean.getConsumeMchId()))
// 资金授权商户号
paySendRedpack.setConsumeMchId(sendRedpackReqBean.getConsumeMchId());
wxPaySendRedpackRequestBuilder.mchBillNo(paySendRedpack.getMchOrderNo()).wxAppid(wxPayConfig.getAppId()).sendName(// 商户名称 来自商户数据库
mchInfo.getMchName()).reOpenid(paySendRedpack.getOpenId()).totalAmount(paySendRedpack.getTotalAmount()).totalNum(paySendRedpack.getTotalNum()).amtType(paySendRedpack.getAmtType()).wishing(paySendRedpack.getWishing()).clientIp(paySendRedpack.getIp()).actName(paySendRedpack.getActName()).remark(paySendRedpack.getRemark()).sceneId(paySendRedpack.getSceneId()).riskInfo(paySendRedpack.getRiskInfo()).consumeMchId(paySendRedpack.getConsumeMchId()).build();
return new R<Boolean>().data(true).success(preFix + "信息验证成功!");
}
use of com.github.liuweijw.business.pay.domain.PayMchInfo in project fw-cloud-framework by liuweijw.
the class PayOrderController method validatePayOrderParams.
private R<Boolean> validatePayOrderParams(PayUnifiedOrder unifiedOrder, PayOrder payOrder, Map<String, String> params) {
String preFix = "[统一下单提示] ";
if (null == unifiedOrder)
return new R<Boolean>().data(false).failure(preFix + "下单信息不能为空!");
// 商户id
String mchId = unifiedOrder.getMchId();
if (StringHelper.isBlank(mchId))
return new R<Boolean>().data(false).failure(preFix + "商户ID不存在!");
// 商户订单号
String mchOrderNo = unifiedOrder.getMchOrderNo();
if (StringHelper.isBlank(mchOrderNo))
return new R<Boolean>().data(false).failure(preFix + "商户订单号不存在!");
// 渠道ID
String channelId = unifiedOrder.getChannelId();
if (StringHelper.isBlank(channelId))
return new R<Boolean>().data(false).failure(preFix + "渠道ID不存在!");
// 支付金额(单位分)
Long amount = unifiedOrder.getAmount();
if (null == amount || amount <= 0)
return new R<Boolean>().data(false).failure(preFix + "支付金额(单位分)不正确!");
// 币种
String currency = unifiedOrder.getCurrency();
if (StringHelper.isBlank(currency))
return new R<Boolean>().data(false).failure(preFix + "币种未设置!");
// 支付结果回调URL
String notifyUrl = unifiedOrder.getNotifyUrl();
if (StringHelper.isBlank(notifyUrl))
return new R<Boolean>().data(false).failure(preFix + "支付回调未设置!");
// 商品主题
String subject = unifiedOrder.getSubject();
if (StringHelper.isBlank(subject))
return new R<Boolean>().data(false).failure(preFix + "商品主题未设置!");
// 商品描述信息
String body = unifiedOrder.getBody();
if (StringHelper.isBlank(body))
return new R<Boolean>().data(false).failure(preFix + "商品描述信息未设置!");
// ip
String ip = unifiedOrder.getIp();
if (StringHelper.isBlank(ip))
return new R<Boolean>().data(false).failure(preFix + "请求IP地址不正确!");
String device = unifiedOrder.getDevice();
if (StringHelper.isBlank(device))
return new R<Boolean>().data(false).failure(preFix + "请求设备信息设置不正确!");
String extra = unifiedOrder.getExtra();
// 根据不同渠道,判断extra参数
if (PayConstant.PAY_CHANNEL_WX_JSAPI.equalsIgnoreCase(channelId)) {
if (StringHelper.isBlank(extra))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra]信息未设置!");
JSONObject extraObject = JSON.parseObject(extra);
if (null == extraObject || !extraObject.containsKey("openId"))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra.openId]信息未设置!");
String openId = extraObject.getString("openId");
if (StringHelper.isBlank(openId))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra.openId]信息未正确设置!");
} else if (PayConstant.PAY_CHANNEL_WX_NATIVE.equalsIgnoreCase(channelId)) {
if (StringHelper.isBlank(extra))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra]信息未设置!");
JSONObject extraObject = JSON.parseObject(extra);
if (null == extraObject || !extraObject.containsKey("productId"))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra.productId]信息未设置!");
String productId = extraObject.getString("productId");
if (StringHelper.isBlank(productId))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra.productId]信息未正确设置!");
} else if (PayConstant.PAY_CHANNEL_WX_MWEB.equalsIgnoreCase(channelId)) {
if (StringHelper.isBlank(extra))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra]信息未设置!");
JSONObject extraObject = JSON.parseObject(WebUtils.buildURLDecoder(extra));
if (null == extraObject || !extraObject.containsKey("sceneInfo"))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra.sceneInfo]信息未设置!");
String sceneInfo = extraObject.getJSONObject("sceneInfo").toJSONString();
if (StringHelper.isBlank(sceneInfo))
return new R<Boolean>().data(false).failure(preFix + channelId + "[extra.sceneInfo]信息未正确设置!");
}
// 签名信息
String sign = unifiedOrder.getSign();
if (StringHelper.isBlank(sign))
return new R<Boolean>().data(false).failure(preFix + "未签名!");
// 查询商户信息
PayMchInfo mchInfo = mchInfoService.findMchInfoByMchId(mchId);
if (null == mchInfo)
return new R<Boolean>().data(false).failure(preFix + "商户信息不存在!");
if (mchInfo.getStatu().intValue() != 1)
return new R<Boolean>().data(false).failure(preFix + "商户信息已失效!");
if (StringHelper.isBlank(mchInfo.getReqKey()))
return new R<Boolean>().data(false).failure(preFix + "商户请求私钥未设置!");
// 查询商户对应的支付渠道
PayChannel payChannel = payChannelService.findPayChannel(channelId, mchId);
if (null == payChannel)
return new R<Boolean>().data(false).failure(preFix + "商户渠道[channelId=" + channelId + ",mchId=" + mchId + "]信息不存在!");
if (payChannel.getStatu().intValue() != 1)
return new R<Boolean>().data(false).failure(preFix + "商户渠道[channelId=" + channelId + ",mchId=" + mchId + "]信息已经失效!");
// 验证签名数据
boolean verifyFlag = PayUtil.verifyPaySign((JSONObject) JSON.toJSON(unifiedOrder), mchInfo.getReqKey());
if (!verifyFlag)
return new R<Boolean>().data(false).failure(preFix + "下单信息验证签名失败!");
payOrder.setPayOrderId(SequenceUtils.getInstance().generateBizSeqNo(BizConstant.PAY_ORDER_PREFIX));
payOrder.setMch_id(mchInfo.getMchId());
payOrder.setMchOrderNo(mchOrderNo);
payOrder.setChannelId(channelId);
payOrder.setAmount(amount);
payOrder.setCurrency(currency);
payOrder.setIp(ip);
payOrder.setDevice(device);
payOrder.setSubject(WebUtils.buildURLDecoder(subject));
payOrder.setBody(WebUtils.buildURLDecoder(body));
payOrder.setExtra(extra);
payOrder.setChannelMchId(payChannel.getChannelMchId());
payOrder.setParam1(unifiedOrder.getParam1());
payOrder.setParam2(unifiedOrder.getParam2());
payOrder.setNotifyUrl(notifyUrl);
params.put("resKey", mchInfo.getResKey());
params.put("channelParam", payChannel.getParam());
// 支付宝支付回调业务地址--非必填
params.put("returnUrl", unifiedOrder.getReturnUrl());
return new R<Boolean>().data(true).success(preFix + "下单信息验证成功!");
}
use of com.github.liuweijw.business.pay.domain.PayMchInfo in project fw-cloud-framework by liuweijw.
the class NotifyServiceImpl method buildNotifyUrl.
private String buildNotifyUrl(PayOrder payOrder) {
String mchId = payOrder.getMch_id();
PayMchInfo mchInfo = mchInfoService.findMchInfoByMchId(mchId);
String resKey = mchInfo.getResKey();
NotifyReqBean notifyReqBean = new NotifyReqBean();
// 支付订单号
notifyReqBean.setPayOrderId(payOrder.getPayOrderId());
// 商户ID
notifyReqBean.setMchId(payOrder.getMch_id());
// 商户订单号
notifyReqBean.setMchOrderNo(payOrder.getMchOrderNo());
// 渠道ID
notifyReqBean.setChannelId(payOrder.getChannelId());
// 支付金额
notifyReqBean.setAmount(payOrder.getAmount());
// 货币类型
notifyReqBean.setCurrency(payOrder.getCurrency());
// 支付状态
notifyReqBean.setStatus(payOrder.getStatus());
// 客户端IP
notifyReqBean.setIp(payOrder.getIp());
// 设备
notifyReqBean.setDevice(WebUtils.buildURLEncoder(payOrder.getDevice()));
// 商品标题
notifyReqBean.setSubject(WebUtils.buildURLEncoder(payOrder.getSubject()));
// 渠道订单号
notifyReqBean.setChannelOrderNo(payOrder.getChannelOrderNo());
// 扩展参数1
notifyReqBean.setParam1(WebUtils.buildURLEncoder(payOrder.getParam1()));
// 扩展参数2
notifyReqBean.setParam2(WebUtils.buildURLEncoder(payOrder.getParam2()));
// 支付成功时间
notifyReqBean.setPaySuccTime(payOrder.getPaySuccTime());
// backType 1:前台页面;2:后台接口
notifyReqBean.setBackType("2");
JSONObject jsonObj = (JSONObject) JSON.toJSON(notifyReqBean);
// 先对原文签名
String reqSign = PayDigestUtil.getSign(jsonObj, resKey);
// 签名
jsonObj.put("sign", reqSign);
String param = PayUtil.buildUrlParams(jsonObj);
StringBuffer sb = new StringBuffer();
sb.append(payOrder.getNotifyUrl()).append("?").append(param);
log.info("notifyUrl:" + sb);
return sb.toString();
}
Aggregations