Browse Source

feature: 支付宝医保下单拼接参数

Walker 1 year ago
parent
commit
3790bf8695

+ 8 - 32
onemini-hospital-empty/src/main/java/com/ywt/alipaympapi/models/outpatient/PreSettleResp.java

@@ -1,44 +1,20 @@
 package com.ywt.alipaympapi.models.outpatient;
 
+import lombok.Data;
+
 /**
  * @author Walker
  * Created on 2023/10/19
  */
+@Data
 public class PreSettleResp {
     private String hiOutput;
     private String output;
     private String payAuthNo;
     private String setlLatlnt;
-
-    public String getHiOutput() {
-        return hiOutput;
-    }
-
-    public void setHiOutput(String hiOutput) {
-        this.hiOutput = hiOutput;
-    }
-
-    public String getOutput() {
-        return output;
-    }
-
-    public void setOutput(String output) {
-        this.output = output;
-    }
-
-    public String getPayAuthNo() {
-        return payAuthNo;
-    }
-
-    public void setPayAuthNo(String payAuthNo) {
-        this.payAuthNo = payAuthNo;
-    }
-
-    public String getSetlLatlnt() {
-        return setlLatlnt;
-    }
-
-    public void setSetlLatlnt(String setlLatlnt) {
-        this.setlLatlnt = setlLatlnt;
-    }
+    // 支付宝新增参数
+    String authUrl; // 当用户需要授权时,返回该参数,医药机构前端直接跳转该地址。
+    String authNo; // 线上身份验证授权码,只能用户身份核验,不能用于支付业务。
+    String medicalCardInstId; // 医保电子凭证机构编号,默认位NATHSA,请保存,后续支付接口需要使用。
+    String medicalCardId; // 用户医保电子凭证授权码,请保存,后续支付接口需要使用。
 }

+ 53 - 6
onemini-hospital-empty/src/main/java/com/ywt/alipaympapi/service/impl/IsvPayServiceImpl.java

@@ -5,11 +5,13 @@ import com.alipay.api.domain.AlipayTradeQueryModel;
 import com.alipay.api.request.AlipayCommerceMedicalAuthinfoAuthQueryRequest;
 import com.alipay.api.response.AlipayCommerceMedicalAuthinfoAuthQueryResponse;
 import com.alipay.api.response.AlipayTradeQueryResponse;
+import com.fasterxml.jackson.databind.JsonNode;
 import com.ywt.alipaympapi.core.utils.*;
 import com.ywt.alipaympapi.face.IPayFace;
 import com.ywt.alipaympapi.face.impl.AlipayService;
 import com.ywt.alipaympapi.models.Constants;
 import com.ywt.alipaympapi.models.auth.AlipayMpCfg;
+import com.ywt.alipaympapi.models.enums.HospitalNameEnum;
 import com.ywt.alipaympapi.models.enums.OutpatientOrderPayInsTypeEnum;
 import com.ywt.alipaympapi.models.enums.PaymentStatusEnum;
 import com.ywt.alipaympapi.models.enums.SexEnum;
@@ -628,7 +630,7 @@ public class IsvPayServiceImpl implements IsvPayService {
                 String userCardNo = resp.getIdNo();
                 if (StringHelper.isNullOrEmpty(userCardNo))
                     throw new AppMessageException("用户诊疗卡身份证信息为空");
-                // 医保支付,先生成系统订单,然后继续使用腾讯医保接口下单
+                // 医保支付,先生成系统订单,然后继续使用支付宝接口下单
                 req = CreateOutpatientOrderRequest.newBuilder()
                         .setDeptCode("")
                         .setDeptName(deptName)
@@ -659,8 +661,53 @@ public class IsvPayServiceImpl implements IsvPayService {
                 }
                 orderNo = result.getValue();
                 orderId = getOrderIdByOrderNo(orderNo);
+                String medicalCardId = "";
+                String medicalCardInstId = "";
+                String medOrgOrd = "";
+                String payOrdId = "";
+                String payAuthNo = "";
+                JsonNode jn = JsonSerializer.readToNode(insUploadFeeResp);
+                if (jn != null) {
+                    medicalCardId = Checker.getStringValue(jn.get("medicalCardId").asText());
+                    medicalCardInstId = Checker.getStringValue(jn.get("medicalCardInstId").asText());
+                    payAuthNo = Checker.getStringValue(jn.get("payAuthNo").asText());
+                    String output = Checker.getStringValue(jn.get("output").asText(), "{}");
+                    JsonNode jn2 = JsonSerializer.readToNode(output);
+                    if (jn2 != null) {
+                        JsonNode jn3 = jn2.get("data");
+                        if (jn3 != null) {
+                            medOrgOrd = Checker.getStringValue(jn3.get("medOrgOrd").asText());
+                            payOrdId = Checker.getStringValue(jn3.get("payOrdId").asText());
+                        }
+                    }
+                }
                 // 使用支付宝接口下单
-                // TODO: 增加医保参数
+                // 增加医保参数
+                AlipayMpCfg cfg = BizUtil.getCfg(terminal);
+                HashMap<String, String> extMap = new HashMap<>();
+                JSONObject extendParams = new JSONObject();
+                extendParams.put("sys_service_provider_id", cfg.getIsvPid());
+                extendParams.put("IS_INSURANCE_PAY", "T"); //是否使用医保支付
+                extendParams.put("medical_card_inst_id", medicalCardInstId); //医保电子凭证机构号 获取线上医保业务授权接口返回medicalCardInstId参数。
+                extendParams.put("medical_card_id", medicalCardId); //医保电子凭证授权码    获取线上医保业务授权接口返回medicalCardId参数。
+                extendParams.put("medical_request_content", "");//医保参数透传体,没有需传空对象串
+
+                JSONObject medicalRequestExt =new JSONObject(); //医保扩展参数
+                medicalRequestExt.put("gmt_out_create", DateUtil.convertTimestampToDateString(new Date().getTime()));//医疗机构下单时间
+                medicalRequestExt.put("out_trade_no", medOrgOrd); //商户网站唯一订单号   医院订单号medOrgOrd
+                medicalRequestExt.put("serial_no", payOrdId); //移动支付中心订单号payOrdId
+                medicalRequestExt.put("bill_no", payOrdId); //移动支付中心订单号payOrdId
+                medicalRequestExt.put("industry", "HOSPITAL"); //行业标识
+                medicalRequestExt.put("org_no", cfg.getYbv2OrgCode()); //医药机构编号
+                medicalRequestExt.put("org_name", HospitalNameEnum.getDisplayName(hospitalId)); //医药机构名称
+                medicalRequestExt.put("pay_auth_no", payAuthNo); //移动支付中心返回授权编号    获取线上医保业务授权接口返回payAuthNo参数
+                medicalRequestExt.put("chinfo", "gjydzf"); //渠道标识
+                medicalRequestExt.put("scene", "TREATMENT"); //使用场景
+                medicalRequestExt.put("insurance_pay_scene", "OUTPATIENT");//医保结算场景
+                medicalRequestExt.put("payment_city_code", "440100");//医保结算地城市编码(国标)
+                extendParams.put("medical_request_ext", JSONObject.toJSONString(medicalRequestExt));
+                extMap.put("extend_params", JSONObject.toJSONString(extendParams));
+
                 CreateAlipayOrderResponse createPayInsOrderResponse = orderCenterServiceBlockingStub.createAlipayOrder(CreateAlipayOrderRequest.newBuilder()
                         .setBody("门诊缴费")
                         .setAlipayUid(request.getAlipayUid())
@@ -669,6 +716,7 @@ public class IsvPayServiceImpl implements IsvPayService {
                         .setAmount(request.getTotal())
                         .setUserId(userId)
                         .setTerminal(ContextHelper.getCurrentTerminalWrapped())
+                        .putAllBizContent(extMap)
                         .build());
                 if (createPayInsOrderResponse.getCode() == ResultCode.SUCCEED_VALUE) {
                     data.setNeedPay(true);//设置是否需要支付宝自费支付
@@ -724,8 +772,7 @@ public class IsvPayServiceImpl implements IsvPayService {
                 // 预结算成功,自动取消之前生成的未支付订单,让前端可以重新创建订单
                 autoCancelPrevOrder(hisOrdNum);
                 PrePayConfirm p = response.getListList().get(0);
-                String invoiceNo = p.getInvoiceNo();
-                return invoiceNo;
+                return p.getInvoiceNo();
             }
             throw new AppMessageException("预结算:HIS 返回列表数据为空");
         }
@@ -778,7 +825,7 @@ public class IsvPayServiceImpl implements IsvPayService {
      * 获取医保支付授权
      * <a href="https://opendocs.alipay.com/pre-open/02iqci#5.2.2%20%E6%8E%A5%E5%8F%A3%E8%AF%A6%E7%BB%86%E8%AF%B4%E6%98%8E">参考文档</a>
      */
-    public GetPayAuthInfo getPayAuthNo(String appId, String alipayUid, String callUrl) {
+    public GetPayAuthInfo getPayAuthInfo(String appId, String alipayUid, String callUrl) {
         GetPayAuthInfo getPayAuthInfo = new GetPayAuthInfo();
         try {
             // 换取 token
@@ -821,7 +868,7 @@ public class IsvPayServiceImpl implements IsvPayService {
                 System.out.println("错误返回:" + response.getSubMsg());
             }
         } catch (Exception e) {
-            log.error("IsvPayServiceImpl#getPayAuthNo(appId={} , alipayUid={} ):\n {}", appId, alipayUid, e.getMessage(), e);
+            log.error("IsvPayServiceImpl#getPayAuthInfo(appId={} , alipayUid={} ):\n {}", appId, alipayUid, e.getMessage(), e);
         }
         return getPayAuthInfo;
     }

+ 12 - 5
onemini-hospital-empty/src/main/java/com/ywt/alipaympapi/web/controller/OutpatientController.java

@@ -6,10 +6,7 @@ import com.ywt.alipaympapi.models.BaseResponse2;
 import com.ywt.alipaympapi.models.enums.MedInsTypeEnum;
 import com.ywt.alipaympapi.models.enums.MpTypeEnum;
 import com.ywt.alipaympapi.models.enums.OutpatientOrderPayInsTypeEnum;
-import com.ywt.alipaympapi.models.outpatient.GetInsuOPDividePreResp;
-import com.ywt.alipaympapi.models.outpatient.PrePayConfirmReq;
-import com.ywt.alipaympapi.models.outpatient.PrePayConfirmResp;
-import com.ywt.alipaympapi.models.outpatient.PreSettleResp;
+import com.ywt.alipaympapi.models.outpatient.*;
 import com.ywt.alipaympapi.service.impl.IsvPayServiceImpl;
 import com.ywt.core.exception.AppMessageException;
 import com.ywt.gapi.ResultCode;
@@ -113,7 +110,12 @@ public class OutpatientController {
                             String authCode = reqData.getAuthCode();
                             CheckUtil.ensureNotEmpty(authCode, "授权码不能为空");
                             // 换取支付授权码
-                            String payAuthNo = isvPayService.getPayAuthNo(appId, ContextHelper.getAlipayUidWrapped(), "").getPayAuthNo();
+                            GetPayAuthInfo payAuthInfo = isvPayService.getPayAuthInfo(appId, ContextHelper.getAlipayUidWrapped(), "");
+                            String authUrl = payAuthInfo.getAuthUrl(); // 当用户需要授权时,返回该参数,医药机构前端直接跳转该地址。
+                            String payAuthNo = payAuthInfo.getPayAuthNo(); // 当用户已经授权支付时,直接返回该字段。线上支付授权编码。
+                            String authNo = payAuthInfo.getAuthNo(); // 线上身份验证授权码,只能用户身份核验,不能用于支付业务。
+                            String medicalCardInstId = payAuthInfo.getMedicalCardInstId(); // 医保电子凭证机构编号,默认位NATHSA,请保存,后续支付接口需要使用。
+                            String medicalCardId = payAuthInfo.getMedicalCardId(); // 用户医保电子凭证授权码,请保存,后续支付接口需要使用。
                             CheckUtil.ensureNotEmpty(payAuthNo, "无法获取支付授权码");
                             PreSettleResponse preSettleResponse = taiheServiceBlockingStub.preSettle(PreSettleRequest.newBuilder()
                                     .setHospitalId(hospitalId)
@@ -131,6 +133,11 @@ public class OutpatientController {
                             psr.setOutput(preSettleResponse.getOutput());
                             psr.setPayAuthNo(preSettleResponse.getPayAuthNo());
                             psr.setSetlLatlnt(preSettleResponse.getSetlLatlnt());
+                            psr.setAuthUrl(authUrl);
+//                            psr.setPayAuthNo(payAuthNo);
+                            psr.setAuthNo(authNo);
+                            psr.setMedicalCardInstId(medicalCardInstId);
+                            psr.setMedicalCardId(medicalCardId);
                             resp.setInsUploadFeeResp(JsonSerializer.toJson(psr));
                             resp.setInsuAdmDr(""); // 暂无该字段
                             resp.setInsuAdmInfoDr("");