|
@@ -3,19 +3,21 @@ package com.pj.api.jh.service;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.crypto.SecureUtil;
|
|
|
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.MerchantApiUtil;
|
|
|
-import com.pj.api.wx.WxUtils;
|
|
|
+import com.pj.api.jh.utils.JhHttpUtils;
|
|
|
+import com.pj.api.jh.utils.MerchantApiUtil;
|
|
|
+import com.pj.api.jh.bo.JhNotifyBO;
|
|
|
import com.pj.api.wx.bo.Attach;
|
|
|
+import com.pj.api.wx.bo.NotifyBO;
|
|
|
import com.pj.api.wx.service.WxService;
|
|
|
import com.pj.current.config.JhConfig;
|
|
|
import com.pj.current.config.MyConfig;
|
|
|
-import com.pj.current.config.WxConfig;
|
|
|
+import com.pj.current.config.PartConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -23,10 +25,8 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @Auther: lzm
|
|
@@ -39,27 +39,29 @@ import java.util.Set;
|
|
|
public class JhService {
|
|
|
|
|
|
@Resource
|
|
|
- WxConfig wxConfig;
|
|
|
- @Resource
|
|
|
MyConfig myConfig;
|
|
|
@Resource
|
|
|
JhConfig jhConfig;
|
|
|
@Resource
|
|
|
- WxUtils wxUtils;
|
|
|
+ PartConfig partConfig;
|
|
|
@Resource
|
|
|
WxService wxService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ JhHttpUtils jhHttpUtils;
|
|
|
+
|
|
|
public JSONObject initPay(HttpServletRequest request) throws Exception {
|
|
|
String money = request.getParameter("money");
|
|
|
-// String openid = request.getParameter("openid");
|
|
|
- String openid = "oDWvn5w-hVkzUuKeY7OBXBV_l1rU";
|
|
|
+ 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");
|
|
|
Attach atchMap = new Attach();
|
|
|
atchMap.setC(c).setB(businessId).setA(a);
|
|
|
String out_trade_no = RandomUtil.randomString(30);
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
+ StaticLog.info("outTradeNo:{}",out_trade_no);
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
params.put("attach", JSONUtil.toJsonStr(atchMap));
|
|
|
params.put("productType", jhConfig.getProductType());
|
|
|
params.put("businessMerchantNo", jhConfig.getBusinessMerchantNo());
|
|
@@ -67,26 +69,23 @@ public class JhService {
|
|
|
params.put("merchantNo", jhConfig.getBusinessMerchantNo());
|
|
|
params.put("tradeType", jhConfig.getTradeType());
|
|
|
params.put("subTradeType", "");
|
|
|
-// String total_free = money+"";
|
|
|
- String total_free = "0.01";
|
|
|
+ String total_free = partConfig.isTestEnv() ? "0.01" : money + "";
|
|
|
log.info("order price:{}", total_free);
|
|
|
params.put("orderPrice", total_free);
|
|
|
params.put("outTradeNo", out_trade_no);
|
|
|
- params.put("productName", "业务订单支付");
|
|
|
+ params.put("productName", desc);
|
|
|
params.put("orderIp", WxService.getIpAddress(request));
|
|
|
String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
params.put("orderTime", now);
|
|
|
params.put("returnUrl", "");
|
|
|
- params.put("notifyUrl", myConfig.getDomain() + "/wx/notify");
|
|
|
- params.put("remark", "业务订单支付");
|
|
|
+ params.put("notifyUrl", myConfig.getDomain() + "/jh/notify");
|
|
|
+ params.put("remark", desc);
|
|
|
String paySecrit = jhConfig.getPaySecret();
|
|
|
String sign = MerchantApiUtil.getSign(params, paySecrit);
|
|
|
params.put("sign", sign);
|
|
|
-
|
|
|
String jsonParam = JSONUtil.toJsonStr(params);
|
|
|
String initPayUrl = jhConfig.getServerUrl() + "/uaps-web-gateway/cnpPay/initPay";
|
|
|
- String result = HttpUtil.createPost(initPayUrl).header("Content-Type", "application/json").body(jsonParam)
|
|
|
- .execute().body();
|
|
|
+ String result = jhHttpUtils.postJson(initPayUrl,jsonParam);
|
|
|
StaticLog.info("调用聚合支付返回:{}", result);
|
|
|
JSONObject jsonResult = JSONUtil.parseObj(result);
|
|
|
if (StrUtil.equals("0000", jsonResult.get("resultCode").toString())) {
|
|
@@ -94,10 +93,37 @@ public class JhService {
|
|
|
String p = payMessage.getStr("package");
|
|
|
Map<String, String> r = wxService.getPayP(payMessage.getStr("timeStamp"), payMessage.getStr("nonceStr"), openid, p);
|
|
|
StaticLog.info("re:{}", JSONUtil.toJsonStr(r));
|
|
|
- return JSONUtil.parseObj(payMessage);
|
|
|
+ JSONObject object = JSONUtil.parseObj(payMessage);
|
|
|
+ object.set("outTradeNo", out_trade_no);
|
|
|
+ return object;
|
|
|
}
|
|
|
throw new Exception("支付信息有误");
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public JSONObject checkPayResult(String outTradeNo) {
|
|
|
+ String url = jhConfig.getServerUrl() + "/uaps-web-gateway/query/singleOrder";
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("businessMerchantNo", jhConfig.getBusinessMerchantNo());
|
|
|
+ params.put("outTradeNo", outTradeNo);
|
|
|
+ String paySecrit = jhConfig.getPaySecret();
|
|
|
+ String sign = MerchantApiUtil.getSign(params, paySecrit);
|
|
|
+ params.put("sign", sign);
|
|
|
+ String result = jhHttpUtils.postForm(url,params);
|
|
|
+ StaticLog.info("调用聚合支付查询支付接口返回:{}", result);
|
|
|
+ return JSONUtil.parseObj(result);
|
|
|
+ }
|
|
|
+ @Async
|
|
|
+ public void notifyResult(JhNotifyBO bo) {
|
|
|
+ StaticLog.info("聚合支付回调:{}", JSONUtil.toJsonStr(bo));
|
|
|
+ if (!"SUCCESS".equals(bo.getTradeStatus().toUpperCase())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NotifyBO notifyBO=new NotifyBO();
|
|
|
+ notifyBO.setOutTradeNo(bo.getOutTradeNo())
|
|
|
+ .setAttach(bo.getAttach())
|
|
|
+ .setTransactionId(bo.getBankTrxNo())
|
|
|
+ .setTotalFee(NumberUtil.mul(bo.getOrderPrice(),100+"").toString());
|
|
|
+ wxService.WxNotify(notifyBO);
|
|
|
+ }
|
|
|
}
|