xiongzhu 4 лет назад
Родитель
Сommit
d9f755846e

+ 17 - 7
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -13,9 +13,11 @@ import com.github.binarywang.wxpay.constant.WxPayConstants;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
+import com.huifu.adapay.model.AdapayCommon;
 import com.huifu.adapay.model.Payment;
 import com.izouma.nineth.config.AdapayProperties;
 import com.izouma.nineth.config.AlipayProperties;
+import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.config.WxPayProperties;
 import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.domain.*;
@@ -32,7 +34,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.EncoderException;
 import org.apache.commons.codec.net.URLCodec;
 import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.event.EventListener;
 import org.springframework.core.env.Environment;
 import org.springframework.data.domain.Page;
@@ -72,6 +73,7 @@ public class OrderService {
     private RedisTemplate<String, Object> redisTemplate;
     private CommissionRecordRepo          commissionRecordRepo;
     private AdapayProperties              adapayProperties;
+    private GeneralProperties             generalProperties;
 
     public Page<Order> all(PageQuery pageQuery) {
         return orderRepo.findAll(JpaUtils.toSpecification(pageQuery, Order.class), JpaUtils.toPageRequest(pageQuery));
@@ -302,9 +304,9 @@ public class OrderService {
         }
 
         if (wxChannels.contains(payChannel)) {
-            if (StringUtils.isBlank(openId)) {
-                throw new BusinessException("缺少openId");
-            }
+//            if (StringUtils.isBlank(openId)) {
+//                throw new BusinessException("缺少openId");
+//            }
             Map<String, Object> expend = new HashMap<>();
             expend.put("open_id", openId);
             expend.put("limit_pay", "1");
@@ -314,8 +316,15 @@ public class OrderService {
             paymentParams.put("expend", expend);
         }
 
-        Map<String, Object> response = Payment.create(paymentParams);
-        AdapayService.checkSuccess(response);
+        Map<String, Object> response;
+        if (wxChannels.contains(payChannel)) {
+            paymentParams.put("adapay_func_code", "wxpay.createOrder");
+            paymentParams.put("callback_url", generalProperties.getHost() + "/9th/orders");
+            response = AdapayCommon.requestAdapayUits(paymentParams);
+        } else {
+            response = Payment.create(paymentParams);
+            AdapayService.checkSuccess(response);
+        }
 
         switch (payChannel) {
             case "alipay_wap":
@@ -323,8 +332,9 @@ public class OrderService {
                 return MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info");
             case "alipay_qr":
                 return MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
+            default:
+                return MapUtils.getMap(response, "expend");
         }
-        return response;
     }
 
     public static BigDecimal divMoney(BigDecimal totalAmount, BigDecimal restAmount, List<Map<String, Object>> divMembers,

+ 2 - 2
src/main/java/com/izouma/nineth/web/OrderPayController.java

@@ -66,8 +66,8 @@ public class OrderPayController {
 
     @RequestMapping(value = "/weixin")
     @ResponseBody
-    public Object payOrderWeixin(@RequestParam Long id, @RequestParam String openId) throws WxPayException, EncoderException {
-        return orderService.payOrderWeixin(id, WxPayConstants.TradeType.JSAPI, openId);
+    public Object payOrderWeixin(@RequestParam Long id) throws BaseAdaPayException {
+        return orderService.payAdapay(id, "wx_lite", null);
     }
 
     @RequestMapping(value = "/weixin_pc")

+ 5 - 2
src/test/java/com/izouma/nineth/service/AdapayServiceTest.java

@@ -6,6 +6,7 @@ import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.huifu.adapay.model.AdapayCommon;
 import com.huifu.adapay.model.Payment;
 import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.config.GeneralProperties;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -17,7 +18,9 @@ import java.util.Map;
 
 public class AdapayServiceTest extends ApplicationTests {
     @Autowired
-    private AdapayService adapayService;
+    private AdapayService     adapayService;
+    @Autowired
+    private GeneralProperties generalProperties;
 
     @Test
     public void testPay() throws BaseAdaPayException {
@@ -61,7 +64,7 @@ public class AdapayServiceTest extends ApplicationTests {
         params.put("goods_title", "Your goods_title");
         params.put("goods_desc", "Your goods_desc");
         params.put("description", "payment Discription");
-        params.put("callback_url", "http://localhost:8080/");
+        params.put("callback_url", generalProperties.getHost() + "/9th/orders");
         Map<String, Object> response = AdapayCommon.requestAdapayUits(params);
         System.out.println("payment result=" + JSON.toJSONString(response, SerializerFeature.PrettyFormat));
     }