use of com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult in project leopard by tanhaichao.
the class WeixinPayClientImpl method unifiedOrder.
@Override
public WxPayUnifiedOrderResult unifiedOrder(String orderNo, TradeType tradeType, double amount, String body, String detail, String notifyUrl, String spbillCreateIp) throws WxPayException {
// String paymentId = StringUtil.uuid();
// weixinPayDao.add(paymentId, orderNo);
// TODO
int totalFee = (int) DecimalUtil.multiply(amount, 100);
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
// 商户订单号
request.setOutTradeNo(orderNo);
// 订单总金额
request.setTotalFee(totalFee);
// TODO 商品ID
request.setProductId(orderNo);
// 商品描述
request.setBody(body);
// 商品详细介绍
request.setDetail(detail);
request.setNotifyURL(notifyUrl);
// JSAPI,NATIVE,APP
request.setTradeType(tradeType.getKey());
request.setSpbillCreateIp(spbillCreateIp);
WxPayUnifiedOrderResult result = wxPayService.unifiedOrder(request);
Json.print(result, "result");
// wxPayService.downloadBill(billDate, billType, tarType, deviceInfo);
return result;
}
use of com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult 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();
}
}
Aggregations