use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl 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());
}
}
use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl 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();
}
}
use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project litemall by linlinjava.
the class WxPayConfiguration method wxPayService.
@Bean
public // @ConditionalOnMissingBean
WxPayService wxPayService(WxPayConfig payConfig) {
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
return wxPayService;
}
use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project weixin-java-pay-demo by binarywang.
the class WxPayConfiguration method wxService.
@Bean
@ConditionalOnMissingBean
public WxPayService wxService() {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId()));
payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(false);
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
return wxPayService;
}
Aggregations