FcbUtils.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package fcb.project.manager.base.utils;
  2. import com.alibaba.fastjson.JSON;
  3. import fdage.back.sdk.base.entity.Result;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.util.CollectionUtils;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12. /**
  13. * 2 * @Author: Abner
  14. * 3 * @Date: 2021/1/18 9:11
  15. * 4
  16. */
  17. public class FcbUtils {
  18. public static Result<Object> getFcbSign(Map<String , Object> params , String fcbClientSecret){
  19. if(CollectionUtils.isEmpty(params)){
  20. return Result.failure("入参不能为空");
  21. }
  22. for (Map.Entry entry : params.entrySet()) {
  23. //1、先剔除value值为null的键值对
  24. if(null == entry.getValue()){
  25. params.remove(entry.getKey());
  26. }
  27. }
  28. //2、新增房车宝的client_secret作为噪点
  29. params.put("client_secret" , fcbClientSecret);
  30. params = DataUtils.sortMapByKey(params);
  31. //3、生成MD5密文,然后转成小写字母
  32. String md5EncryptionStr = DataUtils.md5Encryption(JSON.toJSONString(params));
  33. Map<String , Object> resultMap = new HashMap<>();
  34. resultMap.put("authcode" , md5EncryptionStr);
  35. resultMap.put("timeStamp" , System.currentTimeMillis());
  36. return Result.success(resultMap);
  37. }
  38. }