WechatAccessController.java
6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package cn.com.glsx.dj.access.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.glsx.dj.access.service.WechatAccessService;
import cn.com.glsx.framework.core.beans.ResultEntity;
/**
* 微信接入
* <P>Description: </P>
*
* @author Alvin
* @version 1.0
*/
@Controller
@RequestMapping("wechat")
public class WechatAccessController {
@Autowired
private WechatAccessService wechatAccessService;
/**
* 授权事件处理
* @param request
* @return
* @author Alvin
* @date 2019年5月5日 下午9:02:04
*/
@PostMapping("access")
@ResponseBody
public String access(HttpServletRequest request){
wechatAccessService.access(request);
return "success";
}
/**
* 消息与事件处理
* @param request
* @param bizAppId
* @return
* @author Alvin
* @date 2019年5月5日 下午9:02:19
*/
@PostMapping("{appid}/event")
@ResponseBody
public String event(HttpServletRequest request, @PathVariable("appid") String bizAppId){
return wechatAccessService.access(request, bizAppId);
}
/**
* 微信服务认证
* @param request
* @param bizAppId
* @return
* @author Alvin
* @date 2019年5月5日 下午9:02:19
*/
@GetMapping("{appid}/event")
@ResponseBody
public String auth(HttpServletRequest request, @PathVariable("appid") String bizAppId){
return wechatAccessService.auth(request, bizAppId);
}
/**
* 跳转到授权页面
* @return
* @author Alvin
* @date 2019年5月6日 下午2:07:06
*/
@GetMapping("auth/pc")
public String authPC(){
return "auth";
}
/**
* PC端授权回调
* @param authCode
* @param authType 要授权的帐号类型, 1则商户扫码后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示
* @param merchantId
* @return
* @author Alvin
* @date 2019年5月6日 下午2:07:25
*/
@GetMapping("auth_{authType}_pc/callback/{merchantId}")
public String pcAuthCallback(@RequestParam("auth_code")String authCode
, @PathVariable(required = true, name = "authType")Integer authType
, @PathVariable(required = true, name = "merchantId")Integer merchantId
, Model model){
ResultEntity<Boolean> result = wechatAccessService.authCallback(merchantId, authType, authCode);
if(ResultEntity.ERROR.equals(result.getReturnCode())){
model.addAttribute("msg", result.getMessage());
}
return "callback/pc";
}
/**
* 移动端授权回调
* @param authCode
* @param authType 要授权的帐号类型, 1则商户扫码后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示
* @param merchantId
* @return
* @author Alvin
* @date 2019年5月6日 下午2:08:12
*/
@GetMapping("auth_{authType}_h5/callback/{merchantId}")
public String h5AuthCallback(@RequestParam("auth_code")String authCode
, @PathVariable(required = true, name = "authType")Integer authType
, @PathVariable(required = true, name = "merchantId") Integer merchantId){
wechatAccessService.authCallback(merchantId, authType, authCode);
return "callback/h5";
}
/**
* 快速注册小程序回调
* @param ticket
* @param merchantId
* @param authorizerAppId
* @return
* @author Alvin
* @date 2019年5月6日 下午2:08:24
*/
@GetMapping("fastregister/callback/{merchantId}/{authorizerAppId}")
public String fastRegisterCallback(@RequestParam("ticket")String ticket
, @PathVariable(required = true, name = "merchantId") Integer merchantId
, @PathVariable(required = true, name = "authorizerAppId") String authorizerAppId
, Model model){
ResultEntity<Boolean> result = wechatAccessService.fastRegisterCallback(merchantId, authorizerAppId, ticket);
if(ResultEntity.ERROR.equals(result.getReturnCode())){
model.addAttribute("msg", result.getMessage());
}
return "callback/fastregister";
}
/**
* 获取移动端授权链接
* @param merchantId
* @param authType 要授权的帐号类型, 1则商户扫码后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示
* @return
* @author Alvin
* @date 2019年5月6日 下午2:08:43
*/
@GetMapping("auth/h5/{merchantId}_{authType}")
@ResponseBody
public ResultEntity<String> authH5(@PathVariable(required = true, name = "merchantId") Integer merchantId
, @PathVariable(required = true, name = "authType") Integer authType){
return wechatAccessService.getH5AuthPath(merchantId, authType);
}
/**
* PC端授权跳转
* @param merchantId
* @param authType 要授权的帐号类型, 1则商户扫码后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示
* @return
* @author Alvin
* @date 2019年5月6日 下午2:09:01
*/
@GetMapping("wxauth/agent/{merchantId}_{authType}")
public String authAgent(@PathVariable(required = true, name = "merchantId") Integer merchantId
, @PathVariable(required = true, name = "authType") Integer authType){
return "redirect:".concat(wechatAccessService.getPCAuthPath(merchantId, authType));
}
/**
* 快速注册小程序授权跳转
* @param merchantId
* @param authorizerAppId
* @return
* @author Alvin
* @date 2019年5月6日 下午2:09:42
*/
@GetMapping("fastregister/auth/agent/{merchantId}/{authorizerAppId}")
public String fastRegisterAuthAgent(@PathVariable(required = true, name = "merchantId") Integer merchantId
, @PathVariable(required = true, name = "authorizerAppId") String authorizerAppId){
return "redirect:".concat(wechatAccessService.getFastRegisterAuthPath(merchantId, authorizerAppId).getData());
}
/**
* 跳转到升级提示页面
* @return
* @author Alvin
* @date 2019年6月6日 上午10:24:44
*/
@GetMapping("upgrade")
public String upgrade(){
return "upgrade";
}
}