开启左侧

企微自建运用发送音讯对接流程

[复制链接]
在线会员 zmi 发表于 2025-2-8 08:05:29 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
  1. public static void main(String[] args) throws IOException {
  2.     Integer agentId = 奸淫奸淫*;
  3.     String agentSecret = "奸淫奸淫*";
  4.     String corpId = "奸淫奸淫*";
  5.     //企微API host
  6.     String qiyeUrl = "https://qyapi.weixin.qq.com/cgi-bin";
  7.     //企微API认证地点
  8.     String authorizeUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base#wechat_redirect";
  9.     String tokeUrl = qiyeUrl + "/gettoken?corpid=%s&corpsecret=%s";
  10.     //获得token
  11.     String getTokeUrl = String.format(tokeUrl, corpId, agentSecret);
  12.     String token = null;
  13.     String rtn = HttpUtil.sendHttpsRequest(getTokeUrl, "", "GET");
  14.     JsonNode jsonObj = JsonUtil.toJsonNode(rtn);
  15.     //与到了
  16.     if (jsonObj.get("errcode").asInt() == 0) {
  17.         token = jsonObj.get("access_token").asText();
  18.     }
  19.     String url, resultJson;
  20.     //-----------------收收消息-----------------
  21.     String sendMsgUrl = qiyeUrl + "/message/send?access_token=" + token;
  22.     //营业体系跳转地点(用于鉴权)
  23.     String serviceUrl =     URLEncoder.encode("奸淫奸淫*/thirdServices/userInfo/v1/wechatLogin", "utf-8");
  24.     //跳转地点  微疑认证 --> 认证胜利沉定背 --> 获得用户code --> 获得用户id
  25.     url = String.format(authorizeUrl, corpId, serviceUrl);
  26.     WxTextCardMessage wxMsg = new WxTextCardMessage("liujintai", null, agentId + "", "新进住消息拉收", DateUtil.getCurrentTime("yyyy年MM月dd日"), "", "", url, "概略");
  27.     resultJson = HttpUtil.sendHttpsRequest(sendMsgUrl, JsonUtil.toJson(wxMsg), WeChatWorkConsts.METHOD_POST);
  28.     System.out.println(resultJson);
  29.     //-----------------收收消息-----------------
  30.     //-----------------获得用户疑息-----------------
  31.     //企微认证胜利,从定背会增加用户code  http://奸淫奸淫*/thirdServices/userInfo/v1/wechatLogin?code=UJNwYViUBTWlLNx-OVFSyfDRrZD0am6JzPOmjxJccO4&state=
  32.     String code = "UJNwYViUBTWlLNx-OVFSyfDRrZD0am6JzPOmjxJccO4";
  33.     String userId = "https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=%s&code=%s";
  34.     url = String.format(userId, token, code);
  35.     resultJson = HttpUtil.sendHttpsRequest(url, null, WeChatWorkConsts.METHOD_GET);
  36.     System.out.println(resultJson);
  37.     //-----------------获得用户疑息-----------------
  38. }
复造代码
一、收收使用消息
二、消息中设置跳转地点(微疑认证,增加鉴权)
三、微疑认证胜利沉定背到营业体系
四、按照微疑code获得微诺言户id
五、营业体系完毕鉴权,沉定背到营业前端页里
您需要登录后才可以回帖 登录 | 立即注册 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号 )