| | |
| | | package com.hx.mp.util; |
| | | |
| | | import com.hx.util.HttpMethodUtil; |
| | | import com.hx.util.StringUtils; |
| | | import net.sf.json.JSONException; |
| | | import net.sf.json.JSONObject; |
| | |
| | | import java.sql.Timestamp; |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 微信小程序工具类 |
| | |
| | | return qrStr; |
| | | } |
| | | |
| | | /** |
| | | * 获取小程序链接 |
| | | * @param token 小程序token |
| | | * @param path 小程序页面路径 |
| | | * @param query 传值参数 |
| | | * @param env_version |
| | | * @return 要打开的小程序版本。正式版为 "release",体验版为"trial",开发版为"develop",仅在微信外打开时生效 |
| | | */ |
| | | public static String getAooLetUrl(String token, String path, String query, String env_version) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("access_token", token); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("path", path); |
| | | data.put("query", query); |
| | | 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 小程序appid |
| | | * @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; |
| | | } |
| | | } |