From f516dae0daa5df5fec6ddd834860a23141f68ff2 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 16:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/app/TbCallServiceImpl.java | 6 +- .../cn/ysk/cashier/utils/WxMiniUtils.java | 220 +++++++++--------- 2 files changed, 112 insertions(+), 114 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index 69bb7cb9..36c62df1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -19,7 +19,6 @@ import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.app.TbCallService; import cn.ysk.cashier.utils.Utils; -import cn.ysk.cashier.utils.WxMiniUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -42,7 +41,6 @@ public class TbCallServiceImpl implements TbCallService { private final TbShopInfoRepository shopInfoRepository; private final StringRedisTemplate redisTemplate; private final TbCallQueueMapper tbCallQueueMapper; - private final WxMiniUtils wxMiniUtils; @Override public Object add(CallTableDTO addCallTableDTO) { @@ -222,8 +220,8 @@ public class TbCallServiceImpl implements TbCallService { throw new BadRequestException("此用户未订阅微信小程序消息"); } - wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), - callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); +// wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), +// callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); return callQueueService.updateById(callQueue); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index d728f626..aae056fc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -1,113 +1,113 @@ -package cn.ysk.cashier.utils; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -@Component -@Slf4j -public class WxMiniUtils { - +//package cn.ysk.cashier.utils; +// +//import cn.hutool.core.util.ObjectUtil; +//import cn.hutool.http.HttpRequest; +//import cn.hutool.http.HttpUtil; +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONObject; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.stereotype.Component; +// +//import java.util.HashMap; +//import java.util.LinkedHashMap; +//import java.util.Map; +// +//@Component +//@Slf4j +//public class WxMiniUtils { +// // @Value("${wx.mini.user.appId}") - private String appId = ""; - +// private String appId; +// // @Value("${wx.mini.user.secrete}") - private String secrete =""; - +// private String secrete; +// // @Value("${wx.mini.user.msgId.currentCall}") - private String currentCallTempId =""; - - - static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); - - static { - - linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); - linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); - linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); - linkedHashMap.put("40037","不合法的 template_id"); - linkedHashMap.put("43101","用户未订阅消息"); - linkedHashMap.put("43107","订阅消息能力封禁"); - linkedHashMap.put("43108","并发下发消息给同一个粉丝"); - linkedHashMap.put("45168","命中敏感词"); - linkedHashMap.put("47003","参数错误"); - - } - - public JSONObject getAccessToken(){ - String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; - Map requestUrlParam = new HashMap<>(); - //小程序appId - requestUrlParam.put("appid", appId); - //小程序secret - requestUrlParam.put("secret", secrete); - //默认参数 - requestUrlParam.put("grant_type", "client_credential"); - return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); - } - - public static void main(String[] args) { - String id ="kSxJL9TR4s_UmOmNLE"; -// sendStockWarnMsg("123", "1231", "1231", "23321", id); - } - - - public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { - log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); - JSONObject object= getAccessToken(); - String accessToken=object.get("access_token")+""; - - JSONObject object1=new JSONObject(); - - object1.put("template_id", tempId); - object1.put("touser", toUserOpenId); - object1.put("data",data); - - object1.put("miniprogram_state","trial"); - object1.put("lang","zh_CN"); - - String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); - log.info("微信模板消息发送成功,相应内容:{}",response); - JSONObject resObj=JSONObject.parseObject(response); - if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ - return resObj; - } - - throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); - } - - public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { - Map data = new HashMap() {{ - put("thing1", new HashMap() {{ - put("value", shopName); - }}); - put("phrase2", new HashMap() {{ - put("value", state); - }}); - put("character_string3", new HashMap() {{ - put("value", callNum); - }}); - put("character_string4", new HashMap() {{ - put("value", currentNum); - }}); - put("thing5", new HashMap() {{ - put("value", note); - }}); - }}; - log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); - try { - sendTempMsg(currentCallTempId, openId, data); - } catch (Exception e) { - log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); - } - } -} +// private String currentCallTempId; +// +// +// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); +// +// static { +// +// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); +// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40037","不合法的 template_id"); +// linkedHashMap.put("43101","用户未订阅消息"); +// linkedHashMap.put("43107","订阅消息能力封禁"); +// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); +// linkedHashMap.put("45168","命中敏感词"); +// linkedHashMap.put("47003","参数错误"); +// +// } +// +// public JSONObject getAccessToken(){ +// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; +// Map requestUrlParam = new HashMap<>(); +// //小程序appId +// requestUrlParam.put("appid", appId); +// //小程序secret +// requestUrlParam.put("secret", secrete); +// //默认参数 +// requestUrlParam.put("grant_type", "client_credential"); +// return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); +// } +// +// public static void main(String[] args) { +// String id ="kSxJL9TR4s_UmOmNLE"; +//// sendStockWarnMsg("123", "1231", "1231", "23321", id); +// } +// +// +// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { +// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); +// JSONObject object= getAccessToken(); +// String accessToken=object.get("access_token")+""; +// +// JSONObject object1=new JSONObject(); +// +// object1.put("template_id", tempId); +// object1.put("touser", toUserOpenId); +// object1.put("data",data); +// +// object1.put("miniprogram_state","trial"); +// object1.put("lang","zh_CN"); +// +// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); +// log.info("微信模板消息发送成功,相应内容:{}",response); +// JSONObject resObj=JSONObject.parseObject(response); +// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ +// return resObj; +// } +// +// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); +// } +// +// public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { +// Map data = new HashMap() {{ +// put("thing1", new HashMap() {{ +// put("value", shopName); +// }}); +// put("phrase2", new HashMap() {{ +// put("value", state); +// }}); +// put("character_string3", new HashMap() {{ +// put("value", callNum); +// }}); +// put("character_string4", new HashMap() {{ +// put("value", currentNum); +// }}); +// put("thing5", new HashMap() {{ +// put("value", note); +// }}); +// }}; +// log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); +// try { +// sendTempMsg(currentCallTempId, openId, data); +// } catch (Exception e) { +// log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); +// } +// } +//}