|
@@ -0,0 +1,179 @@
|
|
1
|
+package com.community.huiju.controller;
|
|
2
|
+
|
|
3
|
+import com.alibaba.fastjson.JSONObject;
|
|
4
|
+import com.alipay.api.AlipayApiException;
|
|
5
|
+import com.alipay.api.internal.util.AlipaySignature;
|
|
6
|
+import com.community.commom.constant.Constant;
|
|
7
|
+import com.community.commom.mode.ResponseBean;
|
|
8
|
+import com.community.huiju.common.wxpay.WXPayConstants;
|
|
9
|
+import com.community.huiju.common.wxpay.WXPayUtil;
|
|
10
|
+import com.community.huiju.feign.IFuShiServer;
|
|
11
|
+import com.community.huiju.service.AliMPUserServiceI;
|
|
12
|
+import com.community.huiju.service.WxMPUserServiceI;
|
|
13
|
+import com.google.common.collect.Maps;
|
|
14
|
+import io.swagger.annotations.Api;
|
|
15
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
16
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
17
|
+import io.swagger.annotations.ApiOperation;
|
|
18
|
+import org.slf4j.Logger;
|
|
19
|
+import org.slf4j.LoggerFactory;
|
|
20
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
21
|
+import org.springframework.beans.factory.annotation.Value;
|
|
22
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
23
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
24
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
25
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
26
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
27
|
+import org.springframework.web.bind.annotation.RestController;
|
|
28
|
+
|
|
29
|
+import javax.servlet.http.HttpServletRequest;
|
|
30
|
+import javax.servlet.http.HttpServletResponse;
|
|
31
|
+import java.io.ByteArrayOutputStream;
|
|
32
|
+import java.io.InputStream;
|
|
33
|
+import java.math.BigDecimal;
|
|
34
|
+import java.util.HashMap;
|
|
35
|
+import java.util.Iterator;
|
|
36
|
+import java.util.Map;
|
|
37
|
+
|
|
38
|
+import static com.alipay.api.AlipayConstants.CHARSET_UTF8;
|
|
39
|
+
|
|
40
|
+/**
|
|
41
|
+ * @author FXF
|
|
42
|
+ * @date 2019-07-08
|
|
43
|
+ */
|
|
44
|
+@RestController
|
|
45
|
+@RefreshScope
|
|
46
|
+@RequestMapping("/")
|
|
47
|
+@Api(value = "支付宝生活号API", description = "支付宝生活号API")
|
|
48
|
+public class AliMPUserController {
|
|
49
|
+
|
|
50
|
+ private Logger log = LoggerFactory.getLogger(AliMPUserController.class);
|
|
51
|
+
|
|
52
|
+ @Value("${ali.mp.configs.appId}")
|
|
53
|
+ private String appId;
|
|
54
|
+
|
|
55
|
+ @Value("${ali.mp.configs.secret}")
|
|
56
|
+ private String secret;
|
|
57
|
+
|
|
58
|
+ @Value("${alipay.ALIPAY_PUBLIC_KEY}")
|
|
59
|
+ private String ALIPAY_PUBLIC_KEY;
|
|
60
|
+
|
|
61
|
+ @Autowired
|
|
62
|
+ private AliMPUserServiceI aliMPUserService;
|
|
63
|
+
|
|
64
|
+ @Autowired
|
|
65
|
+ private IFuShiServer fuShiServer;
|
|
66
|
+
|
|
67
|
+ @RequestMapping(value = "/alimp/info", method = RequestMethod.GET)
|
|
68
|
+ @ApiOperation(value = "获取支付宝生活号相关信息", notes = "获取支付宝生活号相关信息")
|
|
69
|
+ @ApiImplicitParams({})
|
|
70
|
+ public ResponseBean getAliMPinfo(){
|
|
71
|
+ ResponseBean responseBean = new ResponseBean();
|
|
72
|
+ Map<String,Object> map = Maps.newHashMap();
|
|
73
|
+ map.put("appId",appId);
|
|
74
|
+ responseBean.addSuccess(map);
|
|
75
|
+ return responseBean;
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ @RequestMapping(value = "/{communityId}/alimp", method = RequestMethod.GET)
|
|
79
|
+ @ApiOperation(value = "根据CODE获取OPENID并判断是否第一次来,并返回数据", notes = "根据CODE获取OPENID并判断是否第一次来,并返回数据")
|
|
80
|
+ @ApiImplicitParams({@ApiImplicitParam(paramType = "path", dataType = "integer", name = "communityId", value = "小区Id"),
|
|
81
|
+ @ApiImplicitParam(paramType = "query", dataType = "String", name = "code", value = "支付宝code")})
|
|
82
|
+ public ResponseBean getUseridByCode(@PathVariable Integer communityId, @RequestParam String code){
|
|
83
|
+ ResponseBean responseBean = aliMPUserService.getTemporaryData(code,appId,secret,communityId);
|
|
84
|
+ return responseBean;
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+ @RequestMapping(value = "/{communityId}/alimp/records", method = RequestMethod.GET)
|
|
89
|
+ @ApiOperation(value = "根据openid获取缴费记录", notes = "根据openid获取缴费记录")
|
|
90
|
+ @ApiImplicitParams({@ApiImplicitParam(paramType = "path", dataType = "integer", name = "communityId", value = "小区Id"),
|
|
91
|
+ @ApiImplicitParam(paramType = "query", dataType = "String", name = "opneid", value = "支付宝opneid")})
|
|
92
|
+ public ResponseBean getRecordsByOpenid(@PathVariable Integer communityId, @RequestParam String opneid){
|
|
93
|
+ ResponseBean responseBean = aliMPUserService.getRecordsByOpenid(opneid,communityId);
|
|
94
|
+ return responseBean;
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ @RequestMapping(value = "/{communityId}/alimp/car", method = RequestMethod.GET)
|
|
98
|
+ @ApiOperation(value = "根据车牌获取数据", notes = "根据车牌获取数据")
|
|
99
|
+ @ApiImplicitParams({@ApiImplicitParam(paramType = "path", dataType = "integer", name = "communityId", value = "小区Id"),
|
|
100
|
+ @ApiImplicitParam(paramType = "query", dataType = "String", name = "carNo", value = "车牌号")})
|
|
101
|
+ public ResponseBean getParkInfoByCarNo(@PathVariable Integer communityId, @RequestParam String carNo){
|
|
102
|
+ ResponseBean responseBean = new ResponseBean();
|
|
103
|
+ String parkInfoByCarNo = fuShiServer.getParkInfoByCarNo(carNo);
|
|
104
|
+ JSONObject carNoJson = JSONObject.parseObject(parkInfoByCarNo);
|
|
105
|
+ //车辆不在停车场
|
|
106
|
+ if (carNoJson.getInteger("code") == 1){
|
|
107
|
+ responseBean.addError(carNoJson.getString("message"));
|
|
108
|
+ return responseBean;
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ if (carNoJson.getInteger("code") == 0 ){
|
|
112
|
+ if (carNoJson.getJSONObject("data").getInteger("DataType") != 3){
|
|
113
|
+ responseBean.addSuccess("储值车不支持在线缴费,月卡车请使用银城慧家APP延期续费");
|
|
114
|
+ return responseBean;
|
|
115
|
+ }
|
|
116
|
+ //返回查询的金额
|
|
117
|
+ JSONObject jsonParam = carNoJson.getJSONObject("data").getJSONObject("JsonParam");
|
|
118
|
+ Map<String,Object> resultMap = Maps.newHashMap();
|
|
119
|
+ resultMap.put("ActualAmount",jsonParam.get("ActualAmount"));
|
|
120
|
+ responseBean.addSuccess(resultMap);
|
|
121
|
+ }
|
|
122
|
+ return responseBean;
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ @ApiOperation(value = "临时车统一下单", notes = "临时车统一下单")
|
|
126
|
+ @ApiImplicitParams({
|
|
127
|
+ @ApiImplicitParam(paramType = "path", dataType = "integer", name = "communityId", value = "小区Id"),
|
|
128
|
+ @ApiImplicitParam(paramType = "query", dataType = "String", name = "carNo", value = "车牌号"),
|
|
129
|
+ @ApiImplicitParam(paramType = "query", dataType = "String", name = "openid", value = "支付宝openid")
|
|
130
|
+ })
|
|
131
|
+ @RequestMapping(value = "/{communityId}/alimp/order",method = RequestMethod.GET)
|
|
132
|
+ public ResponseBean aliTmpOrder(@PathVariable Integer communityId,
|
|
133
|
+ @RequestParam("carNo") String carNo,
|
|
134
|
+ @RequestParam("openid") String openid){
|
|
135
|
+ ResponseBean responseBean = new ResponseBean();
|
|
136
|
+
|
|
137
|
+ //String parkInfoByCarNo = fuShiServer.getParkInfoByCarNo(carNo);
|
|
138
|
+ //JSONObject carNoJson = JSONObject.parseObject(parkInfoByCarNo);
|
|
139
|
+ //String actualAmount = String.valueOf(Double.valueOf(((BigDecimal) carNoJson.getJSONObject("JsonParam").get("ActualAmount")).toString()) * 100);
|
|
140
|
+ //actualAmount = actualAmount.substring(0, actualAmount.lastIndexOf("."));
|
|
141
|
+ //String resp = wxMPUserService.wxTmpOrder(carNo,actualAmount,communityId,openid,(BigDecimal) carNoJson.getJSONObject("JsonParam").get("ActualAmount"));
|
|
142
|
+ String resp = aliMPUserService.aliTmpOrder(carNo,"1",communityId,openid,new BigDecimal("0.1"));
|
|
143
|
+
|
|
144
|
+ responseBean.addSuccess(resp);
|
|
145
|
+ return responseBean;
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ @ApiOperation(value = "手机订单支付完成后回调临时车缴费", notes = "手机订单支付完成后回调临时车缴费")
|
|
149
|
+ @RequestMapping(value = "/aliTmpNotify",method = RequestMethod.POST)
|
|
150
|
+ public void wxBillNotify(HttpServletRequest request, HttpServletResponse response){
|
|
151
|
+ log.info("支付宝 alipay result start =======");
|
|
152
|
+ Map<String,String> params = new HashMap<String,String>();
|
|
153
|
+ Map requestParams = request.getParameterMap();
|
|
154
|
+ for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
|
|
155
|
+ String name = (String) iter.next();
|
|
156
|
+ String[] values = (String[]) requestParams.get(name);
|
|
157
|
+ String valueStr = "";
|
|
158
|
+ for (int i = 0; i < values.length; i++) {
|
|
159
|
+ valueStr = (i == values.length - 1) ? valueStr + values[i]
|
|
160
|
+ : valueStr + values[i] + ",";
|
|
161
|
+ }
|
|
162
|
+ //乱码解决,这段代码在出现乱码时使用。
|
|
163
|
+ //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
|
164
|
+ params.put(name, valueStr);
|
|
165
|
+ }
|
|
166
|
+ //切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。
|
|
167
|
+ try {
|
|
168
|
+ boolean flag = AlipaySignature.rsaCheckV1(params, ALIPAY_PUBLIC_KEY, CHARSET_UTF8,"RSA2");
|
|
169
|
+ if (flag){
|
|
170
|
+ aliMPUserService.updateTmpOrder(params.get("out_trade_no"));
|
|
171
|
+ }
|
|
172
|
+ } catch (AlipayApiException e) {
|
|
173
|
+ e.printStackTrace();
|
|
174
|
+ } catch (Exception e) {
|
|
175
|
+ e.printStackTrace();
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ }
|
|
179
|
+}
|