当前位置:网站首页>企业微信应用授权/静默登录
企业微信应用授权/静默登录
2022-04-23 08:40:00 【HezhezhiyuLe】
前言
企微创建一个新应用,用户点击静默授权登录
企业微信API
操作
这边不按部就班,使用一次性访问
创建一个链接
标准链接
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
赋值
https://open.weixin.qq.com/connect/oauth2/authorize?appid=A&redirect_uri=B&response_type=code&scope=snsapi_base&agentid=C&state=D
- A appid 填写对应参数
- B 回调链接 获取code 需要URLEncoder转码 下文有
- C agentid 填写对应参数
- D 微信重定向后携带的参数(建议写前端地址或者其他)
注意:拼接完成的链接需要配置在企微对应主页地址
注意:B位置的重定向链接需要在企微应用中配置可信任域名,未配置会在code获取时报50001
错误码:50001

重定向链接
上述链接配置好后回调地址,code置换微信用户
/** * 微信用户登录获取用户 * * @param code 回调 * @param state * @param request * @return * @throws IOException */
@GetMapping("oauth2me.do")
@ApiOperation(value = "回调方法")
public RedirectView getuserinfo(@RequestParam String code, @RequestParam String state, HttpServletRequest request) throws IOException {
System.out.println("回调方法code: " + code + "state: " + state);
BaseResult getuserinfo = weChatServicel.getuserinfo(code, request);
String redirectUrl = "";
if (getuserinfo.getErrno() == 200) {
Object o = JSONArray.toJSON(data);
String s = Base64Util.encryptBASE64(o.toString());
String encode = URLEncoder.encode(s, "UTF-8");
redirectUrl = state + "?" + encode;
} else {
redirectUrl = state;
}
System.out.println("重定向URL: " + redirectUrl);
return new RedirectView(redirectUrl);
}
获取访问用户身份
方法体内部调用这个请求就行
请求方式:GET(HTTPS)
请求地址:https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN&code=CODE

返回值
{
"errcode": 0,
"errmsg": "ok",
"CorpId":"CORPID",
"UserId":"USERID",
"DeviceId":"DEVICEID",
"user_ticket": "USER_TICKET",
"expires_in":7200,
"open_userid":"wwxxxx"
}

版权声明
本文为[HezhezhiyuLe]所创,转载请带上原文链接,感谢
https://blog.csdn.net/HezhezhiyuLe/article/details/111581886
边栏推荐
- Detailed description of self feeling of auricular point weight loss 0422
- 耳穴减肥自身感受细节描述0422
- DJ音乐管理软件Pioneer DJ rekordbox
- 匿名类型(C# 指南 基础知识)
- 【58】最后一个单词的长度【LeetCode】
- ESP32程序下载失败,提示超时
- idea底栏打开services
- idea打包 jar文件
- 对li类数组对象随机添加特性,并进行排序
- SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
猜你喜欢

HAL库的RCC简介

Yangtao electronic STM32 Internet of things entry 30 step notes II. Cube ide download, installation, sinicization and setting

00后最关注的职业:公务员排第二,第一是?

《深度学习》学习笔记(八)

测试你的机器学习流水线

数据可视化:使用Excel制作雷达图

Shell脚本进阶

K210学习笔记(二) K210与STM32进行串口通信

Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board

Harbor企业级镜像管理系统实战
随机推荐
扣缴义务人
How to generate assembly file
GUI编程简介 swing
Navicat远程连接mysql
Misunderstanding of flush () method of OutputStream class
OneFlow学习笔记:从Functor到OpExprInterpreter
Reference passing 1
Add listening event to input element
After a circle, I sorted out this set of interview questions..
关于cin,scanf和getline,getchar,cin.getline的混合使用
引用传递1
怎样读取Excel表格到数据库
xctf刷题小记
使用flask和h5搭建网站/应用的简要步骤
信息收集相关知识点及题解
Get the absolute path of the class according to the bytecode
虚拟线上展会-线上vr展馆实现24h沉浸式看展
ajax防止缓存方法
RPC过程
RPC procedure