use of com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest 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.request.WxPayUnifiedOrderRequest in project summer by foxsugar.
the class WechatPayController method pay.
@ResponseBody
@RequestMapping(value = "preOrder")
public AgentResponse pay(HttpServletRequest request) throws Exception {
int money = Integer.valueOf(request.getParameter("money"));
int chargeType = Integer.valueOf(request.getParameter("chargeType"));
Map<String, String> agent = WechatAction.getAgentByToken(request);
if (agent == null)
return new AgentResponse().setCode(1000);
// todo 实现
String openId = agent.get("openId");
long userId = Long.valueOf(agent.get("agentId"));
String ip = Utils.getIpAddr(request);
// 元转成分
Integer moneyPoint = getMoneyPoint(money, chargeType);
logger.info("充值金额: " + money);
if (moneyPoint == null)
return new AgentResponse().setCode(13);
logger.info("增加钱数: " + moneyPoint);
AgentResponse agentResponse = new AgentResponse();
int totalFee = money * 100;
String orderId = "" + createOrderId();
try {
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
orderRequest.setBody("充值");
orderRequest.setOutTradeNo(orderId);
// 元转成分
orderRequest.setTotalFee(totalFee);
orderRequest.setOpenid(openId);
orderRequest.setSpbillCreateIp(ip);
// orderRequest.setTimeStart("yyyyMMddHHmmss");
// orderRequest.setTimeExpire("yyyyMMddHHmmss");
orderRequest.setTradeType("JSAPI");
// notify 地址
String url = "http://" + serverConfig.getDomain() + "/game/wechat/pay/pay";
orderRequest.setNotifyUrl(url);
// 创建订单
agentResponse.data = wxPayService.createOrder(orderRequest);
// 充值记录
Charge charge = new Charge();
charge.setOrderId(orderId);
charge.setUserid(userId);
charge.setMoney(money);
charge.setMoney_point(moneyPoint);
// charge.setOrigin(origin);
charge.setStatus(0);
// charge.setSign(paySign);
charge.setSp_ip(ip);
charge.setRecharge_source("1");
// 充值类型
charge.setChargeType(chargeType);
charge.setCreatetime(new Date());
chargeService.save(charge);
return agentResponse;
} catch (Exception e) {
logger.error("微信支付失败!订单号:{},原因:{}", orderId, e.getMessage());
agentResponse.code = 12;
return agentResponse;
}
}
use of com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest 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.bean.request.WxPayUnifiedOrderRequest in project summer by foxsugar.
the class WechatPayController method pay_app.
@ResponseBody
@RequestMapping(value = "preOrderApp1")
public Map<String, Object> pay_app(HttpServletRequest request) throws Exception {
int money = Integer.valueOf(request.getParameter("money"));
int chargeType = Integer.valueOf(request.getParameter("chargeType"));
long userId = Long.valueOf(request.getParameter("userId"));
String ip = request.getParameter("spIp");
// String ip = getIpAddr(request);
// 元转成分
Integer moneyPoint = getMoneyPoint(money, chargeType);
logger.info("充值金额: " + money);
// if (moneyPoint == null) return new AgentResponse().setCode(13);
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
if (moneyPoint == null) {
result.put("code", 10);
result.put("params", "参数错误");
return result;
}
logger.info("增加钱数: " + moneyPoint);
AgentResponse agentResponse = new AgentResponse();
int totalFee = money * 100;
String orderId = "" + createOrderId();
try {
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
orderRequest.setBody("充值");
orderRequest.setOutTradeNo(orderId);
// 元转成分
orderRequest.setTotalFee(totalFee);
// orderRequest.setOpenid(openId);
orderRequest.setSpbillCreateIp(ip);
// orderRequest.setTimeStart("yyyyMMddHHmmss");
// orderRequest.setTimeExpire("yyyyMMddHHmmss");
orderRequest.setTradeType("APP");
// notify 地址
String url = "http://" + serverConfig.getDomain() + "/game/wechat/pay/payApp";
orderRequest.setNotifyUrl(url);
// 创建订单
Object rtn = wxAppPayService.createOrder(orderRequest);
WxPayAppOrderResult orderResult = wxAppPayService.createOrder(orderRequest);
Map<String, Object> o = new HashMap<>();
o.put("appid", orderResult.getAppId());
o.put("partnerid", orderResult.getPartnerId());
o.put("prepayid", orderResult.getPrepayId());
o.put("noncestr", orderResult.getNonceStr());
o.put("timestamp", orderResult.getTimeStamp());
o.put("package", "Sign=WXPay");
o.put("sign", orderRequest.getSign());
result.put("params", o);
// 充值记录
Charge charge = new Charge();
charge.setOrderId(orderId);
charge.setUserid(userId);
charge.setMoney(money);
charge.setMoney_point(moneyPoint);
// charge.setOrigin(origin);
charge.setStatus(0);
// charge.setSign(paySign);
charge.setSp_ip(ip);
charge.setRecharge_source("1");
// 充值类型
charge.setChargeType(chargeType);
charge.setCreatetime(new Date());
chargeService.save(charge);
return result;
} catch (Exception e) {
logger.error("微信支付失败!订单号:{},原因:{}", orderId, e.getMessage());
agentResponse.code = 12;
result.put("code", 12);
return result;
}
}
use of com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest in project fw-cloud-framework by liuweijw.
the class WxUnifiedOrderServiceImpl method buildUnifiedOrderRequest.
/**
* 构建微信统一下单请求数据
*/
private WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, WxPayConfig wxPayConfig) {
String tradeType = wxPayConfig.getTradeType();
String payOrderId = payOrder.getPayOrderId();
// 支付金额,单位分
Integer totalFee = payOrder.getAmount().intValue();
String deviceInfo = payOrder.getDevice();
String body = payOrder.getBody();
String detail = null;
String attach = null;
String outTradeNo = payOrderId;
String feeType = "CNY";
String spBillCreateIP = payOrder.getIp();
String timeStart = null;
String timeExpire = null;
String goodsTag = null;
String notifyUrl = wxPayConfig.getNotifyUrl();
String productId = null;
if (tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_NATIVE))
productId = JSON.parseObject(payOrder.getExtra()).getString("productId");
String limitPay = null;
String openId = null;
if (tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_JSPAI))
openId = JSON.parseObject(payOrder.getExtra()).getString("openId");
String sceneInfo = null;
if (tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_MWEB)) {
JSONObject extraObject = JSON.parseObject(WebUtils.buildURLDecoder(payOrder.getExtra()));
sceneInfo = extraObject.getJSONObject("sceneInfo").toJSONString();
}
// 微信统一下单请求对象
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
request.setDeviceInfo(deviceInfo);
request.setBody(body);
request.setDetail(detail);
request.setAttach(attach);
request.setOutTradeNo(outTradeNo);
request.setFeeType(feeType);
request.setTotalFee(totalFee);
request.setSpbillCreateIp(spBillCreateIP);
request.setTimeStart(timeStart);
request.setTimeExpire(timeExpire);
request.setGoodsTag(goodsTag);
request.setNotifyUrl(notifyUrl);
request.setTradeType(tradeType);
request.setProductId(productId);
request.setLimitPay(limitPay);
request.setOpenid(openId);
request.setSceneInfo(sceneInfo);
return request;
}
Aggregations