AdapayService.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.izouma.nineth.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.serializer.SerializerFeature;
  4. import com.huifu.adapay.core.exception.BaseAdaPayException;
  5. import com.huifu.adapay.model.AdapayCommon;
  6. import com.izouma.nineth.config.AdapayProperties;
  7. import com.izouma.nineth.exception.BusinessException;
  8. import lombok.AllArgsConstructor;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.commons.collections.MapUtils;
  11. import org.springframework.stereotype.Service;
  12. import java.util.HashMap;
  13. import java.util.Map;
  14. @AllArgsConstructor
  15. @Service
  16. @Slf4j
  17. public class AdapayService {
  18. private final AdapayProperties adapayProperties;
  19. public void createMember(Long id, String tel, String name, String idNo) throws BaseAdaPayException {
  20. Map<String, Object> memberParams = new HashMap<>();
  21. memberParams.put("adapay_func_code", "members.realname");
  22. memberParams.put("member_id", id.toString());
  23. memberParams.put("app_id", adapayProperties.getAppId());
  24. memberParams.put("tel_no", tel);
  25. memberParams.put("user_name", name);
  26. memberParams.put("cert_type", "00");
  27. memberParams.put("cert_id", idNo);
  28. Map<String, Object> member = AdapayCommon.requestAdapay(memberParams);
  29. log.info("createMember\n{}", JSON.toJSONString(member, SerializerFeature.PrettyFormat));
  30. if (!"succeeded".equals(MapUtils.getString(member, "status"))) {
  31. String errMsg = MapUtils.getString(member, "error_msg");
  32. String errCode = MapUtils.getString(member, "error_code");
  33. throw new BusinessException(errMsg + "(" + errCode + ")");
  34. }
  35. }
  36. }