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

+ 1 - 0
src/main/java/com/izouma/nineth/config/AdapayProperties.java

@@ -6,6 +6,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 @Data
 @ConfigurationProperties(prefix = "adapay")
 public class AdapayProperties {
+    private String  appId;
     private boolean debug;
     private boolean prod;
     private String  apiKey;

+ 1 - 2
src/main/java/com/izouma/nineth/exception/BusinessException.java

@@ -9,8 +9,7 @@ public class BusinessException extends RuntimeException implements Supplier<Busi
     private String  error;
 
     public BusinessException(String error) {
-        super();
-        this.error = error;
+        super(error);
     }
 
     public BusinessException(String error, String message) {

+ 1 - 2
src/main/java/com/izouma/nineth/exception/GlobalExceptionHandler.java

@@ -34,8 +34,7 @@ public class GlobalExceptionHandler {
     @ResponseBody
     public Map<String, Object> serviceExceptionHandler(BusinessException e) {
         Map<String, Object> map = new HashMap<>();
-        map.put("error", e.getError());
-        map.put("message", e.getMessage());
+        map.put("error", e.getMessage());
         map.put("code", -1);
         return map;
     }

+ 41 - 0
src/main/java/com/izouma/nineth/service/AdapayService.java

@@ -0,0 +1,41 @@
+package com.izouma.nineth.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.huifu.adapay.core.exception.BaseAdaPayException;
+import com.huifu.adapay.model.AdapayCommon;
+import com.izouma.nineth.config.AdapayProperties;
+import com.izouma.nineth.exception.BusinessException;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.MapUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@AllArgsConstructor
+@Service
+@Slf4j
+public class AdapayService {
+
+    private final AdapayProperties adapayProperties;
+
+    public void createMember(Long id, String tel, String name, String idNo) throws BaseAdaPayException {
+        Map<String, Object> memberParams = new HashMap<>();
+        memberParams.put("adapay_func_code", "members.realname");
+        memberParams.put("member_id", id.toString());
+        memberParams.put("app_id", adapayProperties.getAppId());
+        memberParams.put("tel_no", tel);
+        memberParams.put("user_name", name);
+        memberParams.put("cert_type", "00");
+        memberParams.put("cert_id", idNo);
+        Map<String, Object> member = AdapayCommon.requestAdapay(memberParams);
+        log.info("createMember\n{}", JSON.toJSONString(member, SerializerFeature.PrettyFormat));
+        if (!"succeeded".equals(MapUtils.getString(member, "status"))) {
+            String errMsg = MapUtils.getString(member, "error_msg");
+            String errCode = MapUtils.getString(member, "error_code");
+            throw new BusinessException(errMsg + "(" + errCode + ")");
+        }
+    }
+}

+ 1 - 1
src/main/java/com/izouma/nineth/service/AirDropService.java

@@ -58,7 +58,7 @@ public class AirDropService {
                         BlindBoxItem winItem = collectionService.draw(collection.getId());
                         assetService.createAsset(winItem, user, null, null, "空投", collectionService.getNextNumber(winItem.getCollectionId()));
                     } else {
-                        assetService.createAsset(collection, user, null, null, "空投", collectionService.getNextNumber(collection.getId()));
+                        assetService.createAsset(collection, user, null, null, "空投", collectionService.getNextNumber(collection));
                     }
                     collection.setStock(collection.getStock() - 1);
                     collection.setSale(collection.getSale() + 1);

+ 11 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -279,4 +279,15 @@ public class CollectionService {
         collectionRepo.save(collection);
         return collection.getCurrentNumber();
     }
+
+    public synchronized Integer getNextNumber(Collection collection) {
+        if (collection == null) return 0;
+        if (collection.getCurrentNumber() == null) {
+            collection.setCurrentNumber(0);
+        }
+        collection.setCurrentNumber(collection.getCurrentNumber() + 1);
+        collectionRepo.save(collection);
+        return collection.getCurrentNumber();
+    }
+
 }

+ 1 - 0
src/main/resources/application.yaml

@@ -132,6 +132,7 @@ alipay:
   notify-url: https://nfttest.9space.vip/notify/order/alipay
   return-url: https://nfttest.9space.vip/9th/home
 adapay:
+  app-id: app_f8760acc-f4d8-46f6-8f70-d80e36517075
   debug: true
   prod: true
   api-key: api_live_8818cac1-894b-40bc-ac77-803e02e9c260

+ 18 - 0
src/test/java/com/izouma/nineth/service/AdapayServiceTest.java

@@ -0,0 +1,18 @@
+package com.izouma.nineth.service;
+
+import com.huifu.adapay.core.exception.BaseAdaPayException;
+import com.izouma.nineth.ApplicationTests;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.Assert.*;
+
+public class AdapayServiceTest extends ApplicationTests {
+    @Autowired
+    private AdapayService adapayService;
+
+    @Test
+    public void createMember() throws BaseAdaPayException {
+        adapayService.createMember(99999999999999L, "15077886171", "熊竹", "321002199408304614");
+    }
+}