Browse Source

增加乐器采购清单确认接口

周箭河 5 years ago
parent
commit
2ea83ece10

+ 15 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -5,8 +5,10 @@ import com.ym.mec.biz.dal.entity.SysAccount;
 import com.ym.mec.biz.service.PayService;
 import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.biz.service.SysAccountService;
+import com.ym.mec.thirdparty.adapay.Pay;
 import com.ym.mec.thirdparty.union.UnionPay;
 import com.ym.mec.thirdparty.union.UnionPayFeignService;
+import com.ym.mec.thirdparty.yqpay.YqPayUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -44,12 +46,20 @@ public class PayServiceImpl implements PayService {
     public Map getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody) throws Exception {
         //支付通道决策
         SysAccount routingAccount = getRoutingAccount(amount);
-        HashMap<String, Object> unionPay = new HashMap<>();
-        Map payMap;
+        Map unionPay = new HashMap();
+        Map payMap = null;
+
+
+        if (routingAccount != null) {
+            payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routingAccount.getMerNo());
+        }
+
         payMap = UnionPay.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject);
-        unionPay.put("orderNo", "1017"+orderNo);
-        unionPay.put("type", "UNIONPAY");
+        unionPay.put("orderNo", "1017" + orderNo);
+        //unionPay.put("type", "UNIONPAY");
         unionPay.put("payMap", payMap);
+
+        unionPay.put("type","ADAPY");
         return unionPay;
     }
 
@@ -61,6 +71,7 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 获取收款的账户
+     *
      * @param money
      * @return
      */
@@ -73,9 +84,6 @@ public class PayServiceImpl implements PayService {
             routingAccount = sysAccountService.getPerAccount(money);
         }
 
-        //临时全返回双乾
-        routingAccount = sysAccountService.getPerAccount(money);
-
         return routingAccount;
     }
 

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -47,7 +47,7 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
     @Override
     public List<Goods> getMusicalList(String musicGroupId) {
         List<StudentPaymentOrderDetail> applyOrder = findApplyOrderSuccess(musicGroupId, DealStatusEnum.SUCCESS);
-        if(applyOrder == null){
+        if(applyOrder == null || applyOrder.size()==0){
             return null;
         }
         String goodsIdsStr = "";

+ 7 - 2
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

@@ -1,5 +1,7 @@
 package com.ym.mec.student.controller;
 
+import com.huifu.adapay.model.payment.PayChannelEnum;
+import com.huifu.adapay.model.payment.Payment;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.MusicGroupStudentFeeDao;
@@ -12,6 +14,7 @@ import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.IdGeneratorService;
+import com.ym.mec.thirdparty.adapay.Pay;
 import com.ym.mec.util.string.IdWorker;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -335,8 +338,10 @@ public class MusicGroupController extends BaseController {
 //
         String orderNo = idGeneratorService.generatorId("payment")+"";
         BigDecimal amount = new BigDecimal("0.01");
-        Map map = payService.getPayMap(amount, orderNo, "http://47.99.212.176:8000/studentOrder/notify", "https://baodiu.com", "测试订单", "测试订单");
-       return succeed(map);
+        String payChannel = PayChannelEnum.ALIPAY_QR.getCode();
+        Payment payment = Pay.executePayment(amount, orderNo, payChannel, "测试订单", "测试订单");
+        //Map map = payService.getPayMap(amount, orderNo, "http://47.99.212.176:8000/studentOrder/notify", "https://baodiu.com", "测试订单", "测试订单");
+       return succeed(payment);
     }
 
     @ApiOperation(value = "订单状态查询")

BIN
mec-thirdparty/libs/adapay-java-sdk-1.0.2.jar


+ 14 - 0
mec-thirdparty/pom.xml

@@ -67,6 +67,20 @@
 			<systemPath>${project.basedir}/libs/SADK-3.2.5.2.jar</systemPath>
 		</dependency>
 		<dependency>
+			<groupId>adapay</groupId>
+			<artifactId>adapay-java-sdk</artifactId>
+			<version>1.0.2</version>
+			<scope>system</scope>
+			<systemPath>${project.basedir}/libs/adapay-java-sdk-1.0.2.jar
+			</systemPath>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.paho</groupId>
+			<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
+			<version>1.2.0</version>
+		</dependency>
+
+		<dependency>
 			<groupId>org.springframework.cloud</groupId>
 			<artifactId>spring-cloud-starter-openfeign</artifactId>
 		</dependency>

+ 7 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/BaseDemo.java

@@ -0,0 +1,7 @@
+package com.ym.mec.thirdparty.adapay;
+
+/**
+ * @author jane.zhao
+ */
+public class BaseDemo {
+}

+ 38 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/MainDemo.java

@@ -0,0 +1,38 @@
+package com.ym.mec.thirdparty.adapay;
+
+import com.huifu.adapay.AdaPay;
+import com.huifu.adapay.demo.NotifyCallbackDemo;
+import com.huifu.adapay.demo.PaymentDemo;
+import com.huifu.adapay.demo.RefundDemo;
+
+/**
+ * @author jane.zhao
+ */
+public class MainDemo {
+    public static void main(String[] args) throws Exception {
+        //apiKey,商户联调用
+        String apiKey = "api_test_e640fa26-bbe6-458f-ac44-a71723ee2176";
+        //apiKey,真实交易用(live)
+        String apiKeyLive = "api_live_9c14f264-e390-41df-984d-df15a6952031";
+        //公钥
+        String pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB";
+        //私钥
+        String privateKey= "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMQhsygJ2pp4nCiDAXiqnZm6AzKSVAh+C0BgGR6QaeXzt0TdSi9VR0OQ7Qqgm92NREB3ofobXvxxT+wImrDNk6R6lnHPMTuJ/bYpm+sx397rPboRAXpV3kalQmbZ3P7oxtEWOQch0zV5B1bgQnTvxcG3REAsdaUjGs9Xvg0iDS2tAgMBAAECgYAqGFmNdF/4234Yq9V7ApOE1Qmupv1mPTdI/9ckWjaAZkilfSFY+2KqO8bEiygo6xMFCyg2t/0xDVjr/gTFgbn4KRPmYucGG+FzTRLH0nVIqnliG5Ekla6a4gwh9syHfstbOpIvJR4DfldicZ5n7MmcrdEwSmMwXrdinFbIS/P1+QJBAOr6NpFtlxVSGzr6haH5FvBWkAsF7BM0CTAUx6UNHb+RCYYQJbk8g3DLp7/vyio5uiusgCc04gehNHX4laqIdl8CQQDVrckvnYy+NLz+K/RfXEJlqayb0WblrZ1upOdoFyUhu4xqK0BswOh61xjZeS+38R8bOpnYRbLf7eoqb7vGpZ9zAkEAobhdsA99yRW+WgQrzsNxry3Ua1HDHaBVpnrWwNjbHYpDxLn+TJPCXvI7XNU7DX63i/FoLhOucNPZGExjLYBH/wJATHNZQAgGiycjV20yicvgla8XasiJIDP119h4Uu21A1Su8G15J2/9vbWn1mddg1pp3rwgvxhw312oInbHoFMxsQJBAJlyDDu6x05MeZ2nMor8gIokxq2c3+cnm4GYWZgboNgq/BknbIbOMBMoe8dJFj+ji3YNTvi1MSTDdSDqJuN/qS0=";
+
+        //设置AdaPay全局参数,不同环境设置不同的apiKey/pubKey/privateKey
+        AdaPay.apiKey = apiKeyLive;
+        AdaPay.pubKey = pubKey;
+        AdaPay.privateKey = privateKey;
+        AdaPay.debug = false;
+
+        //启动 mqtt 异步监听
+        AdaPay.iNotifyCallback = new NotifyCallbackDemo();
+        AdaPay.startNotifyListener();
+
+        //test chargeId = "002112019080716223300005091372336111616";
+        //运行支付类接口
+        String chargeId = PaymentDemo.executePaymentTest();
+        //运行退款类接口
+        RefundDemo.executeRefundTest(chargeId);
+    }
+}

+ 82 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/NotifyCallbackDemo.java

@@ -0,0 +1,82 @@
+package com.ym.mec.thirdparty.adapay;
+
+import com.alibaba.fastjson.JSON;
+import com.huifu.adapay.model.payment.Payment;
+import com.huifu.adapay.model.refund.Refund;
+import com.huifu.adapay.notify.INotifyCallback;
+/**
+ * @author jane.zhao
+ */
+public class NotifyCallbackDemo implements INotifyCallback {
+
+    /**
+     * 用户接收并处理支付成功的异步消息
+     * @param payment 成功的支付对象
+     * @throws Exception 异常
+     */
+    @Override
+    public void paymentSuccessMessageArrived(Payment payment) throws Exception {
+        System.out.println("receive paymentSuccess msg=" + JSON.toJSONString(payment));
+
+    }
+
+    /**
+     * 用户接收并处理支付失败的异步消息
+     * @param payment 失败的支付对象
+     * @throws Exception 异常
+     */
+    @Override
+    public void paymentFailedMessageArrived(Payment payment) throws Exception {
+        System.out.println("receive paymentFailed msg=" + JSON.toJSONString(payment));
+    }
+
+    /**
+     * 用户接收并处理关闭支付交易成功的异步消息
+     * @param payment 关闭成功的支付对象
+     * @throws Exception 异常
+     */
+    @Override
+    public void paymentCloseSuccessMessageArrived(Payment payment) throws Exception {
+        System.out.println("receive paymentCloseSuccess msg=" + JSON.toJSONString(payment));
+    }
+
+    /**
+     * 用户接收并处理关闭支付交易失败的异步消息
+     * @param payment 关闭失败的支付对象
+     * @throws Exception 异常
+     */
+    @Override
+    public void paymentCloseFailedMessageArrived(Payment payment) throws Exception {
+        System.out.println("receive paymentCloseFailed msg=" + JSON.toJSONString(payment));
+    }
+
+    /**
+     * 用户接收并处理退款成功的异步消息
+     * @param refund 成功的退款对象
+     * @throws Exception 异常
+     */
+    @Override
+    public void refundSuccessMessageArrived(Refund refund) throws Exception {
+        System.out.println("receive refundSuccess msg=" + JSON.toJSONString(refund));
+    }
+
+    /**
+     * 用户接收并处理退款失败的异步消息
+     * @param refund 失败的退款对象
+     * @throws Exception 异常
+     */
+    @Override
+    public void refundFailedMessageArrived(Refund refund) throws Exception {
+        System.out.println("receive refundFailed msg=" + JSON.toJSONString(refund));
+    }
+
+    /**
+     * 用户接收并处理未知的异步消息
+     * @param msg 未知消息
+     * @throws Exception 异常
+     */
+    @Override
+    public void unknownMessageArrived(String msg) throws Exception {
+        System.out.println("receive unknown msg=" + msg);
+    }
+}

+ 159 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Pay.java

@@ -0,0 +1,159 @@
+package com.ym.mec.thirdparty.adapay;
+
+import com.alibaba.fastjson.JSON;
+import com.huifu.adapay.AdaPay;
+import com.huifu.adapay.demo.BaseDemo;
+import com.huifu.adapay.demo.NotifyCallbackDemo;
+import com.huifu.adapay.exception.BaseAdaPayException;
+import com.huifu.adapay.model.DeviceInfo;
+import com.huifu.adapay.model.payment.*;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author jane.zhao
+ */
+public class Pay {
+    private static final String appId = "app_7d87c043-aae3-4357-9b2c-269349a980d6";
+
+    /**
+     * 运行支付类接口
+     * @return paymentId
+     * @throws Exception 异常
+     */
+    public static void init() throws Exception {
+        //apiKey,商户联调用
+        String apiKey = "api_test_e640fa26-bbe6-458f-ac44-a71723ee2176";
+        //apiKey,真实交易用(live)
+        String apiKeyLive = "api_live_9c14f264-e390-41df-984d-df15a6952031";
+        //公钥
+        String pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB";
+        //私钥
+        String privateKey= "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMQhsygJ2pp4nCiDAXiqnZm6AzKSVAh+C0BgGR6QaeXzt0TdSi9VR0OQ7Qqgm92NREB3ofobXvxxT+wImrDNk6R6lnHPMTuJ/bYpm+sx397rPboRAXpV3kalQmbZ3P7oxtEWOQch0zV5B1bgQnTvxcG3REAsdaUjGs9Xvg0iDS2tAgMBAAECgYAqGFmNdF/4234Yq9V7ApOE1Qmupv1mPTdI/9ckWjaAZkilfSFY+2KqO8bEiygo6xMFCyg2t/0xDVjr/gTFgbn4KRPmYucGG+FzTRLH0nVIqnliG5Ekla6a4gwh9syHfstbOpIvJR4DfldicZ5n7MmcrdEwSmMwXrdinFbIS/P1+QJBAOr6NpFtlxVSGzr6haH5FvBWkAsF7BM0CTAUx6UNHb+RCYYQJbk8g3DLp7/vyio5uiusgCc04gehNHX4laqIdl8CQQDVrckvnYy+NLz+K/RfXEJlqayb0WblrZ1upOdoFyUhu4xqK0BswOh61xjZeS+38R8bOpnYRbLf7eoqb7vGpZ9zAkEAobhdsA99yRW+WgQrzsNxry3Ua1HDHaBVpnrWwNjbHYpDxLn+TJPCXvI7XNU7DX63i/FoLhOucNPZGExjLYBH/wJATHNZQAgGiycjV20yicvgla8XasiJIDP119h4Uu21A1Su8G15J2/9vbWn1mddg1pp3rwgvxhw312oInbHoFMxsQJBAJlyDDu6x05MeZ2nMor8gIokxq2c3+cnm4GYWZgboNgq/BknbIbOMBMoe8dJFj+ji3YNTvi1MSTDdSDqJuN/qS0=";
+
+        //设置AdaPay全局参数,不同环境设置不同的apiKey/pubKey/privateKey
+        AdaPay.apiKey = apiKeyLive;
+        AdaPay.pubKey = pubKey;
+        AdaPay.privateKey = privateKey;
+        AdaPay.debug = true;
+
+        //启动 mqtt 异步监听
+        AdaPay.iNotifyCallback = new NotifyCallbackDemo();
+        AdaPay.startNotifyListener();
+    }
+
+    public static String executePaymentTest() throws Exception{
+        //test chargeId = "002112019080716223300005091372336111616";
+        Pay demo = new Pay();
+        //支付接口
+        String orderNo = "jsdk_payment_"+System.currentTimeMillis();
+        String payChannel = PayChannelEnum.ALIPAY_QR.getCode();
+        BigDecimal amount = new BigDecimal("0.01");
+        String orderSubject = "测试大雅订单";
+        String orderBody = "测试大雅订单";
+        Payment payment = Pay.executePayment(amount,orderNo,payChannel,orderSubject,orderBody);
+        //支付查询接口
+        //demo.queryPayment(payment.getId());
+        //关单接口
+        //demo.closePayment(payment.getId());
+
+        return payment.getId();
+    }
+
+    /**
+     * 执行一个支付交易
+     * @return 创建的支付对象
+     * @throws Exception 异常
+     */
+    public static Payment executePayment(BigDecimal amount,String orderNo,String payChannel,String orderSubject,String orderBody) throws Exception {
+        init();
+        System.out.println("=======execute payment begin=======");
+        //创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id3
+        Map<String, Object> paymentParams = new HashMap<>(10);
+        paymentParams.put("app_id", appId);
+        paymentParams.put("order_no", orderNo);
+        paymentParams.put("pay_channel", payChannel);
+        paymentParams.put("pay_amt", amount);
+        paymentParams.put("currency", CurrencyEnum.CNY.getCode());
+        paymentParams.put("goods_title", orderSubject);
+        paymentParams.put("goods_desc", orderBody);
+
+        DeviceInfo deviceInfo = new DeviceInfo();
+        deviceInfo.setDeviceType(DeviceTypeEnum.MOBILE.getCode());
+        deviceInfo.setDeviceIp("127.0.0.1");
+        paymentParams.put("device_info", deviceInfo);
+
+        List<GoodsDetail> goodsDetailList = new ArrayList<>();
+        GoodsDetail goodsDetail = new GoodsDetail();
+        goodsDetail.setGoodsId("your goods id");
+        goodsDetail.setGoodsName("your goods name");
+        goodsDetail.setQuantity("1");
+        goodsDetail.setPrice("100.00");
+        goodsDetailList.add(goodsDetail);
+
+        PromotionDetail promotionDetail = new PromotionDetail();
+        promotionDetail.setGoodsDetail(goodsDetailList);
+        promotionDetail.setCostPrice("100.00");
+
+        PaymentExpend expend = new PaymentExpend();
+        expend.setPromotionDetail(promotionDetail);
+        expend.setBuyerId("2088012928900274");
+        expend.setBuyerLogonId("");
+
+        paymentParams.put("expend", expend);
+
+        //调用sdk方法,创建支付,得到支付对象
+        Payment payment = null;
+        try {
+            payment = Payment.create(paymentParams);
+        } catch (BaseAdaPayException e) {
+            e.printStackTrace();
+        }
+        System.out.println("payment result="+JSON.toJSONString(payment));
+        return payment;
+    }
+
+    /**
+     * 关闭一个支付交易
+     * @param paymentId 要关闭的支付id
+     * @return 关闭的支付对象
+     * @throws Exception 异常
+     */
+    public Payment closePayment(String paymentId) throws Exception{
+        System.out.println("=======close payment begin=======");
+        //关闭支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id11
+        //调用sdk方法,关闭支付,得到支付对象
+        Payment payment = null;
+        try {
+            payment = Payment.close(paymentId);
+        } catch (BaseAdaPayException e) {
+            e.printStackTrace();
+        }
+        System.out.println("close payment result="+JSON.toJSONString(payment));
+        return payment;
+    }
+
+    /**
+     * 查询一个支付交易
+     * @param paymentId 要查询的支付id
+     * @return 查询的支付对象
+     * @throws Exception 异常
+     */
+    public Payment queryPayment(String paymentId) throws Exception{
+        System.out.println("=======query payment begin=======");
+        //查询支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id7
+        //调用sdk方法,查询支付交易,得到支付对象
+        Payment payment = null;
+        try {
+            payment = Payment.query(paymentId);
+        } catch (BaseAdaPayException e) {
+            e.printStackTrace();
+        }
+        System.out.println("query payment result="+JSON.toJSONString(payment));
+        return payment;
+    }
+}

+ 75 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/RefundDemo.java

@@ -0,0 +1,75 @@
+package com.ym.mec.thirdparty.adapay;
+
+import com.alibaba.fastjson.JSON;
+import com.huifu.adapay.demo.BaseDemo;
+import com.huifu.adapay.model.refund.Refund;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author jane.zhao
+ */
+public class RefundDemo extends BaseDemo {
+
+    /**
+     * 运行退款类接口
+     * @throws Exception 异常
+     */
+    public static void executeRefundTest(String paymentId) throws Exception{
+        RefundDemo demo = new RefundDemo();
+        //退款接口
+        Refund refund = demo.executeRefund(paymentId);
+        //退款查询接口(通过pamentId查询)
+        demo.queryByPaymentId(paymentId);
+        //退款查询接口(通过refundId查询)
+        demo.queryByRefundId(refund.getId());
+    }
+
+    /**
+     * 执行一个退款交易
+     * @param paymentId 要退款的原支付paymentId
+     * @return 创建的退款对象
+     * @throws Exception 异常
+     */
+    public Refund executeRefund(String paymentId) throws Exception {
+        System.out.println("=======execute refund begin=======");
+        Map<String, Object> refundParams = new  HashMap<String, Object>(2);
+        refundParams.put("refund_amt", "0.01");
+        refundParams.put("app_id", "app_7d87c043-aae3-4357-9b2c-269349a980d6");
+        refundParams.put("refund_order_no", "jsdk_refund_"+System.currentTimeMillis());
+        Refund refund = Refund.create(paymentId, refundParams);
+        System.out.println("refund result="+JSON.toJSONString(refund));
+        return refund;
+    }
+
+    /**
+     * 根据原支付id查询一个退款交易
+     * @param paymentId 要查询退款的原支付paymentId
+     * @return 查询的退款对象,可能含多个退款明细RefundDetail
+     * @throws Exception 异常
+     */
+    public Refund queryByPaymentId(String paymentId) throws Exception{
+        System.out.println("=======query refund by paymentId begin=======");
+        Map<String, Object> chargeParams = new  HashMap<String, Object>(1);
+        chargeParams.put("payment_id", paymentId);
+        Refund refund = Refund.query(chargeParams);
+        System.out.println("query refund by paymentid result="+JSON.toJSONString(refund));
+        return refund;
+    }
+
+    /**
+     * 根据退款refundId查询一个退款交易
+     * @param refundId 要查询的退款refundId
+     * @return 查询的退款对象
+     * @throws Exception 异常
+     */
+    public Refund queryByRefundId(String refundId) throws Exception{
+        System.out.println("=======query refund by refundid begin=======");
+        Map<String, Object> chargeParams = new  HashMap<String, Object>(1);
+        chargeParams.put("refund_id", refundId);
+        Refund refund = Refund.query(chargeParams);
+        System.out.println("query refund by refundid result="+JSON.toJSONString(refund));
+        return refund;
+    }
+}