package com.stylefeng.guns.modular.huifu.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.huifu.bspay.sdk.opps.core.utils.RsaUtils; import com.stylefeng.guns.modular.huifu.properties.HuiFuProperties; import com.stylefeng.guns.modular.system.model.TCompanyWithdraw; import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal; import com.stylefeng.guns.modular.system.model.TPubWithdrawal; import com.stylefeng.guns.modular.system.service.ITCompanyWithdrawService; import com.stylefeng.guns.modular.system.service.ITEnterpriseWithdrawalService; import com.stylefeng.guns.modular.system.service.ITPubWithdrawalService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Objects; /** * @author mitao * @date 2025/11/21 */ @Slf4j @RestController @RequestMapping("/base/dougong") public class DouGongNotifyController { @Autowired private HuiFuProperties huiFuProperties; @Autowired private ITCompanyWithdrawService companyWithdrawService; @Autowired private ITPubWithdrawalService pubWithdrawalService; /** * 斗拱主动取现接口企业回调 * @param request * @param response */ @PostMapping("/ent/encashment") public ResponseEntity entEncashment(HttpServletRequest request, HttpServletResponse response) { String sign =request.getParameter("sign"); String resp_data = request.getParameter("resp_data"); log.info("斗拱企业提现响应内容:{}", resp_data); // 使用汇付公钥验签 resp_data = resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")"); boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign); if(verify){ JSONObject respDataJson = JSONObject.parseObject(resp_data); String reqSeqId = respDataJson.getString("req_seq_id"); String hfSeqId = respDataJson.getString("hf_seq_id"); String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S TCompanyWithdraw companyWithdraw = companyWithdrawService.selectOne(new EntityWrapper().eq("reqSeqId", reqSeqId).or().eq("hfSeqId", hfSeqId).last("limit 1")); if (Objects.isNull(companyWithdraw)) { return ResponseEntity.ok(""); } if ("S".equalsIgnoreCase(transStat)) { companyWithdraw.setStatus(1); } else if ("F".equalsIgnoreCase(transStat)) { companyWithdraw.setStatus(2); } companyWithdrawService.updateById(companyWithdraw); log.info("更新企业提现记录成功,更新内容“{}", JSONObject.toJSON(companyWithdraw)); return ResponseEntity.ok("RECV_ORD_ID_" + reqSeqId); } return null; } /** * 斗拱主动取现接口回调 * @param request * @param response */ @PostMapping("/user/encashment") public ResponseEntity userEncashment(HttpServletRequest request, HttpServletResponse response) { String sign =request.getParameter("sign"); String resp_data = request.getParameter("resp_data"); log.info("斗拱企业提现响应内容:{}", resp_data); // 使用汇付公钥验签 resp_data = resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")"); boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign); if(verify){ JSONObject respDataJson = JSONObject.parseObject(resp_data); String reqSeqId = respDataJson.getString("req_seq_id"); String hfSeqId = respDataJson.getString("hf_seq_id"); String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S TPubWithdrawal pubWithdrawal = pubWithdrawalService.selectOne(new EntityWrapper().eq("reqSeqId", reqSeqId).or().eq("hfSeqId", hfSeqId).last("limit 1")); if (Objects.isNull(pubWithdrawal)) { return ResponseEntity.ok(""); } if ("S".equalsIgnoreCase(transStat)) { pubWithdrawal.setState(2); } else if ("F".equalsIgnoreCase(transStat)) { pubWithdrawal.setState(3); } pubWithdrawalService.updateById(pubWithdrawal); log.info("更新用户/司机提现记录成功,更新内容“{}", JSONObject.toJSON(pubWithdrawal)); return ResponseEntity.ok("RECV_ORD_ID_" + reqSeqId); } return null; } }