|
@@ -3,10 +3,6 @@ package thyyxxk.webserver.service.mzpayqrcode;
|
|
|
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.HttpPost;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
@@ -16,11 +12,8 @@ import thyyxxk.webserver.pojo.HrgResponse;
|
|
|
import thyyxxk.webserver.pojo.ResultVo;
|
|
|
import thyyxxk.webserver.pojo.mzpayqrcode.PatInfoPojo;
|
|
|
import thyyxxk.webserver.pojo.mzpayqrcode.RoughIndexPojo;
|
|
|
-import thyyxxk.webserver.pojo.wxapi.WxPayOrder;
|
|
|
import thyyxxk.webserver.utils.*;
|
|
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -36,7 +29,7 @@ public class MzPayQrcodeService {
|
|
|
}
|
|
|
|
|
|
private PatInfoPojo getPatientInfo(String patientId) {
|
|
|
- String socialNo = dao.getSocialNo(patientId);
|
|
|
+ String socialNo = dao.selectSocialNoByPatientId(patientId);
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("patIdType", 11);
|
|
|
obj.put("patIdNo", socialNo);
|
|
@@ -68,7 +61,8 @@ public class MzPayQrcodeService {
|
|
|
return ResultVoUtil.success(list);
|
|
|
}
|
|
|
|
|
|
- public ResultVo<JSONObject> getDetailFees(RoughIndexPojo param) throws Exception {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public ResultVo<JSONObject> getDetailFees(RoughIndexPojo param) {
|
|
|
PatInfoPojo patInfo = getPatientInfo(param.getPatientId());
|
|
|
if (null == patInfo || null == patInfo.getResultCode() || 0 != patInfo.getResultCode()) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "无法获取到患者个人信息!");
|
|
@@ -89,11 +83,13 @@ public class MzPayQrcodeService {
|
|
|
List<Map<String, String>> list = FilterUtil.cast(hrgRes.getData());
|
|
|
JSONObject retObj = new JSONObject();
|
|
|
retObj.put("list", makeSimpleData(list));
|
|
|
- String wxQrcode = createOrder(param.getTotalAmt().intValue(), param.getPatientId(), param.getHisOrdNum());
|
|
|
- if (null == wxQrcode) {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String url = "http://192.168.200.3:8805/wxserver/wxApi/createOrderForMzGuideBill";
|
|
|
+ ResultVo<String> qrResult = restTemplate.postForObject(url, param, ResultVo.class);
|
|
|
+ if (null == qrResult || qrResult.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。");
|
|
|
}
|
|
|
- retObj.put("wxQrcode", wxQrcode);
|
|
|
+ retObj.put("wxQrcode", qrResult.getData());
|
|
|
return ResultVoUtil.success(retObj);
|
|
|
}
|
|
|
|
|
@@ -131,60 +127,4 @@ public class MzPayQrcodeService {
|
|
|
}
|
|
|
return array;
|
|
|
}
|
|
|
-
|
|
|
- private String createOrder(Integer totalAmt, String patientId, String hisOrdNum) throws Exception {
|
|
|
- String outTradeNo = SnowFlakeId.instance().nextId();
|
|
|
- JSONObject body = new JSONObject();
|
|
|
- body.put("appid", WxPayUtil.APP_ID);
|
|
|
- body.put("mchid", WxPayUtil.MERCHANT_ID);
|
|
|
- body.put("description", "湖南泰和医院-门诊缴费");
|
|
|
- body.put("attach", "湖南泰和医院-门诊缴费");
|
|
|
- body.put("out_trade_no", outTradeNo);
|
|
|
- body.put("notify_url", WxPayUtil.NOTIFY_URL);
|
|
|
- JSONObject cny = new JSONObject();
|
|
|
- cny.put("total", totalAmt);
|
|
|
- cny.put("currency", "CNY");
|
|
|
- body.put("amount", cny);
|
|
|
- String reqdata = JSONObject.toJSONString(body);
|
|
|
- log.info("请求微信支付二维码:{}", reqdata);
|
|
|
- HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/native");
|
|
|
- StringEntity entity = new StringEntity(reqdata, StandardCharsets.UTF_8);
|
|
|
- entity.setContentEncoding("UTF-8");
|
|
|
- entity.setContentType("application/json");
|
|
|
- httpPost.setEntity(entity);
|
|
|
- httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
- httpPost.addHeader("Accept", "application/json");
|
|
|
- //完成签名并执行请求
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void insertIntoDb(String outTradeNo, Integer total, String patientId, String hisOrdNum) {
|
|
|
- long timesStamp = System.currentTimeMillis() / 1000;
|
|
|
- WxPayOrder order = new WxPayOrder();
|
|
|
- order.setAppId(WxPayUtil.APP_ID);
|
|
|
- order.setBody("门诊缴费");
|
|
|
- order.setOpenId("");
|
|
|
- order.setTotalFee(DecimalUtil.moneyFenToYuan(total));
|
|
|
- order.setPatientId(patientId);
|
|
|
- order.setPatientName(dao.selectPatientName(patientId));
|
|
|
- order.setMchId(WxPayUtil.MERCHANT_ID);
|
|
|
- order.setTimeStamp(String.valueOf(timesStamp));
|
|
|
- order.setTradeNo(outTradeNo);
|
|
|
- order.setCreateDatetime(new Date());
|
|
|
- order.setPayStatus(0);
|
|
|
- order.setSerialNo(SnowFlakeId.instance().nextId());
|
|
|
- order.setOrderType(2);
|
|
|
- order.setHisOrdNum(hisOrdNum);
|
|
|
- dao.insertNewOrder(order);
|
|
|
- }
|
|
|
}
|