|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.huiju.estateagents.controller;
|
2
|
2
|
|
|
3
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
3
|
4
|
import com.alibaba.fastjson.JSONObject;
|
4
|
5
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
5
|
6
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -7,14 +8,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
7
|
8
|
import com.huiju.estateagents.base.BaseController;
|
8
|
9
|
import com.huiju.estateagents.base.ResponseBean;
|
9
|
10
|
import com.huiju.estateagents.common.StringUtils;
|
|
11
|
+import com.huiju.estateagents.common.WxUtils;
|
10
|
12
|
import com.huiju.estateagents.entity.TaMiniapp;
|
|
13
|
+import com.huiju.estateagents.service.IMiniAppService;
|
11
|
14
|
import com.huiju.estateagents.service.ITaMiniappService;
|
|
15
|
+import org.apache.tomcat.jni.Mmap;
|
12
|
16
|
import org.slf4j.Logger;
|
13
|
17
|
import org.slf4j.LoggerFactory;
|
14
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
19
|
import org.springframework.web.bind.annotation.*;
|
16
|
20
|
|
17
|
21
|
import javax.servlet.http.HttpServletRequest;
|
|
22
|
+import java.util.HashMap;
|
18
|
23
|
|
19
|
24
|
/**
|
20
|
25
|
* <p>
|
|
@@ -33,6 +38,11 @@ public class TaMiniappController extends BaseController {
|
33
|
38
|
@Autowired
|
34
|
39
|
public ITaMiniappService iTaMiniappService;
|
35
|
40
|
|
|
41
|
+ @Autowired
|
|
42
|
+ private IMiniAppService miniAppService;
|
|
43
|
+
|
|
44
|
+ @Autowired
|
|
45
|
+ WxUtils wxUtils;
|
36
|
46
|
|
37
|
47
|
/**
|
38
|
48
|
* 分页查询列表
|
|
@@ -147,21 +157,47 @@ public class TaMiniappController extends BaseController {
|
147
|
157
|
@PostMapping(value = "center/check/taMiniapp")
|
148
|
158
|
public ResponseBean createQRCode(@RequestBody String paramStr) {
|
149
|
159
|
if (StringUtils.isEmpty(paramStr)) {
|
150
|
|
- return ResponseBean.error("生成二维码参数为空", ResponseBean.ERROR_MISSING_PARAMS);
|
|
160
|
+ return ResponseBean.error("参数不能为空", ResponseBean.ERROR_MISSING_PARAMS);
|
151
|
161
|
}
|
152
|
162
|
|
153
|
163
|
JSONObject params = JSONObject.parseObject(paramStr);
|
154
|
164
|
if (null == params) {
|
155
|
|
- return ResponseBean.error("非法生成二维码参数", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
165
|
+ return ResponseBean.error("非法参数", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
156
|
166
|
}
|
157
|
167
|
|
158
|
|
- String appid = params.getString("appid");
|
|
168
|
+ String appid = params.getString("miniappId");
|
159
|
169
|
String secret = params.getString("secret");
|
160
|
170
|
String path = params.getString("path");
|
161
|
171
|
|
162
|
172
|
if (StringUtils.isEmpty(appid) || StringUtils.isEmpty(secret) || StringUtils.isEmpty(path)) {
|
|
173
|
+ return ResponseBean.error("缺失参数", ResponseBean.ERROR_MISSING_PARAMS);
|
|
174
|
+ }
|
163
|
175
|
|
|
176
|
+ TaMiniapp taMiniapp = null;
|
|
177
|
+ WxMaService service = wxUtils.getMiniApp(appid);
|
|
178
|
+ if (null != service) {
|
|
179
|
+ taMiniapp = iTaMiniappService.getById(appid);
|
|
180
|
+ if (null == taMiniapp) {
|
|
181
|
+ return ResponseBean.error("异常, 请联系技术人员", ResponseBean.ERROR_UNAVAILABLE);
|
|
182
|
+ }
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ if (null == service || !secret.equals(taMiniapp.getSecret())){
|
|
186
|
+ service = wxUtils.newService(new TaMiniapp(){{
|
|
187
|
+ setMiniappId(appid);
|
|
188
|
+ setSecret(secret);
|
|
189
|
+ setToken(params.getString("token"));
|
|
190
|
+ }});
|
|
191
|
+ }
|
|
192
|
+
|
|
193
|
+ try {
|
|
194
|
+ String qrCode = miniAppService.createQrCode(service, path);
|
|
195
|
+ return ResponseBean.success(new HashMap<String, Object>(){{
|
|
196
|
+ put("qrCode", qrCode);
|
|
197
|
+ }});
|
|
198
|
+ } catch (Exception e) {
|
|
199
|
+ e.printStackTrace();
|
|
200
|
+ return ResponseBean.error("校验不通过", ResponseBean.ERROR_UNAVAILABLE);
|
164
|
201
|
}
|
165
|
|
- return null;
|
166
|
202
|
}
|
167
|
203
|
}
|