Browse Source

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

周箭河 5 years ago
parent
commit
5a45fe306a

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -33,4 +33,5 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
      */
     List<Goods> findGoodsByIds(@Param("ids") String ids);
 
+    List<Goods> findTypeGoods(@Param("type") String type);
 }

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -31,4 +31,13 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @return
      */
     List<Goods> findGoodsByIds(String ids);
+
+
+    /**
+     * 查询某种类型的商品
+     * @param type
+     * @return
+     */
+    List<Goods> findTypeGoods(String type);
+
 }

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -34,4 +34,9 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	public List<Goods> findGoodsByIds(String ids) {
 		return goodsDao.findGoodsByIds(ids);
 	}
+
+	@Override
+	public List<Goods> findTypeGoods(String type) {
+		return goodsDao.findTypeGoods(type);
+	}
 }

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

@@ -87,7 +87,7 @@ public class MusicGroupSubjectPlanServiceImpl extends BaseServiceImpl<Integer, M
             }
         });
         //获取声部(科目)下其他商品
-        List<Goods> otherGoods = goodsService.findGoodsBySubId(subjectId, "OTHER");
+        List<Goods> otherGoods = goodsService.findTypeGoods( "OTHER");
 
         MusicGroupSubjectGoodsAndInfoDto musicGroupSubjectGoodsAndInfo = new MusicGroupSubjectGoodsAndInfoDto();
         musicGroupSubjectGoodsAndInfo.setMusicGroupSubjectPlan(musicOneSubjectClassPlan);

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -154,4 +154,7 @@
     <select id="findGoodsByIds" resultMap="Goods">
         SELECT * FROM goods WHERE FIND_IN_SET(id_,#{ids})
     </select>
+    <select id="findTypeGoods" resultMap="Goods">
+        SELECT * FROM goods WHERE type_ = #{type}
+    </select>
 </mapper>

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

@@ -339,9 +339,8 @@ public class MusicGroupController extends BaseController {
         String orderNo = idGeneratorService.generatorId("payment")+"";
         BigDecimal amount = new BigDecimal("0.01");
         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);
+        Map map = payService.getPayMap(amount, orderNo, "http://47.99.212.176:8000/studentOrder/notify", "https://baodiu.com", "测试订单", "测试订单");
+       return succeed(map);
     }
 
     @ApiOperation(value = "订单状态查询")

+ 6 - 7
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -95,14 +95,13 @@ public class StudentOrderController extends BaseController {
     }
 
     @ApiOperation(value = "台牌支付")
-    @GetMapping("/executePayment")
-    public Object executePayment() throws Exception {
-        String orderNo = "jsdk_payment_" + System.currentTimeMillis();
+    @PostMapping("/executePayment")
+    public Object executePayment(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody) throws Exception {
         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);
+        if (!new Pay().verifySign(amount, orderNo, notifyUrl, notifyUrl, orderSubject, orderBody)) {
+            return failed("签名验证失败");
+        }
+        Payment payment = new Pay().executePayment(amount, orderNo, payChannel, orderSubject, orderBody);
         return succeed(payment);
     }
 

+ 35 - 7
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Pay.java

@@ -1,18 +1,17 @@
 package com.ym.mec.thirdparty.adapay;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 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 com.huifu.adapay.util.AdaPaySign;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author jane.zhao
@@ -25,7 +24,7 @@ public class Pay {
      * @return paymentId
      * @throws Exception 异常
      */
-    public static void init() throws Exception {
+    public Pay() throws Exception {
         //apiKey,商户联调用
         String apiKey = "api_test_e640fa26-bbe6-458f-ac44-a71723ee2176";
         //apiKey,真实交易用(live)
@@ -55,7 +54,7 @@ public class Pay {
         BigDecimal amount = new BigDecimal("0.01");
         String orderSubject = "测试大雅订单";
         String orderBody = "测试大雅订单";
-        Payment payment = Pay.executePayment(amount,orderNo,payChannel,orderSubject,orderBody);
+        Payment payment = demo.executePayment(amount,orderNo,payChannel,orderSubject,orderBody);
         //支付查询接口
         //demo.queryPayment(payment.getId());
         //关单接口
@@ -64,13 +63,42 @@ public class Pay {
         return payment.getId();
     }
 
+
+    public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String orderSubject, String orderBody) throws Exception {
+
+        Map<String, Object> paymentParams = new HashMap<>(10);
+        paymentParams.put("appId",appId);
+        paymentParams.put("amount", amount);
+        paymentParams.put("orderNo", orderNo);
+        paymentParams.put("notifyUrl", notifyUrl);
+        paymentParams.put("orderSubject", orderSubject);
+        paymentParams.put("orderBody", orderBody);
+        String originalStr = JSONObject.toJSONString(paymentParams);
+
+        String sign  =  AdaPaySign.sign(originalStr, AdaPay.privateKey);
+        paymentParams.put("sign",sign);
+        paymentParams.remove(appId);
+        return  paymentParams;
+    }
+
+    public boolean verifySign(BigDecimal amount, String orderNo, String notifyUrl, String orderSubject, String orderBody, String sign) throws Exception {
+        Map<String, Object> paymentParams = new HashMap<>(10);
+        paymentParams.put("appId",appId);
+        paymentParams.put("amount", amount);
+        paymentParams.put("orderNo", orderNo);
+        paymentParams.put("notifyUrl", notifyUrl);
+        paymentParams.put("orderSubject", orderSubject);
+        paymentParams.put("orderBody", orderBody);
+        String originalStr = JSONObject.toJSONString(paymentParams);
+       return AdaPaySign.verifySign(originalStr,sign, AdaPay.pubKey);
+    }
+
     /**
      * 执行一个支付交易
      * @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);