From 381cc44f30a98d8719463fdd2a091ff7217f2545 Mon Sep 17 00:00:00 2001 From: wangrenhuang <wangren_huang@163.com> Date: 星期四, 19 十月 2023 16:13:17 +0800 Subject: [PATCH] 新增公众号发送小程序卡片客户消息方法 --- src/main/java/com/hx/mp/util/MpUtil.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/mp/util/MpUtil.java b/src/main/java/com/hx/mp/util/MpUtil.java index 1c64291..2dbc9cc 100644 --- a/src/main/java/com/hx/mp/util/MpUtil.java +++ b/src/main/java/com/hx/mp/util/MpUtil.java @@ -374,4 +374,47 @@ data.put("env_version", env_version); return HttpMethodUtil.HttpURLUtilJson("https://api.weixin.qq.com/wxa/generate_urllink", data.toString(), map, null, "POST"); } + + + /** + * 鍏紬鍙峰彂閫佸皬绋嬪簭鍗$墖瀹㈡埛娑堟伅 + * @param access_token access_token + * @param toUser 鐢ㄦ埛openid + * @param title 鏍囬 + * @param appid 灏忕▼搴廰ppid + * @param pagepath 璺宠浆椤甸潰璺緞 + * @param thumb_media_id 缂╃暐鍥�/灏忕▼搴忓崱鐗囧浘鐗囩殑濯掍綋ID锛屽皬绋嬪簭鍗$墖鍥剧墖寤鸿澶у皬涓�520*416 + * @return + */ + public static String sendMpMsg(String access_token, String toUser, String title,String appid,String pagepath,String thumb_media_id) { + String result = "fail"; + + try { + JSONObject obj = new JSONObject(); + obj.put("touser", toUser); + obj.put("msgtype", "miniprogrampage"); + + JSONObject pObj = new JSONObject(); + pObj.put("title", title); + pObj.put("appid", appid); + pObj.put("pagepath", pagepath); + pObj.put("thumb_media_id", thumb_media_id); + obj.put("miniprogrampage", pObj); + + JSONObject rObj = HttpURLUtil(URL_SEND_KF_MSG + access_token, obj.toString()); + if (rObj != null) { + if (rObj.optInt("errcode", -1) == 0) { + result = "suc"; + } else { + result = rObj.optString("errmsg"); + } + } + rObj = null; + obj = null; + } catch (Exception e) { + e.printStackTrace(); + } + + return result; + } } -- Gitblit v1.8.0