Your Name 3 years ago
parent
commit
0b50d444cd

+ 34
- 1
src/main/java/com/yunzhi/marketing/controller/MiniAppController.java View File

194
      */
194
      */
195
     @PostMapping("/login")
195
     @PostMapping("/login")
196
     public ResponseBean login(
196
     public ResponseBean login(
197
-            String code,
197
+            @RequestParam(required = false) String code,
198
             @RequestParam(required = false) String from,
198
             @RequestParam(required = false) String from,
199
             @RequestParam(required = false) String recommender,
199
             @RequestParam(required = false) String recommender,
200
             @RequestParam(required = false) String targetId,
200
             @RequestParam(required = false) String targetId,
201
             @RequestParam(required = false) String lon,
201
             @RequestParam(required = false) String lon,
202
             @RequestParam(required = false) String lat,
202
             @RequestParam(required = false) String lat,
203
+            @RequestParam(required = false, defaultValue = "false") Boolean singleMode,
203
             HttpServletRequest request) {
204
             HttpServletRequest request) {
204
         String appid = request.getHeader("appid");
205
         String appid = request.getHeader("appid");
205
 
206
 
207
+        // 小程序分享朋友圈
208
+        if (singleMode) {
209
+            return loginSingleMode(appid);
210
+        }
211
+
206
         if (StringUtils.isEmpty(code)) {
212
         if (StringUtils.isEmpty(code)) {
207
             return ResponseBean.error("参数 code 不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
213
             return ResponseBean.error("参数 code 不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
208
         }
214
         }
394
         }
400
         }
395
     }
401
     }
396
 
402
 
403
+    /**
404
+     * 小程序分享到朋友圈模式
405
+     * @param appid
406
+     * @return
407
+     */
408
+    private ResponseBean loginSingleMode(String appid) {
409
+        TaMiniapp miniapp = taMiniappService.getById(appid);
410
+        TaPerson person = new TaPerson();
411
+        person.setPersonId("virtual-person-id");
412
+        person.setMiniOpenid("virtual-open-id");
413
+        person.setOrgId(miniapp.getOrgId());
414
+
415
+        Map<String, Object> miniResp = new HashMap<>();
416
+        miniResp.put("openid", person.getMiniOpenid());
417
+        Map<Object, Object> map = new HashMap<>();
418
+        map.put("openId", person.getMiniOpenid());
419
+        map.put("orgId", person.getOrgId());
420
+        map.put("personId", person.getPersonId());
421
+        miniResp.put("token", JWTUtils.newTokenByMap(map));
422
+
423
+        Map<String, Object> result = new HashMap<>();
424
+        result.put("miniApp", miniResp);
425
+        result.put("person", person);
426
+
427
+        return ResponseBean.success(result);
428
+    }
429
+
397
     private ResponseBean checkMiniappStatus(String appid) {
430
     private ResponseBean checkMiniappStatus(String appid) {
398
         TaUser taUser = userService.getAdminByAppID(appid);
431
         TaUser taUser = userService.getAdminByAppID(appid);
399
 
432