开启左侧

企业微信运用授权/静默登录

[复制链接]
在线会员 9KmCyT 发表于 2022-12-30 15:18:17 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
媒介

企微创立一个新使用,用户面打寂静受权登录
企业微疑API

操纵

那边没有循序渐进,使用一次性会见
创立 一个链交
尺度链交
  1. https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
复造代码
赋值
  1.  https://open.weixin.qq.com/connect/oauth2/authorize?appid=A&redirect_uri=B&response_type=code&scope=snsapi_base&agentid=C&state=D
  2.  
复造代码
    A appid 挖写对于应参数B 回调链交 获得code 需要URLEncoder转码 下文有C agentid 挖写对于应参数D 微疑沉定背后照顾的参数(倡议写前端地点大概其余)
留神:拼交完毕的链交需要设置正在企微对于应主页地点
留神:B职位的沉定背链交需要正在企微使用中设置可托任域名,已设置会正在code获得时报50001
毛病码:50001

企业微疑使用受权/寂静登录-1.png


沉定背链交

上述链交设置佳后回调地点,code置换微诺言户
  1. /**
  2.      * 微诺言户登录获得用户
  3.      *
  4.      * @param code    回调
  5.      * @param state
  6.      * @param request
  7.      * @return
  8.      * @throws IOException
  9.      */@GetMapping("oauth2me.do")@ApiOperation(value ="回调办法")public RedirectView getuserinfo(@RequestParam String code,@RequestParam String state, HttpServletRequest request)throws IOException {
  10.         System.out.println("回调办法code: "+ code +"state: "+ state);
  11.         BaseResult getuserinfo = weChatServicel.getuserinfo(code, request);
  12.         String redirectUrl ="";if(getuserinfo.getErrno()==200){
  13.             Object o = JSONArray.toJSON(data);
  14.             String s = Base64Util.encryptBASE64(o.toString());
  15.             String encode = URLEncoder.encode(s,"UTF-8");
  16.             redirectUrl = state +"?"+ encode;}else{
  17.             redirectUrl = state;}
  18.         System.out.println("沉定背URL: "+ redirectUrl);returnnewRedirectView(redirectUrl);}
复造代码
获得会见用户身份

办法体内部挪用那个恳求便止
恳求方法:GET(HTTPS)
恳求地点:https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN&code=CODE
企业微疑使用受权/寂静登录-2.png

前去值
  1. {"errcode":0,"errmsg":"ok","CorpId":"CORPID","UserId":"USERID","DeviceId":"DEVICEID","user_ticket":"USER_TICKET",
  2.    "expires_in":7200,"open_userid":"wwxxxx"}
复造代码
参照链交:获得会见用户身份
企业微疑使用受权/寂静登录-3.jpg
您需要登录后才可以回帖 登录 | 立即注册 qq_login

本版积分规则

发布主题
阅读排行更多+
用专业创造成效
400-778-7781
周一至周五 9:00-18:00
意见反馈:server@mailiao.group
紧急联系:181-67184787
ftqrcode

扫一扫关注我们

Powered by 职贝云数A新零售门户 X3.5© 2004-2025 职贝云数 Inc.( 蜀ICP备2024104722号 )