AppAbstractComponentSMO.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.java110.front.smo;
  2. import com.java110.core.component.AbstractComponentSMO;
  3. import com.java110.core.context.IPageData;
  4. import com.java110.core.factory.WechatFactory;
  5. import com.java110.dto.smallWeChat.SmallWeChatDto;
  6. import com.java110.front.properties.WechatAuthProperties;
  7. import com.java110.utils.cache.MappingCache;
  8. import com.java110.utils.constant.CommonConstant;
  9. import com.java110.utils.constant.WechatConstant;
  10. import com.java110.utils.util.Assert;
  11. import com.java110.utils.util.PayUtil;
  12. import com.java110.utils.util.StringUtil;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.http.*;
  17. import org.springframework.web.client.HttpStatusCodeException;
  18. import org.springframework.web.client.RestTemplate;
  19. import java.util.Map;
  20. import java.util.SortedMap;
  21. import java.util.TreeMap;
  22. public abstract class AppAbstractComponentSMO extends AbstractComponentSMO {
  23. private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
  24. @Autowired
  25. private WechatAuthProperties wechatAuthProperties;
  26. @Autowired
  27. private RestTemplate restTemplate;
  28. //微信支付
  29. public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
  30. // 微信服务商支付开关
  31. public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
  32. //开关ON打开
  33. public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
  34. private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
  35. private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
  36. /**
  37. * 调用中心服务
  38. *
  39. * @return
  40. */
  41. @Override
  42. protected ResponseEntity<String> callCenterService(RestTemplate restTemplate, IPageData pd, String param, String url, HttpMethod httpMethod) {
  43. Assert.notNull(pd.getAppId(), "请求头中未包含应用信息");
  44. ResponseEntity<String> responseEntity = null;
  45. HttpHeaders header = new HttpHeaders();
  46. header.add(CommonConstant.HTTP_APP_ID.toLowerCase(), pd.getAppId());
  47. header.add(CommonConstant.HTTP_USER_ID.toLowerCase(), StringUtil.isEmpty(pd.getUserId()) ? CommonConstant.ORDER_DEFAULT_USER_ID : pd.getUserId());
  48. header.add(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), pd.getTransactionId());
  49. header.add(CommonConstant.HTTP_REQ_TIME.toLowerCase(), pd.getRequestTime());
  50. header.add(CommonConstant.HTTP_SIGN.toLowerCase(), "");
  51. header.add("content-type", "application/json");
  52. HttpEntity<String> httpEntity = new HttpEntity<String>(param, header);
  53. //logger.debug("请求中心服务信息,{}", httpEntity);
  54. try {
  55. responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
  56. } catch (HttpStatusCodeException e) { //这里spring 框架 在4XX 或 5XX 时抛出 HttpServerErrorException 异常,需要重新封装一下
  57. responseEntity = new ResponseEntity<String>(e.getResponseBodyAsString(), e.getStatusCode());
  58. } catch (Exception e) {
  59. responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  60. } finally {
  61. logger.debug("请求地址为,{} 请求中心服务信息,{},中心服务返回信息,{}", url, httpEntity, responseEntity);
  62. return responseEntity;
  63. }
  64. }
  65. }