|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
@@ -19,7 +20,6 @@ import thyyxxk.webserver.pojo.mzpayqrcode.RoughIndexPojo;
|
|
|
import thyyxxk.webserver.pojo.wxrefund.WxPayOrder;
|
|
|
import thyyxxk.webserver.utils.*;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
@@ -156,20 +156,31 @@ public class MzPayQrcodeService {
|
|
|
httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
httpPost.addHeader("Accept", "application/json");
|
|
|
//完成签名并执行请求
|
|
|
- try (CloseableHttpResponse response = WxPayUtil.getClosableHttpClient().execute(httpPost)) {
|
|
|
- int statusCode = response.getStatusLine().getStatusCode();
|
|
|
- String ret = EntityUtils.toString(response.getEntity());
|
|
|
- if (statusCode == 200) {
|
|
|
- insertIntoDb(outTradeNo, totalAmt, patientId, hisOrdNum);
|
|
|
- JSONObject retObj = JSONObject.parseObject(ret);
|
|
|
- return retObj.getString("code_url");
|
|
|
- } else {
|
|
|
- log.error("请求失败:{}", ret);
|
|
|
- return null;
|
|
|
- }
|
|
|
+ CloseableHttpResponse response = WxPayUtil.getClosableHttpClient().execute(httpPost);
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ String ret = EntityUtils.toString(response.getEntity());
|
|
|
+ if (statusCode == 200) {
|
|
|
+ insertIntoDb(outTradeNo, totalAmt, patientId, hisOrdNum);
|
|
|
+ JSONObject retObj = JSONObject.parseObject(ret);
|
|
|
+ return retObj.getString("code_url");
|
|
|
+ } else {
|
|
|
+ log.error("请求失败:{}", ret);
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public JSONObject queryOrderState(String tradeNo) throws Exception {
|
|
|
+ String url = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" +
|
|
|
+ tradeNo + "?mchid=" + WxPayUtil.MERCHANT_ID;
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
+ httpGet.addHeader("Accept", "application/json");
|
|
|
+ CloseableHttpResponse response = WxPayUtil.getClosableHttpClient().execute(httpGet);
|
|
|
+ String ret = EntityUtils.toString(response.getEntity());
|
|
|
+ JSONObject obj = JSONObject.parseObject(ret);
|
|
|
+ log.info("查询订单状态: {}", obj);
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
private void insertIntoDb(String outTradeNo, Integer total, String patientId, String hisOrdNum) {
|
|
|
long timesStamp = System.currentTimeMillis() / 1000;
|
|
|
WxPayOrder order = new WxPayOrder();
|