消息"/>
微信小程序的订阅消息
官网文档
String postUrl ="="+accesstoken;
com.alibaba.fastjson.JSONObject jsonObject = new JSONObject();jsonObject.put("touser", openid); // openidjsonObject.put("template_id", templateId);jsonObject.put("page", page);JSONObject data = new JSONObject();JSONObject thing1 = new JSONObject();thing1.put("value", typeStr);//服务标题JSONObject time2 = new JSONObject();time2.put("value", DateUtils.getTime());//服务时间JSONObject phrase3 = new JSONObject();phrase3.put("value", handle);//服务进度JSONObject thing4 = new JSONObject();thing4.put("value", remark);//备注data.put("thing6",thing1);data.put("time4",time2);data.put("thing3",phrase3);data.put("thing5",thing4);jsonObject.put("data", data);jsonObject.put("miniprogram_state", "trial");//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版String string = HttpClientUtils.sendPostJsonStr(postUrl, jsonObject.toJSONString());com.alibaba.fastjson.JSONObject result = com.alibaba.fastjson.JSON.parseObject(string);
public static String sendPostJsonStr(String url, String jsonString) throws IOException {if (jsonString == null || jsonString.isEmpty()) {return sendPost(url);}String resp = "";StringEntity entityStr = new StringEntity(jsonString,ContentType.create("text/plain", "UTF-8"));CloseableHttpClient httpClient = HttpClients.createDefault();HttpPost httpPost = new HttpPost(url);httpPost.setEntity(entityStr);CloseableHttpResponse response = null;try {response = httpClient.execute(httpPost);HttpEntity entity = response.getEntity();resp = EntityUtils.toString(entity, "UTF-8");EntityUtils.consume(entity);} catch (ClientProtocolException e) {log.error(e.getMessage());} catch (IOException e) {log.error(e.getMessage());} finally {if (response != null) {try {response.close();} catch (IOException e) {log.error(e.getMessage());}}}if (resp == null || resp.equals("")) {return "";}return resp;}
更多推荐
微信小程序的订阅消息
发布评论