use of com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult 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;
}
}
Aggregations