Compare commits

...

2 Commits

@ -0,0 +1,7 @@
FROM openjdk:8u332-jre-slim-bullseye AS runner
WORKDIR /root
ENV TZ=Asia/Shanghai
COPY ./target/gw-charge.jar /root/gw-charge.jar
ENV JAVA_OPTS="-server -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 "
ENV ENV_OPTS="-Dspring.profiles.active=test"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS $ENV_OPTS -Djava.security.egd=file:/dev/./urandom -jar /root/gw-charge.jar" ]

@ -0,0 +1 @@
小程序网关服务

@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: gw-charge
name: gw-charge
namespace: yibin-charge
spec:
ports:
- name: http
port: 7001
protocol: TCP
targetPort: 7001
nodePort: 30701
selector:
app: gw-charge
tier: backend
sessionAffinity: None
type: NodePort

@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: gw-charge
tier: backend
name: gw-charge
namespace: yibin-charge
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: gw-charge
tier: backend
template:
metadata:
labels:
app: gw-charge
tier: backend
spec:
containers:
- env:
- name: CACHE_IGNORE
value: js|html
- name: CACHE_PUBLIC_EXPIRATION
value: 3d
- name: LANG
value: C.UTF-8
- name: JAVA_OPTS
value: '-Dspring.profiles.active=test'
image: $REGISTRY_HARBOR/$REGISTRY_HARBOR_NAMESPACE/gw-charge:latest
readinessProbe:
httpGet:
path: /
port: 7001
timeoutSeconds: 10
failureThreshold: 30
periodSeconds: 5
imagePullPolicy: Always
name: gw-charge
ports:
- containerPort: 7001
protocol: TCP
resources:
limits:
cpu: 300m
memory: 600Mi
requests:
cpu: 100m
memory: 100Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.icharge.framework</groupId>
<artifactId>rough-dependencies</artifactId>
<version>1.0.0</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gw-charge</artifactId>
<version>1.0.0</version>
<name>gw-charge</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-json</artifactId>
<version>5.8.4</version>
</dependency>
<!-- dinger组件-->
<dependency>
<groupId>com.github.answerail</groupId>
<artifactId>dinger-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
<build>
<finalName>gw-charge</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,7 @@
FROM frolvlad/alpine-oraclejre8:8.202.08-slim
VOLUME /tmp
ADD gw-charge.jar app.jar
RUN sh -c 'touch /app.jar'
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

@ -0,0 +1,35 @@
package com.i100c.charge.gw;
import com.i100c.charge.gw.filter.CorsFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
@EnableZuulProxy
public class GwApplication {
@RequestMapping("/")
public String index() {
return "Hello, gw-charge";
}
public static void main(String[] args) {
SpringApplication.run(GwApplication.class, args);
}
@Bean
public FilterRegistrationBean filterRegist() {
FilterRegistrationBean frBean = new FilterRegistrationBean();
frBean.setFilter(new CorsFilter());
frBean.addUrlPatterns("/*");
return frBean;
}
}

@ -0,0 +1,51 @@
package com.i100c.charge.gw.config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
@EnableCaching //启用缓存,这个注解很重要;
public class RedisCacheConfig extends CachingConfigurerSupport {
/**
* .
*/
@Bean
public CacheManager cacheManager(RedisTemplate<?, ?> redisTemplate) {
return new RedisCacheManager(redisTemplate);
}
/**
* redis,jdbcTemplate;
* CacheManagerCache
* RedisTemplate
* RedisStorage;
* @param factory : Springapplication.properties
*/
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(factory);
//key序列化方式;(不然会出现乱码;,但是如果方法上有Long等非String类型的话会报类型转换错误
//所以在没有自己定义key生成策略的时候以下这个代码建议不要这么写可以不配置或者自己实现ObjectRedisSerializer
//或者JdkSerializationRedisSerializer序列化方式;
RedisSerializer<String> redisSerializer = new StringRedisSerializer();//Long类型不可以会出现异常信息;
redisTemplate.setKeySerializer(redisSerializer);
redisTemplate.setHashKeySerializer(redisSerializer);
return redisTemplate;
}
}

@ -0,0 +1,39 @@
package com.i100c.charge.gw.filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter(urlPatterns = "/*")
public class CorsFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;
String uri = request.getRequestURI();
request.getServerName();
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-requested-with, X-Custom-Header, Authorization,type");
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
return;
}
chain.doFilter(req, res);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}

@ -0,0 +1,171 @@
package com.i100c.charge.gw.filter;
import com.i100c.charge.gw.service.AsyncTask;
import com.i100c.charge.gw.service.TokenService;
import com.i100c.charge.gw.util.JwtUtil;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import io.jsonwebtoken.Claims;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
@ConfigurationProperties(prefix = "jwt.filter")
public class ZuulPreFilter extends ZuulFilter {
private static final Logger logger = LoggerFactory.getLogger(ZuulPreFilter.class);
@Value("${jwt.secret}")
private String secret;
@Autowired
private TokenService tokenService;
@Autowired
private AsyncTask asyncTask;
List<String> should_not_filter = new ArrayList<>();
List<String> no_access_filter = new ArrayList<>();
public List<String> getNo_access_filter() {
return no_access_filter;
}
public void setNo_access_filter(List<String> no_access_filter) {
this.no_access_filter = no_access_filter;
}
public List<String> getShould_not_filter() {
return should_not_filter;
}
public void setShould_not_filter(List<String> should_not_filter) {
this.should_not_filter = should_not_filter;
}
@PostConstruct
private void init() {
ArrayList<String> newList = new ArrayList<>();
for (String s : should_not_filter) {
newList.add(s.replaceAll("\\*\\*", "[^\\\\s]*"));
}
this.should_not_filter = newList;
}
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
RequestContext currentContext = RequestContext.getCurrentContext();
HttpServletRequest request = currentContext.getRequest();
String path = request.getRequestURI();
String contextPath = request.getContextPath();
String pathInfo = path.replaceFirst(contextPath, "");
boolean matches = false;
for (String s : should_not_filter) {
Pattern pattern = Pattern.compile(s);
Matcher matcher = pattern.matcher(pathInfo);
matches = matcher.find();
if (matches) break;
}
return !matches;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Map<String, List<String>> requestQueryParams = ctx.getRequestQueryParams();
HttpServletRequest request = ctx.getRequest();
String Authorization = request.getHeader("Authorization");
String uri = ctx.getRequest().getRequestURI();
logger.info("请求api:{}", uri);
if ("OPTIONS".equalsIgnoreCase(request.getMethod().toUpperCase())) {
ctx.getResponse().setStatus(HttpServletResponse.SC_OK);
return ctx.getResponse();
}
if (Authorization == null || Authorization.length() == 0) {
ctx.setSendZuulResponse(false);
ctx.setResponseBody("{\"msg\":\"凭证过期\" ,\"code\":1002}");
ctx.getResponse().setContentType("text/json; charset=utf-8");
ctx.setResponseStatusCode(200);
return ctx.getResponse();
}
String token = Authorization.replaceFirst(JwtUtil.AUTHORIZATION_STARTER, "");
Claims cs = JwtUtil.getClaimsFromToken(token, secret);
if (cs == null || cs.size() == 0) {
ctx.setSendZuulResponse(false);
ctx.setResponseBody("{\"msg\":\"凭证有误\" ,\"code\":1002}");
ctx.getResponse().setContentType("text/json; charset=utf-8");
ctx.setResponseStatusCode(200);
return ctx.getResponse();
}
String userId = (String) cs.get(JwtUtil.CLAIM_KEY_USERID);
String phone = (String) cs.get(JwtUtil.CLAIM_KEY_PHONE);
String type = (String) cs.get(JwtUtil.CLAIM_KEY_TYPE);
//验证数据是否过期
String tokenkey = "";
if (StringUtils.isEmpty(type)) {
tokenkey = TokenService.ONLINE_USER + userId + phone;
} else {
tokenkey = TokenService.ONLINE_USER + type + userId + phone;
}
String checkToken = tokenService.getToken(tokenkey);
if (StringUtils.isEmpty(checkToken)) {
ctx.setSendZuulResponse(false);
ctx.setResponseBody("{\"msg\":\"凭证过期\" ,\"code\":1002}");
ctx.getResponse().setContentType("text/json; charset=utf-8");
ctx.setResponseStatusCode(200);
return ctx.getResponse();
} else {
if (checkToken.equals(Authorization)) {
// tokenService.freshTime(TokenService.ONLINE_USER+userId);
} else {
ctx.setSendZuulResponse(false);
ctx.setResponseBody("{\"msg\":\"凭证过期请重新登录\" ,\"code\":1002}");
ctx.getResponse().setContentType("text/json; charset=utf-8");
ctx.setResponseStatusCode(200);
return ctx.getResponse();
}
}
Map<String, String> zuulRequestHeaders = ctx.getZuulRequestHeaders();
zuulRequestHeaders.put("phone", phone);
zuulRequestHeaders.put("userId", userId);
ctx.setZuulEngineRan();
//记录用户活跃信息
asyncTask.setLoginFlag(userId);
return ctx.getResponse();
}
}

@ -0,0 +1,35 @@
package com.i100c.charge.gw.filter;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class ZuulRoutingFilter extends com.netflix.zuul.ZuulFilter {
@PostConstruct
private void init() {
}
@Override
public String filterType() {
return "routing";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
return false;
}
@Override
public Object run() {
return null;
}
}

@ -0,0 +1,37 @@
package com.i100c.charge.gw.model;
public class CommonResponse {
private Integer code; //返回码
private String msg; //返回提示信息
private Object extraInfo;
private Object data; //返回数据
public Object getExtraInfo() {
return extraInfo;
}
public void setExtraInfo(Object extraInfo) {
this.extraInfo = extraInfo;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

@ -0,0 +1,90 @@
package com.i100c.charge.gw.model;
public class I100cResponse {
/**
*
*/
public static CommonResponse general(CommonResponse res) {
return res;
}
/**
*
*/
public static CommonResponse success(Object data) {
CommonResponse res = new CommonResponse();
res.setCode(1000);
res.setMsg("请求成功");
res.setData(data);
return general(res);
}
public static CommonResponse success() {
CommonResponse res = new CommonResponse();
res.setCode(1000);
res.setMsg("请求成功");
return general(res);
}
public static CommonResponse success(String msg) {
CommonResponse res = new CommonResponse();
res.setCode(1000);
res.setMsg(msg);
return general(res);
}
/**
*
*/
public static CommonResponse exception(String msg) {
CommonResponse res = new CommonResponse();
res.setCode(1001);
res.setMsg(msg);
return general(res);
}
public static CommonResponse exception(String msg, int errorCode) {
CommonResponse res = new CommonResponse();
res.setCode(errorCode);
res.setMsg(msg);
return general(res);
}
public static CommonResponse exception(String msg, int errorCode, Object extraInfo) {
CommonResponse res = new CommonResponse();
res.setCode(errorCode);
res.setMsg(msg);
res.setExtraInfo(extraInfo);
return general(res);
}
public static CommonResponse exception(String msg, Object data) {
CommonResponse res = new CommonResponse();
res.setCode(1001);
res.setMsg(msg);
res.setData(data);
return general(res);
}
public static CommonResponse unKonwException() {
CommonResponse res = new CommonResponse();
res.setCode(1001);
res.setMsg("请稍后再试");
return general(res);
}
/**
*
*/
public static CommonResponse custom(Integer code, String msg) {
CommonResponse res = new CommonResponse();
res.setCode(code);
res.setMsg(msg);
return general(res);
}
}

@ -0,0 +1,79 @@
package com.i100c.charge.gw.provider;
import cn.hutool.json.JSONUtil;
import com.github.jaemon.dinger.DingerSender;
import com.github.jaemon.dinger.core.entity.DingerRequest;
import com.github.jaemon.dinger.core.entity.enums.MessageSubType;
import com.i100c.charge.gw.model.CommonResponse;
import com.i100c.charge.gw.model.I100cResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
*
*/
@Component
public class ApiFallbackProvider implements ZuulFallbackProvider {
@Autowired
private DingerSender dingerSender;
//该Provider应用的Route ID例如testservice如果设置为 * ,那就对所有路由生效
@Override
public String getRoute() {
return "*";
}
@Override
public ClientHttpResponse fallbackResponse() {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() {
return HttpStatus.OK.value();
}
@Override
public String getStatusText() {
return HttpStatus.OK.getReasonPhrase();
}
@Override
public void close() {
}
@Override
public InputStream getBody() {
dingerSender.send(
MessageSubType.MARKDOWN,
DingerRequest.request("网关熔断异常/超时", "网关异常通知")
);
CommonResponse response = I100cResponse.custom(1001, "服务繁忙,请稍后再试");
return new ByteArrayInputStream(JSONUtil.toJsonStr(response).getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
};
}
}

@ -0,0 +1,33 @@
package com.i100c.charge.gw.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
/**
* Created by
*
* @author Administrator on
* @date 2018/9/14.
*/
@Component
public class AsyncTask {
private static final Logger logger = LoggerFactory.getLogger(AsyncTask.class);
@Autowired
private TokenService tokenService;
@Async
public void setLoginFlag(String userId) {
try{
tokenService.setLoginFlag(userId);
}catch (Exception e){
logger.error("setLogin Flag error userId:{} "+e,userId);
}
}
}

@ -0,0 +1,52 @@
package com.i100c.charge.gw.service;
import javax.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@Service
public class TokenService {
public static final String ONLINE_USER = "online_user:";
@Resource
private RedisTemplate<String, String> redisTemplate;
public void setToken(String key, String token) {
ValueOperations<String, String> value = redisTemplate.opsForValue();
value.set(ONLINE_USER + key, token);
}
public void freshTime(String key) {
redisTemplate.expire(key, 10, TimeUnit.DAYS);
}
public String getToken(String key) {
return redisTemplate.boundValueOps(key).get();
}
public void setLoginFlag(String userId) {
Date date =new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String nowdayTime = dateFormat.format(date);
redisTemplate.opsForValue().setBit("LOGIN_DATE:"+nowdayTime, Long.valueOf(userId), true);
DateFormat dateFormat2 = new SimpleDateFormat("yyyyMMddHH");
String nowdayTime2 = dateFormat2.format(date);
redisTemplate.opsForValue().setBit("LOGIN_DATE:"+nowdayTime2, Long.valueOf(userId), true);
DateFormat dateFormat3 = new SimpleDateFormat("yyyyMM");
String nowdayTime3 = dateFormat3.format(date);
redisTemplate.opsForValue().setBit("LOGIN_DATE:"+nowdayTime3, Long.valueOf(userId), true);
}
}

@ -0,0 +1,90 @@
package com.i100c.charge.gw.util;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Created by zhzhan on 2017/6/30.
*/
public class JwtUtil {
public static final String AUTHORIZATION_MONITOR_STARTER="Monitor ";
public static final String AUTHORIZATION_STARTER = "Bearer ";
public static final String CLAIM_KEY_USERID = "userId";
public static final String CLAIM_KEY_OPERATORID = "operatorId";
public static final String CLAIM_KEY_PHONE = "phone";
public static final String CLAIM_KEY_DATE = "date";
public static final String CLAIM_KEY_TYPE = "type";
public static final String SECRET = "ZXZnZWVr5b+r5LmQ5L2g55qE5Ye66KGM";
public static final String CLAIM_MONITOR_ACCOUNT_NAME="accountName";
public static String generateToken(String secret, String userId,String phone,String type) {
Date date = new Date();
return generateToken(secret, userId,phone, date.toString(),type);
}
public static String generateToken(String secret, String userId,String phone, String date,String type) {
Map<String, Object> claims = new HashMap<>();
claims.put(JwtUtil.CLAIM_KEY_USERID, userId);
claims.put(JwtUtil.CLAIM_KEY_PHONE, phone);
claims.put(JwtUtil.CLAIM_KEY_DATE, date);
claims.put(JwtUtil.CLAIM_KEY_TYPE, type);
return Jwts.builder()
.setClaims(claims)
// .setExpiration(date)
.signWith(SignatureAlgorithm.HS512, secret) //采用什么算法是可以自己选择的不一定非要采用HS512
.compact();
}
public static String generateTokenMonitor(String secret, String userId,String phone,String type,String accountName) {
Date date = new Date();
return generateTokenMonitor(secret, userId,phone, date.toString(),type,accountName);
}
public static String generateTokenMonitor(String secret, String userId,String phone, String date,String type,String accountName) {
Map<String, Object> claims = new HashMap<>();
claims.put(JwtUtil.CLAIM_KEY_USERID, userId);
claims.put(JwtUtil.CLAIM_KEY_PHONE, phone);
claims.put(JwtUtil.CLAIM_KEY_DATE, date);
claims.put(JwtUtil.CLAIM_KEY_TYPE, type);
claims.put(JwtUtil.CLAIM_MONITOR_ACCOUNT_NAME, accountName);
return Jwts.builder()
.setClaims(claims)
// .setExpiration(date)
.signWith(SignatureAlgorithm.HS512, secret) //采用什么算法是可以自己选择的不一定非要采用HS512
.compact();
}
public static String generateToken(String secret, String operatorId, Date date) {
Map<String, Object> claims = new HashMap<>();
claims.put(JwtUtil.CLAIM_KEY_OPERATORID, operatorId);
return Jwts.builder()
.setClaims(claims)
.setExpiration(date)
.signWith(SignatureAlgorithm.HS512, secret) //采用什么算法是可以自己选择的不一定非要采用HS512
.compact();
}
public static Claims getClaimsFromToken(String token, String secret) {
Claims claims;
try {
claims = Jwts.parser()
.setSigningKey(secret)
.parseClaimsJws(token)
.getBody();
} catch (Exception e) {
claims = null;
}
return claims;
}
}

@ -0,0 +1,206 @@
jwt:
secret: ZXZnZWVr5b+r5LmQ5L2g55qE5Ye66KGM
filter:
should_not_filter:
- /gw/login
- /userapi/getOpenId
- /userapi/weChatAuth
- /userapi/mobileLogin
- /userapi/sendMs
- /financeapi/wxSmallApp/wxSmallAppPayNotice
- /stationapi/station/queryNearbyStation
- /stationapi/station/queryNearbyStationMapMode
- /stationapi/station/queryYiXingWebsiteStationInfo
- /stationapi/station/identifyQR/PfV6GsETrX.txt
- /stationapi/station/PfV6GsETrX.txt
- /stationapi/station/queryStationList
- /stationapi/station/queryStationOperator
- /noticeapi/park/parkCoupon
- /userapi/getChewei
- /cheweiapi
- /financeapi/alipay/aliPayNotice
- /financeapi/alipay/aliPayNoticeFromSmallApp
- /financeapi/wxpay/wxAppPayNotice
- /financeapi/alipay/aliPayNoticeByCharge
- /userapi/wxLogin
- /userapi/forgetPW
- /userapi/loginByPW
- /userapi/getAccessToken
- /userapi/appWxLogin
- /userapi/getDictByKey
- /userapi/adPage/queryAdPage
- /userapi/appVersion/*
- /userapi/weChat/*
- /userapi/redPacket/getRedPacketDrawRecord
- /userapi/h5/*
- /userapi/groundLockStatus
- /userapi/getDictByKey
- /orderapi/inspectionReport/queryOrder
- /orderapi/inspectionReport/queryUserInfo
- /orderapi/inspectionReport/notificationShallowReport
- /orderapi/inspectionReport/notificationDeepReport
- /openapi/lock/queryConnectorId
- /openapi/lock/queryParkingLock
zuul:
#路径配置
routes:
#用户模块
userapi:
stripPrefix: false
path: /userapi/**
sensitiveHeaders:
#财务模块
financeapi:
stripPrefix: true
path: /financeapi/**
sensitiveHeaders:
#充电站模块
stationapi:
stripPrefix: true
path: /stationapi/**
sensitiveHeaders:
#订单模块
orderapi:
stripPrefix: false
path: /orderapi/**
sensitiveHeaders:
#互联互通模块
openapi:
stripPrefix: true
path: /openapi/**
sensitiveHeaders:
#订单后台模块
orderbkapi:
stripPrefix: false
path: /orderbkapi/**
sensitiveHeaders:
#协议模块
protocolapi:
stripPrefix: false
path: /protocolapi/**
sensitiveHeaders:
#分发模块
distribute:
stripPrefix: false
path: /distribute/**
sensitiveHeaders:
#通知模块
noticeapi:
stripPrefix: false
path: /noticeapi/**
sensitiveHeaders:
#通知模块
cheweiapi:
stripPrefix: false
path: /cheweiapi/**
sensitiveHeaders:
orderbkapi:
ribbon:
listOfServers: 127.0.0.1:7011
distribute:
ribbon:
listOfServers: http://i100c.3322.org:31636
excelapi:
ribbon:
listOfServers: http://i100c.3322.org:30326
financeapi:
ribbon:
listOfServers: http://i100c.3322.org:32134
noticeapi:
ribbon:
listOfServers: http://i100c.3322.org:30745
openapi:
ribbon:
listOfServers: http://i100c.3322.org:31301
orderapi:
ribbon:
listOfServers: http://i100c.3322.org:30258
protocolshenghongapi:
ribbon:
listOfServers: http://i100c.3322.org:31766
stationapi:
ribbon:
listOfServers: http://i100c.3322.org:30836
taskapi:
ribbon:
listOfServers: http://i100c.3322.org:31960
userapi:
ribbon:
listOfServers: http://i100c.3322.org:32150
walletapi:
ribbon:
listOfServers: http://i100c.3322.org:30723
websocketocppapi:
ribbon:
listOfServers: http://i100c.3322.org:30725
mgrapi:
ribbon:
listOfServers: http://i100c.3322.org:30115
cheweiapi:
ribbon:
listOfServers: http://cz.api.cheweiguanjia.com
ribbon:
eureka:
enabled: false #禁用eureka不依赖 eureka
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.AvailabilityFilteringRule #为所有服务配置统一规则,先过滤掉故障实例,再选择并发较小的实例
ReadTimeout: 100000 #请求处理的超时时间 默认1秒单位ms
ConnectTimeout: 100000 #请求连接的超时时间 默认1秒单位ms
MaxAutoRetries: 1 #对当前实例的重试次数 默认0
MaxAutoRetriesNextServer: 3 #切换实例的重试次数 默认1
hystrix:
command:
default:
execution:
timeout:
enabled: true #配置HystrixCommand的执行是否启用超时时间
isolation:
thread:
timeoutInMilliseconds: 8000 #配置HystrixCommand执行的超时时间执行超过该时间会进行服务降级处理 8s
spring:
redis:
database: 0
host: 192.168.128.159
port: 6380
password: rzyc#redis
timeout: 0
pool:
max-active: 8
max-idle: 8
min-idle: 0
dinger:
project-id: ${spring.application.name}-${spring.profiles.active}
dingers:
# 使用钉钉机器人, 请根据自己机器人配置信息进行修改
dingtalk:
# tokenId是创建机器人的webhook
tokenId: ad3700d79705ea1502e57c5fa170fda23d5c6502f3d0410a66dbc2a8e1d06986
# secret是创建机器人的加签
secret: SEC167efa8be3412d3b9dbf87286d9b837836aabd79cf20f9966001333a287a39a5

@ -0,0 +1,211 @@
jwt:
secret: ZXZnZWVr5b+r5LmQ5L2g55qE5Ye66KGM
filter:
should_not_filter:
- /gw/login
- /userapi/getOpenId
- /userapi/weChatAuth
- /userapi/mobileLogin
- /userapi/sendMs
- /financeapi/wxSmallApp/wxSmallAppPayNotice
- /stationapi/station/queryNearbyStation
- /stationapi/station/queryNearbyStationMapMode
- /stationapi/station/queryYiXingWebsiteStationInfo
- /stationapi/station/identifyQR/PfV6GsETrX.txt
- /stationapi/station/PfV6GsETrX.txt
- /stationapi/station/queryStationList
- /stationapi/station/queryStationOperator
- /noticeapi/park/parkCoupon
- /userapi/getChewei
- /cheweiapi/*
- /financeapi/alipay/aliPayNotice
- /financeapi/alipay/aliPayNoticeFromSmallApp
- /financeapi/wxpay/wxAppPayNotice
- /financeapi/alipay/aliPayNoticeByCharge
- /financeapi/wxpay/wxAppChargePayNotice
- /financeapi/wxSmallApp/cmwxSmallAppPayNotice
- /financeapi/hmwxSmallApp/cmwxSmallAppPayNotice
- /financeapi/hmwxSmallApp/cmwxSmallAppPayNoticeByRc
- /userapi/wxLogin
- /userapi/forgetPW
- /userapi/loginByPW
- /userapi/getAccessToken
- /userapi/appWxLogin
- /userapi/user/isReg
- /userapi/adPage/queryAdPage
- /userapi/appVersion/*
- /userapi/weChat/*
- /userapi/redPacket/getRedPacketDrawRecord
- /userapi/rechargeActivity/h5/*
- /userapi/groundLockStatus
- /userapi/getDictByKey
- /orderapi/inspectionReport/queryOrder
- /orderapi/inspectionReport/queryUserInfo
- /orderapi/inspectionReport/notificationShallowReport
- /orderapi/inspectionReport/notificationDeepReport
- /openapi/lock/queryConnectorId
- /openapi/lock/queryParkingLock
- /userapi/h5/*
zuul:
#路径配置
routes:
#用户模块
userapi:
stripPrefix: false
path: /userapi/**
sensitiveHeaders:
#财务模块
financeapi:
stripPrefix: true
path: /financeapi/**
sensitiveHeaders:
#充电站模块
stationapi:
stripPrefix: true
path: /stationapi/**
sensitiveHeaders:
#订单模块
orderapi:
stripPrefix: false
path: /orderapi/**
sensitiveHeaders:
openapi:
stripPrefix: true
path: /openapi/**
sensitiveHeaders:
#订单后台模块
orderbkapi:
stripPrefix: false
path: /orderbkapi/**
sensitiveHeaders:
#协议模块
protocolapi:
stripPrefix: false
path: /protocolapi/**
sensitiveHeaders:
#分发模块
distribute:
stripPrefix: false
path: /distribute/**
sensitiveHeaders:
#通知模块
noticeapi:
stripPrefix: false
path: /noticeapi/**
sensitiveHeaders:
#通知模块
cheweiapi:
stripPrefix: false
path: /cheweiapi/**
sensitiveHeaders:
#运营商账户模块
operatorBill:
stripPrefix: true
path: /operatorBill/**
sensitiveHeaders:
orderbkapi:
ribbon:
listOfServers: ms-admin:7011
distribute:
ribbon:
listOfServers: ms-distribute:7012
excelapi:
ribbon:
listOfServers: ms-excel:7013
financeapi:
ribbon:
listOfServers: ms-finance:7014
noticeapi:
ribbon:
listOfServers: ms-notice:7015
openapi:
ribbon:
listOfServers: ms-openapi:7016
orderapi:
ribbon:
listOfServers: ms-order:7017
protocolshenghongapi:
ribbon:
listOfServers: ms-protocol-shenghong:7019
stationapi:
ribbon:
listOfServers: ms-station:7020
taskapi:
ribbon:
listOfServers: ms-task:7021
userapi:
ribbon:
listOfServers: ms-user:7022
walletapi:
ribbon:
listOfServers: ms-wallet:7023
websocketocppapi:
ribbon:
listOfServers: ms-websocket-ocpp:7025
mgrapi:
ribbon:
listOfServers: ms-saas-mgr:7026
cheweiapi:
ribbon:
listOfServers: http://cz.api.cheweiguanjia.com
ribbon:
eureka:
enabled: false #禁用eureka不依赖 eureka
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.AvailabilityFilteringRule #为所有服务配置统一规则,先过滤掉故障实例,再选择并发较小的实例
ReadTimeout: 100000 #请求处理的超时时间 默认1秒单位ms
ConnectTimeout: 100000 #请求连接的超时时间 默认1秒单位ms
MaxAutoRetries: 1 #对当前实例的重试次数 默认0
MaxAutoRetriesNextServer: 3 #切换实例的重试次数 默认1
hystrix:
command:
default:
execution:
timeout:
enabled: true #配置HystrixCommand的执行是否启用超时时间
isolation:
thread:
timeoutInMilliseconds: 10000 #配置HystrixCommand执行的超时时间执行超过该时间会进行服务降级处理 10s
spring:
redis:
database: 0
host: r-bp14c1p5j5lkpw1jc2.redis.rds.aliyuncs.com
port: 6379
password: Ycharge666
timeout: 0
pool:
max-active: 8
max-idle: 8
min-idle: 0
dinger:
project-id: ${spring.application.name}-${spring.profiles.active}
dingers:
# 使用钉钉机器人, 请根据自己机器人配置信息进行修改
dingtalk:
# tokenId是创建机器人的webhook
tokenId: 6c0cd9de94359329fe166dfefe39da0d8d3fba59211dfdc64d8aba1d1acd89fb
# secret是创建机器人的加签
secret: SEC9e3b8638d5670215e966efc891be4c7d83c09dd8f032df7ca84972a2661effb7

@ -0,0 +1,206 @@
jwt:
secret: ZXZnZWVr5b+r5LmQ5L2g55qE5Ye66KGM
filter:
should_not_filter:
- /gw/login
- /userapi/getOpenId
- /userapi/weChatAuth
- /userapi/mobileLogin
- /userapi/sendMs
- /financeapi/wxSmallApp/wxSmallAppPayNotice
- /stationapi/station/queryNearbyStation
- /stationapi/station/queryNearbyStationMapMode
- /stationapi/station/queryYiXingWebsiteStationInfo
- /stationapi/station/identifyQR/PfV6GsETrX.txt
- /stationapi/station/PfV6GsETrX.txt
- /stationapi/station/queryStationList
- /stationapi/station/queryStationOperator
- /noticeapi/park/parkCoupon
- /userapi/getChewei
- /cheweiapi
- /financeapi/alipay/aliPayNotice
- /financeapi/alipay/aliPayNoticeFromSmallApp
- /financeapi/wxpay/wxAppPayNotice
- /financeapi/alipay/aliPayNoticeByCharge
- /userapi/wxLogin
- /userapi/forgetPW
- /userapi/loginByPW
- /userapi/getAccessToken
- /userapi/appWxLogin
- /userapi/getDictByKey
- /userapi/adPage/queryAdPage
- /userapi/appVersion/*
- /userapi/weChat/*
- /userapi/redPacket/getRedPacketDrawRecord
- /userapi/h5/*
- /userapi/groundLockStatus
- /userapi/getDictByKey
- /orderapi/inspectionReport/queryOrder
- /orderapi/inspectionReport/queryUserInfo
- /orderapi/inspectionReport/notificationShallowReport
- /orderapi/inspectionReport/notificationDeepReport
- /openapi/lock/queryConnectorId
- /openapi/lock/queryParkingLock
zuul:
#路径配置
routes:
#用户模块
userapi:
stripPrefix: false
path: /userapi/**
sensitiveHeaders:
#财务模块
financeapi:
stripPrefix: true
path: /financeapi/**
sensitiveHeaders:
#充电站模块
stationapi:
stripPrefix: true
path: /stationapi/**
sensitiveHeaders:
#订单模块
orderapi:
stripPrefix: false
path: /orderapi/**
sensitiveHeaders:
openapi:
stripPrefix: true
path: /openapi/**
sensitiveHeaders:
#订单后台模块
orderbkapi:
stripPrefix: false
path: /orderbkapi/**
sensitiveHeaders:
#协议模块
protocolapi:
stripPrefix: false
path: /protocolapi/**
sensitiveHeaders:
#分发模块
distribute:
stripPrefix: false
path: /distribute/**
sensitiveHeaders:
#通知模块
noticeapi:
stripPrefix: false
path: /noticeapi/**
sensitiveHeaders:
#通知模块
cheweiapi:
stripPrefix: false
path: /cheweiapi/**
sensitiveHeaders:
orderbkapi:
ribbon:
listOfServers: ms-admin:7011
distribute:
ribbon:
listOfServers: ms-distribute:7012
excelapi:
ribbon:
listOfServers: ms-excel:7013
financeapi:
ribbon:
listOfServers: ms-finance:7014
noticeapi:
ribbon:
listOfServers: ms-notice:7015
openapi:
ribbon:
listOfServers: ms-openapi:7016
orderapi:
ribbon:
listOfServers: ms-order:7017
protocolshenghongapi:
ribbon:
listOfServers: ms-protocol-shenghong:7019
stationapi:
ribbon:
listOfServers: ms-station:7020
taskapi:
ribbon:
listOfServers: ms-task:7021
userapi:
ribbon:
listOfServers: ms-user:7022
walletapi:
ribbon:
listOfServers: ms-wallet:7023
websocketocppapi:
ribbon:
listOfServers: ms-websocket-ocpp:7025
mgrapi:
ribbon:
listOfServers: ms-saas-mgr:7026
cheweiapi:
ribbon:
listOfServers: http://cz.api.cheweiguanjia.com
ribbon:
eureka:
enabled: false #禁用eureka不依赖 eureka
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.AvailabilityFilteringRule #为所有服务配置统一规则,先过滤掉故障实例,再选择并发较小的实例
ReadTimeout: 100000 #请求处理的超时时间 默认1秒单位ms
ConnectTimeout: 100000 #请求连接的超时时间 默认1秒单位ms
MaxAutoRetries: 1 #对当前实例的重试次数 默认0
MaxAutoRetriesNextServer: 3 #切换实例的重试次数 默认1
hystrix:
command:
default:
execution:
timeout:
enabled: true #配置HystrixCommand的执行是否启用超时时间
isolation:
thread:
timeoutInMilliseconds: 8000 #配置HystrixCommand执行的超时时间执行超过该时间会进行服务降级处理 8s
spring:
redis:
database: 0
host: 192.168.128.159
port: 6381
password: ylt#redis
timeout: 0
pool:
max-active: 8
max-idle: 8
min-idle: 0
dinger:
project-id: ${spring.application.name}-${spring.profiles.active}
dingers:
# 使用钉钉机器人, 请根据自己机器人配置信息进行修改
dingtalk:
# tokenId是创建机器人的webhook
tokenId: ad3700d79705ea1502e57c5fa170fda23d5c6502f3d0410a66dbc2a8e1d06986
# secret是创建机器人的加签
secret: SEC167efa8be3412d3b9dbf87286d9b837836aabd79cf20f9966001333a287a39a5

@ -0,0 +1,21 @@
spring:
application:
name: gw-charge
profiles:
active: dev
http:
multipart:
enabled: true
max-file-size: 100MB
max-request-size: 100MB
server:
port: 7001

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script>
!(function(n, e) {
var t = n.documentElement,
i = 'orientationchange' in window ? 'orientationchange' : 'resize',
d = function() {
var n = t.clientWidth;
n &&
(t.style.fontSize = 750 <= n ? '100px' : (n / 750) * 100 + 'px');
};
n.addEventListener &&
(e.addEventListener(i, d, !1),
n.addEventListener('DOMContentLoaded', d, !1));
})(document, window);
</script>
<meta
name="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="./manifest.json" />
<link rel="shortcut icon" href="./favicon.ico" />
<title>充儿使用帮助</title>
<link href="./static/css/main.8bedb333.css" rel="stylesheet" />
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="./static/js/main.f2765746.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Loading…
Cancel
Save