3 changed files with 256 additions and 256 deletions
@ -1,68 +1,68 @@ |
|||||
package com.ccsens.wechatutil.api; |
//package com.ccsens.wechatutil.api;
|
||||
|
//
|
||||
import cn.hutool.core.date.DateUtil; |
//import cn.hutool.core.date.DateUtil;
|
||||
import com.ccsens.util.JsonResponse; |
//import com.ccsens.util.JsonResponse;
|
||||
import com.ccsens.util.PropUtil; |
//import com.ccsens.util.PropUtil;
|
||||
import com.ccsens.util.WebConstant; |
//import com.ccsens.util.WebConstant;
|
||||
import com.ccsens.util.wx.WxXcxUtil; |
//import com.ccsens.util.wx.WxXcxUtil;
|
||||
import com.ccsens.wechatutil.bean.dto.WechatCode; |
//import com.ccsens.wechatutil.bean.dto.WechatCode;
|
||||
import com.ccsens.wechatutil.wxmini.MiniCodeUtil; |
//import com.ccsens.wechatutil.wxmini.MiniCodeUtil;
|
||||
import com.ccsens.wechatutil.wxofficial.OfficialAccountMessageUtil; |
//import com.ccsens.wechatutil.wxofficial.OfficialAccountMessageUtil;
|
||||
import io.swagger.annotations.Api; |
//import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParams; |
//import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation; |
//import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j; |
//import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod; |
//import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController; |
//import org.springframework.web.bind.annotation.RestController;
|
||||
|
//
|
||||
import javax.servlet.http.HttpServletRequest; |
//import javax.servlet.http.HttpServletRequest;
|
||||
|
//
|
||||
@Api(tags = "DEBUG" , description = "DebugController | ") |
//@Api(tags = "DEBUG" , description = "DebugController | ")
|
||||
@RestController |
//@RestController
|
||||
@RequestMapping("/debug") |
//@RequestMapping("/debug")
|
||||
@Slf4j |
//@Slf4j
|
||||
public class DebugController { |
//public class DebugController {
|
||||
|
//
|
||||
|
//
|
||||
|
//
|
||||
@ApiOperation(value = "/测试",notes = "") |
// @ApiOperation(value = "/测试",notes = "")
|
||||
@ApiImplicitParams({ |
// @ApiImplicitParams({
|
||||
}) |
// })
|
||||
@RequestMapping(value="",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) |
// @RequestMapping(value="",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
|
||||
public JsonResponse debug(HttpServletRequest request) throws Exception { |
// public JsonResponse debug(HttpServletRequest request) throws Exception {
|
||||
|
//
|
||||
return JsonResponse.newInstance().ok("测试"); |
// return JsonResponse.newInstance().ok("测试");
|
||||
} |
// }
|
||||
|
//
|
||||
@ApiOperation(value = "/测试",notes = "") |
// @ApiOperation(value = "/测试",notes = "")
|
||||
@ApiImplicitParams({ |
// @ApiImplicitParams({
|
||||
}) |
// })
|
||||
@RequestMapping(value="code",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) |
// @RequestMapping(value="code",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
|
||||
public JsonResponse debugWxCode(HttpServletRequest request) throws Exception { |
// public JsonResponse debugWxCode(HttpServletRequest request) throws Exception {
|
||||
//生成二维码
|
// //生成二维码
|
||||
String fileName = "/gameQrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png"; |
// String fileName = "/gameQrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
|
||||
String path = WebConstant.UPLOAD_PATH_BASE + fileName; |
// String path = WebConstant.UPLOAD_PATH_BASE + fileName;
|
||||
|
//
|
||||
WechatCode.WechatCodeB wechatCodeB = new WechatCode.WechatCodeB(); |
// WechatCode.WechatCodeB wechatCodeB = new WechatCode.WechatCodeB();
|
||||
wechatCodeB.setPage(WebConstant.QRCODE_GAME); |
// wechatCodeB.setPage(WebConstant.QRCODE_GAME);
|
||||
wechatCodeB.setScene("id=1&type=SQ"); |
// wechatCodeB.setScene("id=1&type=SQ");
|
||||
MiniCodeUtil.getWxCodeB(wechatCodeB, path); |
// MiniCodeUtil.getWxCodeB(wechatCodeB, path);
|
||||
// WxXcxUtil.getWxCodeC(WebConstant.QRCODE_GAME+"?id=" + gameRecord.getId() + "&type=" + gameType.getCode(), path, gameType.getCode());
|
//// WxXcxUtil.getWxCodeC(WebConstant.QRCODE_GAME+"?id=" + gameRecord.getId() + "&type=" + gameType.getCode(), path, gameType.getCode());
|
||||
|
//
|
||||
// gameRecord.setQrCodeUrl(PropUtil.qrCode + fileName);
|
//// gameRecord.setQrCodeUrl(PropUtil.qrCode + fileName);
|
||||
log.info("调用微信生成二维码"); |
// log.info("调用微信生成二维码");
|
||||
return JsonResponse.newInstance().ok("测试"); |
// return JsonResponse.newInstance().ok("测试");
|
||||
} |
// }
|
||||
|
//
|
||||
@ApiOperation(value = "/测试公众号消息",notes = "") |
// @ApiOperation(value = "/测试公众号消息",notes = "")
|
||||
@ApiImplicitParams({ |
// @ApiImplicitParams({
|
||||
}) |
// })
|
||||
@RequestMapping(value="message",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) |
// @RequestMapping(value="message",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
|
||||
public JsonResponse debugWxMessage(HttpServletRequest request) throws Exception { |
// public JsonResponse debugWxMessage(HttpServletRequest request) throws Exception {
|
||||
// OfficialAccountMessageUtil.officialMessage();
|
//// OfficialAccountMessageUtil.officialMessage();
|
||||
log.info("发送公众号消息"); |
// log.info("发送公众号消息");
|
||||
return JsonResponse.newInstance().ok("测试"); |
// return JsonResponse.newInstance().ok("测试");
|
||||
} |
// }
|
||||
|
//
|
||||
} |
//}
|
||||
|
@ -1,171 +1,171 @@ |
|||||
package com.ccsens.wechatutil.config; |
//package com.ccsens.wechatutil.config;
|
||||
|
//
|
||||
|
//
|
||||
import cn.hutool.core.lang.Snowflake; |
//import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil; |
//import cn.hutool.core.util.IdUtil;
|
||||
import com.ccsens.util.config.DruidProps; |
//import com.ccsens.util.config.DruidProps;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature; |
//import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule; |
//import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
//import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import org.springframework.beans.factory.annotation.Value; |
//import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean; |
//import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration; |
//import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType; |
//import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter; |
//import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter; |
//import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.*; |
//import org.springframework.web.servlet.config.annotation.*;
|
||||
|
//
|
||||
import javax.annotation.Resource; |
//import javax.annotation.Resource;
|
||||
import javax.sql.DataSource; |
//import javax.sql.DataSource;
|
||||
import java.nio.charset.Charset; |
//import java.nio.charset.Charset;
|
||||
import java.util.ArrayList; |
//import java.util.ArrayList;
|
||||
import java.util.List; |
//import java.util.List;
|
||||
|
//
|
||||
@Configuration |
//@Configuration
|
||||
//public class SpringConfig extends WebMvcConfigurationSupport {
|
////public class SpringConfig extends WebMvcConfigurationSupport {
|
||||
public class SpringConfig implements WebMvcConfigurer { |
//public class SpringConfig implements WebMvcConfigurer {
|
||||
@Resource |
// @Resource
|
||||
private DruidProps druidPropsUtil; |
// private DruidProps druidPropsUtil;
|
||||
@Value("${spring.snowflake.workerId}") |
// @Value("${spring.snowflake.workerId}")
|
||||
private String workerId; |
// private String workerId;
|
||||
@Value("${spring.snowflake.datacenterId}") |
// @Value("${spring.snowflake.datacenterId}")
|
||||
private String datacenterId; |
// private String datacenterId;
|
||||
|
//
|
||||
/** |
// /**
|
||||
* 配置Converter |
// * 配置Converter
|
||||
* @return |
// * @return
|
||||
*/ |
// */
|
||||
@Bean |
// @Bean
|
||||
public HttpMessageConverter<String> responseStringConverter() { |
// public HttpMessageConverter<String> responseStringConverter() {
|
||||
StringHttpMessageConverter converter = new StringHttpMessageConverter( |
// StringHttpMessageConverter converter = new StringHttpMessageConverter(
|
||||
Charset.forName("UTF-8")); |
// Charset.forName("UTF-8"));
|
||||
return converter; |
// return converter;
|
||||
} |
// }
|
||||
|
//
|
||||
@Bean |
|
||||
public HttpMessageConverter<Object> responseJsonConverter(){ |
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
|
||||
List<MediaType> mediaTypeList = new ArrayList<>(); |
|
||||
mediaTypeList.add(MediaType.TEXT_HTML); |
|
||||
mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8); |
|
||||
converter.setSupportedMediaTypes(mediaTypeList); |
|
||||
|
|
||||
//converter.setObjectMapper();
|
|
||||
ObjectMapper objectMapper = new ObjectMapper(); |
|
||||
SimpleModule simpleModule = new SimpleModule(); |
|
||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
|
||||
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
|
||||
objectMapper.registerModule(simpleModule); |
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
|
||||
converter.setObjectMapper(objectMapper); |
|
||||
|
|
||||
return converter; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
||||
//super.configureMessageConverters(converters);
|
|
||||
converters.add(responseStringConverter()); |
|
||||
converters.add(responseJsonConverter()); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { |
|
||||
configurer.favorPathExtension(false); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void addCorsMappings(CorsRegistry registry) { |
|
||||
registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
|
||||
// .allowedMethods("*") // 允许提交请求的方法,*表示全部允许
|
|
||||
.allowedOrigins("*") // #允许向该服务器提交请求的URI,*表示全部允许
|
|
||||
.allowCredentials(true) // 允许cookies跨域
|
|
||||
.allowedHeaders("*") // #允许访问的头信息,*表示全部
|
|
||||
.maxAge(18000L); // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
|
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 配置视图解析器 SpringBoot建议使用Thymeleaf代替jsp,动态页面默认路径:resources/template,静态页面默认路径: resources/static |
|
||||
* @return |
|
||||
*/ |
|
||||
// @Bean
|
// @Bean
|
||||
// public ViewResolver getViewResolver() {
|
// public HttpMessageConverter<Object> responseJsonConverter(){
|
||||
// InternalResourceViewResolver resolver = new InternalResourceViewResolver();
|
// MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
// resolver.setPrefix("/WEB-INF/views/");
|
// List<MediaType> mediaTypeList = new ArrayList<>();
|
||||
// resolver.setSuffix(".jsp");
|
// mediaTypeList.add(MediaType.TEXT_HTML);
|
||||
// return resolver;
|
// mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
|
// converter.setSupportedMediaTypes(mediaTypeList);
|
||||
|
//
|
||||
|
// //converter.setObjectMapper();
|
||||
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
// SimpleModule simpleModule = new SimpleModule();
|
||||
|
// simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
|
// simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
|
// objectMapper.registerModule(simpleModule);
|
||||
|
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
// converter.setObjectMapper(objectMapper);
|
||||
|
//
|
||||
|
// return converter;
|
||||
// }
|
// }
|
||||
|
//
|
||||
|
// @Override
|
||||
|
// public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
|
// //super.configureMessageConverters(converters);
|
||||
|
// converters.add(responseStringConverter());
|
||||
|
// converters.add(responseJsonConverter());
|
||||
|
// }
|
||||
|
//
|
||||
// @Override
|
// @Override
|
||||
// public void configureDefaultServletHandling(
|
// public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
||||
// DefaultServletHandlerConfigurer configurer) {
|
// configurer.favorPathExtension(false);
|
||||
// configurer.enable();
|
|
||||
// }
|
// }
|
||||
|
//
|
||||
|
// @Override
|
||||
/** |
// public void addCorsMappings(CorsRegistry registry) {
|
||||
* 配置静态资源 |
// registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
*/ |
//// .allowedMethods("*") // 允许提交请求的方法,*表示全部允许
|
||||
@Override |
// .allowedOrigins("*") // #允许向该服务器提交请求的URI,*表示全部允许
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
// .allowCredentials(true) // 允许cookies跨域
|
||||
registry.addResourceHandler("swagger-ui.html") |
// .allowedHeaders("*") // #允许访问的头信息,*表示全部
|
||||
.addResourceLocations("classpath:/META-INF/resources/"); |
// .maxAge(18000L); // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
|
||||
registry.addResourceHandler("/webjars/**") |
//
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/"); |
// }
|
||||
|
//
|
||||
registry.addResourceHandler("/uploads/**") |
// /**
|
||||
.addResourceLocations("file:///home/cloud/wechatutil/uploads/"); |
// * 配置视图解析器 SpringBoot建议使用Thymeleaf代替jsp,动态页面默认路径:resources/template,静态页面默认路径: resources/static
|
||||
//super.addResourceHandlers(registry);
|
// * @return
|
||||
} |
// */
|
||||
|
//// @Bean
|
||||
|
//// public ViewResolver getViewResolver() {
|
||||
|
//// InternalResourceViewResolver resolver = new InternalResourceViewResolver();
|
||||
|
//// resolver.setPrefix("/WEB-INF/views/");
|
||||
|
//// resolver.setSuffix(".jsp");
|
||||
|
//// return resolver;
|
||||
|
//// }
|
||||
|
//// @Override
|
||||
|
//// public void configureDefaultServletHandling(
|
||||
|
//// DefaultServletHandlerConfigurer configurer) {
|
||||
|
//// configurer.enable();
|
||||
|
//// }
|
||||
|
//
|
||||
//
|
//
|
||||
// /**
|
// /**
|
||||
// * 配置拦截器
|
// * 配置静态资源
|
||||
// * @param registry
|
|
||||
// */
|
// */
|
||||
// @Override
|
// @Override
|
||||
// public void addInterceptors(InterceptorRegistry registry) {
|
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
//// addPathPatterns 用于添加拦截规则
|
// registry.addResourceHandler("swagger-ui.html")
|
||||
//// excludePathPatterns 用于排除拦截
|
// .addResourceLocations("classpath:/META-INF/resources/");
|
||||
// registry.addInterceptor(tokenInterceptor())
|
// registry.addResourceHandler("/webjars/**")
|
||||
//// .addPathPatterns("/projects/**")
|
// .addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
//// .addPathPatterns("/messages/**")
|
//
|
||||
// .addPathPatterns("/users/**")
|
// registry.addResourceHandler("/uploads/**")
|
||||
// .excludePathPatterns("/users/signin")
|
// .addResourceLocations("file:///home/cloud/wechatutil/uploads/");
|
||||
// .excludePathPatterns("/users/smscode")
|
// //super.addResourceHandlers(registry);
|
||||
// .excludePathPatterns("/users/signup")
|
|
||||
// .excludePathPatterns("/users/password")
|
|
||||
// .excludePathPatterns("/users/account")
|
|
||||
// .excludePathPatterns("/users/token")
|
|
||||
// .excludePathPatterns("/users/claims")
|
|
||||
// .excludePathPatterns("/users/code")
|
|
||||
// .excludePathPatterns("/users/userId");
|
|
||||
//// .addPathPatterns("/plugins/**")
|
|
||||
//// .addPathPatterns("/delivers/**")
|
|
||||
//// .addPathPatterns("/tasks/**")
|
|
||||
//// .addPathPatterns("/members/**")
|
|
||||
//// .addPathPatterns("/templates/**")
|
|
||||
//// .addPathPatterns("/hardware/**");
|
|
||||
//// super.addInterceptors(registry);
|
|
||||
// }
|
// }
|
||||
|
////
|
||||
|
//// /**
|
||||
|
//// * 配置拦截器
|
||||
|
//// * @param registry
|
||||
|
//// */
|
||||
|
//// @Override
|
||||
|
//// public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
////// addPathPatterns 用于添加拦截规则
|
||||
|
////// excludePathPatterns 用于排除拦截
|
||||
|
//// registry.addInterceptor(tokenInterceptor())
|
||||
|
////// .addPathPatterns("/projects/**")
|
||||
|
////// .addPathPatterns("/messages/**")
|
||||
|
//// .addPathPatterns("/users/**")
|
||||
|
//// .excludePathPatterns("/users/signin")
|
||||
|
//// .excludePathPatterns("/users/smscode")
|
||||
|
//// .excludePathPatterns("/users/signup")
|
||||
|
//// .excludePathPatterns("/users/password")
|
||||
|
//// .excludePathPatterns("/users/account")
|
||||
|
//// .excludePathPatterns("/users/token")
|
||||
|
//// .excludePathPatterns("/users/claims")
|
||||
|
//// .excludePathPatterns("/users/code")
|
||||
|
//// .excludePathPatterns("/users/userId");
|
||||
|
////// .addPathPatterns("/plugins/**")
|
||||
|
////// .addPathPatterns("/delivers/**")
|
||||
|
////// .addPathPatterns("/tasks/**")
|
||||
|
////// .addPathPatterns("/members/**")
|
||||
|
////// .addPathPatterns("/templates/**")
|
||||
|
////// .addPathPatterns("/hardware/**");
|
||||
|
////// super.addInterceptors(registry);
|
||||
|
//// }
|
||||
|
////
|
||||
|
//// @Bean
|
||||
|
//// public TokenInterceptor tokenInterceptor(){
|
||||
|
//// return new TokenInterceptor();
|
||||
|
//// }
|
||||
//
|
//
|
||||
|
// /**
|
||||
|
// * 配置数据源(单数据源)
|
||||
|
// */
|
||||
// @Bean
|
// @Bean
|
||||
// public TokenInterceptor tokenInterceptor(){
|
// public DataSource dataSource(){
|
||||
// return new TokenInterceptor();
|
// return druidPropsUtil.createDruidDataSource();
|
||||
|
// }
|
||||
|
//
|
||||
|
// @Bean
|
||||
|
// public Snowflake snowflake(){
|
||||
|
//// return new Snowflake(Long.valueOf(workerId),Long.valueOf(datacenterId));
|
||||
|
// return IdUtil.createSnowflake(Long.valueOf(workerId),Long.valueOf(datacenterId));
|
||||
|
// }
|
||||
//}
|
//}
|
||||
|
|
||||
/** |
|
||||
* 配置数据源(单数据源) |
|
||||
*/ |
|
||||
@Bean |
|
||||
public DataSource dataSource(){ |
|
||||
return druidPropsUtil.createDruidDataSource(); |
|
||||
} |
|
||||
|
|
||||
@Bean |
|
||||
public Snowflake snowflake(){ |
|
||||
// return new Snowflake(Long.valueOf(workerId),Long.valueOf(datacenterId));
|
|
||||
return IdUtil.createSnowflake(Long.valueOf(workerId),Long.valueOf(datacenterId)); |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue