|
@@ -0,0 +1,189 @@
|
|
|
+package com.keao.edu.user.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huifu.adapay.notify.MQTTCallbackHandler;
|
|
|
+import com.keao.edu.thirdparty.adapay.ConfigInit;
|
|
|
+import com.keao.edu.user.entity.ExamRegistrationPayment;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+public class NotifyCallback implements MQTTCallbackHandler {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamRegistrationPaymentService examRegistrationPaymentService;
|
|
|
+
|
|
|
+
|
|
|
+ private static NotifyCallback notifyCallback;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ notifyCallback = this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户接收并处理支付成功的异步消息
|
|
|
+ *
|
|
|
+ * @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);
|
|
|
+ order.setPayChannel(dataObj.getString("pay_channel"));
|
|
|
+ order.setTransStatus("SUCCESS");
|
|
|
+ order.setUpdateTime(new Date());
|
|
|
+ order.setTransSuccessedTime(new Date());
|
|
|
+ notifyCallback.examRegistrationPaymentService.updateOrder(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户接收并处理支付失败的异步消息
|
|
|
+ *
|
|
|
+ * @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);
|
|
|
+ order.setPayChannel(dataObj.getString("pay_channel"));
|
|
|
+ order.setTransStatus("FAILED");
|
|
|
+ order.setUpdateTime(new Date());
|
|
|
+ notifyCallback.examRegistrationPaymentService.updateOrder(order);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户接收并处理关闭支付交易成功的异步消息
|
|
|
+ *
|
|
|
+ * @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);
|
|
|
+ order.setPayChannel(dataObj.getString("pay_channel"));
|
|
|
+ order.setTransStatus("FAILED");
|
|
|
+ order.setUpdateTime(new Date());
|
|
|
+ notifyCallback.examRegistrationPaymentService.updateOrder(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户接收并处理关闭支付交易失败的异步消息
|
|
|
+ *
|
|
|
+ * @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.............");
|
|
|
+ }
|
|
|
+}
|