Przeglądaj źródła

汇付支付修改

周箭河 5 lat temu
rodzic
commit
2dc85d9748

+ 191 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/NotifyCallback.java

@@ -0,0 +1,191 @@
+package com.ym.mec.biz.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.huifu.adapay.notify.MQTTCallbackHandler;
+import com.ym.mec.thirdparty.adapay2.ConfigInit;
+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 StudentPaymentOrderService studentPaymentOrderService;
+
+    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;
+        }
+
+        Map<String, String> notifyMap = new HashMap<>();
+        notifyMap.put("channelType", dataObj.getString("pay_channel"));
+        notifyMap.put("tradeState", "1");
+        notifyMap.put("totalMoney", dataObj.getString("pay_amt"));
+        notifyMap.put("merOrderNo", dataObj.getString("order_no"));
+        notifyCallback.studentPaymentOrderService.updateOrder(notifyMap);
+    }
+
+    /**
+     * 用户接收并处理支付失败的异步消息
+     *
+     * @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;
+        }
+
+        Map<String, String> notifyMap = new HashMap<>();
+        notifyMap.put("channelType", dataObj.getString("pay_channel"));
+        notifyMap.put("tradeState", "0");
+        notifyMap.put("totalMoney", dataObj.getString("pay_amt"));
+        notifyMap.put("merOrderNo", dataObj.getString("order_no"));
+        notifyCallback.studentPaymentOrderService.updateOrder(notifyMap);
+    }
+
+
+    /**
+     * 用户接收并处理关闭支付交易成功的异步消息
+     *
+     * @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;
+        }
+
+        Map<String, String> notifyMap = new HashMap<>();
+        notifyMap.put("channelType", dataObj.getString("pay_channel"));
+        notifyMap.put("tradeState", "0");
+        notifyMap.put("totalMoney", dataObj.getString("pay_amt"));
+        notifyMap.put("merOrderNo", dataObj.getString("order_no"));
+        notifyCallback.studentPaymentOrderService.updateOrder(notifyMap);
+    }
+
+    /**
+     * 用户接收并处理关闭支付交易失败的异步消息
+     *
+     * @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.............");
+    }
+}

+ 15 - 0
mec-student/src/main/java/com/ym/mec/student/StudentApplication.java

@@ -2,6 +2,10 @@ package com.ym.mec.student;
 
 import javax.servlet.Filter;
 
+import com.huifu.adapay.Adapay;
+import com.huifu.adapay.model.MerConfig;
+import com.ym.mec.thirdparty.adapay2.ConfigInit;
+import com.ym.mec.biz.service.NotifyCallback;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -56,4 +60,15 @@ public class StudentApplication {
 		return registration;
 	}
 
+	@Bean
+	public static void startMqtt() {
+		MerConfig merConfig = ConfigInit.merConfig;
+		NotifyCallback notifyCallback = new NotifyCallback();
+		try {
+			Adapay.startMqttListener(merConfig, notifyCallback);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
 }

+ 19 - 12
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -1,5 +1,6 @@
 package com.ym.mec.student.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.OrderTypeEnum;
@@ -24,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.connection.RedisServer;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
@@ -177,7 +179,7 @@ public class StudentOrderController extends BaseController {
         paymentParams.put("pay_amt", amount);
         paymentParams.put("goods_title", orderSubject);
         paymentParams.put("goods_desc", orderBody);
-        paymentParams.put("notify_url", notifyUrl);
+       // paymentParams.put("notify_url", "https://wxwechat.utools.club/studentOrder/adaNotify");
 
         List<Map<String, Object>> divMembers = new ArrayList<>();
         Map<String, Object> divMember = new HashMap<>();
@@ -206,22 +208,27 @@ public class StudentOrderController extends BaseController {
     @PostMapping("/adaNotify")
     public void adaNotify(@ModelAttribute NotifyEvent notifyEvent) throws Exception {
         logger.info(notifyEvent.toString());
-        if (notifyEvent.getType().equals("payment.success") && notifyEvent.getType().equals("payment.failed")) {
+        System.out.println("查看");
+        //[data={"app_id":"app_f0ebdd29-046f-4b60-bd50-92e2c1285c02","created_time":"20200629144014","end_time":"20200629144025","expend":{},"id":"002112020062914401310123566451963129856","order_no":"20062914394700001","out_trans_id":"2020062922001436811416495773","party_order_id":"02212006295281400400681","pay_amt":"0.01","pay_channel":"alipay_qr","status":"succeeded"}]
+
+        if (!notifyEvent.getType().equals("payment.succeeded") && !notifyEvent.getType().equals("payment.failed")) {
             return;
         }
+        String data = notifyEvent.getData();
 
-        Map<String, String> notifyMap = JSON.parseObject(notifyEvent.getData(), Map.class);
+        JSONObject dataObj = JSON.parseObject(notifyEvent.getData());
+        if (!dataObj.getString("app_id").equals(ConfigInit.appId)) {
+            return;
+        }
 
+        Map<String, String> notifyMap = new HashMap<>();
         //支付中订单存在,更新状态
-        if (notifyMap.size() > 0) {
-            String tradeState = notifyEvent.getType().equals("payment.success") ? "1" : "0";
-            notifyMap.put("tradeState", tradeState);
-            notifyMap.put("totalMoney", notifyMap.get("pay_amt"));
-            notifyMap.put("merOrderNo", notifyMap.get("order_no"));
-            notifyMap.put("merOrderNo", notifyMap.get("order_no"));
-            notifyMap.put("remarks", notifyMap.get("description"));
-            studentPaymentOrderService.updateOrder(notifyMap);
-        }
+        String tradeState = notifyEvent.getType().equals("payment.succeeded") ? "1" : "0";
+        notifyMap.put("channelType", dataObj.getString("pay_channel"));
+        notifyMap.put("tradeState", tradeState);
+        notifyMap.put("totalMoney", dataObj.getString("pay_amt"));
+        notifyMap.put("merOrderNo", dataObj.getString("order_no"));
+        studentPaymentOrderService.updateOrder(notifyMap);
     }
 
     @GetMapping("/authorize")

+ 3 - 3
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay2/ConfigInit.java

@@ -15,6 +15,7 @@ public class ConfigInit {
     public final static String wxAppId = "wx80f175c0eb6836e9";
     public final static String wxAppSecret = "f817dc79e4149aaa4fafd6f8279b3593";
     public final static String wxMpOAuth2AccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
+    public final static MerConfig merConfig = new MerConfig();
 
     static {
         try {
@@ -47,7 +48,6 @@ public class ConfigInit {
         String mockApiKey = "api_test_193c8f6a-514f-4d95-a26b-2861c7971105";
         String rsaPrivateKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAL3zHDr2s5Lp3b9FKAD4vB3Y2MyOypv68mKFi8uPznO9JkzBhwYLYRC8mnP+W7tw5Q7Yuf5Szhn8Mo9KZ8Bsv6S6iz3BtXzeHb/8nyeBAH2m477bJzwmapZPhPSroR8md1dnNI+4NttM/0Cn/rdAySzQn+IPHLPxWFwQw+y6FFi7AgMBAAECgYEAkuUBPfAvKzxEyng22ZmCESrzbi43La1B6UMRuxi5NfRfPBilzNzb8c+JOo7Ibgp+eZ7NJ4rt7FaG2x1VYxA2m151I86e6TlgPYNjjj56RpkrD9/LrDqePFE4AlrwO5802fK4X/iac1MCpEhaiVNQ3x6ikwcKWzKmMV/EpdijIcECQQDlt+ou3L5M2TQW8YYg9zA9TKRd+M/Xs0tPLJLE+W6m0+dmyeHBErMW6X874qhmIc3F8HYIW+O51GMy6KDgQ7PrAkEA065ujs1ZkwIPMopgIoqlRi8JDvAxgEZqktDDMMg0o2XZP6J7C5suf2BsrhKnjLlxII7dQPxDfPDiRz4jYpBKcQJBAKd77ev42W5iNk48DdTfJHas+HHjRHY5rMCu+NtQGNLdUKtqqYQBRD2CRFe/K5Q7NTIJ3aS+ikwkg6bMYO7hrb0CQDesuC1c+0M8Fm0vketj1eZotpQ0PoDDhIJK4BuzfIzBW+ttu7kovokH/m2mQGU13Pg4Ox89ei6hWJJuWHYzBzECQQDexzziaTpHMy3achL2M2pOSdaSLYoesmPTmVZ3kOZf82FpRlfxVGUs0nKpEEgagUkiHUQHAu5RVkxIiDqMYrQp";
 
-        MerConfig merConfig = new MerConfig();
         merConfig.setApiKey(apiKey);
         merConfig.setApiMockKey(mockApiKey);
         merConfig.setRSAPrivateKey(rsaPrivateKey);
@@ -55,8 +55,8 @@ public class ConfigInit {
         /**
          *启动MQTT,一个商户只需要 启动一次,启动完成以后一直在服务器后端运行
          */
-        NotifyCallback notifyCallback = new NotifyCallback();
-        Adapay.startMqttListener(merConfig, notifyCallback);
+        // notifyCallback = new NotifyCallback();
+        //Adapay.startMqttListener(merConfig, notifyCallback);
         return instance;
     }
 

+ 1 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay2/MainDemo.java

@@ -21,6 +21,7 @@ public class MainDemo {
 
 
     public static void testMerchant() throws Exception {
+        //Payment.closePayment("002112020062910440410123507019803422720");
 
 
         // 运行支付类接口

+ 0 - 138
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay2/NotifyCallback.java

@@ -1,138 +0,0 @@
-package com.ym.mec.thirdparty.adapay2;
-
-import com.huifu.adapay.notify.MQTTCallbackHandler;
-
-/**
- * @author jane.zhao
- */
-public class NotifyCallback implements MQTTCallbackHandler {
-
-    /**
-     * 用户接收并处理支付成功的异步消息
-     *
-     * @param payment 成功的支付对象
-     * @throws Exception 异常
-     */
-    @Override
-    public void paymentSuccessMessageArrived( String payment) throws Exception {
-        System.out.println(String.format("receive paymentSuccess  msg=%s",  payment));
-
-    }
-
-    /**
-     * 用户接收并处理支付失败的异步消息
-     *
-     * @param payment 失败的支付对象
-     * @throws Exception 异常
-     */
-    @Override
-    public void paymentFailedMessageArrived( String payment) throws Exception {
-        System.out.println(String.format("receive paymentFailed msg=%s",  payment));
-    }
-
-    /**
-     * 用户接收并处理关闭支付交易成功的异步消息
-     *
-     * @param payment 关闭成功的支付对象
-     * @throws Exception 异常
-     */
-    @Override
-    public void paymentCloseSuccessMessageArrived( String payment) throws Exception {
-        System.out.println(String.format("receive paymentCloseSuccess msg=%s",  payment));
-    }
-
-    /**
-     * 用户接收并处理关闭支付交易失败的异步消息
-     *
-     * @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.............");
-    }
-}

+ 4 - 79
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay2/Payment.java

@@ -24,11 +24,12 @@ public class Payment extends ConfigInit {
         //支付接口
         Map<String, Object> paymentParams = new HashMap<>(10);
         paymentParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
-        paymentParams.put("pay_channel", "wx_pub");
+        paymentParams.put("pay_channel", "alipay_wap");
         paymentParams.put("pay_amt", "0.01");
 
         paymentParams.put("goods_title", "your goods title");
         paymentParams.put("goods_desc", "your goods desc");
+        paymentParams.put("notify_url", "https://wxwechat.utools.club/studentOrder/adaNotify");
 
 
         paymentParams.put("div_members", "");
@@ -71,13 +72,11 @@ public class Payment extends ConfigInit {
        // expendParams.put("promotion_detail", promotionDetail);
         paymentParams.put("expend", expendParams);
         Map<String, Object> payment = executePayment(paymentParams);
-        payment = createReverse(merchantKey, "002112020062910440410123507019803422720", appId);
-        payment = createConfirm(merchantKey, "002112020062910440410123507019803422720", appId);
         System.out.println("钱包支付地址:" + payment.get("pay_url"));
         //支付查询接口
-        queryPayment((String) payment.get("id"));
+       // queryPayment((String) payment.get("id"));
         // //关单接口
-        closePayment((String) payment.get("id"));
+       // closePayment((String) payment.get("id"));
 
         return (String) payment.get("id");
     }
@@ -147,7 +146,6 @@ public class Payment extends ConfigInit {
         return payment;
     }
 
-
     /**
      * 查询一个支付交易
      *
@@ -179,79 +177,6 @@ public class Payment extends ConfigInit {
     }
 
 
-    /**
-     * 创建撤销对象
-     *
-     * @param paymentId 要查询的支付id
-     * @return 查询的支付对象
-     * @throws Exception 异常
-     */
-    public static Map<String, Object> createReverse(String merchantKey, String paymentId, String app_id) throws Exception {
-        System.out.println("=======create Reverse  begin=======");
-
-        Map<String, Object> reverse = new HashMap<>();
-
-        reverse.put("payment_id", paymentId);
-        reverse.put("app_id", app_id);
-        reverse.put("order_no", "jsdk_reverse_" + System.currentTimeMillis());
-        reverse.put("app_id", app_id);
-        reverse.put("notify_url", "");
-        reverse.put("reverse_amt", "0.01");
-        reverse.put("reason", "reason");
-        reverse.put("expand", "expend");
-        reverse.put("device_info", "device_info");
-
-
-        try {
-            System.out.println("创建撤销对象" + JSON.toJSONString(reverse));
-            reverse = com.huifu.adapay.model.Payment.createReverse(reverse, merchantKey);
-        } catch (BaseAdaPayException e) {
-            e.printStackTrace();
-        }
-
-        System.out.println("创建撤销对象返回参数:" + JSON.toJSONString(reverse));
-        String error_code = (String) reverse.get("error_code");
-        if (null == error_code) {
-            String error_msg = (String) reverse.get("error_msg");
-            System.out.println("error_code:" + error_code + "............." + error_msg);
-        }
-        System.out.println("=======create Reverse  end=======");
-        return reverse;
-    }
-
-    /**
-     * 创建确认对象
-     *
-     * @return 查询的支付对象
-     * @throws Exception 异常
-     */
-    public static Map<String, Object> createConfirm(String merchantKey, String paymentId, String app_id) throws Exception {
-        System.out.println("=======create confirm  begin=======");
-
-        Map<String, Object> confirm = new HashMap<>();
-
-        confirm.put("payment_id", paymentId);
-        confirm.put("order_no", "jsdk_confirm_" + System.currentTimeMillis());
-        confirm.put("confirm_amt", "0.01");
-        confirm.put("description", "description");
-        confirm.put("div_members", "");
-
-        try {
-            System.out.println("创建确认对象" + JSON.toJSONString(confirm));
-            confirm = com.huifu.adapay.model.Payment.createConfirm(confirm, merchantKey);
-        } catch (BaseAdaPayException e) {
-            e.printStackTrace();
-        }
-        String error_code = (String) confirm.get("error_code");
-        if (null == error_code) {
-            String error_msg = (String) confirm.get("error_msg");
-            System.out.println("error_code:" + error_code + "............." + error_msg);
-        }
-        System.out.println("创建确认对象返回参数:" + JSON.toJSONString(confirm));
-        System.out.println("=======create confirm  end=======");
-        return confirm;
-    }
-
     public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sellerNo, List<Map<String, Object>> tempRoutingList) throws Exception {
         Map<String, Object> paymentParams = new HashMap<>(10);
         paymentParams.put("appId", appId);