| | |
| | | |
| | | //代付二 |
| | | private ServerResponse getObjectServerResponseTwo(Integer withId, HttpServletRequest request, HttpServletResponse response, UserWithdraw userWithdraw, User user, UserAssets userAssets) throws Exception { |
| | | String payoutUrl = "https://api.watchglb.com/pay/transfer"; |
| | | String mchId = "100789033"; |
| | | String key = "CZ5Q6NNI6D9YTCXZAIWIC8SAQCC35UZR"; |
| | | String backUrl = "https://api.nalandacapital.mom/user/payoutCallback.do"; |
| | | |
| | | String payoutUrl = "https://gateway.kings-pays.com/gateway/payout/init";//正式地址 |
| | | String merchantKey = "qqaC1DH/LeR9iPvm";//商户key 需替换 |
| | | String aesKey = "ge6vK40fHNZPFJ4p";//商户aesKey 需替换 |
| | | String aesIv = "6gJoHTEE1i2O3ovE";//商户aesIv 需替换 |
| | | String bankCode = StringUtils.defaultIfBlank(userWithdraw.getBankAddress(), "").trim(); |
| | | String receiveAccount = StringUtils.defaultIfBlank(userWithdraw.getBankNo(), "").trim(); |
| | | String receiveName = StringUtils.defaultIfBlank(userWithdraw.getWithName(), user.getRealName()); |
| | | receiveName = StringUtils.defaultIfBlank(receiveName, user.getNickName()); |
| | | |
| | | // 1. 生成商户订单号 |
| | | String merchantOrderNo = generatePayoutOrderId(withId); |
| | | |
| | | // 2. 构建加密前的业务参数 |
| | | JSONObject dataObj = new JSONObject(); |
| | | dataObj.put("amount", userWithdraw.getWithAmt().intValue()); // 注意金额单位(示例中为整数) |
| | | dataObj.put("transferType", "BANK_TRANSFER"); |
| | | dataObj.put("beneficiaryName", user.getNickName()); |
| | | dataObj.put("beneficiaryEmail", "null@gmail.com"); |
| | | dataObj.put("beneficiaryPhoneNo", user.getPhone()); |
| | | dataObj.put("beneficiaryAccount", userWithdraw.getBankNo()); |
| | | dataObj.put("beneficiaryIFSC", userWithdraw.getBankAddress()); |
| | | dataObj.put("merchantOrderNo", merchantOrderNo); |
| | | dataObj.put("notifyUrl", "https://api.greenbackcaps.top/user/payoutCallbackTwo.do"); |
| | | |
| | | // 3. AES 加密 |
| | | String encryptedData = AesEncryptUtil.encrypt(dataObj.toJSONString(), aesKey, aesIv); |
| | | JSONObject requestObj = new JSONObject(); |
| | | requestObj.put("data", encryptedData); |
| | | |
| | | // 4. 设置请求头 |
| | | Headers headers = new Headers.Builder() |
| | | .add("merchant_key", merchantKey) |
| | | .build(); |
| | | |
| | | // 5. 发送 HTTP 请求 |
| | | log.info("代付请求参数:{}", requestObj.toJSONString()); |
| | | String respStr = doPost(payoutUrl, requestObj.toJSONString(), headers); |
| | | log.info("代付响应原始数据:{}", respStr); |
| | | |
| | | // 6. 解析响应(使用 Jackson 或 fastjson,这里以 fastjson 为例) |
| | | JSONObject respJson = JSONObject.parseObject(respStr); |
| | | int code = respJson.getIntValue("code"); |
| | | boolean success = respJson.getBooleanValue("success"); |
| | | String msg = respJson.getString("msg"); |
| | | |
| | | // 6.1 接口调用失败(code != 0 或 success = false) |
| | | if (code != 0 || !success) { |
| | | handleFailure(userAssets, userWithdraw, "Failure? Please contact customer service."); |
| | | return ServerResponse.createByErrorMsg("代付请求失败:" + msg, request); |
| | | if (StringUtils.isBlank(bankCode) || StringUtils.isBlank(receiveAccount) || StringUtils.isBlank(receiveName)) { |
| | | handleFailure(userAssets, userWithdraw, "Withdrawal failed:bank information incomplete"); |
| | | return ServerResponse.createByErrorMsg("Incomplete bank card information", request); |
| | | } |
| | | if (userWithdraw.getWithAmt().stripTrailingZeros().scale() > 0) { |
| | | handleFailure(userAssets, userWithdraw, "Withdrawal failed:amount must be integer yuan"); |
| | | return ServerResponse.createByErrorMsg("The amount must be an integer ", request); |
| | | } |
| | | |
| | | // 6.2 获取 data 部分 |
| | | JSONObject data = respJson.getJSONObject("data"); |
| | | String status = data.getString("status"); // ACCEPT / FAILURE / PROCESSING |
| | | String failMsg = data.getString("message"); // 失败时的具体原因 |
| | | String merchantOrderNo = generatePayoutOrderId(withId); |
| | | String applyDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | String transferAmount = userWithdraw.getWithAmt().toBigInteger().toString(); |
| | | |
| | | // 7. 根据 status 判断业务是否成功 |
| | | if ("ACCEPT".equals(status)) { |
| | | // 代付订单被接受(不一定最终成功,需等待回调) |
| | | String platformOrderNo = data.getString("orderNo"); |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("sign_type", "MD5"); |
| | | params.put("mch_id", mchId); |
| | | params.put("mch_transferId", merchantOrderNo); |
| | | params.put("transfer_amount", transferAmount); |
| | | params.put("apply_date", applyDate); |
| | | params.put("bank_code", bankCode); |
| | | params.put("receive_name", receiveName); |
| | | params.put("receive_account", receiveAccount); |
| | | params.put("back_url", backUrl); |
| | | if (StringUtils.isNotBlank(user.getPhone())) { |
| | | params.put("receiver_telephone", user.getPhone().trim()); |
| | | } |
| | | |
| | | // 保存代付记录 |
| | | saveTransferRecord(merchantOrderNo, platformOrderNo, userWithdraw.getWithAmt(), user.getId(), withId); |
| | | Map<String, String> signParams = new TreeMap<>(); |
| | | for (Map.Entry<String, String> entry : params.entrySet()) { |
| | | if (!"sign".equals(entry.getKey()) && !"sign_type".equals(entry.getKey()) |
| | | && StringUtils.isNotBlank(entry.getValue())) { |
| | | signParams.put(entry.getKey(), entry.getValue()); |
| | | } |
| | | } |
| | | String sign = PaymentSignUtil.generateSign(signParams, key); |
| | | params.put("sign", sign); |
| | | |
| | | // 更新提现记录为“已提交” |
| | | userWithdraw.setWithStatus(4); // 4:已提交 |
| | | log.info("watchglb代付请求参数:{}", params); |
| | | String respStr = HttpClientUtil.doPost(payoutUrl, params, "utf-8"); |
| | | log.info("watchglb代付响应原始数据:{}", respStr); |
| | | |
| | | JSONObject respJson = JSONObject.parseObject(respStr); |
| | | String respCode = respJson.getString("respCode"); |
| | | String errorMsg = respJson.getString("errorMsg"); |
| | | if (!"SUCCESS".equalsIgnoreCase(respCode)) { |
| | | String failMsg = StringUtils.defaultIfBlank(errorMsg, "unknown"); |
| | | handleFailure(userAssets, userWithdraw, "Withdrawal failed:" + failMsg); |
| | | return ServerResponse.createByErrorMsg("" + failMsg, request); |
| | | } |
| | | |
| | | String platformOrderNo = StringUtils.defaultIfBlank(respJson.getString("tradeNo"), merchantOrderNo); |
| | | String respSign = respJson.getString("sign"); |
| | | saveTransferRecordV2(merchantOrderNo, platformOrderNo, userWithdraw.getWithAmt(), user.getId(), withId, respSign); |
| | | |
| | | userWithdraw.setWithStatus(4); |
| | | userWithdraw.setTransTime(new Date()); |
| | | userWithdrawMapper.updateByPrimaryKeySelective(userWithdraw); |
| | | |
| | | log.info("代付下单成功,商户订单号:{}", merchantOrderNo); |
| | | log.info("watchglb代付下单成功,商户订单号:{},平台订单号:{}", merchantOrderNo, platformOrderNo); |
| | | return ServerResponse.createBySuccessMsg("代付申请已提交,请等待处理"); |
| | | } else { |
| | | // 业务失败(如 FAILURE) |
| | | String errorMsg = (failMsg != null && !failMsg.isEmpty()) ? failMsg : msg; |
| | | handleFailure(userAssets, userWithdraw, "Withdrawal failed:" + errorMsg); |
| | | return ServerResponse.createByErrorMsg("Withdrawal failed:" + errorMsg, request); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | UserWithdraw userWithdraw, User user, UserAssets userAssets) throws Exception { |
| | | String merchantOrderNo = generatePayoutOrderId(withId); |
| | | BigDecimal amount = userWithdraw.getWithAmt().setScale(2, RoundingMode.HALF_UP); |
| | | String notifyUrl = "https://api.greenbackcaps.top/user/payoutCallbackThree.do"; |
| | | String notifyUrl = "https://api.nalandacapital.mom/user/payoutCallbackThree.do"; |
| | | |
| | | UserBank bank = userBankMapper.selectOne(new LambdaQueryWrapper<UserBank>() |
| | | .eq(UserBank::getUserId, user.getId()) |
| | |
| | | params.put("payout_mode", "INDIA_IMPS"); // 代付模式,根据实际情况选择 |
| | | params.put("customer_account_type", userWithdraw.getBankAddress()); // 账号类型 |
| | | params.put("customer_account_no", userWithdraw.getBankNo()); // 收款人账号(银行卡号或UPI ID) |
| | | params.put("notify_url", "https://api.greenbackcaps.top/user/payoutCallback.do"); // 异步通知地址 |
| | | params.put("notify_url", "https://api.nalandacapital.mom/user/payoutCallback.do"); // 异步通知地址 |
| | | |
| | | // 生成签名 |
| | | String sign = PaymentSignUtil.generateSign(params, key); |