|
|
@@ -1,25 +1,26 @@
|
|
|
package modules.user;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jdcloud.sdk.service.sms.model.BatchSendResponse;
|
|
|
import com.jfinal.aop.Before;
|
|
|
import com.jfinal.aop.Inject;
|
|
|
+import com.jfinal.json.Json;
|
|
|
import com.jfinal.kit.HashKit;
|
|
|
+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.empty.EmptyInterface;
|
|
|
import common.interceptor.role.RequiredRoleInterface;
|
|
|
import common.jfinal.AppConfig;
|
|
|
-import common.model.DepositLog;
|
|
|
+import common.model.Deposit;
|
|
|
import common.model.User;
|
|
|
import common.utils.http.MyController;
|
|
|
import common.utils.http.MyRet;
|
|
|
import common.utils.http.VerifyCode;
|
|
|
import common.utils.hyg.AESUtils;
|
|
|
-import common.utils.hyg.HygSDK;
|
|
|
import common.utils.jdcloud.SMS;
|
|
|
-import modules.deposit.DepositLogService;
|
|
|
+import common.utils.wechat.WeChatService;
|
|
|
import modules.order.OrderService;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
@@ -40,7 +41,7 @@ public class UserController extends MyController {
|
|
|
private UserService service;
|
|
|
|
|
|
@Inject
|
|
|
- private DepositLogService depositLogService;
|
|
|
+ private BalanceLogService depositLogService;
|
|
|
|
|
|
@Inject
|
|
|
private OrderService orderService;
|
|
|
@@ -385,70 +386,76 @@ public class UserController extends MyController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 慧用工充值回调地址
|
|
|
- public void hygDeposited() {
|
|
|
- JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
|
|
|
-
|
|
|
- AppConfig.LOGGER.info("hygDeposited {}", requestBodyJson);
|
|
|
-
|
|
|
- // 每条回调都保存到数据库
|
|
|
- DepositLog log = new DepositLog();
|
|
|
- log.setCreateTime(System.currentTimeMillis());
|
|
|
- log.setHygOriginal(requestBodyJson.toJSONString());
|
|
|
- log.setIsDeleted(0);
|
|
|
+ // 微信充值回调地址
|
|
|
+ public void wxDeposited() {
|
|
|
+ String originalBody = HttpKit.readData(getRequest());
|
|
|
+ AppConfig.LOGGER.info("wx notify {}", originalBody);
|
|
|
+
|
|
|
+ // 保证每条回调都保存到数据库
|
|
|
+ Deposit deposit = new Deposit();
|
|
|
+ deposit.setCreateTime(System.currentTimeMillis());
|
|
|
+ deposit.setWxOriginal(originalBody);
|
|
|
+ deposit.setIsDeleted(0);
|
|
|
|
|
|
- // 解析businessBody
|
|
|
- String businessBodyEncryptedHex = requestBodyJson.getString("businessBody");
|
|
|
try {
|
|
|
- String body = AESUtils.decryptByHex(businessBodyEncryptedHex);
|
|
|
- JSONObject businessBody = JSONObject.parseObject(body);
|
|
|
+ // 获取回调通知中的相关数据
|
|
|
+ String wechatPaySerial = getRequest().getHeader("Wechatpay-Serial");
|
|
|
+ String wechatpayNonce = getRequest().getHeader("Wechatpay-Nonce");
|
|
|
+ String wechatSignature = getRequest().getHeader("Wechatpay-Signature");
|
|
|
+ String wechatTimestamp = getRequest().getHeader("Wechatpay-Timestamp");
|
|
|
+
|
|
|
+ // 解析完成
|
|
|
+ Transaction tx = WeChatService.parseTransaction(originalBody, wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp);
|
|
|
+ Json json = Json.getJson();
|
|
|
+ String txJson = json.toJson(tx);
|
|
|
+
|
|
|
+ // // 这里开始进行日志记录
|
|
|
+ // String payerAccount = businessBody.getString("businessBody");
|
|
|
+ // String orderNo = businessBody.getString("orderNo");
|
|
|
+ // // 不要重复处理已存在的充值单号,并且要加款成功
|
|
|
+ // if (depositLogService.findByOrderNo(orderNo) == null && businessBody.getString("rechargeStatus").equals("20")) {
|
|
|
+ // User user = service.findUserByBankCard(payerAccount);
|
|
|
+ //
|
|
|
+ // // 有充值信息但是未找到充值者
|
|
|
+ // Integer paymentAmount = businessBody.getInteger("paymentAmount");
|
|
|
+ // if (user == null) {
|
|
|
+ // log.setDescription("未找到充值者");
|
|
|
+ // log.setAmount(paymentAmount);
|
|
|
+ // log.setUserId((long) -1);
|
|
|
+ // } else {
|
|
|
+ // // 对用户进行充值
|
|
|
+ // user.setBalance(user.getBalance() + paymentAmount);
|
|
|
+ // user.update();
|
|
|
+ //
|
|
|
+ // // 交易者信息存档
|
|
|
+ // log.setDescription("用户充值");
|
|
|
+ // log.setAmount(paymentAmount);
|
|
|
+ // log.setUserId(user.getId());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 日志入库
|
|
|
+ deposit.setWxDecrypted(txJson);
|
|
|
+ deposit.update();
|
|
|
|
|
|
- // 这里开始进行日志记录
|
|
|
- String payerAccount = businessBody.getString("businessBody");
|
|
|
- String orderNo = businessBody.getString("orderNo");
|
|
|
- // 不要重复处理已存在的充值单号,并且要加款成功
|
|
|
- if (depositLogService.findByOrderNo(orderNo) == null && businessBody.getString("rechargeStatus").equals("20")) {
|
|
|
- User user = service.findUserByBankCard(payerAccount);
|
|
|
-
|
|
|
- // 有充值信息但是未找到充值者
|
|
|
- Integer paymentAmount = businessBody.getInteger("paymentAmount");
|
|
|
- if (user == null) {
|
|
|
- log.setDescription("未找到充值者");
|
|
|
- log.setAmount(paymentAmount);
|
|
|
- log.setUserId((long) -1);
|
|
|
- } else {
|
|
|
- // 对用户进行充值
|
|
|
- user.setBalance(user.getBalance() + paymentAmount);
|
|
|
- user.update();
|
|
|
-
|
|
|
- // 交易者信息存档
|
|
|
- log.setDescription("用户充值");
|
|
|
- log.setAmount(paymentAmount);
|
|
|
- log.setUserId(user.getId());
|
|
|
- }
|
|
|
-
|
|
|
- // 日志入库
|
|
|
- log.setHygOrderNo(orderNo);
|
|
|
- log.setHygDecrypted(body);
|
|
|
- log.save();
|
|
|
- }
|
|
|
+ AppConfig.LOGGER.info("入库成功 {}", deposit);
|
|
|
|
|
|
- // 给慧用工的回调信息
|
|
|
- Map<String, Object> responseJson = new HashMap<>();
|
|
|
- responseJson.put("statusCode", "000000");
|
|
|
- responseJson.put("statusText", "回调成功");
|
|
|
- renderJson(responseJson);
|
|
|
+ // 成功入库后给微信的回调信息
|
|
|
+ getResponse().setStatus(200);
|
|
|
+ renderText("");
|
|
|
} catch (Exception e) {
|
|
|
+ // 回调日志入库
|
|
|
+ deposit.save();
|
|
|
+
|
|
|
Map<String, Object> responseJson = new HashMap<>();
|
|
|
- responseJson.put("statusCode", "100000");
|
|
|
- responseJson.put("statusText", "回调失败 " + e.getMessage());
|
|
|
+ responseJson.put("code", "FAIL");
|
|
|
+ responseJson.put("message", "回调失败 " + e.getMessage());
|
|
|
|
|
|
- AppConfig.LOGGER.info("回调失败 " + e.getMessage());
|
|
|
+ AppConfig.LOGGER.error("回调失败 {}", e.getMessage());
|
|
|
|
|
|
+ // 返回500错误码
|
|
|
+ getResponse().setStatus(500);
|
|
|
renderJson(responseJson);
|
|
|
-
|
|
|
- // 回调日志入库
|
|
|
- log.save();
|
|
|
}
|
|
|
}
|
|
|
|