|
@@ -3,26 +3,15 @@ package modules.deposit;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jfinal.aop.Before;
|
|
import com.jfinal.aop.Before;
|
|
|
import com.jfinal.aop.Inject;
|
|
import com.jfinal.aop.Inject;
|
|
|
-import com.jfinal.json.Json;
|
|
|
|
|
-import com.jfinal.kit.HttpKit;
|
|
|
|
|
-import com.jfinal.kit.StrKit;
|
|
|
|
|
-import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
|
|
import common.interceptor.LoginInterceptor;
|
|
import common.interceptor.LoginInterceptor;
|
|
|
import common.interceptor.empty.EmptyInterface;
|
|
import common.interceptor.empty.EmptyInterface;
|
|
|
import common.interceptor.role.RequiredRoleInterface;
|
|
import common.interceptor.role.RequiredRoleInterface;
|
|
|
-import common.jfinal.AppConfig;
|
|
|
|
|
-import common.model.Deposit;
|
|
|
|
|
import common.model.User;
|
|
import common.model.User;
|
|
|
-import common.utils.IpAddressUtil;
|
|
|
|
|
import common.utils.http.MyController;
|
|
import common.utils.http.MyController;
|
|
|
import common.utils.http.MyRet;
|
|
import common.utils.http.MyRet;
|
|
|
-import common.utils.wechat.WeChatService;
|
|
|
|
|
import modules.user.UserController;
|
|
import modules.user.UserController;
|
|
|
import modules.user.UserService;
|
|
import modules.user.UserService;
|
|
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
public class DepositController extends MyController {
|
|
public class DepositController extends MyController {
|
|
|
@Inject
|
|
@Inject
|
|
|
DepositService service;
|
|
DepositService service;
|
|
@@ -33,134 +22,134 @@ public class DepositController extends MyController {
|
|
|
renderJson(MyRet.ok(service.hello()));
|
|
renderJson(MyRet.ok(service.hello()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 微信充值回调地址
|
|
|
|
|
- public void deposited() {
|
|
|
|
|
- String originalBody = HttpKit.readData(getRequest());
|
|
|
|
|
- AppConfig.LOGGER.info("wechat notify {}", originalBody);
|
|
|
|
|
-
|
|
|
|
|
- // 保证每条回调都保存到数据库
|
|
|
|
|
- Deposit deposit = new Deposit();
|
|
|
|
|
- deposit.setCreateTime(System.currentTimeMillis());
|
|
|
|
|
- deposit.setWxOriginal(originalBody);
|
|
|
|
|
- deposit.setIsDeleted(0);
|
|
|
|
|
-
|
|
|
|
|
- // 获取回调通知中的相关数据
|
|
|
|
|
- String wechatPaySerial = getRequest().getHeader("Wechatpay-Serial");
|
|
|
|
|
- String wechatpayNonce = getRequest().getHeader("Wechatpay-Nonce");
|
|
|
|
|
- String wechatSignature = getRequest().getHeader("Wechatpay-Signature");
|
|
|
|
|
- String wechatTimestamp = getRequest().getHeader("Wechatpay-Timestamp");
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- // 解析完成
|
|
|
|
|
- Transaction tx = WeChatService.parseTransaction(originalBody, wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp);
|
|
|
|
|
- Json json = Json.getJson();
|
|
|
|
|
- String txJson = json.toJson(tx);
|
|
|
|
|
-
|
|
|
|
|
- // 商户下单时传入的商户系统内部订单号。
|
|
|
|
|
- String orderNo = tx.getOutTradeNo();
|
|
|
|
|
- // 获取库中存放的tx
|
|
|
|
|
- Deposit dbDeposit = service.findDepositByWxOrderNo(orderNo);
|
|
|
|
|
- // 付款数量
|
|
|
|
|
- Integer paymentAmount = tx.getAmount().getTotal();
|
|
|
|
|
- // 状态描述
|
|
|
|
|
- String status = tx.getTradeState().toString();
|
|
|
|
|
-
|
|
|
|
|
- if (dbDeposit == null) {
|
|
|
|
|
- deposit.setWxDecrypted(txJson);
|
|
|
|
|
- deposit.setWxOrderStatus(status);
|
|
|
|
|
- deposit.setDescription("未提前入库的订单,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
- deposit.setAmount(paymentAmount);
|
|
|
|
|
- deposit.save();
|
|
|
|
|
-
|
|
|
|
|
- AppConfig.LOGGER.warn("未提前入库的订单 {}", deposit);
|
|
|
|
|
- } else {
|
|
|
|
|
- deposit = dbDeposit;
|
|
|
|
|
-
|
|
|
|
|
- // 记录解密后的信息
|
|
|
|
|
- deposit.setAmount(paymentAmount);
|
|
|
|
|
- deposit.setWxDecrypted(txJson);
|
|
|
|
|
-
|
|
|
|
|
- // 不要重复处理已存在的充值单号,并且要加款成功
|
|
|
|
|
- if (StrKit.isBlank(deposit.getWxOrderStatus())) {
|
|
|
|
|
- User user = userService.findUserById(deposit.getUserId() + "");
|
|
|
|
|
-
|
|
|
|
|
- // 记录订单状态
|
|
|
|
|
- deposit.setWxOrderStatus(tx.getTradeState().toString());
|
|
|
|
|
-
|
|
|
|
|
- // 有充值信息但是未找到充值者
|
|
|
|
|
- if (user == null) {
|
|
|
|
|
- deposit.setDescription("未找到充值者,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
- } else {
|
|
|
|
|
- // 判断订单状态
|
|
|
|
|
- if (tx.getTradeState() == Transaction.TradeStateEnum.SUCCESS) {
|
|
|
|
|
- // 如果充值成功,对用户进行充值
|
|
|
|
|
- user.setBalance(user.getBalance() + paymentAmount);
|
|
|
|
|
- user.update();
|
|
|
|
|
-
|
|
|
|
|
- deposit.setDescription("用户充值成功,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
- } else {
|
|
|
|
|
- deposit.setDescription("用户充值失败,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 充值记录入库
|
|
|
|
|
- deposit.update();
|
|
|
|
|
-
|
|
|
|
|
- AppConfig.LOGGER.info("入库成功 {}", deposit);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 成功入库后给微信的回调信息
|
|
|
|
|
- getResponse().setStatus(200);
|
|
|
|
|
- renderText("");
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // 回调日志入库
|
|
|
|
|
- if (StrKit.notBlank(wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp)) {
|
|
|
|
|
- deposit.save();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> responseJson = new HashMap<>();
|
|
|
|
|
- responseJson.put("code", "FAIL");
|
|
|
|
|
- responseJson.put("message", "回调失败 " + e.getMessage());
|
|
|
|
|
-
|
|
|
|
|
- AppConfig.LOGGER.error("回调失败 {}", e.getMessage());
|
|
|
|
|
-
|
|
|
|
|
- // 返回500错误码
|
|
|
|
|
- getResponse().setStatus(500);
|
|
|
|
|
- renderJson(responseJson);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // // 微信充值回调地址
|
|
|
|
|
+ // public void deposited() {
|
|
|
|
|
+ // String originalBody = HttpKit.readData(getRequest());
|
|
|
|
|
+ // AppConfig.LOGGER.info("wechat notify {}", originalBody);
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 保证每条回调都保存到数据库
|
|
|
|
|
+ // Deposit deposit = new Deposit();
|
|
|
|
|
+ // deposit.setCreateTime(System.currentTimeMillis());
|
|
|
|
|
+ // deposit.setWxOriginal(originalBody);
|
|
|
|
|
+ // deposit.setIsDeleted(0);
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 获取回调通知中的相关数据
|
|
|
|
|
+ // String wechatPaySerial = getRequest().getHeader("Wechatpay-Serial");
|
|
|
|
|
+ // String wechatpayNonce = getRequest().getHeader("Wechatpay-Nonce");
|
|
|
|
|
+ // String wechatSignature = getRequest().getHeader("Wechatpay-Signature");
|
|
|
|
|
+ // String wechatTimestamp = getRequest().getHeader("Wechatpay-Timestamp");
|
|
|
|
|
+ //
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // // 解析完成
|
|
|
|
|
+ // Transaction tx = WeChatService.parseTransaction(originalBody, wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp);
|
|
|
|
|
+ // Json json = Json.getJson();
|
|
|
|
|
+ // String txJson = json.toJson(tx);
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 商户下单时传入的商户系统内部订单号。
|
|
|
|
|
+ // String orderNo = tx.getOutTradeNo();
|
|
|
|
|
+ // // 获取库中存放的tx
|
|
|
|
|
+ // Deposit dbDeposit = service.findDepositByWxOrderNo(orderNo);
|
|
|
|
|
+ // // 付款数量
|
|
|
|
|
+ // Integer paymentAmount = tx.getAmount().getTotal();
|
|
|
|
|
+ // // 状态描述
|
|
|
|
|
+ // String status = tx.getTradeState().toString();
|
|
|
|
|
+ //
|
|
|
|
|
+ // if (dbDeposit == null) {
|
|
|
|
|
+ // deposit.setWxDecrypted(txJson);
|
|
|
|
|
+ // deposit.setWxOrderStatus(status);
|
|
|
|
|
+ // deposit.setDescription("未提前入库的订单,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
+ // deposit.setAmount(paymentAmount);
|
|
|
|
|
+ // deposit.save();
|
|
|
|
|
+ //
|
|
|
|
|
+ // AppConfig.LOGGER.warn("未提前入库的订单 {}", deposit);
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // deposit = dbDeposit;
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 记录解密后的信息
|
|
|
|
|
+ // deposit.setAmount(paymentAmount);
|
|
|
|
|
+ // deposit.setWxDecrypted(txJson);
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 不要重复处理已存在的充值单号,并且要加款成功
|
|
|
|
|
+ // if (StrKit.isBlank(deposit.getWxOrderStatus())) {
|
|
|
|
|
+ // User user = userService.findUserById(deposit.getUserId() + "");
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 记录订单状态
|
|
|
|
|
+ // deposit.setWxOrderStatus(tx.getTradeState().toString());
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 有充值信息但是未找到充值者
|
|
|
|
|
+ // if (user == null) {
|
|
|
|
|
+ // deposit.setDescription("未找到充值者,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // // 判断订单状态
|
|
|
|
|
+ // if (tx.getTradeState() == Transaction.TradeStateEnum.SUCCESS) {
|
|
|
|
|
+ // // 如果充值成功,对用户进行充值
|
|
|
|
|
+ // user.setBalance(user.getBalance() + paymentAmount);
|
|
|
|
|
+ // user.update();
|
|
|
|
|
+ //
|
|
|
|
|
+ // deposit.setDescription("用户充值成功,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // deposit.setDescription("用户充值失败,wx:" + tx.getTradeStateDesc());
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 充值记录入库
|
|
|
|
|
+ // deposit.update();
|
|
|
|
|
+ //
|
|
|
|
|
+ // AppConfig.LOGGER.info("入库成功 {}", deposit);
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 成功入库后给微信的回调信息
|
|
|
|
|
+ // getResponse().setStatus(200);
|
|
|
|
|
+ // renderText("");
|
|
|
|
|
+ // } catch (Exception e) {
|
|
|
|
|
+ // // 回调日志入库
|
|
|
|
|
+ // if (StrKit.notBlank(wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp)) {
|
|
|
|
|
+ // deposit.save();
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // Map<String, Object> responseJson = new HashMap<>();
|
|
|
|
|
+ // responseJson.put("code", "FAIL");
|
|
|
|
|
+ // responseJson.put("message", "回调失败 " + e.getMessage());
|
|
|
|
|
+ //
|
|
|
|
|
+ // AppConfig.LOGGER.error("回调失败 {}", e.getMessage());
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 返回500错误码
|
|
|
|
|
+ // getResponse().setStatus(500);
|
|
|
|
|
+ // renderJson(responseJson);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
- // 创建微信支付订单
|
|
|
|
|
- @Before(LoginInterceptor.class)
|
|
|
|
|
- @EmptyInterface({"amount"})
|
|
|
|
|
- public void create() {
|
|
|
|
|
- JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
|
|
|
|
|
-
|
|
|
|
|
- // 获取支付数量(分)
|
|
|
|
|
- String amountStr = requestBodyJson.getString("amount");
|
|
|
|
|
- int amount;
|
|
|
|
|
- try {
|
|
|
|
|
- amount = Integer.parseInt(amountStr);
|
|
|
|
|
-
|
|
|
|
|
- if (amount <= 0) {
|
|
|
|
|
- renderJson(MyRet.fail("支付数量(amount)期待是正整数,你传的是: " + amountStr));
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- renderJson(MyRet.fail("支付数量(amount)格式不正确: " + e.getMessage()));
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 获取公网ip地址
|
|
|
|
|
- String ip = IpAddressUtil.getClientIpAddress(this);
|
|
|
|
|
-
|
|
|
|
|
- // 获取当前用户
|
|
|
|
|
- User user = userService.findUserByMobileNumber(getSessionAttr("mobile_number"));
|
|
|
|
|
-
|
|
|
|
|
- // 创建并返回支付链接给前端
|
|
|
|
|
- renderJson(service.createDepositOrder(amount, ip, user.getId()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // // 创建微信支付订单
|
|
|
|
|
+ // @Before(LoginInterceptor.class)
|
|
|
|
|
+ // @EmptyInterface({"amount"})
|
|
|
|
|
+ // public void create() {
|
|
|
|
|
+ // JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 获取支付数量(分)
|
|
|
|
|
+ // String amountStr = requestBodyJson.getString("amount");
|
|
|
|
|
+ // int amount;
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // amount = Integer.parseInt(amountStr);
|
|
|
|
|
+ //
|
|
|
|
|
+ // if (amount <= 0) {
|
|
|
|
|
+ // renderJson(MyRet.fail("支付数量(amount)期待是正整数,你传的是: " + amountStr));
|
|
|
|
|
+ // return;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // } catch (Exception e) {
|
|
|
|
|
+ // renderJson(MyRet.fail("支付数量(amount)格式不正确: " + e.getMessage()));
|
|
|
|
|
+ // return;
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 获取公网ip地址
|
|
|
|
|
+ // String ip = IpAddressUtil.getClientIpAddress(this);
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 获取当前用户
|
|
|
|
|
+ // User user = userService.findUserByMobileNumber(getSessionAttr("mobile_number"));
|
|
|
|
|
+ //
|
|
|
|
|
+ // // 创建并返回支付链接给前端
|
|
|
|
|
+ // renderJson(service.createDepositOrder(amount, ip, user.getId()));
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
@Before(LoginInterceptor.class)
|
|
@Before(LoginInterceptor.class)
|
|
|
@EmptyInterface({"page_size", "page_number"})
|
|
@EmptyInterface({"page_size", "page_number"})
|