From ab6a423cf604b83f06b5768dbc162ece744a32d9 Mon Sep 17 00:00:00 2001
From: shane <88386378@qq.com>
Date: 星期五, 20 八月 2021 00:34:11 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity
---
service-front/src/main/java/com/java110/front/smo/payment/impl/ToNotifySMOImpl.java | 176 +++-------------------------------------------------------
1 files changed, 11 insertions(+), 165 deletions(-)
diff --git a/service-front/src/main/java/com/java110/front/smo/payment/impl/ToNotifySMOImpl.java b/service-front/src/main/java/com/java110/front/smo/payment/impl/ToNotifySMOImpl.java
old mode 100644
new mode 100755
index b7928b8..1c88f2d
--- a/service-front/src/main/java/com/java110/front/smo/payment/impl/ToNotifySMOImpl.java
+++ b/service-front/src/main/java/com/java110/front/smo/payment/impl/ToNotifySMOImpl.java
@@ -7,13 +7,17 @@
import com.java110.front.properties.WechatAuthProperties;
import com.java110.front.smo.AppAbstractComponentSMO;
import com.java110.front.smo.payment.IToNotifySMO;
+import com.java110.front.smo.payment.adapt.IPayNotifyAdapt;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.constant.ServiceCodeConstant;
import com.java110.utils.constant.ServiceConstant;
+import com.java110.utils.constant.WechatConstant;
+import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.PayUtil;
+import com.java110.utils.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,180 +33,22 @@
public class ToNotifySMOImpl implements IToNotifySMO {
private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
- private static final String APP_ID = "992020011134400001";
- @Autowired
- private RestTemplate restTemplate;
+ private static final String DEFAULT_PAY_NOTIFY_ADAPT = "wechatPayNotifyAdapt";// 榛樿寰俊閫氱敤鏀粯
- @Autowired
- private WechatAuthProperties wechatAuthProperties;
@Override
public ResponseEntity<String> toNotify(String param, HttpServletRequest request) {
- String resXml = "";
- ResponseEntity responseEntity = null;
- try {
- Map<String, Object> map = PayUtil.getMapFromXML(param);
- logger.info("銆愬皬绋嬪簭鏀粯鍥炶皟銆� 鍥炶皟鏁版嵁锛� \n" + map);
- String returnCode = (String) map.get("return_code");
- if ("SUCCESS".equalsIgnoreCase(returnCode)) {
- String returnmsg = (String) map.get("result_code");
- if ("SUCCESS".equals(returnmsg)) {
- //鏇存柊鏁版嵁
- int result = confirmPayFee(map);
- if (result > 0) {
- //鏀粯鎴愬姛
- resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
- + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml>";
- }
- } else {
- resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
- + "<return_msg><![CDATA[鎶ユ枃涓虹┖]></return_msg>" + "</xml>";
- logger.info("鏀粯澶辫触:" + resXml);
- }
- } else {
- resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
- + "<return_msg><![CDATA[鎶ユ枃涓虹┖]></return_msg>" + "</xml>";
- logger.info("銆愯鍗曟敮浠樺け璐ャ��");
- }
- } catch (Exception e) {
- logger.error("閫氱煡澶辫触", e);
- resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
- + "<return_msg><![CDATA[閴存潈澶辫触]></return_msg>" + "</xml>";
- }
+ String wId = request.getParameter("wId");
+ String payNotifyAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_NOTIFY_ADAPT);
+ payNotifyAdapt = StringUtil.isEmpty(payNotifyAdapt) ? DEFAULT_PAY_NOTIFY_ADAPT : payNotifyAdapt;
+ //鏀粯閫傞厤鍣�
+ IPayNotifyAdapt tPayNotifyAdapt = ApplicationContextFactory.getBean(payNotifyAdapt, IPayNotifyAdapt.class);
+ String resXml = tPayNotifyAdapt.confirmPayFee(param,wId);
logger.info("銆愬皬绋嬪簭鏀粯鍥炶皟鍝嶅簲銆� 鍝嶅簲鍐呭锛歕n" + resXml);
return new ResponseEntity<String>(resXml, HttpStatus.OK);
}
-
- public int confirmPayFee(Map<String, Object> map) {
- String wId = map.get("wId").toString();
- wId = wId.replace(" ", "+");
- SortedMap<String, String> paramMap = new TreeMap<String, String>();
- ResponseEntity<String> responseEntity = null;
- for (String key : map.keySet()) {
- if ("wId".equals(key)) {
- continue;
- }
- paramMap.put(key, map.get(key).toString());
- }
- String appId = WechatFactory.getAppId(wId);
- SmallWeChatDto smallWeChatDto = getSmallWechat(appId);
-
- if (smallWeChatDto == null) { //浠庨厤缃枃浠朵腑鑾峰彇 灏忕▼搴忛厤缃俊鎭�
- smallWeChatDto = new SmallWeChatDto();
- smallWeChatDto.setAppId(wechatAuthProperties.getAppId());
- smallWeChatDto.setAppSecret(wechatAuthProperties.getSecret());
- smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
- smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
- }
- String sign = PayUtil.createSign(paramMap, smallWeChatDto.getPayPassword());
-
- if (!sign.equals(map.get("sign"))) {
- throw new IllegalArgumentException("閴存潈澶辫触");
- }
-
- String outTradeNo = map.get("out_trade_no").toString();
- String openId = "";
- String paySwitch = MappingCache.getValue(AppAbstractComponentSMO.DOMAIN_WECHAT_PAY, AppAbstractComponentSMO.WECHAT_SERVICE_PAY_SWITCH);
- if (AppAbstractComponentSMO.WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) {
- openId = map.get("sub_openid").toString();
- } else {
- openId = map.get("openid").toString();
- }
-
- responseEntity = getUserInfoByOpenId(restTemplate, openId);
-
- logger.debug("鏌ヨ鐢ㄦ埛淇℃伅杩斿洖鎶ユ枃锛�" + responseEntity);
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- throw new IllegalArgumentException("鏍圭粷openId 鏌ヨ鐢ㄦ埛淇℃伅寮傚父" + openId);
- }
-
- JSONObject userResult = JSONObject.parseObject(responseEntity.getBody());
- JSONObject realUserInfo = userResult.getJSONArray("data").getJSONObject(0);
- String useId = realUserInfo.getString("userId");
-
- //鏌ヨ鐢ㄦ埛ID
- JSONObject paramIn = new JSONObject();
- paramIn.put("oId", outTradeNo);
- String url = ServiceConstant.SERVICE_API_URL + "/api/fee.payFeeConfirm";
- responseEntity = this.callCenterService(restTemplate, useId, paramIn.toJSONString(), url, HttpMethod.POST);
-
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- return 0;
- }
- return 1;
- }
-
- /**
- * 鑾峰彇鐢ㄦ埛淇℃伅
- *
- * @param restTemplate
- * @return
- */
- protected ResponseEntity<String> getUserInfoByOpenId(RestTemplate restTemplate, String openId) {
- //Assert.hasLength(pd.getUserId(), "鐢ㄦ埛鏈櫥褰曡鍏堢櫥褰�");
- ResponseEntity<String> responseEntity = null;
- responseEntity = this.callCenterService(restTemplate, "-1", "",
- ServiceConstant.SERVICE_API_URL + "/api/" + ServiceCodeConstant.LIST_APPUSERBINDINGOWNERS + "?openId=" + openId + "&page=1&row=1", HttpMethod.GET);
- // 杩囨护杩斿洖鎶ユ枃涓殑瀛楁锛屽彧杩斿洖name瀛楁
- //{"address":"","orderTypeCd":"Q","serviceCode":"","responseTime":"20190401194712","sex":"","localtionCd":"","userId":"302019033054910001","levelCd":"00","transactionId":"-1","dataFlowId":"-1","response":{"code":"0000","message":"鎴愬姛"},"name":"996icu","tel":"18909780341","bId":"-1","businessType":"","email":""}
-
- return responseEntity;
-
- }
-
- /**
- * 璋冪敤涓績鏈嶅姟
- *
- * @return
- */
- protected ResponseEntity<String> callCenterService(RestTemplate restTemplate, String userId, String param, String url, HttpMethod httpMethod) {
-
- ResponseEntity<String> responseEntity = null;
- HttpHeaders header = new HttpHeaders();
- header.add(CommonConstant.HTTP_APP_ID.toLowerCase(), APP_ID);
- header.add(CommonConstant.HTTP_USER_ID.toLowerCase(), userId);
- header.add(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), UUID.randomUUID().toString());
- header.add(CommonConstant.HTTP_REQ_TIME.toLowerCase(), DateUtil.getDefaultFormateTimeString(new Date()));
- header.add(CommonConstant.HTTP_SIGN.toLowerCase(), "");
- HttpEntity<String> httpEntity = new HttpEntity<String>(param, header);
- //logger.debug("璇锋眰涓績鏈嶅姟淇℃伅锛寋}", httpEntity);
- try {
- responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
- } catch (HttpStatusCodeException e) { //杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�
- responseEntity = new ResponseEntity<String>(e.getResponseBodyAsString(), e.getStatusCode());
- } catch (Exception e) {
- responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
- } finally {
- logger.debug("璇锋眰鍦板潃涓�,{} 璇锋眰涓績鏈嶅姟淇℃伅锛寋},涓績鏈嶅姟杩斿洖淇℃伅锛寋}", url, httpEntity, responseEntity);
- return responseEntity;
- }
-
- }
-
-
- private SmallWeChatDto getSmallWechat(String appId) {
-
- ResponseEntity responseEntity = null;
-
- responseEntity = this.callCenterService(restTemplate, "-1", "",
- ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId="
- + appId + "&page=1&row=1", HttpMethod.GET);
-
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- return null;
- }
- JSONObject smallWechatObj = JSONObject.parseObject(responseEntity.getBody().toString());
- JSONArray smallWeChats = smallWechatObj.getJSONArray("smallWeChats");
-
- if (smallWeChats == null || smallWeChats.size() < 1) {
- return null;
- }
-
- return BeanConvertUtil.covertBean(smallWeChats.get(0), SmallWeChatDto.class);
- }
-
}
--
Gitblit v1.8.0