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 | 143 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 141 insertions(+), 2 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 eaa55d1..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
@@ -1,14 +1,41 @@
package com.java110.app.smo.payment.impl;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.java110.app.properties.WechatAuthProperties;
import com.java110.app.smo.AppAbstractComponentSMO;
import com.java110.app.smo.payment.IToPaySMO;
import com.java110.core.context.IPageData;
+import com.java110.dto.order.WxOrderDto;
+import com.java110.utils.constant.ServiceConstant;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.PayUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+import java.util.HashMap;
+import java.util.Map;
+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);
+
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private WechatAuthProperties wechatAuthProperties;
+
@Override
public ResponseEntity<String> toPay(IPageData pd) {
return super.businessProcess(pd);
@@ -17,10 +44,122 @@
@Override
protected void validate(IPageData pd, JSONObject paramIn) {
+ Assert.jsonObjectHaveKey(paramIn, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId鑺傜偣");
+ Assert.jsonObjectHaveKey(paramIn, "cycles", "璇锋眰鎶ユ枃涓湭鍖呭惈cycles鑺傜偣");
+ Assert.jsonObjectHaveKey(paramIn, "receivedAmount", "璇锋眰鎶ユ枃涓湭鍖呭惈receivedAmount鑺傜偣");
+ Assert.jsonObjectHaveKey(paramIn, "feeId", "璇锋眰鎶ユ枃涓湭鍖呭惈feeId鑺傜偣");
+ Assert.jsonObjectHaveKey(paramIn, "feeName", "璇锋眰鎶ユ枃涓湭鍖呭惈feeName鑺傜偣");
+
}
@Override
- protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws IOException {
- return null;
+ protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws Exception {
+
+ ResponseEntity responseEntity = null;
+ //鏌ヨ鐢ㄦ埛ID
+ paramIn.put("userId", pd.getUserId());
+ String url = ServiceConstant.SERVICE_API_URL + "/api/fee.payFeePre";
+ responseEntity = super.callCenterService(restTemplate, pd, paramIn.toJSONString(), url, HttpMethod.POST);
+
+ if (responseEntity.getStatusCode() != HttpStatus.OK) {
+ return responseEntity;
+ }
+ JSONObject orderInfo = JSONObject.parseObject(responseEntity.getBody().toString());
+ String orderId = orderInfo.getString("oId");
+ double money = Double.parseDouble(orderInfo.getString("receivableAmount"));
+ Map tmpParamIn = new HashMap();
+ tmpParamIn.put("userId", pd.getUserId());
+ responseEntity = super.getUserAndAttr(pd, restTemplate, tmpParamIn);
+ logger.debug("鏌ヨ鐢ㄦ埛淇℃伅杩斿洖鎶ユ枃锛�" + responseEntity);
+ if (responseEntity.getStatusCode() != HttpStatus.OK) {
+ throw new IllegalArgumentException("鏈煡璇㈢敤鎴蜂俊鎭紓甯�" + tmpParamIn);
+ }
+
+ JSONObject userResult = JSONObject.parseObject(responseEntity.getBody().toString());
+ int total = userResult.getIntValue("total");
+ if (total < 1) {
+ //鏈煡璇㈠埌鐢ㄦ埛淇℃伅
+ throw new IllegalArgumentException("鏈煡璇㈠井淇$敤鎴�");
+ }
+
+ JSONObject realUserInfo = userResult.getJSONArray("users").getJSONObject(0);
+
+ String openId = realUserInfo.getString("openId");
+
+ //寰俊涓嬪崟PayUtil
+ Map result = super.java110Payment(restTemplate,paramIn.getString("feeName"), orderId, money, openId);
+ responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
+
+ return responseEntity;
}
+
+
+ /**
+ * 棰勪笅鍗�
+ *
+ * @param orderNum
+ * @param money
+ * @param openId
+ * @return
+ * @throws Exception
+ */
+// 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