longz
2026-06-04 da780b14b8db78043d2c0f27d3bfd73111e6d550
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
package com.stylefeng.guns.modular.api;
 
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
 
@RestController
@Slf4j
@RequestMapping("")
public class WinxinController {
 
 
    @Autowired
    private IDriverService driverService;
 
    @ResponseBody
    @PostMapping("/api/wx/getOpenId")
    @ApiOperation(value = "获取最新openId", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "code", name = "code", required = true, dataType = "String"),
    })
    public ResultUtil getOpenId(@RequestParam String code, HttpServletRequest request) {
        try {
            Integer uid = driverService.getUserIdFormRedis(request);
            if (ToolUtil.isEmpty(code)) {
                return ResultUtil.error("参数为空");
            }
//            //未登录过获取openId进行授权
//            String openID = null;
//            WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
//            openID = accessToken.getOpenId();
            Driver driver = driverService.selectById(uid);
            driver.setAppletsOpenId(code);
            driverService.updateById(driver);
            return ResultUtil.success();
        } catch (Exception e) {
            e.printStackTrace();    //尽量不要使用这个打印异常,会造成内存锁,使用log日志就
            return ResultUtil.error("获取openID异常");
        }
 
    }
}