wangqifan 3 lat temu
rodzic
commit
c498aaa473

+ 96 - 4
src/main/java/com/izouma/nineth/service/SandPayService.java

@@ -15,6 +15,7 @@ import com.izouma.nineth.repo.GiftOrderRepo;
 import com.izouma.nineth.repo.MintOrderRepo;
 import com.izouma.nineth.repo.OrderRepo;
 import com.izouma.nineth.utils.DateTimeUtils;
+import com.izouma.nineth.utils.MD5Util;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -25,14 +26,13 @@ import org.springframework.stereotype.Service;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 
 @Service
 @AllArgsConstructor
@@ -346,6 +346,98 @@ public class SandPayService {
         return res.getJSONObject("body").getString("credential");
     }
 
+    public String payQuickBind(String orderId, String subject, BigDecimal amount, LocalDateTime expireAt,
+                               String type, String returnUrl, Long userId, String name, String idNo) {
+        String pOrderId = paddingOrderId(orderId);
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        Calendar calendar = Calendar.getInstance();
+        String createTime = sdf.format(calendar.getTime());
+        calendar.add(Calendar.HOUR, 1);
+        String endTime = sdf.format(calendar.getTime());
+
+        String version = "10";
+        String mer_no = sandPayProperties.getMid();
+        //key1
+        String mer_key = "S+ICbmNah6PrBJ5Negl3adhc1Z1YIWy2g4NYKglZlOdlqRNcSK4EtNoff1X0g1+YcKvdbn60nDQ=";
+        UUID uuid = UUID.randomUUID();
+        String mer_order_no = uuid.toString().replaceAll("-", "");
+        String notify_url = sandPayProperties.getNotifyUrl();
+        String order_amt = amount.toPlainString();
+        //"userId":"用户在商户下唯一标识 1-10位","userName":"证件姓名","idCard":"18位身份证号码"
+        String pay_extra = "{\"userId\":\"" + userId + "\",\"userName\":\"" + name + "\",\"idCard\":\"" + idNo + "\"}";
+        //md5key
+        String key = "hqjaLGvxlOl6FvUmVkwPvGRUz87WPlXFxd8gCVbmg/NjQYBijBiPoEL0Tiz+vcoIfVv0rryZ6BNhA1fB2EXVHUlY+10niZ7pS8uq8g0wXKHvgpKNIKgJmztiHrBkFR1ZJTpJBY1UEpVixuz+UKFTiw==";
+
+        JSONObject extend = new JSONObject();
+        extend.put("type", type);
+        extend.put("orderId", pOrderId);
+        extend.put("id", pOrderId);
+
+        Map<String, String> map = new LinkedHashMap<>();
+        map.put("accsplit_flag", "NO");
+        map.put("create_ip", "127_0_0_1");
+        map.put("create_time", createTime);
+        map.put("extend", extend.toJSONString());
+//        if(!(gh_static_url==null||"".equals(gh_static_url)))map.put("gh_static_url",gh_static_url);;
+        map.put("mer_key", mer_key);
+        map.put("mer_no", mer_no);
+        map.put("mer_order_no", mer_order_no);
+        map.put("notify_url", notify_url);
+        map.put("order_amt", order_amt);
+        map.put("pay_extra", pay_extra);
+        map.put("return_url", returnUrl);
+        map.put("sign_type", "MD5");
+        map.put("store_id", "000000");
+        map.put("version", version);
+        map.put("key", key);
+
+
+//        map.put("extend", "aaa");
+//        map.put("expire_time",endTime);
+//        map.put("goods_name",goods_name);
+//        map.put("product_code","02010006");
+//        map.put("clear_cycle","0");
+
+        String signature = "";
+
+        for (String s : map.keySet()) {
+            if (!(map.get(s) == null || map.get(s).equals(""))) {
+                signature += s + "=";
+                signature += map.get(s) + "&";
+            }
+        }
+        signature = signature.substring(0, signature.length() - 1);
+        String sign = MD5Util.encode(signature).toUpperCase();
+
+
+        //url
+        return "https://sandcash.mixienet.com.cn/pay/h5/quicktopup?" +
+                "version=" + version +
+                "&mer_no=" + mer_no +
+                "&mer_key=" + URLEncoder.encode(mer_key, StandardCharsets.UTF_8) +
+                "&mer_order_no=" + mer_order_no +
+                "&create_time=" + createTime +
+                "&expire_time=" + getTimeout(expireAt, 0) +
+                "&extend=" + URLEncoder.encode(extend.toJSONString(), StandardCharsets.UTF_8) +
+                "&order_amt=" + order_amt +
+                "&notify_url=" + URLEncoder.encode(notify_url, StandardCharsets.UTF_8) +
+                "&return_url=" + URLEncoder.encode(returnUrl, StandardCharsets.UTF_8) +
+                "&create_ip=127_0_0_1" +
+                "&goods_name=" + URLEncoder.encode(subject, StandardCharsets.UTF_8) +
+                "&store_id=000000" +
+                "&product_code=06030003" +
+                "&clear_cycle=3" +
+                "&pay_extra=" + URLEncoder.encode(pay_extra, StandardCharsets.UTF_8) +
+                "&meta_option=%5B%7B%22s%22%3A%22Android%22,%22n%22%3A%22wxDemo%22,%22id%22%3A%22com.pay.paytypetest%22,%22sc%22%3A%22com.pay.paytypetest%22%7D%5D" +
+                "&accsplit_flag=NO" +
+                "&jump_scheme=" +
+//                "&gh_static_url="+gh_static_url+""+
+                "&sign_type=MD5" +
+                "&key=" + URLEncoder.encode(key, StandardCharsets.UTF_8) +
+                "&sign=" + sign;
+    }
+
     @Cacheable(value = "sandPayQuick", key = "#orderId")
     public String payMintQuick(Long orderId) {
         MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));

+ 51 - 0
src/main/java/com/izouma/nineth/utils/MD5Util.java

@@ -0,0 +1,51 @@
+package com.izouma.nineth.utils;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+
+public class MD5Util {
+    private MD5Util() {
+    }
+
+    private static final String[] hex = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
+
+    public static String encode(String password) {
+        try {
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            byte[] byteArray = md5.digest(password.getBytes(StandardCharsets.UTF_8));
+            return byteArrayToHexString(byteArray);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return password;
+    }
+
+    public static String encode(String password, String enc) {
+        try {
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            byte[] byteArray = md5.digest(password.getBytes(enc));
+            return byteArrayToHexString(byteArray);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return password;
+    }
+
+    private static String byteArrayToHexString(byte[] byteArray) {
+        StringBuilder sb = new StringBuilder();
+        for (byte b : byteArray) {
+            sb.append(byteToHexChar(b));
+        }
+        return sb.toString();
+    }
+
+    private static Object byteToHexChar(byte b) {
+        int n = b;
+        if (n < 0) {
+            n = 256 + n;
+        }
+        int d1 = n / 16;
+        int d2 = n % 16;
+        return hex[d1] + hex[d2];
+    }
+}

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

@@ -5,9 +5,14 @@ import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
 import com.github.binarywang.wxpay.constant.WxPayConstants;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
+import com.izouma.nineth.config.Constants;
+import com.izouma.nineth.config.GeneralProperties;
+import com.izouma.nineth.domain.IdentityAuth;
 import com.izouma.nineth.domain.Order;
+import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.enums.OrderStatus;
 import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.IdentityAuthRepo;
 import com.izouma.nineth.repo.OrderRepo;
 import com.izouma.nineth.service.*;
 import io.swagger.annotations.ApiOperation;
@@ -18,6 +23,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import org.apache.commons.codec.EncoderException;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
@@ -29,13 +35,15 @@ import java.util.regex.Pattern;
 @Slf4j
 @AllArgsConstructor
 public class OrderPayController {
-    private final OrderService     orderService;
-    private final AssetService     assetService;
-    private final WxMpService      wxMpService;
-    private final GiftOrderService giftOrderService;
-    private final OrderRepo        orderRepo;
-    private final MintOrderService mintOrderService;
-    private final SandPayService   sandPayService;
+    private final OrderService      orderService;
+    private final AssetService      assetService;
+    private final WxMpService       wxMpService;
+    private final GiftOrderService  giftOrderService;
+    private final OrderRepo         orderRepo;
+    private final MintOrderService  mintOrderService;
+    private final SandPayService    sandPayService;
+    private final GeneralProperties generalProperties;
+    private final IdentityAuthRepo  identityAuthRepo;
 
     @RequestMapping(value = "/alipay_h5", method = RequestMethod.GET)
     @ResponseBody
@@ -78,12 +86,33 @@ public class OrderPayController {
         return sandPayService.payOrder(id);
     }
 
-    @ApiOperation("衫德h5快捷")
-    @RequestMapping(value = "/sandQuick", method = RequestMethod.GET, produces = "text/html")
+//    @ApiOperation("衫德h5快捷")
+//    @RequestMapping(value = "/sandQuick", method = RequestMethod.GET, produces = "text/html")
+//    @ResponseBody
+//    public String sandQuick(@RequestParam Long id, Model model) throws BaseAdaPayException {
+//        return sandPayService.payOrderQuick(id);
+//    }
+
+    @ApiOperation("衫德h5快捷+绑卡")
+    @RequestMapping("/sandQuick")
     @ResponseBody
-    public String sandQuick(@RequestParam Long id, Model model) throws BaseAdaPayException {
-//        return (String) orderService.payAdapay(id, "alipay_wap", null);
-        return sandPayService.payOrderQuick(id);
+    public String sandQuickBind(@RequestParam Long id) {
+        return payOrderQuickBind(id);
+    }
+
+    @Cacheable(value = "payOrder", key = "'order#'+#orderId")
+    public String payOrderQuickBind(Long orderId) {
+        Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != OrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+        IdentityAuth identityAuth = identityAuthRepo
+                .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
+                .orElseThrow(new BusinessException("请先完成实名认证"));
+        return sandPayService.payQuickBind(orderId + "", order.getName(), order.getTotalPrice(),
+                order.getCreatedAt().plusMinutes(3), "order",
+                generalProperties.getHost() + "/9th/home",
+                order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
     }