|
@@ -1,5 +1,6 @@
|
|
|
package com.pj.api.jh.service;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -7,6 +8,7 @@ import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import cn.hutool.log.StaticLog;
|
|
|
+import com.pj.api.jh.task.CheckPayStatusTask;
|
|
|
import com.pj.api.jh.utils.JhHttpUtils;
|
|
|
import com.pj.api.jh.utils.MerchantApiUtil;
|
|
|
import com.pj.api.jh.bo.JhNotifyBO;
|
|
@@ -16,6 +18,7 @@ import com.pj.api.wx.service.WxService;
|
|
|
import com.pj.current.config.JhConfig;
|
|
|
import com.pj.current.config.MyConfig;
|
|
|
import com.pj.current.config.PartConfig;
|
|
|
+import com.pj.current.task.TaskService;
|
|
|
import com.pj.project.tb_order.TbOrder;
|
|
|
import com.pj.project.tb_order.TbOrderService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -54,17 +57,24 @@ public class JhService {
|
|
|
JhHttpUtils jhHttpUtils;
|
|
|
@Resource
|
|
|
private TbOrderService tbOrderService;
|
|
|
+ @Resource
|
|
|
+ private TaskService taskService;
|
|
|
|
|
|
- public JSONObject initPay(HttpServletRequest request) throws Exception {
|
|
|
+ public Map<String, ?> initPay(HttpServletRequest request) throws Exception {
|
|
|
+ if (!jhConfig.isEnable()) {
|
|
|
+ return wxService.prePay(request);
|
|
|
+ }
|
|
|
String money = request.getParameter("money");
|
|
|
String openid = request.getParameter("openid");
|
|
|
String desc = request.getParameter("desc");
|
|
|
String businessId = request.getParameter("b");
|
|
|
String c = request.getParameter("c");
|
|
|
String a = request.getParameter("a");
|
|
|
+ String tradeType = request.getParameter("tradeType");
|
|
|
+ String businessType = request.getParameter("businessType");
|
|
|
Attach atchMap = new Attach();
|
|
|
atchMap.setC(c).setB(businessId).setA(a);
|
|
|
- String out_trade_no = RandomUtil.randomString(30);
|
|
|
+ String out_trade_no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(6);
|
|
|
StaticLog.info("outTradeNo:{}", out_trade_no);
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("attach", JSONUtil.toJsonStr(atchMap));
|
|
@@ -72,7 +82,7 @@ public class JhService {
|
|
|
params.put("businessMerchantNo", jhConfig.getBusinessMerchantNo());
|
|
|
params.put("openId", openid);
|
|
|
params.put("merchantNo", jhConfig.getBusinessMerchantNo());
|
|
|
- params.put("tradeType", jhConfig.getTradeType());
|
|
|
+ params.put("tradeType", businessType);
|
|
|
params.put("subTradeType", "");
|
|
|
String total_free = partConfig.isTestEnv() ? "0.01" : money + "";
|
|
|
log.info("order price:{}", total_free);
|
|
@@ -99,6 +109,7 @@ public class JhService {
|
|
|
Map<String, String> r = wxService.getPayP(payMessage.getStr("timeStamp"), payMessage.getStr("nonceStr"), openid, p);
|
|
|
StaticLog.info("re:{}", JSONUtil.toJsonStr(r));
|
|
|
JSONObject object = JSONUtil.parseObj(payMessage);
|
|
|
+
|
|
|
object.set("outTradeNo", out_trade_no);
|
|
|
TbOrder tbOrder = new TbOrder();
|
|
|
tbOrder.setAttach(JSONUtil.toJsonStr(atchMap))
|
|
@@ -106,7 +117,8 @@ public class JhService {
|
|
|
.setOrderTime(new Date())
|
|
|
.setOutTradeNo(out_trade_no).setPrice(money);
|
|
|
tbOrderService.save(tbOrder);
|
|
|
- return object;
|
|
|
+ taskService.addTask(new CheckPayStatusTask(RandomUtil.randomNumbers(12), 2000, out_trade_no));
|
|
|
+ return BeanUtil.beanToMap(object);
|
|
|
}
|
|
|
throw new Exception("支付信息有误");
|
|
|
}
|
|
@@ -130,14 +142,20 @@ public class JhService {
|
|
|
|
|
|
@Async
|
|
|
public void notifyResult(JhNotifyBO bo) {
|
|
|
- if (!"SUCCESS".equals(bo.getTradeStatus().toUpperCase()) && !"FINISH".equals(bo.getTradeStatus().toUpperCase())) {
|
|
|
+ String orderStatus=bo.getTradeStatus();
|
|
|
+ if (!"SUCCESS".equals(orderStatus) && !"FINISH".equals(orderStatus)) {
|
|
|
return;
|
|
|
}
|
|
|
NotifyBO notifyBO = new NotifyBO();
|
|
|
+ String outTradeNo = bo.getOutTradeNo();
|
|
|
notifyBO.setOutTradeNo(bo.getOutTradeNo())
|
|
|
.setAttach(bo.getAttach())
|
|
|
.setTransactionId(bo.getBankTrxNo())
|
|
|
.setTotalFee(NumberUtil.mul(bo.getOrderPrice(), 100 + "").toString());
|
|
|
wxService.WxNotify(notifyBO);
|
|
|
+ TbOrder tbOrder = tbOrderService.findByOutTradeNo(outTradeNo);
|
|
|
+ tbOrder.setOrderStatus(orderStatus)
|
|
|
+ .setTransactionId(bo.getBankTrxNo())
|
|
|
+ .setCompleteDate(bo.getSuccessTime());
|
|
|
}
|
|
|
}
|