Commit f0fdd9d6 by 吕明尚

更改微信配置

parent 55e93835
package share.web.controller.common;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.hutool.core.date.LocalDateTimeUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import share.common.core.domain.AjaxResult;
import share.system.service.WxMsgPushConService;
import share.system.util.WXMsgPushUtils;
......@@ -31,8 +23,8 @@ public class WxMsgPushController {
@Value("${wechat.token}")
private String token;
@Autowired
private WxMsgPushConService wxMsgPushConService;
// @Autowired
// private WxMsgPushConService wxMsgPushConService;
......@@ -62,11 +54,5 @@ public class WxMsgPushController {
return echostr;
}
@GetMapping("/api/zphs/sendZbhsMsg")
@ApiOperation("传openId发送微信服务通知")
public AjaxResult<Boolean> sendMsg(String openID) throws WxErrorException {
wxMsgPushConService.sendSmallMsg(openID);
return AjaxResult.success(true);
}
}
package share.web.core.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
@Data
@ConfigurationProperties(prefix = "wx.miniapp")
public class WxMaProperties {
private List<Config> configs;
@Data
public static class Config {
/**
* 设置微信小程序的appid
*/
private String appid;
/**
* 设置微信小程序的Secret
*/
private String secret;
/**
* 设置微信小程序消息服务器配置的token
*/
private String token;
/**
* 设置微信小程序消息服务器配置的EncodingAESKey
*/
private String aesKey;
/**
* 消息格式,XML或者JSON
*/
private String msgDataFormat;
}
}
//package share.web.core.config;
//
//import lombok.Data;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//
//import java.util.List;
//
//@Data
//@ConfigurationProperties(prefix = "wx.miniapp")
//public class WxMaProperties {
//
// private List<Config> configs;
//
// @Data
// public static class Config {
// /**
// * 设置微信小程序的appid
// */
// private String appid;
//
// /**
// * 设置微信小程序的Secret
// */
// private String secret;
//
// /**
// * 设置微信小程序消息服务器配置的token
// */
// private String token;
//
// /**
// * 设置微信小程序消息服务器配置的EncodingAESKey
// */
// private String aesKey;
//
// /**
// * 消息格式,XML或者JSON
// */
// private String msgDataFormat;
// }
//
//}
//
......@@ -21,6 +21,7 @@ wechat:
mchId: 1658895429
signKey: ZEKu56XCezuESfNEdM4zVZEN3cz2PuHz
certPath: /Users/project/pseer/apiclient_cert.p12
token: coujio
wx:
miniapp:
configs:
......
......@@ -51,11 +51,6 @@ public class RedisTask {
@Autowired
private ISOrderService isOrderService;
@Value("${wechat.appid}")
private String appid;
@Value("${wechat.secret}")
private String secret;
public void AuToReceiptCode() {
//获取redis中所有以tuangou.receipt.prepare开头的key
......@@ -93,20 +88,6 @@ public class RedisTask {
}
}
public void AutoWXAccessToken() throws IOException {
Boolean b = redisTemplate.hasKey(ReceiptRdeisEnum.ACCESS_TOKEN_KEY.getValue());
if (!b) {
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String strEntity = EntityUtils.toString(entity, "UTF-8");
JSONObject jsonObject = new JSONObject(strEntity);
redisUtil.set(ReceiptRdeisEnum.ACCESS_TOKEN_KEY.getValue(), jsonObject.getStr("access_token"), Long.valueOf(jsonObject.getInt("expires_in") - 60 * 30), TimeUnit.SECONDS);
}
}
//自动添加保洁记录
public void AutoAddSCleanRecords() {
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + "*");
......
......@@ -129,11 +129,6 @@
<artifactId>spring-integration-mqtt</artifactId>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
......
package share.system.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.hutool.core.date.LocalDateTimeUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import share.system.service.WxMsgPushConService;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service
public class WxMsgPushConServiceeImpl implements WxMsgPushConService {
@Autowired
private WxMaService wxMaService;
/**
* 跳转的小程序页面
*/
private static final String PAGES_ZP = "pages/draft-review/list/list";
@Override
public void sendSmallMsg(String openID) {
Map<String, String> map = new HashMap<>();
map.put("thing4", "预约门店");
map.put("thing7", "服务名称");
map.put("date3", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
map.put("thing5", "地址");
WxMaSubscribeMessage wxMaSubscribeMessage = WxMaSubscribeMessage.builder()
.toUser(openID)
.templateId("oTc000e4NHkoc7v9OLBZiwM6Q6SFzguemrx6d0iuVS8")
.page(PAGES_ZP)
.build();
// 设置将推送的消息
map.forEach((k, v) -> {
wxMaSubscribeMessage.addData(new WxMaSubscribeMessage.MsgData(k, v));
});
try {
log.info("开始发送消息!!!!");
wxMaService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
log.info("消息发送成功!!!!");
} catch (WxErrorException e) {
e.printStackTrace();
}
}
}
//package share.system.service.impl;
//
//import cn.binarywang.wx.miniapp.api.WxMaService;
//import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
//import cn.hutool.core.date.LocalDateTimeUtil;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import me.chanjar.weixin.common.error.WxErrorException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Repository;
//import org.springframework.stereotype.Service;
//import share.system.service.WxMsgPushConService;
//
//import javax.annotation.Resource;
//import java.time.LocalDateTime;
//import java.util.HashMap;
//import java.util.Map;
//
//@Slf4j
//@Service
//public class WxMsgPushConServiceeImpl implements WxMsgPushConService {
// @Resource
// private WxMaService wxMaService;
// /**
// * 跳转的小程序页面
// */
// private static final String PAGES_ZP = "pages/draft-review/list/list";
//
// @Override
// public void sendSmallMsg(String openID) {
// Map<String, String> map = new HashMap<>();
// map.put("thing4", "预约门店");
// map.put("thing7", "服务名称");
// map.put("date3", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
// map.put("thing5", "地址");
// WxMaSubscribeMessage wxMaSubscribeMessage = WxMaSubscribeMessage.builder()
// .toUser(openID)
// .templateId("oTc000e4NHkoc7v9OLBZiwM6Q6SFzguemrx6d0iuVS8")
// .page(PAGES_ZP)
// .build();
// // 设置将推送的消息
// map.forEach((k, v) -> {
// wxMaSubscribeMessage.addData(new WxMaSubscribeMessage.MsgData(k, v));
// });
// try {
// log.info("开始发送消息!!!!");
// wxMaService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
// log.info("消息发送成功!!!!");
// } catch (WxErrorException e) {
// e.printStackTrace();
// }
// }
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment