| | |
| | | package com.gkhy.exam.pay.service.impl; |
| | | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.gkhy.exam.pay.entity.CoalPayStudent; |
| | | import com.gkhy.exam.pay.entity.NonCoalPayStudent; |
| | | import com.gkhy.exam.pay.mapper.CoalPayStudentMapper; |
| | | import com.gkhy.exam.pay.mapper.NonCoalPayStudentMapper; |
| | | import com.gkhy.exam.pay.service.PaymentService; |
| | | import com.gkhy.exam.pay.utils.CaiZhengConstans; |
| | | import com.gkhy.exam.pay.utils.PayUtils; |
| | | import jar.org.apache.commons.codec.binary.Base64; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static com.ruoyi.common.utils.Threads.sleep; |
| | | |
| | | @Service |
| | | @Slf4j |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String reqdatastr1 = "{\"orderNo\": \"" + orderNo + "\"}"; |
| | | String mac1 = getMD5("A1749891493E4CDDBFE4506357B1F0AB||" + getBase64(reqdatastr1)); |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("appid", "A1749891493E4CDDBFE4506357B1F0AB"); |
| | | jsonObject1.put("mac", mac1); |
| | | jsonObject1.put("reqdata", getBase64(reqdatastr1)); |
| | | String resultStr1 = HttpUtil.post("http://finpt.xjcz.gov.cn/fs-service/fs-pay/notifyConfirm.do", jsonObject1); |
| | | System.out.println("通知确定入参===" + jsonObject1); |
| | | JSONObject result1 = JSONObject.parseObject(resultStr1); |
| | | System.out.println("通知确定回参===" + result1); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | public String getMD5(String input) { |
| | | try { |
| | | MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | byte[] messageDigest = md.digest(input.getBytes()); |
| | | StringBuilder hexString = new StringBuilder(); |
| | | for (byte b : messageDigest) { |
| | | hexString.append(String.format("%02x", new Object[]{Byte.valueOf(b)})); |
| | | } |
| | | return hexString.toString(); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public String getBase64(String str) { |
| | | String encodedStr = Base64.encodeBase64String(str.getBytes()); |
| | | return encodedStr; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void schedulePayment() { |
| | | List<NonCoalPayStudent> nonCoalPayStudents = nonCoalPayStudentMapper.getsch(); |
| | | |
| | | if (nonCoalPayStudents != null) { |
| | | for (NonCoalPayStudent nonCoalPayStudent : nonCoalPayStudents) { |
| | | sleep(5000); |
| | | if (nonCoalPayStudent.getGovPayStatus() == 2 && nonCoalPayStudent.getPayStatus() == 0) { |
| | | try { |
| | | JSONObject result = payUtils.query(nonCoalPayStudent.getOrderNo()); |
| | | log.info("查询财政订单返回结果:" + result); |
| | | String respcode = result.getString("respcode"); |
| | | if (CaiZhengConstans.CAI_ZHENG_SUCCESS.equals(respcode)) { |
| | | JSONObject respdata = result.getJSONObject("respdata"); |
| | | if (respdata != null && "1".equals(respdata.getString("status"))) { |
| | | nonCoalPayStudentMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate() |
| | | .set(NonCoalPayStudent::getPayStatus, 1) |
| | | .set(NonCoalPayStudent::getPayTime, respdata.getDate("payTime")) |
| | | .eq(NonCoalPayStudent::getOrderNo, nonCoalPayStudent.getOrderNo()).eq(NonCoalPayStudent::getDelFlag, 0) |
| | | .eq(NonCoalPayStudent::getPayStatus, 0)); |
| | | // 回调确认支付 |
| | | nonCoalPayStudent.setPayStatus(1L); |
| | | payUtils.affirmPost(nonCoalPayStudent.getOrderNo()); |
| | | } else { |
| | | log.error("查询财政订单失败:" + result.getString("respmsg") + ",错误编码:" + result.getString("respcode")); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("查询财政订单失败:" + e.getMessage()); |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |