AppAbstractComponentSMO.java 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. protected static final String DEFAULT_PAY_ADAPT = "wechatPayAdapt";// 默认微信通用支付
  25. @Autowired
  26. private WechatAuthProperties wechatAuthProperties;
  27. @Autowired
  28. private RestTemplate restTemplate;
  29. //微信支付
  30. public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
  31. // 微信服务商支付开关
  32. public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
  33. //开关ON打开
  34. public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
  35. private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
  36. private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
  37. /**
  38. * 调用中心服务
  39. *
  40. * @return
  41. */
  42. @Override
  43. protected ResponseEntity<String> callCenterService(RestTemplate restTemplate, IPageData pd, String param, String url, HttpMethod httpMethod) {
  44. Assert.notNull(pd.getAppId(), "请求头中未包含应用信息");
  45. ResponseEntity<String> responseEntity = null;
  46. HttpHeaders header = new HttpHeaders();
  47. header.add(CommonConstant.HTTP_APP_ID.toLowerCase(), pd.getAppId());
  48. header.add(CommonConstant.HTTP_USER_ID.toLowerCase(), StringUtil.isEmpty(pd.getUserId()) ? CommonConstant.ORDER_DEFAULT_USER_ID : pd.getUserId());
  49. header.add(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), pd.getTransactionId());
  50. header.add(CommonConstant.HTTP_REQ_TIME.toLowerCase(), pd.getRequestTime());
  51. header.add(CommonConstant.HTTP_SIGN.toLowerCase(), "");
  52. header.add("content-type", "application/json");
  53. HttpEntity<String> httpEntity = new HttpEntity<String>(param, header);
  54. //logger.debug("请求中心服务信息,{}", httpEntity);
  55. try {
  56. responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
  57. } catch (HttpStatusCodeException e) { //这里spring 框架 在4XX 或 5XX 时抛出 HttpServerErrorException 异常,需要重新封装一下
  58. responseEntity = new ResponseEntity<String>(e.getResponseBodyAsString(), e.getStatusCode());
  59. } catch (Exception e) {
  60. responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  61. } finally {
  62. logger.debug("请求地址为,{} 请求中心服务信息,{},中心服务返回信息,{}", url, httpEntity, responseEntity);
  63. return responseEntity;
  64. }
  65. }
  66. }