feat:回调处理
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.cool.store.handler;
|
package com.cool.store.handler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cool.store.dao.PartnerUserWechatBindDAO;
|
import com.cool.store.dao.PartnerUserWechatBindDAO;
|
||||||
import com.cool.store.dto.wechat.WechatUserInfoDTO;
|
import com.cool.store.dto.wechat.WechatUserInfoDTO;
|
||||||
import com.cool.store.service.wechat.WechatTemplateService;
|
import com.cool.store.service.wechat.WechatTemplateService;
|
||||||
@@ -99,6 +100,8 @@ public class WeChatHandler {
|
|||||||
//根据openId 获取用户信息
|
//根据openId 获取用户信息
|
||||||
WechatUserInfoDTO userInfo = wechatTemplateService.getUserInfo(fromUserName, null);
|
WechatUserInfoDTO userInfo = wechatTemplateService.getUserInfo(fromUserName, null);
|
||||||
|
|
||||||
|
log.info("handleSubscribeEvent: {}", JSONObject.toJSONString(userInfo));
|
||||||
|
|
||||||
//根据unionId 更新服务号ID
|
//根据unionId 更新服务号ID
|
||||||
if (userInfo != null) {
|
if (userInfo != null) {
|
||||||
partnerUserWechatBindDAO.updateByUnionId(userInfo.getUnionid(),fromUserName);
|
partnerUserWechatBindDAO.updateByUnionId(userInfo.getUnionid(),fromUserName);
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public class OpenApiValidateFilter implements Filter {
|
|||||||
private String coolAppKey;
|
private String coolAppKey;
|
||||||
@Value("${cool.api.secret}")
|
@Value("${cool.api.secret}")
|
||||||
private String coolAppSecret;
|
private String coolAppSecret;
|
||||||
|
private static final Set<String> WHITELIST_URIS = new HashSet<>(Arrays.asList(
|
||||||
|
"/zxjp/open/v1/statusRefresh",
|
||||||
|
"/zxjp/open/v1/getStoreUser"
|
||||||
|
));
|
||||||
private static final List<String> oldUrlMapping = new ArrayList<>(Arrays.asList(
|
private static final List<String> oldUrlMapping = new ArrayList<>(Arrays.asList(
|
||||||
"/zxjp/open/v1/statusRefresh","/zxjp/open/v1/changePaymentStatus",
|
"/zxjp/open/v1/statusRefresh","/zxjp/open/v1/changePaymentStatus",
|
||||||
"/zxjp/open/v1/getYlsToken", "/zxjp/open/v1/getStoreList",
|
"/zxjp/open/v1/getYlsToken", "/zxjp/open/v1/getStoreList",
|
||||||
@@ -61,7 +65,7 @@ public class OpenApiValidateFilter implements Filter {
|
|||||||
}
|
}
|
||||||
MDC.put(CommonConstants.REQUEST_ID, UUIDUtils.get32UUID());
|
MDC.put(CommonConstants.REQUEST_ID, UUIDUtils.get32UUID());
|
||||||
//statusRefresh 放开不需要验签
|
//statusRefresh 放开不需要验签
|
||||||
if (uri.startsWith("/zxjp/open/v1/statusRefresh") || uri.startsWith("/zxjp/open/v1/getStoreUser")) {
|
if (isWhitelistUri(uri)) {
|
||||||
filterChain.doFilter(servletRequest, response);
|
filterChain.doFilter(servletRequest, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -174,6 +178,9 @@ public class OpenApiValidateFilter implements Filter {
|
|||||||
return OpenSignatureUtil.generateOldSign(params, coolAppSecret);
|
return OpenSignatureUtil.generateOldSign(params, coolAppSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isWhitelistUri(String uri) {
|
||||||
|
return WHITELIST_URIS.stream().anyMatch(uri::startsWith);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.cool.store.context.PartnerUserHolder;
|
|||||||
import com.cool.store.dto.*;
|
import com.cool.store.dto.*;
|
||||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||||
import com.cool.store.dto.wx.MiniProgramFreeLoginDTO;
|
import com.cool.store.dto.wx.MiniProgramFreeLoginDTO;
|
||||||
|
import com.cool.store.handler.WeChatHandler;
|
||||||
import com.cool.store.request.OpenApiStoreRequest;
|
import com.cool.store.request.OpenApiStoreRequest;
|
||||||
import com.cool.store.request.StoreCodeDTO;
|
import com.cool.store.request.StoreCodeDTO;
|
||||||
import com.cool.store.request.*;
|
import com.cool.store.request.*;
|
||||||
@@ -15,10 +16,12 @@ import com.cool.store.request.xgj.ReceiptCallBackRequest;
|
|||||||
import com.cool.store.response.ResponseResult;
|
import com.cool.store.response.ResponseResult;
|
||||||
import com.cool.store.response.bigdata.ApiResponse;
|
import com.cool.store.response.bigdata.ApiResponse;
|
||||||
import com.cool.store.service.*;
|
import com.cool.store.service.*;
|
||||||
|
import com.cool.store.utils.poi.StringUtils;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -52,6 +55,8 @@ public class OpenApiController {
|
|||||||
MessageTemplateService messageTemplateService;
|
MessageTemplateService messageTemplateService;
|
||||||
@Resource
|
@Resource
|
||||||
WechatMiniAppService wechatMiniAppService;
|
WechatMiniAppService wechatMiniAppService;
|
||||||
|
@Autowired
|
||||||
|
WeChatHandler weChatHandler;
|
||||||
|
|
||||||
@PostMapping("/statusRefresh")
|
@PostMapping("/statusRefresh")
|
||||||
public ApiResponse<Boolean> statusRefresh(@RequestBody StatusRefreshDTO statusRefreshDTO){
|
public ApiResponse<Boolean> statusRefresh(@RequestBody StatusRefreshDTO statusRefreshDTO){
|
||||||
@@ -185,4 +190,31 @@ public class OpenApiController {
|
|||||||
public ApiResponse<String> getTokenByMobile(@RequestBody @Validated MiniProgramFreeLoginDTO param) {
|
public ApiResponse<String> getTokenByMobile(@RequestBody @Validated MiniProgramFreeLoginDTO param) {
|
||||||
return ApiResponse.success(wechatMiniAppService.getShortTermTokenByMobile(param));
|
return ApiResponse.success(wechatMiniAppService.getShortTermTokenByMobile(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/callback", produces = "application/xml;charset=UTF-8")
|
||||||
|
@ApiOperation("callback")
|
||||||
|
public String handleWechatMessage(
|
||||||
|
@RequestParam("signature") String signature,
|
||||||
|
@RequestParam("timestamp") String timestamp,
|
||||||
|
@RequestParam("nonce") String nonce,
|
||||||
|
@RequestParam(value = "echostr", required = false) String echostr,
|
||||||
|
@RequestBody(required = false) String requestBody) {
|
||||||
|
|
||||||
|
System.out.println("收到微信消息:");
|
||||||
|
System.out.println("signature: " + signature);
|
||||||
|
System.out.println("timestamp: " + timestamp);
|
||||||
|
System.out.println("nonce: " + nonce);
|
||||||
|
System.out.println("echostr: " + echostr);
|
||||||
|
System.out.println("requestBody: " + requestBody);
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(requestBody)) {
|
||||||
|
try {
|
||||||
|
return weChatHandler.processMessage(weChatHandler.parseXmlToMap(requestBody));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("回调处理失败 e:{}",e.getMessage());
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nonce;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,14 +98,16 @@ public class PCTestController {
|
|||||||
private HttpRestTemplateService httpRestTemplateService;
|
private HttpRestTemplateService httpRestTemplateService;
|
||||||
@Resource
|
@Resource
|
||||||
FranchiseFeeMapper franchiseFeeMapper;
|
FranchiseFeeMapper franchiseFeeMapper;
|
||||||
|
@Resource
|
||||||
|
WechatTemplateService wechatTemplateService;
|
||||||
@Resource
|
@Resource
|
||||||
ShopInfoMapper shopInfoMapper;
|
ShopInfoMapper shopInfoMapper;
|
||||||
@Resource
|
@Resource
|
||||||
LinePayService linePayService;
|
LinePayService linePayService;
|
||||||
@Resource
|
@Resource
|
||||||
LinePayDAO linePayDAO;
|
LinePayDAO linePayDAO;
|
||||||
|
@Autowired
|
||||||
|
WeChatHandler weChatHandler;
|
||||||
@GetMapping("/syncStore")
|
@GetMapping("/syncStore")
|
||||||
public ResponseResult<Boolean> syncStore(@RequestParam("shopId")Long shopId){
|
public ResponseResult<Boolean> syncStore(@RequestParam("shopId")Long shopId){
|
||||||
syncMainSysServer.syncStore(shopId);
|
syncMainSysServer.syncStore(shopId);
|
||||||
@@ -561,8 +563,7 @@ public class PCTestController {
|
|||||||
}
|
}
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
@Autowired
|
|
||||||
WeChatHandler weChatHandler;
|
|
||||||
|
|
||||||
@RequestMapping(value = "/testWxNotice", produces = "application/xml;charset=UTF-8")
|
@RequestMapping(value = "/testWxNotice", produces = "application/xml;charset=UTF-8")
|
||||||
@ApiOperation("testWxNotice")
|
@ApiOperation("testWxNotice")
|
||||||
@@ -590,8 +591,6 @@ public class PCTestController {
|
|||||||
}
|
}
|
||||||
return nonce;
|
return nonce;
|
||||||
}
|
}
|
||||||
@Resource
|
|
||||||
WechatTemplateService wechatTemplateService;
|
|
||||||
|
|
||||||
@ApiOperation("测试小程序模板消息")
|
@ApiOperation("测试小程序模板消息")
|
||||||
@PostMapping("/testMiniAppTemplate")
|
@PostMapping("/testMiniAppTemplate")
|
||||||
|
|||||||
Reference in New Issue
Block a user