From 219655836dce9581cc668c77950204ab283d8d45 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期日, 23 二月 2020 16:24:05 +0800
Subject: [PATCH] 优化登录功能
---
AppFrontService/src/main/java/com/java110/app/smo/payment/impl/ToPaySMOImpl.java | 121 +++++++++++++++++++++-------------------
1 files changed, 64 insertions(+), 57 deletions(-)
diff --git a/AppFrontService/src/main/java/com/java110/app/smo/payment/impl/ToPaySMOImpl.java b/AppFrontService/src/main/java/com/java110/app/smo/payment/impl/ToPaySMOImpl.java
index a428fc7..452a297 100644
--- a/AppFrontService/src/main/java/com/java110/app/smo/payment/impl/ToPaySMOImpl.java
+++ b/AppFrontService/src/main/java/com/java110/app/smo/payment/impl/ToPaySMOImpl.java
@@ -16,6 +16,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
@@ -24,6 +25,7 @@
import java.util.SortedMap;
import java.util.TreeMap;
+@Service("toPaySMOImpl")
public class ToPaySMOImpl extends AppAbstractComponentSMO implements IToPaySMO {
private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
@@ -46,6 +48,7 @@
Assert.jsonObjectHaveKey(paramIn, "cycles", "璇锋眰鎶ユ枃涓湭鍖呭惈cycles鑺傜偣");
Assert.jsonObjectHaveKey(paramIn, "receivedAmount", "璇锋眰鎶ユ枃涓湭鍖呭惈receivedAmount鑺傜偣");
Assert.jsonObjectHaveKey(paramIn, "feeId", "璇锋眰鎶ユ枃涓湭鍖呭惈feeId鑺傜偣");
+ Assert.jsonObjectHaveKey(paramIn, "feeName", "璇锋眰鎶ユ枃涓湭鍖呭惈feeName鑺傜偣");
}
@@ -74,7 +77,7 @@
JSONObject userResult = JSONObject.parseObject(responseEntity.getBody().toString());
int total = userResult.getIntValue("total");
- if(total < 1){
+ if (total < 1) {
//鏈煡璇㈠埌鐢ㄦ埛淇℃伅
throw new IllegalArgumentException("鏈煡璇㈠井淇$敤鎴�");
}
@@ -84,7 +87,7 @@
String openId = realUserInfo.getString("openId");
//寰俊涓嬪崟PayUtil
- Map result = java110Payment(orderId, money, openId);
+ Map result = super.java110Payment(restTemplate,paramIn.getString("feeName"), orderId, money, openId);
responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
return responseEntity;
@@ -100,59 +103,63 @@
* @return
* @throws Exception
*/
- private Map<String, String> java110Payment(String orderNum, double money, String openId) throws Exception {
- logger.info("銆愬皬绋嬪簭鏀粯銆� 缁熶竴涓嬪崟寮�濮�, 璁㈠崟缂栧彿=" + orderNum);
- SortedMap<String, String> resultMap = new TreeMap<String, String>();
-//鐢熸垚鏀粯閲戦锛屽紑鍙戠幆澧冨鐞嗘敮浠橀噾棰濇暟鍒�0.01銆�0.02銆�0.03鍏�
-
- double payAmount = PayUtil.getPayAmountByEnv("DEV", money);
-//娣诲姞鎴栨洿鏂版敮浠樿褰�(鍙傛暟璺熻繘鑷繁涓氬姟闇�姹傛坊鍔�)
-
- Map<String, String> resMap = this.java110UnifieldOrder(orderNum, wechatAuthProperties.TRADE_TYPE_JSAPI, payAmount, openId);
- if ("SUCCESS".equals(resMap.get("return_code")) && "SUCCESS".equals(resMap.get("result_code"))) {
- resultMap.put("appId", wechatAuthProperties.getAppId());
- resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
- resultMap.put("nonceStr", PayUtil.makeUUID(32));
- resultMap.put("package", "prepay_id=" + resMap.get("prepay_id"));
- resultMap.put("signType", "MD5");
- resultMap.put("sign", PayUtil.createSign(resultMap, wechatAuthProperties.getKey()));
- resultMap.put("returnCode", "SUCCESS");
- resultMap.put("returnMsg", "OK");
- logger.info("銆愬皬绋嬪簭鏀粯銆戠粺涓�涓嬪崟鎴愬姛锛岃繑鍥炲弬鏁�:" + resultMap);
- } else {
- resultMap.put("returnCode", resMap.get("return_code"));
- resultMap.put("returnMsg", resMap.get("return_msg"));
- logger.info("銆愬皬绋嬪簭鏀粯銆戠粺涓�涓嬪崟澶辫触锛屽け璐ュ師鍥�:" + resMap.get("return_msg"));
- }
- return resultMap;
- }
-
- /**
- * 灏忕▼搴忔敮浠樼粺涓�涓嬪崟
- */
- private Map<String, String> java110UnifieldOrder(String orderNum, String tradeType, double payAmount, String openid) throws Exception {
-//灏佽鍙傛暟
- SortedMap<String, String> paramMap = new TreeMap<String, String>();
- paramMap.put("appid", wechatAuthProperties.getAppId());
- paramMap.put("mch_id", wechatAuthProperties.getMchId());
- paramMap.put("nonce_str", PayUtil.makeUUID(32));
- paramMap.put("body", "");
- paramMap.put("out_trade_no", orderNum);
- paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount));
- paramMap.put("spbill_create_ip", PayUtil.getLocalIp());
- paramMap.put("notify_url", wechatAuthProperties.getWxNotifyUrl());
- paramMap.put("trade_type", tradeType);
- paramMap.put("openid", openid);
- paramMap.put("sign", PayUtil.createSign(paramMap, wechatAuthProperties.getKey()));
-//杞崲涓簒ml
- String xmlData = PayUtil.mapToXml(paramMap);
-
- ResponseEntity<String> responseEntity = restTemplate.postForEntity(
- wechatAuthProperties.getWxPayUnifiedOrder(), xmlData, String.class);
-//璇锋眰寰俊鍚庡彴锛岃幏鍙栭鏀粯ID
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- throw new IllegalArgumentException("鏀粯澶辫触" + responseEntity.getBody());
- }
- return PayUtil.xmlStrToMap(responseEntity.getBody());
- }
+// private Map<String, String> java110Payment(String feeName, String orderNum, double money, String openId) throws Exception {
+// logger.info("銆愬皬绋嬪簭鏀粯銆� 缁熶竴涓嬪崟寮�濮�, 璁㈠崟缂栧彿=" + orderNum);
+// SortedMap<String, String> resultMap = new TreeMap<String, String>();
+////鐢熸垚鏀粯閲戦锛屽紑鍙戠幆澧冨鐞嗘敮浠橀噾棰濇暟鍒�0.01銆�0.02銆�0.03鍏�
+//
+// double payAmount = PayUtil.getPayAmountByEnv("DEV", money);
+////娣诲姞鎴栨洿鏂版敮浠樿褰�(鍙傛暟璺熻繘鑷繁涓氬姟闇�姹傛坊鍔�)
+//
+// Map<String, String> resMap = this.java110UnifieldOrder(feeName, orderNum, wechatAuthProperties.TRADE_TYPE_JSAPI, payAmount, openId);
+// if ("SUCCESS".equals(resMap.get("return_code")) && "SUCCESS".equals(resMap.get("result_code"))) {
+// resultMap.put("appId", wechatAuthProperties.getAppId());
+// resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
+// resultMap.put("nonceStr", PayUtil.makeUUID(32));
+// resultMap.put("package", "prepay_id=" + resMap.get("prepay_id"));
+// resultMap.put("signType", "MD5");
+// resultMap.put("sign", PayUtil.createSign(resultMap, wechatAuthProperties.getKey()));
+// resultMap.put("code", "0");
+// resultMap.put("msg", "涓嬪崟鎴愬姛");
+// logger.info("銆愬皬绋嬪簭鏀粯銆戠粺涓�涓嬪崟鎴愬姛锛岃繑鍥炲弬鏁�:" + resultMap);
+// } else {
+// resultMap.put("code", resMap.get("return_code"));
+// resultMap.put("msg", resMap.get("return_msg"));
+// logger.info("銆愬皬绋嬪簭鏀粯銆戠粺涓�涓嬪崟澶辫触锛屽け璐ュ師鍥�:" + resMap.get("return_msg"));
+// }
+// return resultMap;
+// }
+//
+// /**
+// * 灏忕▼搴忔敮浠樼粺涓�涓嬪崟
+// */
+// private Map<String, String> java110UnifieldOrder(String feeName, String orderNum, String tradeType, double payAmount, String openid) throws Exception {
+////灏佽鍙傛暟
+// SortedMap<String, String> paramMap = new TreeMap<String, String>();
+// paramMap.put("appid", wechatAuthProperties.getAppId());
+// paramMap.put("mch_id", wechatAuthProperties.getMchId());
+// paramMap.put("nonce_str", PayUtil.makeUUID(32));
+// paramMap.put("body", "HC鏅烘収瀹跺洯-" + feeName);
+// paramMap.put("out_trade_no", orderNum);
+// paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount));
+// paramMap.put("spbill_create_ip", PayUtil.getLocalIp());
+// paramMap.put("notify_url", wechatAuthProperties.getWxNotifyUrl());
+// paramMap.put("trade_type", tradeType);
+// paramMap.put("openid", openid);
+// paramMap.put("sign", PayUtil.createSign(paramMap, wechatAuthProperties.getKey()));
+////杞崲涓簒ml
+// String xmlData = PayUtil.mapToXml(paramMap);
+//
+// logger.debug("璋冪敤鏀粯缁熶竴涓嬪崟鎺ュ彛" + xmlData);
+//
+// ResponseEntity<String> responseEntity = restTemplate.postForEntity(
+// wechatAuthProperties.getWxPayUnifiedOrder(), xmlData, String.class);
+//
+// logger.debug("缁熶竴涓嬪崟杩斿洖" + responseEntity);
+////璇锋眰寰俊鍚庡彴锛岃幏鍙栭鏀粯ID
+// if (responseEntity.getStatusCode() != HttpStatus.OK) {
+// throw new IllegalArgumentException("鏀粯澶辫触" + responseEntity.getBody());
+// }
+// return PayUtil.xmlStrToMap(responseEntity.getBody());
+// }
}
--
Gitblit v1.8.0