ソースを参照

房车宝签名获取的接口

houweiyu 4 年 前
コミット
c4b9d9cc70

+ 3 - 4
src/main/java/fcb/project/manager/base/utils/DataUtils.java

@@ -143,12 +143,11 @@ public class DataUtils {
      *
      * 生成MD5 32位小写字符的密码串
      * */
-    public static String encryption(String OrderNo) {
-        String result = OrderNo+"354039456123789"+"andriod";
+    public static String md5Encryption(String jsonStr) {
         String re_md5 = new String();
         try {
             MessageDigest md = MessageDigest.getInstance("MD5");
-            md.update(result.getBytes());
+            md.update(jsonStr.getBytes());
             byte b[] = md.digest();
             StringBuffer buf = new StringBuffer("");
             int i;
@@ -164,7 +163,7 @@ public class DataUtils {
             }
             re_md5 = buf.toString();
         } catch (NoSuchAlgorithmException e) {
-            log.info("生成MD5密出错了:{}" , e);
+            log.info("生成MD5密出错了:{}" , e);
             e.printStackTrace();
         }
         return re_md5.toLowerCase();

+ 30 - 1
src/main/java/fcb/project/manager/base/utils/FcbUtils.java

@@ -1,15 +1,44 @@
 package fcb.project.manager.base.utils;
 
+import com.alibaba.fastjson.JSON;
+import fdage.back.sdk.base.entity.Result;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 2 * @Author: Abner
  * 3 * @Date: 2021/1/18 9:11
  * 4
  */
-@Service
 public class FcbUtils {
 
 
+    public static Result<Object> getFcbSign(Map<String , Object> params , String fcbClientSecret){
+
+        if(CollectionUtils.isEmpty(params)){
+            return Result.failure("入参不能为空");
+        }
+        for (Map.Entry entry : params.entrySet()) {
+            //1、先剔除value值为null的键值对
+            if(null  == entry.getValue()){
+               params.remove(entry.getKey());
+            }
+        }
+        //2、新增房车宝的client_secret作为噪点
+        params.put("client_secret" , fcbClientSecret);
+        params = DataUtils.sortMapByKey(params);
+        //3、生成MD5密文,然后转成小写字母
+        String md5EncryptionStr = DataUtils.md5Encryption(JSON.toJSONString(params));
+        Map<String , Object> resultMap = new HashMap<>();
+        resultMap.put("authcode" , md5EncryptionStr);
+        return Result.success(resultMap);
 
+    }
 }

+ 11 - 0
src/main/java/fcb/project/manager/core/controller/ApiQueryHouseController.java

@@ -10,6 +10,7 @@ import fcb.project.manager.base.entity.TmHouse;
 import fcb.project.manager.base.service.impl.TmApiHouseInfoServiceImpl;
 import fcb.project.manager.base.service.impl.TmApiHouseRecommendServiceImpl;
 import fcb.project.manager.base.service.impl.TmHouseServiceImpl;
+import fcb.project.manager.base.utils.FcbUtils;
 import fcb.project.manager.base.utils.RedisServiceUtils;
 import fdage.back.sdk.base.entity.Result;
 import fdage.back.sdk.base.enums.ResultCodeEnum;
@@ -22,6 +23,7 @@ import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
@@ -56,6 +58,15 @@ public class ApiQueryHouseController {
     @Autowired
     private TmHouseServiceImpl tmHouseService;
 
+    @Value("${fcb.client.secret}")
+    private String fcbClientSecret;
+
+
+    @ApiOperation(value = "获取房车宝的签名")
+    @PostMapping("/authCode")
+    public Result<Object> getFcbSign(@RequestBody Map<String , Object> params) {
+        return FcbUtils.getFcbSign(params , fcbClientSecret);
+    }
 
     @ApiOperation(value = "H5页面请求房源信息")
     @GetMapping(value = "/getHouseInfo")

+ 3 - 0
src/main/resources/application-dev.properties

@@ -26,3 +26,6 @@ spring.redis.jedis.pool.max-wait=-1
 spring.redis.jedis.pool.min-idle=0
 
 4dkankan.host.url=https://test.4dkankan.com/vrHouse.html?m=
+
+fcb.client.code=zxd9WS2twZ3J4DuhJ2r3y6qz1OZ2hMbr
+fcb.client.secret=UyUaWPJuLw1xfN9wXusgiZxJ7vu9cre9

+ 3 - 0
src/main/resources/application-prod.properties

@@ -28,3 +28,6 @@ spring.redis.jedis.pool.min-idle=0
 
 4dkankan.host.url=https://4dkankan.com/vrHouse.html?m=
 
+fcb.client.code=zxd9WS2twZ3J4DuhJ2r3y6qz1OZ2hMbr
+fcb.client.secret=UyUaWPJuLw1xfN9wXusgiZxJ7vu9cre9
+

+ 4 - 1
src/main/resources/application-test.properties

@@ -27,4 +27,7 @@ spring.redis.jedis.pool.max-wait=-1
 spring.redis.jedis.pool.min-idle=0
 
 
-4dkankan.host.url=https://test.4dkankan.com/vrHouse.html?m=
+4dkankan.host.url=https://test.4dkankan.com/vrHouse.html?m=
+
+fcb.client.code=zxd9WS2twZ3J4DuhJ2r3y6qz1OZ2hMbr
+fcb.client.secret=UyUaWPJuLw1xfN9wXusgiZxJ7vu9cre9