|
@@ -1,24 +1,21 @@
|
1
|
1
|
package com.yunzhi.niucai.controller;
|
2
|
2
|
|
3
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
3
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
6
|
4
|
import com.yunzhi.niucai.common.BaseController;
|
7
|
5
|
import com.yunzhi.niucai.common.ResponseBean;
|
|
6
|
+import com.yunzhi.niucai.entity.TaOrder;
|
|
7
|
+import com.yunzhi.niucai.service.ITaWxpayService;
|
8
|
8
|
import io.swagger.annotations.Api;
|
9
|
9
|
import io.swagger.annotations.ApiOperation;
|
10
|
10
|
import io.swagger.annotations.ApiParam;
|
|
11
|
+import org.apache.commons.io.IOUtils;
|
11
|
12
|
import org.slf4j.Logger;
|
12
|
13
|
import org.slf4j.LoggerFactory;
|
13
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
15
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
16
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
18
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
19
|
|
-import com.yunzhi.niucai.service.ITaWxpayService;
|
20
|
|
-import com.yunzhi.niucai.entity.TaWxpay;
|
21
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
15
|
+import org.springframework.web.bind.annotation.*;
|
|
16
|
+
|
|
17
|
+import javax.servlet.http.HttpServletRequest;
|
|
18
|
+import java.io.IOException;
|
22
|
19
|
|
23
|
20
|
/**
|
24
|
21
|
* <p>
|
|
@@ -39,81 +36,26 @@ public class TaWxpayController extends BaseController {
|
39
|
36
|
@Autowired
|
40
|
37
|
public ITaWxpayService iTaWxpayService;
|
41
|
38
|
|
42
|
|
-
|
43
|
|
- /**
|
44
|
|
- * 分页查询列表
|
45
|
|
- * @param pageNum
|
46
|
|
- * @param pageSize
|
47
|
|
- * @return
|
48
|
|
- */
|
49
|
|
- @RequestMapping(value="/taWxpay",method= RequestMethod.GET)
|
50
|
|
- @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
|
51
|
|
- public ResponseBean taWxpayList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
52
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
|
53
|
|
-
|
54
|
|
- IPage<TaWxpay> pg = new Page<>(pageNum, pageSize);
|
55
|
|
- QueryWrapper<TaWxpay> queryWrapper = new QueryWrapper<>();
|
56
|
|
- queryWrapper.orderByDesc("create_date");
|
57
|
|
-
|
58
|
|
- IPage<TaWxpay> result = iTaWxpayService.page(pg, queryWrapper);
|
59
|
|
- return ResponseBean.success(result);
|
60
|
|
- }
|
61
|
|
-
|
62
|
39
|
/**
|
63
|
|
- * 保存对象
|
64
|
|
- * @param taWxpay 实体对象
|
|
40
|
+ * 手机app获取唤醒支付宝的参数
|
|
41
|
+ * @param request
|
|
42
|
+ * @param taOrder
|
65
|
43
|
* @return
|
|
44
|
+ * @throws Exception
|
66
|
45
|
*/
|
67
|
|
- @RequestMapping(value="/taWxpay",method= RequestMethod.POST)
|
68
|
|
- @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
69
|
|
- public ResponseBean taWxpayAdd(@ApiParam("保存内容") @RequestBody TaWxpay taWxpay) throws Exception{
|
70
|
|
-
|
71
|
|
- if (iTaWxpayService.save(taWxpay)){
|
72
|
|
- return ResponseBean.success(taWxpay);
|
73
|
|
- }else {
|
74
|
|
- return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
75
|
|
- }
|
76
|
|
- }
|
77
|
|
-
|
78
|
|
- /**
|
79
|
|
- * 根据id删除对象
|
80
|
|
- * @param id 实体ID
|
81
|
|
- */
|
82
|
|
- @RequestMapping(value="/taWxpay/{id}", method= RequestMethod.DELETE)
|
83
|
|
- @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
|
84
|
|
- public ResponseBean taWxpayDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
85
|
|
- if(iTaWxpayService.removeById(id)){
|
86
|
|
- return ResponseBean.success("success");
|
87
|
|
- }else {
|
88
|
|
- return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
89
|
|
- }
|
90
|
|
- }
|
91
|
|
-
|
92
|
|
- /**
|
93
|
|
- * 修改对象
|
94
|
|
- * @param id 实体ID
|
95
|
|
- * @param taWxpay 实体对象
|
96
|
|
- * @return
|
97
|
|
- */
|
98
|
|
- @RequestMapping(value="/taWxpay/{id}",method= RequestMethod.PUT)
|
99
|
|
- @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
|
100
|
|
- public ResponseBean taWxpayUpdate(@ApiParam("对象ID") @PathVariable Integer id,
|
101
|
|
- @ApiParam("更新内容") @RequestBody TaWxpay taWxpay) throws Exception{
|
102
|
|
-
|
103
|
|
- if (iTaWxpayService.updateById(taWxpay)){
|
104
|
|
- return ResponseBean.success(iTaWxpayService.getById(id));
|
105
|
|
- }else {
|
106
|
|
- return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
107
|
|
- }
|
|
46
|
+ @PostMapping("/app/wxpay/order")
|
|
47
|
+ @ApiOperation(value = "创建订单", notes = "创建订单", httpMethod = "POST", response = ResponseBean.class)
|
|
48
|
+ public ResponseBean create(HttpServletRequest request,@ApiParam("下单记录") @RequestBody TaOrder taOrder) throws Exception {
|
|
49
|
+ return iTaWxpayService.orderPaying(taOrder,request.getRemoteAddr(),request.getHeader("user-agent"));
|
108
|
50
|
}
|
109
|
51
|
|
110
|
52
|
/**
|
111
|
|
- * 根据id查询对象
|
112
|
|
- * @param id 实体ID
|
|
53
|
+ * 支付成功回调
|
|
54
|
+ * @param request
|
113
|
55
|
*/
|
114
|
|
- @RequestMapping(value="/taWxpay/{id}",method= RequestMethod.GET)
|
115
|
|
- @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
116
|
|
- public ResponseBean taWxpayGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
117
|
|
- return ResponseBean.success(iTaWxpayService.getById(id));
|
|
56
|
+ @GetMapping("/app/callback/wxpay/pay")
|
|
57
|
+ public String callback(HttpServletRequest request) throws IOException, WxPayException {
|
|
58
|
+ String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
|
|
59
|
+ return iTaWxpayService.payCallback(xmlResult);
|
118
|
60
|
}
|
119
|
61
|
}
|