springboot小程序推送信息的项目实践-mile米乐体育
目录
- 1.小程序推送信息列如我们去餐厅等位有预约提醒,剩余桌数
- 2.申请小程序信息,申请信息模板
- 3.根据开发文档开发
- 4.代码如下:
- 5.推送结果
1.小程序推送信息列如我们去餐厅等位有预约提醒,剩余桌数
首先申请一个小程序,微信开放平台:小程序
2.申请小程序信息,申请信息模板
appid
appsecret
3.根据开发文档开发
subscribemessage.send | 微信开放文档
4.代码如下:
引入依赖
先准备一个http工具类z
import org.apache.http.httpentity; import org.apache.http.client.methods.closeablehttpresponse; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.conn.ssl.noophostnameverifier; import org.apache.http.conn.ssl.sslconnectionsocketfactory; import org.apache.http.conn.ssl.trustselfsignedstrategy; import org.apache.http.entity.stringentity; import org.apache.http.impl.client.closeablehttpclient; import org.apache.http.impl.client.httpclients; import org.apache.http.ssl.sslcontexts; import org.apache.http.util.entityutils; import java.io.ioexception; /** * @author lrx * @description: todo * @date 2021/3/9 9:50 */ public class httpclientutils { //http协议get请求 public static string httpget(string url) throws ioexception { //初始化httpclient closeablehttpclient httpclient = httpclients.createdefault(); //创建httpget httpget httpget = new httpget(url); //发起请求,获取response对象 closeablehttpresponse response = httpclient.execute(httpget); //获取请求状态码 //response.getstatusline().getstatuscode(); //获取返回数据实体对象 httpentity entity = response.getentity(); //转为字符串 string result = entityutils.tostring(entity, "utf-8"); return result; } //http协议post请求 public static string httppost(string url, string json) throws exception { //初始httpclient closeablehttpclient httpclient = httpclients.createdefault(); //创建post对象 httppost httppost = new httppost(url); //设置content-type /* httppost.setheader("content-type", "application/x-www-form-urlencoded");*/ stringentity se = new stringentity(json,"utf-8"); se.setcontenttype(odo 小程序推送 * @date 2022/4/11 13:32 */ public class testxcxmain { public static void main(string[] args) throws exception { string appid = ""; //appid string secret = ""恰卡编程网; //secret //登录链接获取token string loginurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" appid "&secret=" secret; map
5.推送结果
到此这篇关于springboot小程序推送信息的项目实践的文章就介绍到这了,更多相关springboot小程序推送信息内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!