From 487c4921b481da06d485182aaaa94297c70f149a Mon Sep 17 00:00:00 2001 From: lige <bestlige@outlook.com> Date: 星期一, 20 十一月 2023 13:52:09 +0800 Subject: [PATCH] 通知 --- ltkj-admin/src/main/java/com/ltkj/web/wxUtils/WxUtil.java | 89 ++++++++ ltkj-admin/src/test/java/lgTest.java | 46 ++++ ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java | 289 ++++++++++++++++++++++++++++ ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java | 50 +++++ ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java | 102 +++++++++ 5 files changed, 567 insertions(+), 9 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java index 40e6f00..17b0d98 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java @@ -1,6 +1,7 @@ package com.ltkj.web.controller.app; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.google.common.base.Joiner; @@ -15,6 +16,7 @@ import com.ltkj.mall.service.IMallTimeConfigService; import com.ltkj.system.service.ISysConfigService; import com.ltkj.web.config.redis.OrderDelayService; +import com.ltkj.web.wxUtils.WxUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -24,10 +26,7 @@ import javax.annotation.Resource; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; /** * @Author: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 @@ -153,6 +152,47 @@ config.setNowNum(config.getNowNum()-1); mallTimeConfigService.updateById(config); } + + //鍙戣鍗曚俊鎭粰wx璁㈤槄鏈嶅姟娑堟伅鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�攕tart鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + Map<String, Object> res = new HashMap<>(); + res.put("touser",wxuser.getOpenid()); + res.put("template_id","M4K_BNVG7g4hOAcrIDO18ux8KOTneHeNide5GdPW3kc"); + res.put("page","pages/mine/index"); + res.put("miniprogram_state","trial"); + //璁㈤槄娑堟伅鍙傛暟鍊� + JSONObject data = new JSONObject(); + + JSONObject name1 = new JSONObject(); + name1.put("value",tjReservation.getName()); + data.put("thing1", name1); + + JSONObject amount3 = new JSONObject(); + amount3.put("value", "浣撴涓績"); + data.put("thing2", amount3); + + JSONObject time4 = new JSONObject(); + String dateFormat = DateUtil.format(tjReservation.getReservationTime(), "yyyy-MM-dd"); + time4.put("value", dateFormat); + data.put("time4", time4); + + final TjPackage byId = packageService.getById(tjReservation.getPacId()); + if (byId!=null){ + JSONObject thing5 = new JSONObject(); + thing5.put("value",byId.getPacName()); + data.put("thing5", thing5); + }else { + JSONObject thing5 = new JSONObject(); + thing5.put("value","鏈煡"); + data.put("thing5", thing5); + } + + + JSONObject thing6 = new JSONObject(); + thing6.put("value", "浣撴鍓嶄竴澶╄鎮ㄨ繘娓呮贰楗,鍕块ギ閰掞紒"); + data.put("thing6", thing6); + WxUtil.sendCommonSubscribeMessage(res,data); + //鍙戣鍗曚俊鎭粰wx璁㈤槄鏈嶅姟娑堟伅鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�攅nd鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + return AjaxResult.success("棰勭害鎴愬姛!!!",tjReservation.getId()); } return AjaxResult.error("棰勭害澶辫触"); @@ -162,10 +202,15 @@ @ApiOperation(value = "鎾ら攢涓汉棰勭害") @Transactional public AjaxResult cusDeletedReservation(@RequestBody TjReservation reservation) { - LambdaQueryWrapper<TjReservation> wq = new LambdaQueryWrapper<>(); - wq.eq(TjReservation::getIdCard, reservation.getIdCard()); - wq.eq(TjReservation::getIsExpire, 2); - TjReservation one = reservationService.getOne(wq); + Wxuser wxuser = UserHoder.getWxuser(); +// LambdaQueryWrapper<TjReservation> wq = new LambdaQueryWrapper<>(); +// wq.eq(TjReservation::getIdCard, reservation.getIdCard()); +// wq.eq(TjReservation::getIsExpire, 2); +// TjReservation one = reservationService.getOne(wq); + if (reservation.getId()==null){ + return AjaxResult.success("鍑洪敊浜嗭紝璇疯仈绯诲伐浣滀汉鍛橈紒"); + } + TjReservation one = reservationService.getById(reservation.getId()); if (null != one) { String isPays = configService.selectConfigByKey("isPay"); if(null !=isPays && isPays.equals("true") ){ @@ -181,7 +226,46 @@ transitionService.deletedTbTransitionByCusId(reservation.getIdCard()); reservationService.removeById(one); - return AjaxResult.success(); + + //鍙戣鍗曚俊鎭粰wx璁㈤槄鏈嶅姟娑堟伅鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�攕tart鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + Map<String, Object> res = new HashMap<>(); + res.put("touser",wxuser.getOpenid()); + res.put("template_id","X467Xtd8HnFDNk-IoT0ChcdoBnClLZJQQwP7DMztYQ8"); + res.put("page","pages/mine/index"); + res.put("miniprogram_state","trial"); + //璁㈤槄娑堟伅鍙傛暟鍊� + JSONObject data = new JSONObject(); + + JSONObject amount3 = new JSONObject(); + amount3.put("value", "浣撴涓績"); + data.put("thing3", amount3); + + JSONObject name1 = new JSONObject(); + name1.put("value",reservation.getName()); + data.put("name1", name1); + + final TjPackage byId = packageService.getById(reservation.getPacId()); + if (byId!=null){ + JSONObject thing5 = new JSONObject(); + thing5.put("value",byId.getPacName()); + data.put("thing4", thing5); + }else { + JSONObject thing5 = new JSONObject(); + thing5.put("value","鏈煡"); + data.put("thing4", thing5); + } + + JSONObject time4 = new JSONObject(); + String dateFormat = DateUtil.format(reservation.getReservationTime(), "yyyy-MM-dd"); + time4.put("value", dateFormat); + data.put("date2", time4); + + JSONObject thing6 = new JSONObject(); + thing6.put("value", "鎮ㄥ凡鎴愬姛鍙栨秷鏈棰勭害锛屾杩庡啀娆′娇鐢紒"); + data.put("thing5", thing6); + WxUtil.sendCommonSubscribeMessage(res,data); + //鍙戣鍗曚俊鎭粰wx璁㈤槄鏈嶅姟娑堟伅鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�攅nd鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + return AjaxResult.success("鍙栨秷鎴愬姛"); } return AjaxResult.success("鏆傛棤棰勭害淇℃伅"); } diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java index 84c7cd8..d99d87d 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java @@ -2,6 +2,8 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; @@ -29,6 +31,7 @@ import com.ltkj.mall.mallOrderUtils.OrderUtil; import com.ltkj.system.service.ISysConfigService; import com.ltkj.web.config.redis.OrderDelayService; +import com.ltkj.web.wxUtils.WxUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -465,6 +468,53 @@ // final MallTimeConfig one = mallTimeConfigService.getOne(wq); // one.setNowNum(one.getNowNum()-1); // mallTimeConfigService.updateById(one); + //鍙戣鍗曚俊鎭粰wx璁㈤槄鏈嶅姟娑堟伅鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�攕tart鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + + Map<String, Object> res = new HashMap<>(); + res.put("touser",UserHoder.getWxuser().getOpenid()); + res.put("template_id","Gzc2BgzSsEY9uki6FThNQRLD1_An6uqpSve3PaU58PQ"); + res.put("page","pages/mine/index"); + res.put("miniprogram_state","trial"); + //璁㈤槄娑堟伅鍙傛暟鍊� + JSONObject data = new JSONObject(); + + JSONObject amount3 = new JSONObject(); + amount3.put("value", order.getOrderSn()); + data.put("character_string2", amount3); + + JSONObject time4 = new JSONObject(); + String dateFormat = DateUtil.format(order.getCreateTime(), "yyyy-MM-dd HH:mm:ss"); + time4.put("value", dateFormat); + data.put("time1", time4); + + final TjPackage byId = packageService.getById(order.getPacId()); + if (byId!=null){ + JSONObject thing5 = new JSONObject(); + thing5.put("value",byId.getPacName()); + data.put("thing3", thing5); + }else { + JSONObject thing5 = new JSONObject(); + thing5.put("value","浣撴椤圭洰"); + data.put("thing3", thing5); + } + + JSONObject name1 = new JSONObject(); + name1.put("value",order.getActualPrice()+"鍏�"); + data.put("amount4", name1); + + if (order.getPayId()!=null){ + JSONObject thing6 = new JSONObject(); + thing6.put("value", "宸蹭粯娆�"); + data.put("phrase8", thing6); + }else { + JSONObject thing6 = new JSONObject(); + thing6.put("value", "鏈粯娆�"); + data.put("phrase8", thing6); + } + + WxUtil.sendCommonSubscribeMessage(res,data); + //鍙戣鍗曚俊鎭粰wx璁㈤槄鏈嶅姟娑堟伅鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�攅nd鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + return AjaxResult.success(); } diff --git a/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java b/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java new file mode 100644 index 0000000..6b8b492 --- /dev/null +++ b/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java @@ -0,0 +1,289 @@ +package com.ltkj.web.wxUtils; + + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import com.ltkj.web.wxUtils.HttpClientUtils; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.util.PublicSuffixMatcher; +import org.apache.http.conn.util.PublicSuffixMatcherLoader; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.springframework.stereotype.Component; + +import java.io.*; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + + +/** + * httpClient 宸ュ叿绫� + * @create 2019-02-10 涓嬪崍 2:49 + */ +@Component +public class HttpClientUtils { + + /** + * 榛樿鍙傛暟璁剧疆 + * setConnectTimeout锛氳缃繛鎺ヨ秴鏃舵椂闂达紝鍗曚綅姣銆� + * setConnectionRequestTimeout锛氳缃粠connect Manager鑾峰彇Connection 瓒呮椂鏃堕棿锛屽崟浣嶆绉掋�� + * setSocketTimeout锛氳姹傝幏鍙栨暟鎹殑瓒呮椂鏃堕棿锛屽崟浣嶆绉掋�傝闂竴涓帴鍙o紝澶氬皯鏃堕棿鍐呮棤娉曡繑鍥炴暟鎹紝灏辩洿鎺ユ斁寮冩娆¤皟鐢ㄣ�� 鏆傛椂瀹氫箟15鍒嗛挓 + */ + private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(600000).setConnectTimeout(600000).setConnectionRequestTimeout(600000).build(); + + /** + * 闈欐�佸唴閮ㄧ被---浣滅敤锛氬崟渚嬩骇鐢熺被鐨勫疄渚� + * @author Administrator + * + */ + private static class LazyHolder { + private static final HttpClientUtils INSTANCE = new HttpClientUtils(); + + } + HttpClientUtils(){} + public static HttpClientUtils getInstance(){ + return LazyHolder.INSTANCE; + } + + /** + * 鍙戦�� post璇锋眰 + * @param httpUrl 鍦板潃 + */ + public String sendHttpPost(String httpUrl) { + HttpPost httpPost = new HttpPost(httpUrl);// 鍒涘缓httpPost + return sendHttpPost(httpPost); + } + + /** + * 鍙戦�� post璇锋眰 + * @param httpUrl 鍦板潃 + * @param params 鍙傛暟(鏍煎紡:key1=value1&key2=value2) + */ + public String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 鍒涘缓httpPost + try { + //璁剧疆鍙傛暟 + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType("application/x-www-form-urlencoded"); + httpPost.setEntity(stringEntity); + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 鍙戦�� post璇锋眰 + * @param httpUrl 鍦板潃 + * @param maps 鍙傛暟 + */ + public String sendHttpPost(String httpUrl, Map<String, String> maps) { + HttpPost httpPost = new HttpPost(httpUrl);// 鍒涘缓httpPost + // 鍒涘缓鍙傛暟闃熷垪 + List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); + for (String key : maps.keySet()) { + nameValuePairs.add(new BasicNameValuePair(key, maps.get(key))); + } + try { + httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + /** + * 鍙戦�丳ost璇锋眰 + * @param httpPost + * @return + */ + private String sendHttpPost(HttpPost httpPost) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 鍒涘缓榛樿鐨刪ttpClient瀹炰緥 + httpClient = HttpClients.createDefault(); + httpPost.setConfig(requestConfig); + // 鎵ц璇锋眰 + long execStart = System.currentTimeMillis(); + response = httpClient.execute(httpPost); + long execEnd = System.currentTimeMillis(); + System.out.println("=================鎵цpost璇锋眰鑰楁椂锛�"+(execEnd-execStart)+"ms"); + long getStart = System.currentTimeMillis(); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + long getEnd = System.currentTimeMillis(); + System.out.println("=================鑾峰彇鍝嶅簲缁撴灉鑰楁椂锛�"+(getEnd-getStart)+"ms"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 鍏抽棴杩炴帴,閲婃斁璧勬簮 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 鍙戦�� get璇锋眰 + * @param httpUrl + */ + public String sendHttpGet(String httpUrl) { + HttpGet httpGet = new HttpGet(httpUrl);// 鍒涘缓get璇锋眰 + return sendHttpGet(httpGet); + } + + /** + * 鍙戦�� get璇锋眰Https + * @param httpUrl + */ + public String sendHttpsGet(String httpUrl) { + HttpGet httpGet = new HttpGet(httpUrl);// 鍒涘缓get璇锋眰 + return sendHttpsGet(httpGet); + } + + /** + * 鍙戦�丟et璇锋眰 + * @param httpGet + * @return + */ + private String sendHttpGet(HttpGet httpGet) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 鍒涘缓榛樿鐨刪ttpClient瀹炰緥. + + + httpClient = HttpClients.createDefault(); + + httpGet.setConfig(requestConfig); + // 鎵ц璇锋眰 + response = httpClient.execute(httpGet); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 鍏抽棴杩炴帴,閲婃斁璧勬簮 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 鍙戦�丟et璇锋眰Https + * @param httpGet + * @return + */ + private String sendHttpsGet(HttpGet httpGet) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 鍒涘缓榛樿鐨刪ttpClient瀹炰緥. + PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString())); + DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher); + httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build(); + httpGet.setConfig(requestConfig); + // 鎵ц璇锋眰 + response = httpClient.execute(httpGet); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 鍏抽棴杩炴帴,閲婃斁璧勬簮 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 鍙戦�亁ml鏁版嵁 + * @param url + * @param xmlData + * @return + * @throws ClientProtocolException + * @throws IOException + */ + public static HttpResponse sendXMLDataByPost(String url, String xmlData) + throws ClientProtocolException, IOException { + HttpClient httpClient = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(url); + StringEntity entity = new StringEntity(xmlData); + httppost.setEntity(entity); + httppost.setHeader("Content-Type", "text/xml;charset=UTF-8"); + HttpResponse response = httpClient.execute(httppost); + return response; + } + + /** + * 鑾峰緱鍝嶅簲HTTP瀹炰綋鍐呭 + * + * @param response + * @return + * @throws IOException + * @throws UnsupportedEncodingException + */ + public static String getHttpEntityContent(HttpResponse response) throws IOException, UnsupportedEncodingException { + HttpEntity entity = response.getEntity(); + if (entity != null) { + InputStream is = entity.getContent(); + BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String line = br.readLine(); + StringBuilder sb = new StringBuilder(); + while (line != null) { + sb.append(line + "\n"); + line = br.readLine(); + } + return sb.toString(); + } + return ""; + } + + +} diff --git a/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/WxUtil.java b/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/WxUtil.java new file mode 100644 index 0000000..4f96e8b --- /dev/null +++ b/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/WxUtil.java @@ -0,0 +1,89 @@ +package com.ltkj.web.wxUtils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Value; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Map; + +public class WxUtil { + + @Value("${wx.miniapp.appid}") + private static String APPID; + + @Value("${wx.miniapp.secret}") + private static String APPSECRET; + + public static String getAccessToken(){ + String APPID="wx40a545f1a8eb1d9d"; + String APPSECRET="c86c1ff7f91c16380111878e9a259237"; + String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET; + System.out.println("accessTokenUrl = " + accessTokenUrl); + HttpClientUtils hru = new HttpClientUtils(); + String access_token = hru.sendHttpGet(accessTokenUrl); + JSONObject jsonObject= JSON.parseObject(access_token); + String token = jsonObject.get("access_token").toString();//鑾峰彇access_token + System.out.println("access_token = " + token); + return token; + } + + + /** + * 璋冪敤寰俊寮�鏀炬帴鍙ubscribeMessage.send鍙戦�佽闃呮秷鎭� 閫氱敤绫� + * POST https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN + */ + public static void sendCommonSubscribeMessage(Map<String,Object> params,JSONObject data){ + HttpURLConnection httpConn = null; + InputStream is = null; + BufferedReader rd = null; + String accessToken = null; + String str = null; + try + { + //鑾峰彇token 灏忕▼搴忓叏灞�鍞竴鍚庡彴鎺ュ彛璋冪敤鍑嵁 + accessToken = getAccessToken(); + + JSONObject xmlData = new JSONObject(); + xmlData.put("touser", params.get("touser"));//鎺ユ敹鑰咃紙鐢ㄦ埛锛夌殑 openid + xmlData.put("template_id", params.get("template_id"));//鎵�闇�涓嬪彂鐨勮闃呮ā鏉縤d + xmlData.put("page", params.get("page"));//鐐瑰嚮妯℃澘鍗$墖鍚庣殑璺宠浆椤甸潰锛屼粎闄愭湰灏忕▼搴忓唴鐨勯〉闈� + xmlData.put("miniprogram_state", params.get("miniprogram_state"));//璺宠浆灏忕▼搴忕被鍨嬶細developer涓哄紑鍙戠増锛泃rial涓轰綋楠岀増锛沠ormal涓烘寮忕増锛涢粯璁や负姝e紡鐗� + xmlData.put("lang", "zh_CN");//杩涘叆灏忕▼搴忔煡鐪嬧�濈殑璇█绫诲瀷锛屾敮鎸亃h_CN(绠�浣撲腑鏂�)銆乪n_US(鑻辨枃)銆亃h_HK(绻佷綋涓枃)銆亃h_TW(绻佷綋涓枃)锛岄粯璁や负zh_CN杩斿洖鍊� + xmlData.put("data", data);//灏忕▼搴忔ā鏉挎暟鎹� + + + System.out.println("鍙戦�佹ā鏉挎秷鎭痻mlData:" + xmlData); + URL url = new URL( + "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + + accessToken); + httpConn = (HttpURLConnection)url.openConnection(); + httpConn.setRequestProperty("Host", "https://api.weixin.qq.com"); + // httpConn.setRequestProperty("Content-Length", String.valueOf(xmlData.)); + httpConn.setRequestProperty("Content-Type", "text/xml; charset=\"UTF-8\""); + httpConn.setRequestMethod("POST"); + httpConn.setDoInput(true); + httpConn.setDoOutput(true); + OutputStream out = httpConn.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(out, "UTF-8"); + osw.write(xmlData.toString()); + osw.flush(); + osw.close(); + out.close(); + is = httpConn.getInputStream(); + rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); + + while ((str = rd.readLine()) != null) + { + System.out.println("杩斿洖鏁版嵁锛�" + str); + } + } + catch (Exception e) + { + System.out.println("鍙戦�佹ā鏉挎秷鎭け璐�.." + e.getMessage()); + } + } + +} diff --git a/ltkj-admin/src/test/java/lgTest.java b/ltkj-admin/src/test/java/lgTest.java new file mode 100644 index 0000000..9abb6f8 --- /dev/null +++ b/ltkj-admin/src/test/java/lgTest.java @@ -0,0 +1,46 @@ +import com.ltkj.LtkjApplication; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: lige + * @Date: 2023/11/16 16:42 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = LtkjApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Slf4j +@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) +public class lgTest { + @Test + public void lige() { +// List<String> a=new ArrayList<>(); +// a.add("ozImg61ibpygYZNRWLqtrdpoICh4"); +//// a.add("ozImg66H5FbsXzzAHto5Ue_SN5W4"); +//// a.add("ozImg64_ViFuhCWvnwLtMWyUCz7g"); +//// a.add("ozImg61ibpygYZNRWLqtrdpoICh4"); +// +// for (String s : a) { +// WxUtil.sendSubscribeMessage(s); +// } + //String openid = "o524m6a1xomIOW5fymo7WmE-z3Dg";//闇�瑕佽鐢ㄦ埛宸茬粡鎺堟潈杩囪璁㈤槄娑堟伅鎵嶈兘鍙戦�� + + + } + + public static void main(String[] args) { + Long a=12L; + final long l = a + 10000; + final String s = "V" + l; + System.out.println(s); + + } +} -- Gitblit v1.8.0