From 81ef8a9a8f5c67abb381a3055bbc40669967af94 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Mon, 17 Jul 2023 17:41:13 +0800 Subject: [PATCH] 用户登录获取用户的微信昵称和头像 --- src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java index b43d312..ab34249 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java @@ -300,7 +300,10 @@ if (ObjectUtil.isNotEmpty(mallMember)) { return; } + log.info("收到accessToken:{}", accessToken); + log.info("收到openId:{}", openId); String requrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+accessToken+"&openid="+openId+"&lang=zh_CN"; + // 创建一个StringHttpMessageConverter,并设置字符集为UTF-8 StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charset.forName("UTF-8")); stringConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_PLAIN)); @@ -321,15 +324,19 @@ } String nickname = json.getString("nickname"); String headImgUrl = json.getString("headimgurl"); + log.info("收到nickname:{}", nickname); + log.info("收到headImgUrl:{}", headImgUrl); + mallMember.setName(nickname); mallMember.setAvatar(headImgUrl); memberMapper.updateById(mallMember); + return; } public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); - String accessToken = "70_6yOz-tXaDx6qMswGgmfl6j3LfgG-ur3JE-top_QvX5Oea9ryFxzEBwgVoW53IpMrzcS7mpPJf7tI3czT_kA2l5Y_Xu1WS7d7xDNbMs97ARk"; + String accessToken = "70__DR_q_qmjcMfPQEBwmjdfJFWnpml55Bq6JK2vt9MMdcRLsHaYM1BQGFWzLUISjcFC8HAYTKOaPJH93KHNvo4KIeMZkxFF2qP66nAdygUQ6c"; String openId = "oXL7Y6LW5KGQTbmmP5W3JljjApSo"; String requrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+accessToken+"&openid="+openId+"&lang=zh_CN"; // 创建一个StringHttpMessageConverter,并设置字符集为UTF-8 -- Gitblit v1.9.1