|
@@ -3,7 +3,6 @@ package thyyxxk.wxservice_server.controller.api;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.tencent.mip.DataHandler;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpEntity;
|
|
@@ -31,6 +30,7 @@ import thyyxxk.wxservice_server.utils.DateUtil;
|
|
|
import thyyxxk.wxservice_server.utils.ResultVoUtil;
|
|
|
import thyyxxk.wxservice_server.utils.SnowFlakeId;
|
|
|
import thyyxxk.wxservice_server.utils.TokenUtil;
|
|
|
+import thyyxxk.wxservice_server.utils.mip.DataHandler;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
@@ -43,40 +43,28 @@ public class PowersiMiPayPlugin {
|
|
|
private final PowersiPluginDao dao;
|
|
|
private final IdCardAnalyzeService idCardAnalyzeService;
|
|
|
private final ThmzService thmzService;
|
|
|
- private static final String MZ_API_URL = "http://172.16.30.26:1100/mobilePayApi";
|
|
|
-
|
|
|
- // 移动支付测试环境
|
|
|
-// private final static String chnlId = "1I14E7CSC05E4460C80A0000D6788E13";
|
|
|
-// private final static String sm4key = "1I14E7CSC05F4460C80A000070CF4673";
|
|
|
-// private final static String prvKey = "AOyLayJnHqXC56ENBW2vdfd5aPrncBOA3TK27LkvXHfI";
|
|
|
-// private final static String pubKey = "BBVwpoYbrrguE9NEpi0PDKYqJKS5w7lksW1nLtNmVctgrli+B/sKs83tZQBlV3FTvTSaaHbxNidsBjsdisd0XDE=";
|
|
|
-
|
|
|
- private final static String chnlId = "FBEBNX3X60526RPYJQ7PZ4CRPNZO8NC9";
|
|
|
- private final static String sm4key = "SN7YCGQA4R1JJELBZNGKEMV3O4P9KF9F";
|
|
|
- private final static String prvKey = "ATePKWH4x/ooLSoA5A5rxDrCgCbhFzPG/FvdqF2RkEI=";
|
|
|
- private final static String pubKey = "BLaISfgVDY1OdD22WBSXO1z/PwHialH1lKxeB1SN7ZkCPEutbMCUpIJnl/009sXoXw7ubAHxfpHyn2aSgXAvkHI=";
|
|
|
|
|
|
+ private static final String MZ_API_URL = "http://172.16.30.26:1100/mobilePayApi";
|
|
|
|
|
|
- private final DataHandler dataHandler = DataHandler.newInstance(chnlId, sm4key, pubKey, prvKey);
|
|
|
+ private final DataHandler dataHandler = DataHandler.newInstance();
|
|
|
|
|
|
@Autowired
|
|
|
public PowersiMiPayPlugin(PowersiPluginDao dao, IdCardAnalyzeService idCardAnalyzeService, ThmzService thmzService) throws IOException {
|
|
|
this.dao = dao;
|
|
|
this.idCardAnalyzeService = idCardAnalyzeService;
|
|
|
this.thmzService = thmzService;
|
|
|
- dataHandler.setSkipVerify(true);
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/getOpenid")
|
|
|
- public ResultVo<String> getOpenid(@RequestBody InsuinfoRequest request) throws Exception {
|
|
|
+ @PostMapping("/lockOrder")
|
|
|
+ public ResultVo<String> lockOrder(@RequestBody InsuinfoRequest request) throws Exception {
|
|
|
+ dao.lockOrder(request.getHisOrdNum());
|
|
|
return ResultVoUtil.success(TokenUtil.getInstance().getUserOpenid());
|
|
|
}
|
|
|
|
|
|
private JSONObject decryptRequest(JSONObject body) throws Exception {
|
|
|
body.put("code", 0);
|
|
|
- String decrypt = dataHandler.processRspData(body.toJSONString());
|
|
|
- JSONObject temp = JSONObject.parseObject(decrypt);
|
|
|
- return temp.getJSONObject("data");
|
|
|
+ JSONObject decrypt = dataHandler.processRspData(body.toJSONString());
|
|
|
+ return decrypt.getJSONObject("data");
|
|
|
}
|
|
|
|
|
|
@PassToken
|
|
@@ -121,6 +109,9 @@ public class PowersiMiPayPlugin {
|
|
|
List<Map<String, Object>> feeList = vo.getData();
|
|
|
for (Map<String, Object> map : feeList) {
|
|
|
BillInfo billInfo = new BillInfo(map);
|
|
|
+ if (billInfo.getVipFlag() == 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
String url = MZ_API_URL + "/writeMtReceipt?hisOrdNum=" + billInfo.getBizId();
|
|
|
String writeMtReceipt = new RestTemplate().getForObject(url, String.class);
|
|
|
if (Objects.equals(writeMtReceipt, "SUCCESS")) {
|
|
@@ -191,27 +182,39 @@ public class PowersiMiPayPlugin {
|
|
|
public CommonResponse settleNotify(@RequestBody JSONObject body) throws Exception {
|
|
|
JSONObject request = decryptRequest(body);
|
|
|
PowersiMipSetlinfo setlinfo = dao.selectById(request.getString("platformOrderId"));
|
|
|
- if (null != setlinfo) {
|
|
|
- return new CommonResponse();
|
|
|
+ if (null == setlinfo) {
|
|
|
+ setlinfo = JSONObject.parseObject(request.toJSONString(), PowersiMipSetlinfo.class);
|
|
|
+ int insert = dao.insert(setlinfo);
|
|
|
+ if (insert == 1) {
|
|
|
+ saveMzOrder(setlinfo);
|
|
|
+ return new CommonResponse();
|
|
|
+ }
|
|
|
+ return new CommonResponse("HIS业务处理失败。");
|
|
|
}
|
|
|
- setlinfo = JSONObject.parseObject(request.toJSONString(), PowersiMipSetlinfo.class);
|
|
|
- int insert = dao.insert(setlinfo);
|
|
|
- if (insert == 1) {
|
|
|
- SaveMzPayRequest saveMzPayRequest = new SaveMzPayRequest.Builder()
|
|
|
- .payTime(DateUtil.formatDatetime(setlinfo.getTraceTime()))
|
|
|
- .patCardNo(setlinfo.getMedOrgOrd().split("_")[0])
|
|
|
- .agtOrdNum(setlinfo.getThirdOrderId())
|
|
|
- .payAmt(setlinfo.getFeeSumamt())
|
|
|
- .fundpayAmt(setlinfo.getFundPay())
|
|
|
- .acctpayAmt(setlinfo.getPsnAcctPay())
|
|
|
- .couponAmt(BigDecimal.ZERO)
|
|
|
- .cashpayAmt(setlinfo.getOwnpayAmt())
|
|
|
- .hisOrdNum(setlinfo.getMedOrgOrd())
|
|
|
- .psOrdNum(setlinfo.getPlatformOrderId()).build();
|
|
|
- thmzService.saveMzPay(saveMzPayRequest);
|
|
|
+ if (setlinfo.getMzSaved() == 0) {
|
|
|
+ saveMzOrder(setlinfo);
|
|
|
return new CommonResponse();
|
|
|
}
|
|
|
- return new CommonResponse("接收通知失败。");
|
|
|
+ return new CommonResponse();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveMzOrder(PowersiMipSetlinfo setlinfo) {
|
|
|
+ SaveMzPayRequest saveMzPayRequest = new SaveMzPayRequest.Builder()
|
|
|
+ .payTime(DateUtil.formatDatetime(setlinfo.getTraceTime()))
|
|
|
+ .patCardNo(setlinfo.getMedOrgOrd().split("_")[0])
|
|
|
+ .agtOrdNum(setlinfo.getThirdOrderId())
|
|
|
+ .payAmt(setlinfo.getFeeSumamt())
|
|
|
+ .fundpayAmt(setlinfo.getFundPay())
|
|
|
+ .acctpayAmt(setlinfo.getPsnAcctPay())
|
|
|
+ .couponAmt(BigDecimal.ZERO)
|
|
|
+ .cashpayAmt(setlinfo.getOwnpayAmt())
|
|
|
+ .hisOrdNum(setlinfo.getMedOrgOrd())
|
|
|
+ .psOrdNum(setlinfo.getPlatformOrderId())
|
|
|
+ .isNormalClinic(true).build();
|
|
|
+ ResultVo<String> res = thmzService.saveMzPay(saveMzPayRequest);
|
|
|
+ if (res.getCode() == ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ dao.updateMzSaved(setlinfo.getPlatformOrderId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PassToken
|
|
@@ -252,13 +255,10 @@ public class PowersiMiPayPlugin {
|
|
|
HttpEntity<String> entity = new HttpEntity<>(body, headers);
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
String encRes = restTemplate.postForObject(url, entity, String.class);
|
|
|
- String decRes = dataHandler.processRspData(encRes);
|
|
|
- JSONObject resObj = JSONObject.parseObject(decRes);
|
|
|
-
|
|
|
- log.info("医保移动支付退款结果: {}", resObj);
|
|
|
- Integer code = resObj.getInteger("code");
|
|
|
+ JSONObject decRes = dataHandler.processRspData(encRes);
|
|
|
+ Integer code = decRes.getInteger("code");
|
|
|
if (null != code && code == 0) {
|
|
|
- JSONObject data = resObj.getJSONObject("data");
|
|
|
+ JSONObject data = decRes.getJSONObject("data");
|
|
|
OrdState state = OrdState.get(data.getString("refStatus"));
|
|
|
if (null == state) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
@@ -276,7 +276,7 @@ public class PowersiMiPayPlugin {
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, data.getString("failMsg"));
|
|
|
}
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, resObj.getString("message"));
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, decRes.getString("message"));
|
|
|
}
|
|
|
|
|
|
private PowersiMipSetlinfo getRefundableSetl(String id) {
|
|
@@ -319,11 +319,10 @@ public class PowersiMiPayPlugin {
|
|
|
HttpEntity<String> entity = new HttpEntity<>(body, headers);
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
String encRes = restTemplate.postForObject(url, entity, String.class);
|
|
|
- String decRes = dataHandler.processRspData(encRes);
|
|
|
- JSONObject resObj = JSONObject.parseObject(decRes);
|
|
|
- Integer code = resObj.getInteger("code");
|
|
|
+ JSONObject decRes = dataHandler.processRspData(encRes);
|
|
|
+ Integer code = decRes.getInteger("code");
|
|
|
if (null != code && code == 0) {
|
|
|
- JSONObject data = resObj.getJSONObject("data");
|
|
|
+ JSONObject data = decRes.getJSONObject("data");
|
|
|
data.remove("hiExtData");
|
|
|
OrdState state = OrdState.get(data.getString("refdStatus"));
|
|
|
if (null == state) {
|
|
@@ -333,7 +332,7 @@ public class PowersiMiPayPlugin {
|
|
|
dao.updateRefundState(refId, state);
|
|
|
return ResultVoUtil.success(state.toString());
|
|
|
}
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, resObj.getString("message"));
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, decRes.getString("message"));
|
|
|
}
|
|
|
|
|
|
}
|