微信企业号二次开发(推送和获取用户信息)

微信企业号不同于公众号和服务号,它提供了比较强大的接口,可以自由开发出各种应用和功能


----------------------利用微信企业号推送用户信息-----------------------------

import java.io.IOException;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;

/**微信企业号给关注的用户主动发送推送消息 企业号发消息条数没有限制*/
public class SendMessage {
// 获取配置文件中的值
private final static String CORPID = "ww40fde****";// 登录企业号,在“我的企业”里面的CorpID
private final static String AgentId = "100***";    //企业应用 里面的某一个应用的AgentId
private final static String CORPSECRET = "e-UQWiLTYY***";   //企业应用 里面的某一个应用的Secret
// 获取访问权限码URL
private final static String ACCESS_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+CORPID+"&corpsecret="+CORPSECRET;
// 创建会话请求URL
private final static String CREATE_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=";

// 获取接口访问权限码token函数
public String getAccessToken() {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(ACCESS_TOKEN_URL);
post.releaseConnection();
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
String result = "";
try {
client.executeMethod(post);
result = new String(post.getResponseBodyAsString().getBytes("gbk"));
} catch (IOException e) {
e.printStackTrace();
}
// 将数据转换成json
net.sf.json.JSONObject jasonObject = JSONObject.fromObject(result);
result = (String) jasonObject.get("access_token");
post.releaseConnection();
return result;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值