记得上下班打卡 | git大法好,push需谨慎

Commit 974ca8e5 authored by jiangxiulong's avatar jiangxiulong

in2112 apply

parent c13188af
...@@ -2,8 +2,11 @@ package com.liquidnet.service.sweet.config; ...@@ -2,8 +2,11 @@ package com.liquidnet.service.sweet.config;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
import com.liquidnet.service.sweet.handler.ApplySubscribeHandler;
import com.liquidnet.service.sweet.handler.ApplyUnsubscribeHandler;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -71,9 +74,16 @@ public class WechatMaConfigure { ...@@ -71,9 +74,16 @@ public class WechatMaConfigure {
private WxMaService wxMaAppletFiveService; private WxMaService wxMaAppletFiveService;
private WxMaService wxMaAppletMdskService; private WxMaService wxMaAppletMdskService;
private WxMaMessageRouter wxMaZhengzaiMessageRouter;
@Autowired @Autowired
private StringRedisTemplate stringRedisTemplate; private StringRedisTemplate stringRedisTemplate;
@Autowired
private ApplySubscribeHandler unsubscribeHandler;
@Autowired
private ApplyUnsubscribeHandler subscribeHandler;
@PostConstruct @PostConstruct
public void init() { public void init() {
wxMaAppletZhengzaiService = new WxMaServiceImpl() { wxMaAppletZhengzaiService = new WxMaServiceImpl() {
...@@ -125,6 +135,7 @@ public class WechatMaConfigure { ...@@ -125,6 +135,7 @@ public class WechatMaConfigure {
this.setWxMaConfig(wxMaDefaultConfig); this.setWxMaConfig(wxMaDefaultConfig);
} }
}; };
wxMaZhengzaiMessageRouter = new WxMaMessageRouter(wxMaAppletZhengzaiService);
} }
public WxMaService getWxMaService(Integer anum) { public WxMaService getWxMaService(Integer anum) {
...@@ -154,4 +165,32 @@ public class WechatMaConfigure { ...@@ -154,4 +165,32 @@ public class WechatMaConfigure {
} }
return ""; return "";
} }
public WxMaMessageRouter getWxMaMessageRouter(Integer pnum) {
switch (pnum) {
case 4:
return wxMaZhengzaiMessageRouter;
}
return null;
}
public WxMaMessageRouter messageRouter(Integer type) {
WxMaMessageRouter router = getWxMaMessageRouter(type);
// 消息去重
// router.setMessageDuplicateChecker(wxMessageInMemoryDuplicateChecker);
// 关注事件
router.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
.event(WxConsts.EventType.SUBSCRIBE)
.handler(subscribeHandler)
.end();
// 取消关注事件
router.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
.event(WxConsts.EventType.UNSUBSCRIBE)
.handler(unsubscribeHandler)
.end();
return router;
}
} }
package com.liquidnet.service.sweet.controller;
import com.liquidnet.service.sweet.service.impl.SweetWechatApplyEventPushServiceImpl;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Api(tags = "小程序-事件推送")
@RestController
@RequestMapping("/applyEventPush")
@Slf4j
public class SweetWechatApplyEventPushController {
@Autowired
private SweetWechatApplyEventPushServiceImpl pushService;
@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@PathVariable Integer type,
@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr) {
log.info("\n接收到来自微信服务器的认证消息:signature = [{}], timestamp = [{}], nonce = [{}], echostr = [{}]",
signature, timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
throw new IllegalArgumentException("请求参数非法,请核实!");
}
return pushService.authGet(type, timestamp, nonce, signature, echostr);
}
@PostMapping(produces = "application/xml; charset=UTF-8")
public String post(@PathVariable Integer type,
@RequestBody String requestBody,
@RequestParam(name = "msg_signature", required = false) String msgSignature,
@RequestParam(name = "encrypt_type", required = false) String encryptType,
@RequestParam(name = "signature", required = false) String signature,
@RequestParam("timestamp") String timestamp,
@RequestParam("nonce") String nonce) {
log.info("\n接收微信请求:[msg_signature=[{}], encrypt_type=[{}], signature=[{}]," +
" timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
msgSignature, encryptType, signature, timestamp, nonce, requestBody);
return pushService.post(type, requestBody, msgSignature, encryptType, signature, timestamp, nonce);
}
}
package com.liquidnet.service.sweet.handler;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
import cn.binarywang.wx.miniapp.message.WxMaXmlOutMessage;
import com.liquidnet.service.sweet.config.WechatMpConfigure;
import com.liquidnet.service.sweet.service.impl.SweetWechatTemplateServiceImpl;
import com.liquidnet.service.sweet.utils.QueueUtils;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* <p>
* 关注
* </p>
*
* @author jiangxiulong
* @since 2021-07-31 5:06 下午
*/
@Component
@Slf4j
public class ApplySubscribeHandler implements WxMaMessageHandler {
@Autowired
private WechatUsersRedisUtils redisUtils;
@Autowired
private QueueUtils queueUtils;
@Autowired
WechatMpConfigure wechatMpConfigure;
@Autowired
private SweetWechatTemplateServiceImpl sweetWechatTemplateService;
@Override
public WxMaXmlOutMessage handle(WxMaMessage message, Map<String, Object> context, WxMaService service, WxSessionManager sessionManager) throws WxErrorException {
return null;
}
}
package com.liquidnet.service.sweet.handler;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
import cn.binarywang.wx.miniapp.message.WxMaXmlOutMessage;
import com.liquidnet.service.sweet.config.WechatMpConfigure;
import com.liquidnet.service.sweet.utils.QueueUtils;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* <p>
* 取消关注
* </p>
*
* @author jiangxiulong
* @since 2021-07-31 5:08 下午
*/
@Component
@Slf4j
public class ApplyUnsubscribeHandler implements WxMaMessageHandler {
@Autowired
private WechatUsersRedisUtils redisUtils;
@Autowired
private QueueUtils queueUtils;
@Autowired
WechatMpConfigure wechatMpConfigure;
@Override
public WxMaXmlOutMessage handle(WxMaMessage message, Map<String, Object> context, WxMaService service, WxSessionManager sessionManager) throws WxErrorException {
return null;
}
}
...@@ -165,7 +165,7 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg ...@@ -165,7 +165,7 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg
Integer prizeType = sweetIntegralActivityPrize.getPrizeType(); Integer prizeType = sweetIntegralActivityPrize.getPrizeType();
if (prizeType == 2) {// 中奖积分 if (prizeType == 2) {// 中奖积分
// 增加积分 // 增加积分
ResponseDto<String> in2111 = feignStoneIntegralClient.in2111(userId, sweetIntegralActivityPrize.getPrizeTypeNum(), integralActivity.getActivityTitle()); ResponseDto<String> in2111 = feignStoneIntegralClient.in2112(userId, sweetIntegralActivityPrize.getPrizeTypeNum(), integralActivity.getActivityTitle());
log.info("中奖加积分返回值情况 in2111:{}", in2111); log.info("中奖加积分返回值情况 in2111:{}", in2111);
// 发放状态 // 发放状态
receivingStatus = 2; receivingStatus = 2;
......
package com.liquidnet.service.sweet.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import com.liquidnet.service.sweet.config.WechatMaConfigure;
import com.liquidnet.service.sweet.utils.WechatSignUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* <p>
* 公众号动作回调 服务实现类
* </p>
*
* @author liquidnet
* @since 2021-07-31
*/
@Service
@Slf4j
public class SweetWechatApplyEventPushServiceImpl {
@Autowired
WechatMaConfigure wechatMaConfigure;
@Autowired
private WechatSignUtils wechatSignUtils;
public String authGet(Integer type, String timestamp, String nonce, String signature, String echostr) {
if (wechatSignUtils.checkSignature(signature, timestamp, nonce)) {
log.info("验签通过");
return echostr;
} else {
log.info("验签未通过");
return "非法请求";
}
}
public String post(Integer type, String requestBody, String msgSignature, String encryptType, String signature, String timestamp, String nonce) {
WxMaService wxService = wechatMaConfigure.getWxMaService(type);
final boolean isJson = Objects.equals(wxService.getWxMaConfig().getMsgDataFormat(),
WxMaConstants.MsgDataFormat.JSON);
if (StringUtils.isBlank(encryptType)) {
// 明文传输的消息
WxMaMessage inMessage;
if (isJson) {
inMessage = WxMaMessage.fromJson(requestBody);
} else {//xml
inMessage = WxMaMessage.fromXml(requestBody);
}
wechatMaConfigure.messageRouter(type).route(inMessage);
return "success";
}
if ("aes".equals(encryptType)) {
// 是aes加密的消息
WxMaMessage inMessage;
if (isJson) {
inMessage = WxMaMessage.fromEncryptedJson(requestBody, wxService.getWxMaConfig());
} else {//xml
inMessage = WxMaMessage.fromEncryptedXml(requestBody, wxService.getWxMaConfig(),
timestamp, nonce, msgSignature);
}
wechatMaConfigure.messageRouter(type).route(inMessage);
return "success";
}
throw new RuntimeException("不可识别的加密类型:" + encryptType);
}
}
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