1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信公众号推送图文消息

微信公众号推送图文消息

时间:2021-09-11 09:49:53

相关推荐

微信公众号推送图文消息

需求

准备工作

代码编写

最终效果

目录

需求

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

准备工作

公众号为服务号

获取公众号token

代码编写

public static void main(String[] args) {String openId = "od9apwdSsaFOpTOr64d8HLsUY3Zc";String token="14_W9bKeI1tyBEO6MvAky821XRWokVfSgY2ke3m1FZXrRpC0Ko9fElwyssRegxbtGOHh4bFqsnDlJ6btgmE6f9LYokdka6wU2ehfsj-Qk-Y8JyeKabYDczN9kBoTU8BWJgAEAPKX";String url = "/";String requestUrl = "https://api./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", "/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();}}

最终效果

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。