| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- package com.keao.edu.user.service;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.huifu.adapay.Adapay;
- import com.huifu.adapay.notify.MQTTCallbackHandler;
- import com.keao.edu.thirdparty.adapay.ConfigInit;
- import com.keao.edu.user.dao.SysConfigDao;
- import com.keao.edu.user.entity.ExamRegistrationPayment;
- import com.keao.edu.user.enums.TransStatusEnum;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.PostConstruct;
- import java.util.HashMap;
- import java.util.Map;
- @Service
- public class NotifyCallback implements MQTTCallbackHandler {
- @Autowired
- private ExamRegistrationPaymentService examRegistrationPaymentService;
- @Autowired
- private SysConfigDao sysConfigDao;
- private static NotifyCallback notifyCallback;
- @PostConstruct
- public void init() {
- notifyCallback = this;
- String baseApiUrl = notifyCallback.sysConfigDao.findConfigValue("base_api_url");
- Adapay.setDeviceID(baseApiUrl);
- }
- /**
- * 用户接收并处理支付成功的异步消息
- *
- * @param payment 成功的支付对象
- * @throws Exception 异常
- */
- @Override
- public void paymentSuccessMessageArrived(String payment) throws Exception {
- System.out.println(String.format("receive paymentSuccess msg=%s", payment));
- JSONObject dataObj = JSON.parseObject(payment);
- if (!dataObj.getString("app_id").equals(ConfigInit.appId)) {
- return;
- }
- String orderNo = dataObj.getString("order_no");
- ExamRegistrationPayment order = notifyCallback.examRegistrationPaymentService.getByOrderNo(orderNo);
- if (order == null || !order.getTransStatus().equals(TransStatusEnum.ING)) {
- return;
- }
- Map<String,String> rpMap = new HashMap<>();
- rpMap.put("channelType", dataObj.getString("pay_channel"));
- rpMap.put("transStatus","SUCCESS");
- rpMap.put("orderNo",orderNo);
- rpMap.put("transNo",order.getTransNo());
- notifyCallback.examRegistrationPaymentService.updateOrder(rpMap);
- }
- /**
- * 用户接收并处理支付失败的异步消息
- *
- * @param payment 失败的支付对象
- * @throws Exception 异常
- */
- @Override
- public void paymentFailedMessageArrived(String payment) throws Exception {
- System.out.println(String.format("receive paymentFailed msg=%s", payment));
- JSONObject dataObj = JSON.parseObject(payment);
- if (!dataObj.getString("app_id").equals(ConfigInit.appId)) {
- return;
- }
- String orderNo = dataObj.getString("order_no");
- ExamRegistrationPayment order = notifyCallback.examRegistrationPaymentService.getByOrderNo(orderNo);
- if (order == null || !order.getTransStatus().equals("ING")) {
- return;
- }
- Map<String,String> rpMap = new HashMap<>();
- rpMap.put("channelType", dataObj.getString("pay_channel"));
- rpMap.put("transStatus","FAILED");
- rpMap.put("orderNo",orderNo);
- rpMap.put("transNo",order.getTransNo());
- notifyCallback.examRegistrationPaymentService.updateOrder(rpMap);
- }
- /**
- * 用户接收并处理关闭支付交易成功的异步消息
- *
- * @param payment 关闭成功的支付对象
- * @throws Exception 异常
- */
- @Override
- public void paymentCloseSuccessMessageArrived(String payment) throws Exception {
- System.out.println(String.format("receive paymentCloseSuccess msg=%s", payment));
- JSONObject dataObj = JSON.parseObject(payment);
- if (!dataObj.getString("app_id").equals(ConfigInit.appId)) {
- return;
- }
- String orderNo = dataObj.getString("order_no");
- ExamRegistrationPayment order = notifyCallback.examRegistrationPaymentService.getByOrderNo(orderNo);
- if (order == null || !order.getTransStatus().equals(TransStatusEnum.ING)) {
- return;
- }
- Map<String,String> rpMap = new HashMap<>();
- rpMap.put("channelType", dataObj.getString("pay_channel"));
- rpMap.put("transStatus","FAILED");
- rpMap.put("orderNo",orderNo);
- rpMap.put("transNo",order.getTransNo());
- notifyCallback.examRegistrationPaymentService.updateOrder(rpMap);
- }
- /**
- * 用户接收并处理关闭支付交易失败的异步消息
- *
- * @param payment 关闭失败的支付对象
- * @throws Exception 异常
- */
- @Override
- public void paymentCloseFailedMessageArrived(String payment) throws Exception {
- System.out.println(String.format("receive paymentCloseFailed msg=%s", payment));
- }
- @Override
- public void paymentReverseFailedMessageArrived(String payment) throws Exception {
- System.out.println(String.format("receive payment ReverseFailed msg=%s", payment));
- }
- @Override
- public void paymentReverseSuccessMessageArrived(String payment) throws Exception {
- System.out.println(String.format("receive payment ReverseSuccess msg=%s", payment));
- }
- /**
- * 用户接收并处理退款成功的异步消息
- *
- * @param refund 成功的退款对象
- * @throws Exception 异常
- */
- @Override
- public void refundSuccessMessageArrived(String refund) throws Exception {
- System.out.println(String.format("receive refundSuccess msg=%s", refund));
- }
- /**
- * 用户接收并处理退款失败的异步消息
- *
- * @param refund 失败的退款对象
- * @throws Exception 异常
- */
- @Override
- public void refundFailedMessageArrived(String refund) throws Exception {
- System.out.println(String.format("receive refundFailed msg=%s", refund));
- }
- @Override
- public void corpMemberSuccessMessageArrived(String corpMember) throws Exception {
- System.out.println(String.format("receive corpMember msg=%s", corpMember));
- }
- @Override
- public void corpMemberFailedMessageArrived(String corpMember) throws Exception {
- System.out.println(String.format("receive corpMember msg=%s", corpMember));
- }
- @Override
- public void unknowMessageArrived(String message) throws Exception {
- System.out.println(String.format("receive unknow msg=%s", message));
- }
- @Override
- public void drawCashFailedMessageArrived(String drawCash) throws Exception {
- System.out.println(String.format("receive unknow msg=%s", drawCash));
- }
- @Override
- public void drawCashSuccessedMessageArrived(String drawCash) throws Exception {
- System.out.println(String.format("receive unknow msg=%s", drawCash));
- }
- @Override
- public void pagePaymentFailedMessageArrived(String arg0) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void pagePaymentSuccessedMessageArrived(String arg0) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void connectionLost(String message) throws Exception {
- // TODO Auto-generated method stub
- System.out.println("mqtt...........lost.............");
- }
- @Override
- public void connectSuccess() throws Exception {
- System.out.println("mqtt...........connect.............");
- }
- }
|