微信公众号推送图文消息

需求

准备工作

代码编写

最终效果

目录

需求

 用户在做完某个操作后,发送图文消息到用户微信公众号显示提醒

准备工作

  公众号为服务号

  获取公众号token

代码编写

	public static void main(String[] args) {
		
		String openId = "od9apwdSsaFOpTOr64d8HLsUY3Zc";
		String token="14_W9bKeI1tyBEO6MvAky821XRWokVfSgY2ke3m1FZXrRpC0Ko9fElwyssRegxbtGOHh4bFqsnDlJ6btgmE6f9LYokdka6wU2ehfsj-Qk-Y8JyeKabYDczN9kBoTU8BWJgAEAPKX";
		
		String url = "http://www.baidu.com/";
		String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
		requestUrl = requestUrl.replace("ACCESS_TOKEN", token); // 发送客服消息
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("msgtype", "news");
		jsonObject.put("touser", openId);
		JSONObject jsonContent = new JSONObject();
		jsonContent.put("title", "您好!请点击查看报告");
		jsonContent.put("description", "检测时间:"+ new Date());
		jsonContent.put("url", url);
		jsonContent.put("picurl", "http://www.jiankangzhan.com/img/coupon10.png");
		
		JSONArray articles = new JSONArray();
		articles.add(jsonContent);
		JSONObject articlesO = new JSONObject();
		articlesO.put("articles", articles);
		jsonObject.put("news", articlesO);
		String jsonStr;
		try {
			jsonStr = HttpUtils.sendPostBuffer(requestUrl, jsonObject.toString());
			System.out.println(jsonStr);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

最终效果


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值