尚医通项目-微信登陆-无法显示二维码的解决方案

尚医通的多人文档里面给了无法显示二维码的解决方案,感谢不知名老哥

image

所以在 service_user 模块里修改配置文件:

wx.open.app_id=wxed9954c01bb89b47
wx.open.app_secret=a7482517235173ddb4083788de60b90e
wx.open.redirect_url=http://localhost:8160/api/ucenter/wx/callback
yygh.baseUrl=http://localhost:3000

另外网关的配置:

# 微信路由
# 设置路由id
spring.cloud.gateway.routes[4].id=service-user
# 设置路由的uri
spring.cloud.gateway.routes[4].uri=lb://service-user
# 设置路由断言,代理servicerId为auth-service的/auth/路径
spring.cloud.gateway.routes[4].predicates= Path=/*/ucenter/**

后端 controller:

    /**
     * 获取微信登录参数
     */
@GetMapping("getLoginParam")
@ResponseBody
public Result genQrConnect(HttpSession session) throws UnsupportedEncodingException {
    String redirectUri = URLEncoder.encode(ConstantPropertiesUtil.WX_OPEN_REDIRECT_URL, "UTF-8");
    Map<String, Object> map = new HashMap<>();
    map.put("appid", ConstantPropertiesUtil.WX_OPEN_APP_ID);
    map.put("redirectUri", redirectUri);
    map.put("scope", "snsapi_login");
    map.put("state", System.currentTimeMillis() + "");//System.currentTimeMillis()+""
    return Result.ok(map);
}

注意前端要能显示二维码,跟 map.put("redirectUri", redirectUri); 这行有关,前端需要得到这个参数,由于是放在 map 中返回的,前端调用 response.data.redirectUri 就可以获得。

posted @ 2022-12-01 11:21  ShaunY  阅读(224)  评论(0编辑  收藏  举报