| | |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.pay.CmcPayOuterRequestUtil; |
| | | import com.nq.utils.pay.CmcPayTool; |
| | | import com.nq.utils.pay.OcocnPayUtil; |
| | | import com.nq.vo.pay.FlyPayVO; |
| | | import com.nq.vo.pay.GuoPayVO; |
| | | import com.nq.vo.pay.OcocnPayVO; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse ococnPay(String payType, String payAmt, HttpServletRequest request) { |
| | | if (StringUtils.isBlank(payType) || StringUtils.isBlank(payAmt)) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | | BigDecimal payAmtBig = new BigDecimal(payAmt); |
| | | if (payAmtBig.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return ServerResponse.createByErrorMsg("支付金额必须大于0"); |
| | | } |
| | | |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("请先登录"); |
| | | } |
| | | |
| | | String ordersn = KeyUtils.getRechargeOrderSn(); |
| | | String money = payAmtBig.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); |
| | | String pid = PropertiesUtil.getProperty("ococn.pay.pid"); |
| | | String key = PropertiesUtil.getProperty("ococn.pay.key"); |
| | | String submitUrl = PropertiesUtil.getProperty("ococn.pay.url"); |
| | | String apiDomain = trimTrailingSlash(PropertiesUtil.getProperty("website.domain.url")); |
| | | if (StringUtils.isAnyBlank(pid, key, submitUrl, apiDomain)) { |
| | | return ServerResponse.createByErrorMsg("支付配置不完整,请联系管理员"); |
| | | } |
| | | String notifyUrl = apiDomain + "/api/pay/ococnNotify.do"; |
| | | String returnUrl = apiDomain + "/api/pay/ococnReturn.do"; |
| | | String sitename = StringUtils.defaultString(PropertiesUtil.getProperty("ococn.pay.sitename", ""), ""); |
| | | String productName = PropertiesUtil.getProperty("ococn.pay.name", "账户充值"); |
| | | |
| | | UserRecharge userRecharge = new UserRecharge(); |
| | | userRecharge.setUserId(user.getId()); |
| | | userRecharge.setNickName(user.getRealName()); |
| | | userRecharge.setAgentId(user.getAgentId()); |
| | | userRecharge.setOrderSn(ordersn); |
| | | userRecharge.setPayChannel(getOcocnChannelName(payType)); |
| | | userRecharge.setPayAmt(payAmtBig); |
| | | userRecharge.setOrderStatus(Integer.valueOf(0)); |
| | | userRecharge.setAddTime(new Date()); |
| | | |
| | | int insertCount = this.userRechargeMapper.insert(userRecharge); |
| | | if (insertCount <= 0) { |
| | | return ServerResponse.createByErrorMsg("创建支付订单失败"); |
| | | } |
| | | |
| | | String sign = OcocnPayUtil.buildSubmitSign(money, productName, notifyUrl, ordersn, pid, returnUrl, sitename, payType, key); |
| | | log.info("ococn支付 notifyUrl={} returnUrl={}", notifyUrl, returnUrl); |
| | | StringBuilder payUrlBuilder = new StringBuilder(submitUrl).append("?"); |
| | | payUrlBuilder.append("pid=").append(pid) |
| | | .append("&type=").append(payType) |
| | | .append("&out_trade_no=").append(ordersn) |
| | | .append("¬ify_url=").append(OcocnPayUtil.encode(notifyUrl)) |
| | | .append("&return_url=").append(OcocnPayUtil.encode(returnUrl)) |
| | | .append("&name=").append(OcocnPayUtil.encode(productName)) |
| | | .append("&money=").append(money); |
| | | if (StringUtils.isNotBlank(sitename)) { |
| | | payUrlBuilder.append("&sitename=").append(OcocnPayUtil.encode(sitename)); |
| | | } |
| | | payUrlBuilder.append("&sign=").append(sign).append("&sign_type=MD5"); |
| | | String payUrl = payUrlBuilder.toString(); |
| | | |
| | | OcocnPayVO ococnPayVO = new OcocnPayVO(); |
| | | ococnPayVO.setPayUrl(payUrl); |
| | | log.info("ococn支付,创建订单成功 orderSn={}", ordersn); |
| | | return ServerResponse.createBySuccess(ococnPayVO); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse ococnNotify(HttpServletRequest request) { |
| | | Map<String, String> params = OcocnPayUtil.parseRequestParams(request); |
| | | log.info("ococn支付通知参数: {}", params); |
| | | |
| | | String outTradeNo = params.get("out_trade_no"); |
| | | String tradeNo = params.get("trade_no"); |
| | | String money = params.get("money"); |
| | | String tradeStatus = params.get("trade_status"); |
| | | String sign = params.get("sign"); |
| | | |
| | | if (StringUtils.isAnyBlank(outTradeNo, tradeNo, money, tradeStatus, sign)) { |
| | | return ServerResponse.createByErrorMsg("回调参数不完整"); |
| | | } |
| | | |
| | | String key = PropertiesUtil.getProperty("ococn.pay.key"); |
| | | if (!OcocnPayUtil.verifyNotifySign(params, key)) { |
| | | log.error("ococn支付通知签名校验失败, remoteSign={}, params={}", sign, params); |
| | | return ServerResponse.createByErrorMsg("签名校验失败"); |
| | | } |
| | | |
| | | if (!"TRADE_SUCCESS".equals(tradeStatus)) { |
| | | return ServerResponse.createByErrorMsg("支付未成功"); |
| | | } |
| | | |
| | | UserRecharge existing = this.userRechargeMapper.findUserRechargeByOrderSn(outTradeNo); |
| | | if (existing != null && existing.getOrderStatus().intValue() != 0) { |
| | | return ServerResponse.createBySuccessMsg("订单已处理"); |
| | | } |
| | | |
| | | return doSuccess(outTradeNo, money); |
| | | } |
| | | |
| | | @Override |
| | | public String ococnReturn(HttpServletRequest request) { |
| | | Map<String, String> params = OcocnPayUtil.parseRequestParams(request); |
| | | log.info("ococn支付同步跳转: {}", params); |
| | | String frontendUrl = StringUtils.defaultIfBlank( |
| | | PropertiesUtil.getProperty("ococn.pay.frontend_redirect"), |
| | | trimTrailingSlash(PropertiesUtil.getProperty("frontend.domain.url", "")) + "/#/user" |
| | | ); |
| | | return frontendUrl; |
| | | } |
| | | |
| | | private String getOcocnChannelName(String payType) { |
| | | if ("alipay".equals(payType)) { |
| | | return "支付宝-线上"; |
| | | } |
| | | if ("wxpay".equals(payType)) { |
| | | return "微信-线上"; |
| | | } |
| | | if ("qqpay".equals(payType)) { |
| | | return "QQ钱包-线上"; |
| | | } |
| | | if ("tenpay".equals(payType)) { |
| | | return "财付通-线上"; |
| | | } |
| | | return "线上支付"; |
| | | } |
| | | |
| | | private String trimTrailingSlash(String url) { |
| | | if (url == null) { |
| | | return null; |
| | | } |
| | | return url.endsWith("/") ? url.substring(0, url.length() - 1) : url; |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse juhenewpayNotify(HttpServletRequest request) throws UnsupportedEncodingException { |
| | | LinkedMap map = new LinkedMap(); |
| | | String out_trade_no = request.getParameter("out_trade_no"); |