如何通过自己的网站后台主动向微信发送消息

baduolin 2015-03-23 01:01:38
如何通过自己的网站后台主动向微信公众平台的用户群发消息
...全文
1145 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
youz1976 2015-11-05
  • 打赏
  • 举报
回复
public static void main(String[] args) {
	//应用ID 账号   部门  标签  消息类型  内容
	Send_msg("5","SL00007","","1","text","嘎嘎");

}
youz1976 2015-11-05
  • 打赏
  • 举报
回复
public static int Send_msg(String agentid,String  touser,String toparty,String totag,String msgtype,String content){
	int errCode=0;
	//拼接请求地址
	String requestUrl=WXURLUtil.SEND_MSG_URL.replace("ACCESS_TOKEN",  GetAccessToken.getAccessToken());
	//需要提交的数据
	String postJson = "{\"agentid\":\"%s\",\"touser\":\"%s\",\"toparty\":\"[1, %s]\",\"totag\":\"%s\",\"msgtype\":\"text\",\"%s\":{\"content\":\"%s\"},\"safe\":\"0\"}";	
	String outputStr=String.format(postJson,agentid,touser,toparty,totag,msgtype, content);
	System.out.println(outputStr);
	//创建成员
	JSONObject jsonObject=CommonUtil.httpsRequest(requestUrl, "POST", outputStr);
	if(null!=jsonObject){
		System.out.println(jsonObject.toString()+"=====");
//		    int errcode = jsonObject.getInt("errcode");
//			errCode=jsonObject.getInt("errcode");
			
	}
	return errCode;
}
 //	发送消息
		public static String SEND_MSG_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN";
	

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧