From 21b343eb84845477ff05a6edb1243742862c6788 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期日, 05 七月 2020 17:07:35 +0800
Subject: [PATCH] 优化自定义参数 不参与签名问题
---
service-front/src/main/java/com/java110/front/smo/payment/impl/ToNotifySMOImpl.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 49 insertions(+), 10 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
index 4e50bd6..585cde8 100644
--- 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
@@ -1,12 +1,17 @@
package com.java110.front.smo.payment.impl;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.java110.core.factory.WechatFactory;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.front.properties.WechatAuthProperties;
import com.java110.front.smo.AppAbstractComponentSMO;
import com.java110.front.smo.payment.IToNotifySMO;
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.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.PayUtil;
import org.slf4j.Logger;
@@ -45,12 +50,10 @@
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>";
}
@@ -75,12 +78,26 @@
}
public int confirmPayFee(Map<String, Object> map) {
+ String wId = map.get("wId").toString();
SortedMap<String, String> paramMap = new TreeMap<String, String>();
ResponseEntity<String> responseEntity = null;
for (String key : map.keySet()) {
+ if("wId".equals(wId)){
+ continue;
+ }
paramMap.put(key, map.get(key).toString());
}
- String sign = PayUtil.createSign(paramMap, wechatAuthProperties.getKey());
+ 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("閴存潈澶辫触");
@@ -90,8 +107,8 @@
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("sub_openid").toString();
+ } else {
openId = map.get("openid").toString();
}
@@ -103,7 +120,7 @@
}
JSONObject userResult = JSONObject.parseObject(responseEntity.getBody());
- JSONObject realUserInfo = userResult.getJSONArray("users").getJSONObject(0);
+ JSONObject realUserInfo = userResult.getJSONArray("data").getJSONObject(0);
String useId = realUserInfo.getString("userId");
//鏌ヨ鐢ㄦ埛ID
@@ -128,7 +145,7 @@
//Assert.hasLength(pd.getUserId(), "鐢ㄦ埛鏈櫥褰曡鍏堢櫥褰�");
ResponseEntity<String> responseEntity = null;
responseEntity = this.callCenterService(restTemplate, "-1", "",
- ServiceConstant.SERVICE_API_URL + "/api/user.listUsers?openId=" + openId + "&page=1&row=1", HttpMethod.GET);
+ 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":""}
@@ -155,7 +172,7 @@
try {
responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
} catch (HttpStatusCodeException e) { //杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�
- responseEntity = new ResponseEntity<String>( e.getResponseBodyAsString(), e.getStatusCode());
+ responseEntity = new ResponseEntity<String>(e.getResponseBodyAsString(), e.getStatusCode());
} catch (Exception e) {
responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} finally {
@@ -165,4 +182,26 @@
}
+
+ 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