微信公众号发送图文消息

//这里是公众号的id(自己数据里面的)

String id="7f04f5b8af8248b9b83a74aff6c607d620170915141439";

SellerPublicNumber sellerPublicNumber = SellerPublicNumber.dao.findById(id);

ApiConfigKit.putApiConfig(WxConfigUitils.getApiConfig(sellerPublicNumber.getToKen(), sellerPublicNumber.getAppId(), sellerPublicNumber.getAppSecret()));

//以上四行代码就是为了下面的getAccessToken()


//接收消息的openid

String ToUserName="oRvVatwa2sxv6CCTSM1RBwVPqTn0";
String Title="小石潭记";

String Description="从小丘西行百二十步隔篁竹闻水声如鸣佩环心乐之";

//图片地址

String PicUrl="http://www.joffro.com/Activity/upload/hello.jpg";

//点击跳转的链接

扫描二维码关注公众号,回复: 26142 查看本文章

String Url="http://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3db6ea684d097397&redirect_uri=http%3a%2f%2fwww.joffro.com%2fActivity%2fbreakEgg%2fgetGoods%3fappid%3dwx3db6ea684d097397&response_type=code&scope=snsapi_userinfo&state=wx#wechat_redirect";

//这就是要发送的消息拼接

String result="{\"touser\":\""+ToUserName+"\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\""+Title+"\",\"description\":\""+Description+"\",\"url\":\""+Url+"\",\"picurl\":\""+PicUrl+"\"}]}}";

//post发送消息

String ps = HttpUtils.post("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + getAccessToken(),result);




//发送文本消息

String toUser="oRvVatwa2sxv6CCTSM1RBwVPqTn0";
String content="我曾经跨过山和大海,也穿过人山人海。。。";
String json = "{\"touser\": \""+toUser+"\",\"msgtype\": \"text\", \"text\": {\"content\": \""+content+"\"}}";
String ps =HttpUtils.post("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + getAccessToken(),json);

猜你喜欢

转载自blog.csdn.net/qq_33371766/article/details/79965986