|
@@ -20,10 +20,12 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
import thyyxxk.wxservice_server.entity.ResultVo;
|
|
|
+import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
|
|
|
import thyyxxk.wxservice_server.entity.appointment.WeChatPayParam;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.JsApiSHA1;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.GenMzPayQrcodeParam;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
|
|
|
+import thyyxxk.wxservice_server.entity.wxapi.WxPyQrcdPrm;
|
|
|
import thyyxxk.wxservice_server.utils.*;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
@@ -208,6 +210,9 @@ public class WxApiService {
|
|
|
case 3:
|
|
|
saveRet = savePayResultService.saveZyYjjInfo(order);
|
|
|
break;
|
|
|
+ case 4:
|
|
|
+ saveRet = ResultVoUtil.success("订单已支付。");
|
|
|
+ break;
|
|
|
default:
|
|
|
log.info("未识别到的订单类型:{},订单号:{}", order.getOrderType(), tradeNo);
|
|
|
saveRet = ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未识别到的订单类型,请联系服务中心。");
|
|
@@ -307,4 +312,70 @@ public class WxApiService {
|
|
|
log.error("请求门诊指引单二维码失败:{}", ret);
|
|
|
return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。"));
|
|
|
}
|
|
|
+
|
|
|
+ public ResultVo<Map<String, String>> getWxPayQrcode(WxPyQrcdPrm prm) throws Exception {
|
|
|
+ String patName = dao.selectPatientName(prm.getPatientId());
|
|
|
+ if (null == patName) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到患者信息,请检查patientId是否正确!");
|
|
|
+ }
|
|
|
+ String outTradeNo = SnowFlakeId.instance().nextId();
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ body.put("appid", PropertiesUtil.getProperty("appId"));
|
|
|
+ body.put("mchid", PropertiesUtil.getProperty("mchId"));
|
|
|
+ body.put("description", prm.getDescription());
|
|
|
+ body.put("attach", prm.getDescription());
|
|
|
+ body.put("out_trade_no", outTradeNo);
|
|
|
+ body.put("notify_url", PropertiesUtil.getProperty("notifyUrl"));
|
|
|
+ JSONObject cny = new JSONObject();
|
|
|
+ cny.put("total", prm.getTotalAmt());
|
|
|
+ cny.put("currency", "CNY");
|
|
|
+ body.put("amount", cny);
|
|
|
+ String reqdata = JSONObject.toJSONString(body);
|
|
|
+ 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");
|
|
|
+ //完成签名并执行请求
|
|
|
+ CloseableHttpClient httpClient = WxHttpUtil.getClosableHttpClient();
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ String ret = EntityUtils.toString(response.getEntity());
|
|
|
+ httpClient.close();
|
|
|
+ log.info("请求微信支付二维码:{},结果:{}", prm, ret);
|
|
|
+ if (statusCode == ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ long timesStamp = System.currentTimeMillis() / 1000;
|
|
|
+ WxPayOrder order = new WxPayOrder();
|
|
|
+ order.setAppId(PropertiesUtil.getProperty("appId"));
|
|
|
+ order.setBody(prm.getOrderType() == 4 ? "自助机缴费" : "体检缴费");
|
|
|
+ order.setOpenId("");
|
|
|
+ order.setTotalFee(DecimalTool.moneyFenToYuan(prm.getTotalAmt()));
|
|
|
+ order.setPatientId(prm.getPatientId());
|
|
|
+ order.setPatientName(patName);
|
|
|
+ order.setMchId(PropertiesUtil.getProperty("mchId"));
|
|
|
+ order.setTimeStamp(String.valueOf(timesStamp));
|
|
|
+ order.setTradeNo(outTradeNo);
|
|
|
+ order.setCreateDatetime(new Date());
|
|
|
+ order.setPayStatus(0);
|
|
|
+ order.setSerialNo(SnowFlakeId.instance().nextId());
|
|
|
+ order.setOrderType(4);
|
|
|
+ dao.insertNewOrder(order);
|
|
|
+ JSONObject retObj = JSONObject.parseObject(ret);
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("qrcodeUrl", retObj.getString("code_url"));
|
|
|
+ map.put("tradeNo", outTradeNo);
|
|
|
+ return ResultVoUtil.success(map);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。");
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<DoctorInfo> getDoctorInfo(String doctorCode) {
|
|
|
+ DoctorInfo doctorInfo = dao.selectDoctorInfo(doctorCode);
|
|
|
+ if (null == doctorInfo) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "未找到医生信息!");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(doctorInfo);
|
|
|
+ }
|
|
|
}
|