Skip to content

Commit d8a8ffc

Browse files
committed
加入微信扫码支付
1 parent cbf6878 commit d8a8ffc

8 files changed

Lines changed: 298 additions & 12 deletions

File tree

java110-bean/src/main/java/com/java110/dto/rentingPool/RentingPoolDto.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ public class RentingPoolDto extends PageDto implements Serializable {
1919
public static final String STATE_PROXY_AUDIT = "1";
2020
public static final String STATE_PROXY_VIEW_ROOM = "2";
2121
public static final String STATE_TO_PAY = "3";
22+
public static final String STATE_OWNER_TO_PAY = "7";
2223
public static final String STATE_APPLY_AGREE = "4";
2324
public static final String STATE_ADMIN_AUDIT = "5";
2425
public static final String STATE_FINISH = "6";
2526

27+
//房屋服务费 redis前缀
28+
public static final String REDIS_PAY_RENTING = "PAY_RENTING_";
29+
2630
private String latitude;
2731
private String ownerTel;
2832
private String rentingConfigId;
@@ -49,6 +53,13 @@ public class RentingPoolDto extends PageDto implements Serializable {
4953

5054
private String statusCd = "0";
5155

56+
private String serviceOwnerRate;
57+
private String serviceTenantRate;
58+
private String adminSeparateRate;
59+
private String proxySeparateRate;
60+
private String propertySeparateRate;
61+
private String servicePrice;
62+
5263

5364
public String getLatitude() {
5465
return latitude;
@@ -218,4 +229,52 @@ public String getRoomName() {
218229
public void setRoomName(String roomName) {
219230
this.roomName = roomName;
220231
}
232+
233+
public String getServiceOwnerRate() {
234+
return serviceOwnerRate;
235+
}
236+
237+
public void setServiceOwnerRate(String serviceOwnerRate) {
238+
this.serviceOwnerRate = serviceOwnerRate;
239+
}
240+
241+
public String getServiceTenantRate() {
242+
return serviceTenantRate;
243+
}
244+
245+
public void setServiceTenantRate(String serviceTenantRate) {
246+
this.serviceTenantRate = serviceTenantRate;
247+
}
248+
249+
public String getAdminSeparateRate() {
250+
return adminSeparateRate;
251+
}
252+
253+
public void setAdminSeparateRate(String adminSeparateRate) {
254+
this.adminSeparateRate = adminSeparateRate;
255+
}
256+
257+
public String getProxySeparateRate() {
258+
return proxySeparateRate;
259+
}
260+
261+
public void setProxySeparateRate(String proxySeparateRate) {
262+
this.proxySeparateRate = proxySeparateRate;
263+
}
264+
265+
public String getPropertySeparateRate() {
266+
return propertySeparateRate;
267+
}
268+
269+
public void setPropertySeparateRate(String propertySeparateRate) {
270+
this.propertySeparateRate = propertySeparateRate;
271+
}
272+
273+
public String getServicePrice() {
274+
return servicePrice;
275+
}
276+
277+
public void setServicePrice(String servicePrice) {
278+
this.servicePrice = servicePrice;
279+
}
221280
}

java110-db/src/main/resources/mapper/user/RentingPoolServiceDaoImplMapper.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
statusCd,t.renting_title,t.renting_title rentingTitle,t.check_in,t.check_in
2323
checkIn,t.renting_id,t.renting_id rentingId,t.room_id,t.room_id roomId,t.payment_type,t.payment_type
2424
paymentType,t.owner_name,t.owner_name ownerName,t.price,t.state,t.community_id,t.community_id
25-
communityId,t.longitude,td.name stateName,td2.name paymentTypeName,rc.renting_type rentingType
25+
communityId,t.longitude,td.name stateName,td2.name paymentTypeName,rc.renting_type rentingType,
26+
rc.service_owner_rate serviceOwnerRate,rc.service_tenant_rate serviceTenantRate,rc.admin_separate_rate adminSeparateRate,
27+
rc.proxy_separate_rate proxySeparateRate,rc.property_separate_rate propertySeparateRate,rc.service_price servicePrice
2628
from renting_pool t
2729
left join t_dict td on td.status_cd = t.state and td.table_name = 'renting_pool' and td.table_columns = 'state'
2830
left join t_dict td2 on td2.status_cd = t.payment_type and td2.table_name = 'renting_pool' and td2.table_columns = 'payment_type'

java110-utils/src/main/java/com/java110/utils/cache/CommonCache.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class CommonCache extends BaseCache {
1111
public final static int defaultExpireTime = 5 * 60;
1212
public final static int RESEND_DEFAULT_EXPIRETIME = 1 * 60;
1313

14+
//支付默认回话
15+
public final static int PAY_DEFAULT_EXPIRE_TIME = 2 * 60 * 60;
16+
1417
/**
1518
* 获取值(用户ID)
1619
*

service-front/src/main/java/com/java110/front/controller/PaymentController.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.java110.front.controller;
22

3-
import com.java110.front.smo.payment.IToNotifySMO;
4-
import com.java110.front.smo.payment.IToPaySMO;
5-
import com.java110.front.smo.payment.IToPayTempCarInoutSMO;
63
import com.java110.core.base.controller.BaseController;
74
import com.java110.core.context.IPageData;
85
import com.java110.core.context.PageData;
6+
import com.java110.front.smo.payment.IRentingToPaySMO;
7+
import com.java110.front.smo.payment.IToNotifySMO;
8+
import com.java110.front.smo.payment.IToPaySMO;
9+
import com.java110.front.smo.payment.IToPayTempCarInoutSMO;
910
import com.java110.utils.constant.CommonConstant;
1011
import com.java110.utils.util.StringUtil;
1112
import org.slf4j.Logger;
@@ -30,6 +31,9 @@ public class PaymentController extends BaseController {
3031
@Autowired
3132
private IToPaySMO toPaySMOImpl;
3233

34+
@Autowired
35+
private IRentingToPaySMO rentingToPaySMOImpl;
36+
3337
@Autowired
3438
private IToPayTempCarInoutSMO toPayTempCarInoutSMOImpl;
3539

@@ -46,8 +50,8 @@ public class PaymentController extends BaseController {
4650
public ResponseEntity<String> toPay(@RequestBody String postInfo, HttpServletRequest request) {
4751
IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
4852
/*IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);*/
49-
String appId = request.getHeader("APP_ID");
50-
if(StringUtil.isEmpty(appId)){
53+
String appId = request.getHeader("APP_ID");
54+
if (StringUtil.isEmpty(appId)) {
5155
appId = request.getHeader("APP-ID");
5256
}
5357

@@ -68,7 +72,7 @@ public ResponseEntity<String> toPayTempCarInout(@RequestBody String postInfo, Ht
6872
IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
6973
/*IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);*/
7074
String appId = request.getHeader("APP_ID");
71-
if(StringUtil.isEmpty(appId)){
75+
if (StringUtil.isEmpty(appId)) {
7276
appId = request.getHeader("APP-ID");
7377
}
7478
IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getUserName(), pd.getToken(), postInfo,
@@ -89,9 +93,29 @@ public ResponseEntity<String> notify(@RequestBody String postInfo, HttpServletRe
8993

9094
logger.debug("微信支付回调报文" + postInfo);
9195

92-
return toNotifySMOImpl.toNotify(postInfo,request);
96+
return toNotifySMOImpl.toNotify(postInfo, request);
97+
98+
99+
}
93100

101+
/**
102+
* <p>出租统一下单入口</p>
103+
*
104+
* @param request
105+
* @throws Exception
106+
*/
107+
@RequestMapping(path = "/rentingToPay", method = RequestMethod.POST)
108+
public ResponseEntity<String> rentingToPay(@RequestBody String postInfo, HttpServletRequest request) {
109+
IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
110+
String appId = request.getHeader("APP_ID");
111+
if (StringUtil.isEmpty(appId)) {
112+
appId = request.getHeader("APP-ID");
113+
}
94114

115+
IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getUserName(), pd.getToken(), postInfo,
116+
"", "", "", pd.getSessionId(),
117+
appId);
118+
return rentingToPaySMOImpl.toPay(newPd);
95119
}
96120

97121
}

service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
1616
import org.springframework.beans.factory.annotation.Autowired;
17-
import org.springframework.http.*;
17+
import org.springframework.http.HttpEntity;
18+
import org.springframework.http.HttpHeaders;
19+
import org.springframework.http.HttpMethod;
20+
import org.springframework.http.HttpStatus;
21+
import org.springframework.http.ResponseEntity;
1822
import org.springframework.web.client.HttpStatusCodeException;
1923
import org.springframework.web.client.RestTemplate;
2024

@@ -112,6 +116,9 @@ protected Map<String, String> java110Payment(RestTemplate outRestTemplate,
112116
resultMap.put("prepayid", resMap.get("prepay_id"));
113117
//resultMap.put("signType", "MD5");
114118
resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
119+
} else if (WechatAuthProperties.TRADE_TYPE_NATIVE.equals(tradeType)) {
120+
resultMap.put("prepayId", resMap.get("prepay_id"));
121+
resultMap.put("codeUrl", resMap.get("code_url"));
115122
}
116123
resultMap.put("code", "0");
117124
resultMap.put("msg", "下单成功");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.java110.front.smo.payment;
2+
3+
import com.java110.core.context.IPageData;
4+
import org.springframework.http.ResponseEntity;
5+
6+
/**
7+
* 统一下单接口类
8+
*/
9+
public interface IRentingToPaySMO {
10+
11+
/**
12+
* 下单
13+
* @param pd
14+
* @return
15+
*/
16+
public ResponseEntity<String> toPay(IPageData pd);
17+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package com.java110.front.smo.payment.impl;
2+
3+
import com.alibaba.fastjson.JSONArray;
4+
import com.alibaba.fastjson.JSONObject;
5+
import com.java110.core.context.IPageData;
6+
import com.java110.core.context.PageData;
7+
import com.java110.core.factory.GenerateCodeFactory;
8+
import com.java110.dto.owner.OwnerAppUserDto;
9+
import com.java110.dto.rentingPool.RentingPoolDto;
10+
import com.java110.dto.smallWeChat.SmallWeChatDto;
11+
import com.java110.front.properties.WechatAuthProperties;
12+
import com.java110.front.smo.AppAbstractComponentSMO;
13+
import com.java110.front.smo.payment.IRentingToPaySMO;
14+
import com.java110.utils.cache.CommonCache;
15+
import com.java110.utils.constant.ServiceConstant;
16+
import com.java110.utils.util.Assert;
17+
import com.java110.utils.util.BeanConvertUtil;
18+
import com.java110.vo.ResultVo;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.http.HttpMethod;
23+
import org.springframework.http.HttpStatus;
24+
import org.springframework.http.ResponseEntity;
25+
import org.springframework.stereotype.Service;
26+
import org.springframework.web.client.RestTemplate;
27+
28+
import java.math.BigDecimal;
29+
import java.util.HashMap;
30+
import java.util.Map;
31+
32+
@Service("rentingToPaySMOImpl")
33+
public class RentingToPaySMOImpl extends AppAbstractComponentSMO implements IRentingToPaySMO {
34+
private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
35+
36+
37+
@Autowired
38+
private RestTemplate restTemplate;
39+
40+
@Autowired
41+
private RestTemplate outRestTemplate;
42+
43+
44+
@Autowired
45+
private WechatAuthProperties wechatAuthProperties;
46+
47+
@Override
48+
public ResponseEntity<String> toPay(IPageData pd) {
49+
return super.businessProcess(pd);
50+
}
51+
52+
@Override
53+
protected void validate(IPageData pd, JSONObject paramIn) {
54+
55+
Assert.jsonObjectHaveKey(paramIn, "rentingId", "请求报文中未包含房源ID");
56+
57+
}
58+
59+
@Override
60+
protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws Exception {
61+
62+
ResponseEntity responseEntity = null;
63+
64+
SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
65+
smallWeChatDto.setAppId(wechatAuthProperties.getAppId());
66+
smallWeChatDto.setAppSecret(wechatAuthProperties.getSecret());
67+
smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
68+
smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
69+
70+
71+
//查询用户ID
72+
paramIn.put("userId", pd.getUserId());
73+
//查询
74+
String url = ServiceConstant.SERVICE_API_URL + "/api/renting/queryRentingPool?rentingId="
75+
+ paramIn.getString("rentingId") + "&row=1&page=1";
76+
responseEntity = super.callCenterService(restTemplate, pd, "", url, HttpMethod.GET);
77+
78+
if (responseEntity.getStatusCode() != HttpStatus.OK) {
79+
return responseEntity;
80+
}
81+
82+
JSONObject body = JSONObject.parseObject(responseEntity.getBody().toString());
83+
84+
if (ResultVo.CODE_OK != body.getInteger("code")) {
85+
return responseEntity;
86+
}
87+
88+
if (body.getInteger("total") < 1) {
89+
return responseEntity;
90+
}
91+
92+
RentingPoolDto rentingPoolDto = BeanConvertUtil.covertBean(body.getJSONArray("data").get(0), RentingPoolDto.class);
93+
94+
String appType = OwnerAppUserDto.APP_TYPE_WECHAT;
95+
96+
Map tmpParamIn = new HashMap();
97+
tmpParamIn.put("userId", pd.getUserId());
98+
tmpParamIn.put("appType", appType);
99+
100+
String orderId = GenerateCodeFactory.getOId();
101+
double service = Double.parseDouble(rentingPoolDto.getServicePrice());
102+
double rate = 0.0;
103+
String feeName = rentingPoolDto.getRoomName() + "出租服务费";
104+
if (RentingPoolDto.STATE_TO_PAY.equals(rentingPoolDto.getState())) {
105+
rate = Double.parseDouble(rentingPoolDto.getServiceTenantRate());
106+
feeName += "(租客)";
107+
} else if (RentingPoolDto.STATE_TO_PAY.equals(rentingPoolDto.getState())) {
108+
rate = Double.parseDouble(rentingPoolDto.getServiceOwnerRate());
109+
feeName += "(业主)";
110+
} else {
111+
throw new IllegalAccessException("当前状态不是支付状态");
112+
}
113+
114+
BigDecimal serviceDec = new BigDecimal(service);
115+
BigDecimal rateDec = new BigDecimal(rate);
116+
double money = serviceDec.multiply(rateDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
117+
118+
Map result = super.java110Payment(outRestTemplate, feeName, WechatAuthProperties.TRADE_TYPE_NATIVE, orderId, money, "", smallWeChatDto);
119+
result.put("money", money);
120+
responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
121+
if (!"0".equals(result.get("code"))) {
122+
return responseEntity;
123+
}
124+
125+
Map orderInfo = BeanConvertUtil.beanCovertMap(rentingPoolDto);
126+
orderInfo.put("orderId", orderId);
127+
orderInfo.put("money", money);
128+
orderInfo.put("feeName", feeName);
129+
130+
String order = JSONObject.toJSONString(orderInfo);
131+
132+
CommonCache.setValue(RentingPoolDto.REDIS_PAY_RENTING + orderId, order, CommonCache.PAY_DEFAULT_EXPIRE_TIME);
133+
134+
return responseEntity;
135+
}
136+
137+
138+
private SmallWeChatDto getSmallWechat(IPageData pd, JSONObject paramIn) {
139+
140+
ResponseEntity responseEntity = null;
141+
142+
pd = PageData.newInstance().builder(pd.getUserId(), "", "", pd.getReqData(),
143+
"", "", "", "",
144+
pd.getAppId());
145+
responseEntity = this.callCenterService(restTemplate, pd, "",
146+
ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId="
147+
+ paramIn.getString("appId") + "&page=1&row=1", HttpMethod.GET);
148+
149+
if (responseEntity.getStatusCode() != HttpStatus.OK) {
150+
return null;
151+
}
152+
JSONObject smallWechatObj = JSONObject.parseObject(responseEntity.getBody().toString());
153+
JSONArray smallWeChats = smallWechatObj.getJSONArray("smallWeChats");
154+
155+
if (smallWeChats == null || smallWeChats.size() < 1) {
156+
return null;
157+
}
158+
159+
return BeanConvertUtil.covertBean(smallWeChats.get(0), SmallWeChatDto.class);
160+
}
161+
162+
163+
}

0 commit comments

Comments
 (0)