diff --git a/changelog.md b/changelog.md index ebe0cbb8..c6822c03 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # changelog +## 3.2.0 + +- 使用alibaba cloud + +Hoxton.SR3(Spring Cloud Version), 2.2.1.RELEASE(Spring Cloud Alibaba Version), 2.2.5.RELEASE(Spring Boot Version) + +- 优化pom文件 +- 优化灰度发布 + ## 3.1.5 修复文件上传大小不一致问题 diff --git a/doc/docs/_sidebar.md b/doc/docs/_sidebar.md index ce5dde51..a6b48b7e 100644 --- a/doc/docs/_sidebar.md +++ b/doc/docs/_sidebar.md @@ -1,39 +1,39 @@ -* [首页](/?t=1589794156310) +* [首页](/?t=1591927043815) * 开发文档 - * [快速体验](files/10010_快速体验.md?t=1589794156312) - * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1589794156333) - * [新增接口](files/10020_新增接口.md?t=1589794156333) - * [开发流程](files/10021_开发流程.md?t=1589794156333) - * [业务参数校验](files/10030_业务参数校验.md?t=1589794156333) - * [错误处理](files/10040_错误处理.md?t=1589794156333) - * [编写文档](files/10041_编写文档.md?t=1589794156333) - * [接口交互详解](files/10050_接口交互详解.md?t=1589794156333) - * [easyopen支持](files/10070_easyopen支持.md?t=1589794156333) - * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1589794156334) - * [ISV管理](files/10085_ISV管理.md?t=1589794156334) - * [自定义返回结果](files/10087_自定义返回结果.md?t=1589794156334) - * [自定义过滤器](files/10088_自定义过滤器.md?t=1589794156334) - * [自定义校验token](files/10089_自定义校验token.md?t=1589794156334) - * [网关拦截器](files/10090_网关拦截器.md?t=1589794156334) - * [路由授权](files/10090_路由授权.md?t=1589794156335) - * [接口限流](files/10092_接口限流.md?t=1589794156335) - * [路由监控](files/10093_路由监控.md?t=1589794156335) - * [SDK开发](files/10095_SDK开发.md?t=1589794156335) - * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1589794156335) - * [应用授权](files/10097_应用授权.md?t=1589794156335) - * [提供restful接口](files/10100_提供restful接口.md?t=1589794156335) - * [文件上传](files/10104_文件上传.md?t=1589794156336) - * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1589794156336) - * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1589794156336) - * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1589794156336) - * [使用eureka](files/10112_使用eureka.md?t=1589794156336) - * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1589794156336) + * [快速体验](files/10010_快速体验.md?t=1591927043817) + * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1591927043835) + * [新增接口](files/10020_新增接口.md?t=1591927043836) + * [开发流程](files/10021_开发流程.md?t=1591927043836) + * [业务参数校验](files/10030_业务参数校验.md?t=1591927043836) + * [错误处理](files/10040_错误处理.md?t=1591927043836) + * [编写文档](files/10041_编写文档.md?t=1591927043836) + * [接口交互详解](files/10050_接口交互详解.md?t=1591927043836) + * [easyopen支持](files/10070_easyopen支持.md?t=1591927043836) + * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1591927043836) + * [ISV管理](files/10085_ISV管理.md?t=1591927043836) + * [自定义返回结果](files/10087_自定义返回结果.md?t=1591927043837) + * [自定义过滤器](files/10088_自定义过滤器.md?t=1591927043837) + * [自定义校验token](files/10089_自定义校验token.md?t=1591927043837) + * [网关拦截器](files/10090_网关拦截器.md?t=1591927043837) + * [路由授权](files/10090_路由授权.md?t=1591927043837) + * [接口限流](files/10092_接口限流.md?t=1591927043837) + * [路由监控](files/10093_路由监控.md?t=1591927043837) + * [SDK开发](files/10095_SDK开发.md?t=1591927043837) + * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1591927043837) + * [应用授权](files/10097_应用授权.md?t=1591927043837) + * [提供restful接口](files/10100_提供restful接口.md?t=1591927043838) + * [文件上传](files/10104_文件上传.md?t=1591927043838) + * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1591927043838) + * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1591927043838) + * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1591927043838) + * [使用eureka](files/10112_使用eureka.md?t=1591927043838) + * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1591927043838) * 原理分析 - * [网关性能测试](files/90001_网关性能测试.md?t=1589794156336) - * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1589794156337) - * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1589794156337) - * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1589794156337) - * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1589794156337) - * [原理分析之预发布灰度发布](files/90014_原理分析之预发布灰度发布.md?t=1589794156337) - * [2.x升3.x注意事项](files/90099_2.x升3.x注意事项.md?t=1589794156337) - * [常见问题](files/90100_常见问题.md?t=1589794156337) + * [网关性能测试](files/90001_网关性能测试.md?t=1591927043838) + * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1591927043838) + * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1591927043838) + * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1591927043839) + * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1591927043839) + * [原理分析之预发布灰度发布](files/90014_原理分析之预发布灰度发布.md?t=1591927043839) + * [2.x升3.x注意事项](files/90099_2.x升3.x注意事项.md?t=1591927043839) + * [常见问题](files/90100_常见问题.md?t=1591927043839) diff --git a/doc/docs/files/10010_快速体验.md b/doc/docs/files/10010_快速体验.md index 8029b969..b27e9ae4 100644 --- a/doc/docs/files/10010_快速体验.md +++ b/doc/docs/files/10010_快速体验.md @@ -12,7 +12,7 @@ - 启动微服务:打开`sop-example/sop-story/sop-story-web`下的`application-dev.properties`文件 1. 指定nacos地址,如果nacos安装在本机则不用改 2. 运行`SopStoryApplication.java` -- 找到sop-test,打开`AllInOneTest.java`进行接口调用测试 +- 找到sop-test,运行`com.gitee.sop.test.AlipayClientPostTest.testGet`进行接口调用测试 ## 使用admin diff --git a/doc/docs/files/10087_自定义返回结果.md b/doc/docs/files/10087_自定义返回结果.md index 352f7ccf..123cf503 100644 --- a/doc/docs/files/10087_自定义返回结果.md +++ b/doc/docs/files/10087_自定义返回结果.md @@ -78,7 +78,7 @@ public class ZuulConfig extends AlipayZuulConfiguration { } ``` -**注**:网关设置了CustomDataNameBuilder后,SDK也要做相应的更改:`SdkConfig.dataNameBuilder = new CustomDataNameBuilder();` +**注**:网关设置了CustomDataNameBuilder后,SDK也要做相应的更改:`OpenConfig.dataNameBuilder = new CustomDataNameBuilder();` ## 自定义结果处理 diff --git a/doc/docs/files/10092_接口限流.md b/doc/docs/files/10092_接口限流.md index 2c36cd00..8f1c9ef8 100644 --- a/doc/docs/files/10092_接口限流.md +++ b/doc/docs/files/10092_接口限流.md @@ -67,15 +67,14 @@ spring.redis.host=127.0.0.1 spring.redis.port=6379 ``` -- ZuulConfig.java中添加如下代码: +- 在启动类中添加如下代码: ```java @Autowired private RedisTemplate redisTemplate; -@Override -protected void doAfter() { - super.doAfter(); +@PostConstruct +public void doAfter() { ApiConfig.getInstance().setLimitManager(new RedisLimitManager(redisTemplate)); } ``` diff --git a/pom.xml b/pom.xml index ca648159..ffd2adce 100644 --- a/pom.xml +++ b/pom.xml @@ -2,12 +2,18 @@ + + org.springframework.boot + spring-boot-starter-parent + 2.2.5.RELEASE + + + 4.0.0 com.gitee.sop sop-parent 1.0.0-SNAPSHOT pom - 一个开放平台解决方案项目,基于Spring Cloud实现,目标是能够让用户快速得搭建起自己的开放平台 @@ -21,4 +27,224 @@ sop-sdk sop-website + + + 1.8 + + UTF-8 + 1.8 + 1.8 + + + 2.2.5.RELEASE + + Hoxton.SR3 + + + 2.2.1.RELEASE + + + + 1.2.3 + 1.7.5 + + + 4.11 + + 1.2.70 + 2.5 + 1.3.3 + 3.2.2 + 3.8.1 + 1.11 + 1.2 + 2.0.1.Final + 6.0.13.Final + 1.9.1 + 2.3.0.RELEASE + 27.1-jre + 1.5.21 + 2.9.2 + 1.16.9 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + com.google.guava + guava + ${guava.version} + + + + com.alibaba + fastjson + ${fastjson.version} + + + + net.oschina.durcframework + fastmybatis-spring-boot-starter + ${fastmybatis.version} + + + + io.springfox + springfox-spring-web + ${springfox-spring-web.version} + + + io.swagger + swagger-annotations + ${swagger.version} + + + + net.oschina.durcframework + easyopen + ${easyopen.version} + + + + net.oschina.durcframework + easyopen-spring-boot-starter + ${easyopen.version} + + + + javax.validation + validation-api + ${validation-api.version} + + + org.hibernate + hibernate-validator + ${hibernate-validator.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + commons-collections + commons-collections + ${commons-collection.version} + + + commons-io + commons-io + ${commons-io.version} + + + commons-codec + commons-codec + ${commons-codec.version} + + + commons-fileupload + commons-fileupload + ${commons-fileupload.version} + + + commons-logging + commons-logging + ${commons-logging.version} + + + + org.projectlombok + lombok + 1.18.4 + + + javax.servlet + javax.servlet-api + 3.1.0 + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${java.version} + ${java.version} + UTF-8 + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + \ No newline at end of file diff --git a/sop-admin/pom.xml b/sop-admin/pom.xml index bf55daf0..43d110ba 100644 --- a/sop-admin/pom.xml +++ b/sop-admin/pom.xml @@ -2,8 +2,15 @@ + + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml + + 4.0.0 - com.gitee.sop sop-admin 1.0.0-SNAPSHOT pom diff --git a/sop-admin/sop-admin-server/pom.xml b/sop-admin/sop-admin-server/pom.xml index bcd2e93e..00ca5cd8 100644 --- a/sop-admin/sop-admin-server/pom.xml +++ b/sop-admin/sop-admin-server/pom.xml @@ -1,60 +1,45 @@ + + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 - com.gitee.sop sop-admin-server 1.0.0-SNAPSHOT jar - sop-admin-server - sop-admin-server - - - org.springframework.boot - spring-boot-starter-parent - 2.1.4.RELEASE - - - + 1.8 UTF-8 UTF-8 - 1.8 - 3.11.0 - - 0.2.3 - com.alibaba.boot - nacos-config-spring-boot-starter - ${nacos-spring-boot-starter.version} - - - com.alibaba.boot - nacos-discovery-spring-boot-starter - ${nacos-spring-boot-starter.version} + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery net.oschina.durcframework easyopen-spring-boot-starter - 1.16.6.1 net.oschina.durcframework fastmybatis-spring-boot-starter - 1.8.6.1 com.squareup.okhttp3 okhttp - ${okhttp.version} @@ -67,6 +52,7 @@ org.springframework.boot spring-boot-starter-web + org.springframework.boot spring-boot-starter-thymeleaf diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java index e388660d..52bf77ac 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java @@ -2,7 +2,9 @@ package com.gitee.sop.adminserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +@EnableDiscoveryClient @SpringBootApplication public class SopAdminServerApplication { diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigServiceRoute.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigServiceRoute.java index 0234fb21..30b817af 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigServiceRoute.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigServiceRoute.java @@ -46,8 +46,8 @@ public class ConfigServiceRoute { /** uri后面跟的path, 数据库字段:path */ private String path; - /** 路由执行的顺序, 数据库字段:order */ - private Integer order; + /** 路由执行的顺序, 数据库字段:order_index */ + private Integer orderIndex; /** 是否忽略验证,业务参数验证除外, 数据库字段:ignore_validate */ private Byte ignoreValidate; diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/ServerService.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/ServerService.java index 4949567e..4880084f 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/ServerService.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/ServerService.java @@ -1,9 +1,12 @@ package com.gitee.sop.adminserver.service; +import com.gitee.fastmybatis.core.query.Query; import com.gitee.sop.adminserver.api.service.param.ServiceSearchParam; import com.gitee.sop.adminserver.api.service.result.ServiceInstanceVO; import com.gitee.sop.adminserver.bean.ServiceInfo; import com.gitee.sop.adminserver.bean.ServiceInstance; +import com.gitee.sop.adminserver.entity.ConfigGrayInstance; +import com.gitee.sop.adminserver.mapper.ConfigGrayInstanceMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; @@ -12,8 +15,12 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @author tanghc @@ -22,9 +29,13 @@ import java.util.concurrent.atomic.AtomicInteger; @Service public class ServerService { + public static final int GRAY_OPEN = 1; @Autowired private RegistryService registryService; + @Autowired + private ConfigGrayInstanceMapper grayInstanceMapper; + public List listService(ServiceSearchParam param) { List serviceInfos; try { @@ -33,6 +44,10 @@ public class ServerService { log.error("获取服务实例失败", e); return Collections.emptyList(); } + List configGrayInstances = grayInstanceMapper.list(new Query()); + // key: instanceId + Map grayInstanceMap = configGrayInstances.stream() + .collect(Collectors.toMap(ConfigGrayInstance::getInstanceId, Function.identity())); List serviceInfoVoList = new ArrayList<>(); AtomicInteger idGen = new AtomicInteger(1); serviceInfos.stream() @@ -58,12 +73,22 @@ public class ServerService { instanceVO.setId(id); instanceVO.setParentId(pid); if (instanceVO.getMetadata() == null) { - instanceVO.setMetadata(Collections.emptyMap()); + instanceVO.setMetadata(new HashMap<>(8)); } + bindGrayEnv(instanceVO, grayInstanceMap); serviceInfoVoList.add(instanceVO); } }); return serviceInfoVoList; } + + private void bindGrayEnv(ServiceInstanceVO instanceVO, Map grayInstanceMap) { + String instanceId = instanceVO.getInstanceId(); + ConfigGrayInstance configGrayInstance = grayInstanceMap.get(instanceId); + if (configGrayInstance != null && configGrayInstance.getStatus() == GRAY_OPEN) { + Map metadata = instanceVO.getMetadata(); + metadata.put("env", "gray"); + } + } } diff --git a/sop-admin/sop-admin-server/src/main/resources/public/index.html b/sop-admin/sop-admin-server/src/main/resources/public/index.html index 69e80a53..9375a706 100644 --- a/sop-admin/sop-admin-server/src/main/resources/public/index.html +++ b/sop-admin/sop-admin-server/src/main/resources/public/index.html @@ -1 +1 @@ -SOP Admin
\ No newline at end of file +SOP Admin
\ No newline at end of file diff --git a/sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9f479afe.4609bf8b.js b/sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9f479afe.4609bf8b.js new file mode 100644 index 00000000..eb8f7b8d --- /dev/null +++ b/sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9f479afe.4609bf8b.js @@ -0,0 +1 @@ +(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-9f479afe"],{"02f4":function(e,t,n){var r=n("4588"),o=n("be13");e.exports=function(e){return function(t,n){var i,a,s=String(o(t)),l=r(n),c=s.length;return l<0||l>=c?e?"":void 0:(i=s.charCodeAt(l),i<55296||i>56319||l+1===c||(a=s.charCodeAt(l+1))<56320||a>57343?e?s.charAt(l):i:e?s.slice(l,l+2):a-56320+(i-55296<<10)+65536)}}},"0390":function(e,t,n){"use strict";var r=n("02f4")(!0);e.exports=function(e,t,n){return t+(n?r(e,t).length:1)}},"0bfb":function(e,t,n){"use strict";var r=n("cb7c");e.exports=function(){var e=r(this),t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.unicode&&(t+="u"),e.sticky&&(t+="y"),t}},"214f":function(e,t,n){"use strict";n("b0c5");var r=n("2aba"),o=n("32e9"),i=n("79e5"),a=n("be13"),s=n("2b4c"),l=n("520a"),c=s("species"),u=!i(function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$")}),f=function(){var e=/(?:)/,t=e.exec;e.exec=function(){return t.apply(this,arguments)};var n="ab".split(e);return 2===n.length&&"a"===n[0]&&"b"===n[1]}();e.exports=function(e,t,n){var d=s(e),v=!i(function(){var t={};return t[d]=function(){return 7},7!=""[e](t)}),p=v?!i(function(){var t=!1,n=/a/;return n.exec=function(){return t=!0,null},"split"===e&&(n.constructor={},n.constructor[c]=function(){return n}),n[d](""),!t}):void 0;if(!v||!p||"replace"===e&&!u||"split"===e&&!f){var g=/./[d],y=n(a,d,""[e],function(e,t,n,r,o){return t.exec===l?v&&!o?{done:!0,value:g.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}),h=y[0],m=y[1];r(String.prototype,e,h),o(RegExp.prototype,d,2==t?function(e,t){return m.call(e,this,t)}:function(e){return m.call(e,this)})}}},"28a5":function(e,t,n){"use strict";var r=n("aae3"),o=n("cb7c"),i=n("ebd6"),a=n("0390"),s=n("9def"),l=n("5f1b"),c=n("520a"),u=n("79e5"),f=Math.min,d=[].push,v="split",p="length",g="lastIndex",y=4294967295,h=!u(function(){RegExp(y,"y")});n("214f")("split",2,function(e,t,n,u){var m;return m="c"=="abbc"[v](/(b)*/)[1]||4!="test"[v](/(?:)/,-1)[p]||2!="ab"[v](/(?:ab)*/)[p]||4!="."[v](/(.?)(.?)/)[p]||"."[v](/()()/)[p]>1||""[v](/.?/)[p]?function(e,t){var o=String(this);if(void 0===e&&0===t)return[];if(!r(e))return n.call(o,e,t);var i,a,s,l=[],u=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),f=0,v=void 0===t?y:t>>>0,h=new RegExp(e.source,u+"g");while(i=c.call(h,o)){if(a=h[g],a>f&&(l.push(o.slice(f,i.index)),i[p]>1&&i.index=v))break;h[g]===i.index&&h[g]++}return f===o[p]?!s&&h.test("")||l.push(""):l.push(o.slice(f)),l[p]>v?l.slice(0,v):l}:"0"[v](void 0,0)[p]?function(e,t){return void 0===e&&0===t?[]:n.call(this,e,t)}:n,[function(n,r){var o=e(this),i=void 0==n?void 0:n[t];return void 0!==i?i.call(n,o,r):m.call(String(o),n,r)},function(e,t){var r=u(m,e,this,t,m!==n);if(r.done)return r.value;var c=o(e),d=String(this),v=i(c,RegExp),p=c.unicode,g=(c.ignoreCase?"i":"")+(c.multiline?"m":"")+(c.unicode?"u":"")+(h?"y":"g"),b=new v(h?c:"^(?:"+c.source+")",g),_=void 0===t?y:t>>>0;if(0===_)return[];if(0===d.length)return null===l(b,d)?[d]:[];var w=0,x=0,I=[];while(x1&&i.call(a[0],n,function(){for(u=1;u0&&"pre"===t.row.metadata.env?n("el-tag",{attrs:{type:"warning"}},[e._v("预发布")]):e._e(),e._v(" "),t.row.parentId>0&&"gray"===t.row.metadata.env?n("el-tag",{attrs:{type:"info"}},[e._v("灰度")]):e._e(),e._v(" "),t.row.parentId>0&&!t.row.metadata.env?n("el-tag",{attrs:{type:"success"}},[e._v("线上")]):e._e()],1):e._e()]}}])}),e._v(" "),n("el-table-column",{attrs:{prop:"metadata",label:"metadata",width:"250"},scopedSlots:e._u([{key:"default",fn:function(t){return[t.row.parentId>0?n("span",[e._v(e._s(JSON.stringify(t.row.metadata)))]):e._e()]}}])}),e._v(" "),n("el-table-column",{attrs:{prop:"status",label:"服务状态",width:"100"},scopedSlots:e._u([{key:"default",fn:function(t){return[t.row.parentId>0&&"UP"===t.row.status?n("el-tag",{attrs:{type:"success"}},[e._v("正常")]):e._e(),e._v(" "),t.row.parentId>0&&"STARTING"===t.row.status?n("el-tag",{attrs:{type:"info"}},[e._v("正在启动")]):e._e(),e._v(" "),t.row.parentId>0&&"UNKNOWN"===t.row.status?n("el-tag",[e._v("未知")]):e._e(),e._v(" "),t.row.parentId>0&&("OUT_OF_SERVICE"===t.row.status||"DOWN"===t.row.status)?n("el-tag",{attrs:{type:"danger"}},[e._v("已禁用")]):e._e()]}}])}),e._v(" "),n("el-table-column",{attrs:{label:"操作",width:"250"},scopedSlots:e._u([{key:"default",fn:function(t){return[e.blackList.indexOf(t.row.serviceId.toLowerCase())<0?n("div",[0===t.row.parentId?n("div",[n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onGrayConfigUpdate(t.row)}}},[e._v("设置灰度参数")])],1):e._e(),e._v(" "),t.row.parentId>0?n("div",["UP"===t.row.status?n("span",["pre"===t.row.metadata.env?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvPreClose(t.row)}}},[e._v("结束预发布")]):e._e(),e._v(" "),"gray"===t.row.metadata.env?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvGrayClose(t.row)}}},[e._v("结束灰度")]):e._e(),e._v(" "),t.row.metadata.env?e._e():n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvPreOpen(t.row)}}},[e._v("开启预发布")]),e._v(" "),t.row.metadata.env?e._e():n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvGrayOpen(t.row)}}},[e._v("开启灰度")])],1):e._e(),e._v(" "),n("span",{staticStyle:{"margin-left":"10px"}},["UP"===t.row.status?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onDisable(t.row)}}},[e._v("禁用")]):e._e(),e._v(" "),"OUT_OF_SERVICE"===t.row.status?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnable(t.row)}}},[e._v("启用")]):e._e()],1)]):e._e()]):e._e()]}}])})],1),e._v(" "),n("el-dialog",{attrs:{title:"灰度设置",visible:e.grayDialogVisible,"close-on-click-modal":!1},on:{"update:visible":function(t){e.grayDialogVisible=t},close:function(t){return e.resetForm("grayForm")}}},[n("el-form",{ref:"grayForm",attrs:{model:e.grayForm,rules:e.grayFormRules,size:"mini"}},[n("el-form-item",{attrs:{label:"serviceId"}},[e._v("\n "+e._s(e.grayForm.serviceId)+"\n ")]),e._v(" "),n("el-tabs",{attrs:{type:"card"},model:{value:e.tabsActiveName,callback:function(t){e.tabsActiveName=t},expression:"tabsActiveName"}},[n("el-tab-pane",{attrs:{label:"灰度用户",name:"first"}},[n("el-alert",{staticStyle:{"margin-bottom":"20px"},attrs:{title:"可以是appId或IP地址,多个用英文逗号隔开",type:"info",closable:!1}}),e._v(" "),n("el-form-item",{attrs:{prop:"userKeyContent"}},[n("el-input",{attrs:{placeholder:"可以是appId或IP地址,多个用英文逗号隔开",type:"textarea",rows:6},model:{value:e.grayForm.userKeyContent,callback:function(t){e.$set(e.grayForm,"userKeyContent",t)},expression:"grayForm.userKeyContent"}})],1)],1),e._v(" "),n("el-tab-pane",{attrs:{label:"接口配置",name:"second"}},[n("el-form-item",[n("el-button",{attrs:{type:"text"},on:{click:e.addNameVersion}},[e._v("新增灰度接口")])],1),e._v(" "),n("table",{attrs:{cellpadding:"0",cellspacing:"0"}},e._l(e.grayForm.grayRouteConfigList,function(t,r){return n("tr",{key:t.key},[n("td",[n("el-form-item",{key:t.key,attrs:{prop:"grayRouteConfigList."+r+".oldRouteId",rules:{required:!0,message:"不能为空",trigger:["blur","change"]}}},[e._v("\n 老接口:\n "),n("el-select",{staticStyle:{"margin-right":"10px"},on:{change:function(n){return e.onChangeOldRoute(t)}},model:{value:t.oldRouteId,callback:function(n){e.$set(t,"oldRouteId",n)},expression:"grayRouteConfig.oldRouteId"}},e._l(e.routeList,function(e){return n("el-option",{key:e.id,attrs:{label:e.name+"("+e.version+")",value:e.id}})}),1)],1)],1),e._v(" "),n("td",[n("el-form-item",{key:t.key+1,attrs:{prop:"grayRouteConfigList."+r+".newVersion",rules:{required:!0,message:"不能为空",trigger:["blur","change"]}}},[e._v("\n 灰度接口:\n "),n("el-select",{attrs:{"no-data-text":"无数据"},model:{value:t.newVersion,callback:function(n){e.$set(t,"newVersion",n)},expression:"grayRouteConfig.newVersion"}},e._l(e.getGraySelectData(t.oldRouteId),function(e){return n("el-option",{key:e.id,attrs:{label:e.name+"("+e.version+")",value:e.version}})}),1)],1)],1),e._v(" "),n("td",{staticStyle:{"vertical-align":"baseline"}},[n("el-button",{directives:[{name:"show",rawName:"v-show",value:e.grayForm.grayRouteConfigList.length>1,expression:"grayForm.grayRouteConfigList.length > 1"}],attrs:{type:"text"},on:{click:function(n){return n.preventDefault(),e.removeNameVersion(t)}}},[e._v("删除")])],1)])}),0)],1)],1)],1),e._v(" "),n("span",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[n("el-button",{on:{click:function(t){e.grayDialogVisible=!1}}},[e._v("取 消")]),e._v(" "),n("el-button",{attrs:{type:"primary"},on:{click:e.onGrayConfigSave}},[e._v("确 定")])],1)],1)],1)},o=[],i=(n("28a5"),n("ac6a"),n("7f7f"),{data:function(){var e=/^\S+(,\S+)*$/,t=function(t,n,r){""===n?r(new Error("不能为空")):(e.test(n)||r(new Error("格式不正确")),r())};return{searchFormData:{serviceId:""},blackList:["sop-gateway","sop-admin"],grayDialogVisible:!1,grayForm:{serviceId:"",userKeyContent:"",onlyUpdateGrayUserkey:!1,grayRouteConfigList:[]},tabsActiveName:"first",routeList:[],selectNameVersion:[],grayFormRules:{userKeyContent:[{required:!0,message:"不能为空",trigger:"blur"},{validator:t,trigger:"blur"}]},tableData:[]}},created:function(){this.loadTable()},methods:{loadTable:function(){this.post("service.instance.list",this.searchFormData,function(e){this.tableData=this.buildTreeData(e.data)})},loadRouteList:function(e){this.post("route.list/1.2",{serviceId:e.toLowerCase()},function(e){this.routeList=e.data})},getGraySelectData:function(e){return this.routeList.filter(function(t){return e!==t.id&&e.indexOf(t.name)>-1})},buildTreeData:function(e){return e.forEach(function(t){var n=t.parentId;0===n||e.forEach(function(e){if(e.id===n){var r=e.children;r||(r=[]),r.push(t),e.children=r}})}),e=e.filter(function(e){return 0===e.parentId}),e},onSearchTable:function(){this.loadTable()},onDisable:function(e){this.confirm("确定要禁用 ".concat(e.serviceId,"(").concat(e.ipPort,") 吗?"),function(t){this.post("service.instance.offline",e,function(){this.tip("禁用成功"),t(),this.loadTableDelay()})})},onEnable:function(e){this.confirm("确定要启用 ".concat(e.serviceId,"(").concat(e.ipPort,") 吗?"),function(t){this.post("service.instance.online",e,function(){this.tip("启用成功"),t(),this.loadTableDelay()})})},doEnvOnline:function(e,t){this.post("service.instance.env.online",e,function(){t&&t.call(this)})},onEnvPreOpen:function(e){this.confirm("确定要开启 ".concat(e.serviceId,"(").concat(e.ipPort,") 预发布吗?"),function(t){this.post("service.instance.env.pre.open",e,function(){this.tip("预发布成功"),t(),this.loadTableDelay()})})},onEnvPreClose:function(e){this.confirm("确定要结束 ".concat(e.serviceId,"(").concat(e.ipPort,") 预发布吗?"),function(t){this.doEnvOnline(e,function(){this.tip("操作成功"),t(),this.loadTableDelay()})})},onEnvGrayOpen:function(e){this.confirm("确定要开启 ".concat(e.serviceId,"(").concat(e.ipPort,") 灰度吗?"),function(t){this.post("service.instance.env.gray.open",e,function(){this.tip("开启成功"),t(),this.loadTableDelay()})})},onEnvGrayClose:function(e){this.confirm("确定要结束 ".concat(e.serviceId,"(").concat(e.ipPort,") 灰度吗?"),function(t){this.doEnvOnline(e,function(){this.tip("操作成功"),t(),this.loadTableDelay()})})},onGrayConfigUpdate:function(e){var t=e.serviceId;this.loadRouteList(t),this.post("service.gray.config.get",{serviceId:t},function(e){var n=this;this.grayDialogVisible=!0,this.$nextTick(function(){var r=e.data;Object.assign(n.grayForm,{serviceId:t,userKeyContent:r.userKeyContent||"",grayRouteConfigList:n.createGrayRouteConfigList(r.nameVersionContent)})})})},onGrayConfigSave:function(){var e=this;this.$refs.grayForm.validate(function(t){if(t){for(var n=[],r=e.grayForm.grayRouteConfigList,o=0;o=c?e?"":void 0:(i=s.charCodeAt(l),i<55296||i>56319||l+1===c||(a=s.charCodeAt(l+1))<56320||a>57343?e?s.charAt(l):i:e?s.slice(l,l+2):a-56320+(i-55296<<10)+65536)}}},"0390":function(e,t,n){"use strict";var r=n("02f4")(!0);e.exports=function(e,t,n){return t+(n?r(e,t).length:1)}},"0bfb":function(e,t,n){"use strict";var r=n("cb7c");e.exports=function(){var e=r(this),t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.unicode&&(t+="u"),e.sticky&&(t+="y"),t}},"214f":function(e,t,n){"use strict";n("b0c5");var r=n("2aba"),o=n("32e9"),i=n("79e5"),a=n("be13"),s=n("2b4c"),l=n("520a"),c=s("species"),u=!i(function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$")}),f=function(){var e=/(?:)/,t=e.exec;e.exec=function(){return t.apply(this,arguments)};var n="ab".split(e);return 2===n.length&&"a"===n[0]&&"b"===n[1]}();e.exports=function(e,t,n){var d=s(e),v=!i(function(){var t={};return t[d]=function(){return 7},7!=""[e](t)}),p=v?!i(function(){var t=!1,n=/a/;return n.exec=function(){return t=!0,null},"split"===e&&(n.constructor={},n.constructor[c]=function(){return n}),n[d](""),!t}):void 0;if(!v||!p||"replace"===e&&!u||"split"===e&&!f){var g=/./[d],y=n(a,d,""[e],function(e,t,n,r,o){return t.exec===l?v&&!o?{done:!0,value:g.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}),h=y[0],m=y[1];r(String.prototype,e,h),o(RegExp.prototype,d,2==t?function(e,t){return m.call(e,this,t)}:function(e){return m.call(e,this)})}}},"28a5":function(e,t,n){"use strict";var r=n("aae3"),o=n("cb7c"),i=n("ebd6"),a=n("0390"),s=n("9def"),l=n("5f1b"),c=n("520a"),u=n("79e5"),f=Math.min,d=[].push,v="split",p="length",g="lastIndex",y=4294967295,h=!u(function(){RegExp(y,"y")});n("214f")("split",2,function(e,t,n,u){var m;return m="c"=="abbc"[v](/(b)*/)[1]||4!="test"[v](/(?:)/,-1)[p]||2!="ab"[v](/(?:ab)*/)[p]||4!="."[v](/(.?)(.?)/)[p]||"."[v](/()()/)[p]>1||""[v](/.?/)[p]?function(e,t){var o=String(this);if(void 0===e&&0===t)return[];if(!r(e))return n.call(o,e,t);var i,a,s,l=[],u=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),f=0,v=void 0===t?y:t>>>0,h=new RegExp(e.source,u+"g");while(i=c.call(h,o)){if(a=h[g],a>f&&(l.push(o.slice(f,i.index)),i[p]>1&&i.index=v))break;h[g]===i.index&&h[g]++}return f===o[p]?!s&&h.test("")||l.push(""):l.push(o.slice(f)),l[p]>v?l.slice(0,v):l}:"0"[v](void 0,0)[p]?function(e,t){return void 0===e&&0===t?[]:n.call(this,e,t)}:n,[function(n,r){var o=e(this),i=void 0==n?void 0:n[t];return void 0!==i?i.call(n,o,r):m.call(String(o),n,r)},function(e,t){var r=u(m,e,this,t,m!==n);if(r.done)return r.value;var c=o(e),d=String(this),v=i(c,RegExp),p=c.unicode,g=(c.ignoreCase?"i":"")+(c.multiline?"m":"")+(c.unicode?"u":"")+(h?"y":"g"),b=new v(h?c:"^(?:"+c.source+")",g),_=void 0===t?y:t>>>0;if(0===_)return[];if(0===d.length)return null===l(b,d)?[d]:[];var w=0,x=0,I=[];while(x1&&i.call(a[0],n,function(){for(u=1;u0&&"pre"===t.row.metadata.env?n("el-tag",{attrs:{type:"warning"}},[e._v("预发布")]):e._e(),e._v(" "),t.row.parentId>0&&"gray"===t.row.metadata.env?n("el-tag",{attrs:{type:"info"}},[e._v("灰度")]):e._e(),e._v(" "),t.row.parentId>0&&!t.row.metadata.env?n("el-tag",{attrs:{type:"success"}},[e._v("线上")]):e._e()],1):e._e()]}}])}),e._v(" "),n("el-table-column",{attrs:{prop:"metadata",label:"metadata",width:"250"},scopedSlots:e._u([{key:"default",fn:function(t){return[t.row.parentId>0?n("span",[e._v(e._s(JSON.stringify(t.row.metadata)))]):e._e()]}}])}),e._v(" "),n("el-table-column",{attrs:{prop:"status",label:"服务状态",width:"100"},scopedSlots:e._u([{key:"default",fn:function(t){return[t.row.parentId>0&&"UP"===t.row.status?n("el-tag",{attrs:{type:"success"}},[e._v("正常")]):e._e(),e._v(" "),t.row.parentId>0&&"STARTING"===t.row.status?n("el-tag",{attrs:{type:"info"}},[e._v("正在启动")]):e._e(),e._v(" "),t.row.parentId>0&&"UNKNOWN"===t.row.status?n("el-tag",[e._v("未知")]):e._e(),e._v(" "),t.row.parentId>0&&("OUT_OF_SERVICE"===t.row.status||"DOWN"===t.row.status)?n("el-tag",{attrs:{type:"danger"}},[e._v("已禁用")]):e._e()]}}])}),e._v(" "),n("el-table-column",{attrs:{label:"操作",width:"250"},scopedSlots:e._u([{key:"default",fn:function(t){return["sop-gateway"!==t.row.serviceId.toLowerCase()?n("div",[0===t.row.parentId?n("div",[n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onGrayConfigUpdate(t.row)}}},[e._v("设置灰度参数")])],1):e._e(),e._v(" "),t.row.parentId>0?n("div",["UP"===t.row.status?n("span",["pre"===t.row.metadata.env?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvPreClose(t.row)}}},[e._v("结束预发布")]):e._e(),e._v(" "),"gray"===t.row.metadata.env?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvGrayClose(t.row)}}},[e._v("结束灰度")]):e._e(),e._v(" "),t.row.metadata.env?e._e():n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvPreOpen(t.row)}}},[e._v("开启预发布")]),e._v(" "),t.row.metadata.env?e._e():n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnvGrayOpen(t.row)}}},[e._v("开启灰度")])],1):e._e(),e._v(" "),n("span",{staticStyle:{"margin-left":"10px"}},["UP"===t.row.status?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onDisable(t.row)}}},[e._v("禁用")]):e._e(),e._v(" "),"OUT_OF_SERVICE"===t.row.status?n("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(n){return e.onEnable(t.row)}}},[e._v("启用")]):e._e()],1)]):e._e()]):e._e()]}}])})],1),e._v(" "),n("el-dialog",{attrs:{title:"灰度设置",visible:e.grayDialogVisible,"close-on-click-modal":!1},on:{"update:visible":function(t){e.grayDialogVisible=t},close:function(t){return e.resetForm("grayForm")}}},[n("el-form",{ref:"grayForm",attrs:{model:e.grayForm,rules:e.grayFormRules,size:"mini"}},[n("el-form-item",{attrs:{label:"serviceId"}},[e._v("\n "+e._s(e.grayForm.serviceId)+"\n ")]),e._v(" "),n("el-tabs",{attrs:{type:"card"},model:{value:e.tabsActiveName,callback:function(t){e.tabsActiveName=t},expression:"tabsActiveName"}},[n("el-tab-pane",{attrs:{label:"灰度用户",name:"first"}},[n("el-alert",{staticStyle:{"margin-bottom":"20px"},attrs:{title:"可以是appId或IP地址,多个用英文逗号隔开",type:"info",closable:!1}}),e._v(" "),n("el-form-item",{attrs:{prop:"userKeyContent"}},[n("el-input",{attrs:{placeholder:"可以是appId或IP地址,多个用英文逗号隔开",type:"textarea",rows:6},model:{value:e.grayForm.userKeyContent,callback:function(t){e.$set(e.grayForm,"userKeyContent",t)},expression:"grayForm.userKeyContent"}})],1)],1),e._v(" "),n("el-tab-pane",{attrs:{label:"接口配置",name:"second"}},[n("el-form-item",[n("el-button",{attrs:{type:"text"},on:{click:e.addNameVersion}},[e._v("新增灰度接口")])],1),e._v(" "),n("table",{attrs:{cellpadding:"0",cellspacing:"0"}},e._l(e.grayForm.grayRouteConfigList,function(t,r){return n("tr",{key:t.key},[n("td",[n("el-form-item",{key:t.key,attrs:{prop:"grayRouteConfigList."+r+".oldRouteId",rules:{required:!0,message:"不能为空",trigger:["blur","change"]}}},[e._v("\n 老接口:\n "),n("el-select",{staticStyle:{"margin-right":"10px"},on:{change:function(n){return e.onChangeOldRoute(t)}},model:{value:t.oldRouteId,callback:function(n){e.$set(t,"oldRouteId",n)},expression:"grayRouteConfig.oldRouteId"}},e._l(e.routeList,function(e){return n("el-option",{key:e.id,attrs:{label:e.name+"("+e.version+")",value:e.id}})}),1)],1)],1),e._v(" "),n("td",[n("el-form-item",{key:t.key+1,attrs:{prop:"grayRouteConfigList."+r+".newVersion",rules:{required:!0,message:"不能为空",trigger:["blur","change"]}}},[e._v("\n 灰度接口:\n "),n("el-select",{attrs:{"no-data-text":"无数据"},model:{value:t.newVersion,callback:function(n){e.$set(t,"newVersion",n)},expression:"grayRouteConfig.newVersion"}},e._l(e.getGraySelectData(t.oldRouteId),function(e){return n("el-option",{key:e.id,attrs:{label:e.name+"("+e.version+")",value:e.version}})}),1)],1)],1),e._v(" "),n("td",{staticStyle:{"vertical-align":"baseline"}},[n("el-button",{directives:[{name:"show",rawName:"v-show",value:e.grayForm.grayRouteConfigList.length>1,expression:"grayForm.grayRouteConfigList.length > 1"}],attrs:{type:"text"},on:{click:function(n){return n.preventDefault(),e.removeNameVersion(t)}}},[e._v("删除")])],1)])}),0)],1)],1)],1),e._v(" "),n("span",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[n("el-button",{on:{click:function(t){e.grayDialogVisible=!1}}},[e._v("取 消")]),e._v(" "),n("el-button",{attrs:{type:"primary"},on:{click:e.onGrayConfigSave}},[e._v("确 定")])],1)],1)],1)},o=[],i=(n("28a5"),n("ac6a"),n("7f7f"),{data:function(){var e=/^\S+(,\S+)*$/,t=function(t,n,r){""===n?r(new Error("不能为空")):(e.test(n)||r(new Error("格式不正确")),r())};return{searchFormData:{serviceId:""},grayDialogVisible:!1,grayForm:{serviceId:"",userKeyContent:"",onlyUpdateGrayUserkey:!1,grayRouteConfigList:[]},tabsActiveName:"first",routeList:[],selectNameVersion:[],grayFormRules:{userKeyContent:[{required:!0,message:"不能为空",trigger:"blur"},{validator:t,trigger:"blur"}]},tableData:[]}},created:function(){this.loadTable()},methods:{loadTable:function(){this.post("service.instance.list",this.searchFormData,function(e){this.tableData=this.buildTreeData(e.data)})},loadRouteList:function(e){this.post("route.list/1.2",{serviceId:e.toLowerCase()},function(e){this.routeList=e.data})},getGraySelectData:function(e){return this.routeList.filter(function(t){return e!==t.id&&e.indexOf(t.name)>-1})},buildTreeData:function(e){return e.forEach(function(t){var n=t.parentId;0===n||e.forEach(function(e){if(e.id===n){var r=e.children;r||(r=[]),r.push(t),e.children=r}})}),e=e.filter(function(e){return 0===e.parentId}),e},onSearchTable:function(){this.loadTable()},onDisable:function(e){this.confirm("确定要禁用 ".concat(e.serviceId,"(").concat(e.ipPort,") 吗?"),function(t){this.post("service.instance.offline",e,function(){this.tip("禁用成功"),t(),this.loadTableDelay()})})},onEnable:function(e){this.confirm("确定要启用 ".concat(e.serviceId,"(").concat(e.ipPort,") 吗?"),function(t){this.post("service.instance.online",e,function(){this.tip("启用成功"),t(),this.loadTableDelay()})})},doEnvOnline:function(e,t){this.post("service.instance.env.online",e,function(){t&&t.call(this)})},onEnvPreOpen:function(e){this.confirm("确定要开启 ".concat(e.serviceId,"(").concat(e.ipPort,") 预发布吗?"),function(t){this.post("service.instance.env.pre.open",e,function(){this.tip("预发布成功"),t(),this.loadTableDelay()})})},onEnvPreClose:function(e){this.confirm("确定要结束 ".concat(e.serviceId,"(").concat(e.ipPort,") 预发布吗?"),function(t){this.doEnvOnline(e,function(){this.tip("操作成功"),t(),this.loadTableDelay()})})},onEnvGrayOpen:function(e){this.confirm("确定要开启 ".concat(e.serviceId,"(").concat(e.ipPort,") 灰度吗?"),function(t){this.post("service.instance.env.gray.open",e,function(){this.tip("开启成功"),t(),this.loadTableDelay()})})},onEnvGrayClose:function(e){this.confirm("确定要结束 ".concat(e.serviceId,"(").concat(e.ipPort,") 灰度吗?"),function(t){this.doEnvOnline(e,function(){this.tip("操作成功"),t(),this.loadTableDelay()})})},onGrayConfigUpdate:function(e){var t=e.serviceId;this.loadRouteList(t),this.post("service.gray.config.get",{serviceId:t},function(e){var n=this;this.grayDialogVisible=!0,this.$nextTick(function(){var r=e.data;Object.assign(n.grayForm,{serviceId:t,userKeyContent:r.userKeyContent||"",grayRouteConfigList:n.createGrayRouteConfigList(r.nameVersionContent)})})})},onGrayConfigSave:function(){var e=this;this.$refs.grayForm.validate(function(t){if(t){for(var n=[],r=e.grayForm.grayRouteConfigList,o=0;o @@ -204,6 +204,7 @@ export default { searchFormData: { serviceId: '' }, + blackList: ['sop-gateway', 'sop-admin'], grayDialogVisible: false, grayForm: { serviceId: '', diff --git a/sop-auth/pom.xml b/sop-auth/pom.xml index fcd794dc..09f02e60 100644 --- a/sop-auth/pom.xml +++ b/sop-auth/pom.xml @@ -1,22 +1,21 @@ - 4.0.0 + - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml - com.gitee.sop + + 4.0.0 sop-auth - 1.0.0-SNAPSHOT sop-auth 授权程序 1.8 - Greenwich.RELEASE 0.31 @@ -26,35 +25,14 @@ com.gitee.sop sop-service-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT - - org.springframework.cloud + com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery - 0.2.2.RELEASE - - - com.alibaba.nacos - nacos-client - - - - - com.alibaba.nacos - nacos-client - 1.1.0 - - --> - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client @@ -72,7 +50,6 @@ net.oschina.durcframework fastmybatis-spring-boot-starter - 1.7.1 mysql @@ -123,18 +100,6 @@
- - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - diff --git a/sop-auth/src/main/java/com/gitee/sop/sopauth/auth/impl/OAuth2ManagerRedis.java b/sop-auth/src/main/java/com/gitee/sop/sopauth/auth/impl/OAuth2ManagerRedis.java index 3cabfd59..4acfac37 100644 --- a/sop-auth/src/main/java/com/gitee/sop/sopauth/auth/impl/OAuth2ManagerRedis.java +++ b/sop-auth/src/main/java/com/gitee/sop/sopauth/auth/impl/OAuth2ManagerRedis.java @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; * oauth2管理redis实现,这个类跟OAuth2ManagerCache类只能用一个, * 如果要用这个类, * 1、注释掉OAuth2ManagerCache的@Service。 - * 2、打开yml中redis部分 + * 2、在properties中配置redis * 3、启用这个类的@Service * * @author tanghc diff --git a/sop-common/pom.xml b/sop-common/pom.xml index db936343..00e5bfdd 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -2,35 +2,21 @@ + + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml + + 4.0.0 - com.gitee.sop sop-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT pom 1.8 - UTF-8 - 1.8 - 1.8 - Greenwich.RELEASE - 2.1.2.RELEASE - - 1.0.13 - 1.7.5 - - - 4.11 - - 1.2.62 - 2.5 - 1.3.3 - 3.2.2 - 3.8.1 - 1.11 - 2.0.1.Final - 6.0.13.Final - 0.9.0.RELEASE @@ -40,149 +26,5 @@ sop-bridge-gateway - - - - - org.springframework.boot - spring-boot-dependencies - ${spring-boot.version} - pom - import - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - org.springframework.cloud - spring-cloud-alibaba-nacos-discovery - ${spring-cloud-alibaba-nacos.version} - pom - import - - - org.springframework.cloud - spring-cloud-alibaba-nacos-config - ${spring-cloud-alibaba-nacos.version} - pom - import - - - - - - - - com.alibaba - fastjson - ${fastjson.version} - - - - javax.validation - validation-api - ${validation-api.version} - - - org.hibernate - hibernate-validator - ${hibernate-validator.version} - - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - commons-collections - commons-collections - ${commons-collection.version} - - - commons-io - commons-io - ${commons-io.version} - - - - - org.springframework.data - spring-data-redis - 2.1.4.RELEASE - true - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - - org.projectlombok - lombok - 1.18.4 - provided - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - true - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - UTF-8 - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - \ No newline at end of file diff --git a/sop-common/sop-bridge-gateway/pom.xml b/sop-common/sop-bridge-gateway/pom.xml index 61a4ab53..89b05e72 100644 --- a/sop-common/sop-bridge-gateway/pom.xml +++ b/sop-common/sop-bridge-gateway/pom.xml @@ -3,13 +3,13 @@ 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"> - sop-common com.gitee.sop - 3.1.5-SNAPSHOT - ../pom.xml + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml 4.0.0 - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT sop-bridge-gateway @@ -17,7 +17,7 @@ com.gitee.sop sop-gateway-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT diff --git a/sop-common/sop-bridge-zuul/pom.xml b/sop-common/sop-bridge-zuul/pom.xml index 7ef13041..58ba3568 100644 --- a/sop-common/sop-bridge-zuul/pom.xml +++ b/sop-common/sop-bridge-zuul/pom.xml @@ -3,13 +3,14 @@ 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"> - sop-common com.gitee.sop - 3.1.5-SNAPSHOT - ../pom.xml + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + 4.0.0 - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT sop-bridge-zuul @@ -17,7 +18,7 @@ com.gitee.sop sop-gateway-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index 8b7535ee..d231e93b 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -1,20 +1,19 @@ - 4.0.0 + com.gitee.sop - sop-common - 3.1.5-SNAPSHOT - ../pom.xml + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 sop-gateway-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT jar - sop-gateway-common - sop-gateway-common - 1.8 @@ -23,9 +22,12 @@ com.google.guava guava - 27.1-jre + + org.apache.commons + commons-lang3 + commons-fileupload commons-fileupload @@ -36,22 +38,20 @@ commons-codec ${commons-codec.version} + + commons-collections + commons-collections + org.springframework.cloud spring-cloud-netflix-ribbon - compile - org.springframework.cloud - spring-cloud-alibaba-nacos-discovery - true - - - org.springframework.cloud - spring-cloud-alibaba-nacos-config + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery true @@ -74,22 +74,34 @@ org.springframework.cloud spring-cloud-netflix-eureka-server - 2.1.0.RELEASE true + - com.netflix.ribbon - ribbon-eureka - 2.3.0 + org.springframework.data + spring-data-redis true + junit junit 4.12 test + + + org.projectlombok + lombok + provided + + + javax.servlet + javax.servlet-api + provided + + diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteDefinition.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteDefinition.java index c8d239ef..004623bf 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteDefinition.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteDefinition.java @@ -1,6 +1,7 @@ package com.gitee.sop.gatewaycommon.bean; import lombok.Data; +import org.springframework.cloud.gateway.route.Route; import java.util.ArrayList; import java.util.Collections; @@ -80,4 +81,6 @@ public class RouteDefinition { * 是否是兼容模式,即使用了@ApiAbility注解 */ private int compatibleMode; + + private Route route; } \ No newline at end of file diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java index aa248d9c..986af8e7 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java @@ -7,8 +7,8 @@ import org.reactivestreams.Publisher; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter; +import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage; import org.springframework.cloud.gateway.support.BodyInserterContext; -import org.springframework.cloud.gateway.support.CachedBodyOutputMessage; import org.springframework.cloud.gateway.support.DefaultClientResponse; import org.springframework.core.Ordered; import org.springframework.core.io.buffer.DataBuffer; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java index 64a9d4ae..df32dc52 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java @@ -13,8 +13,8 @@ import com.gitee.sop.gatewaycommon.validate.Validator; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage; import org.springframework.cloud.gateway.support.BodyInserterContext; -import org.springframework.cloud.gateway.support.CachedBodyOutputMessage; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.io.buffer.DataBuffer; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/loadbalancer/NacosServerIntrospector.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/loadbalancer/NacosServerIntrospector.java index 565fa79a..e4eb72d5 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/loadbalancer/NacosServerIntrospector.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/loadbalancer/NacosServerIntrospector.java @@ -1,7 +1,7 @@ package com.gitee.sop.gatewaycommon.gateway.loadbalancer; +import com.alibaba.cloud.nacos.ribbon.NacosServer; import com.netflix.loadbalancer.Server; -import org.springframework.cloud.alibaba.nacos.ribbon.NacosServer; import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector; import java.util.Map; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java index 5070027d..3f19bddb 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java @@ -42,10 +42,13 @@ public class GatewayRouteRepository implements RouteRepository getRoutes() { + if (routeLocator == null) { + return Flux.empty(); + } return routeLocator.getRoutes(); } @@ -59,6 +62,7 @@ public class GatewayRouteRepository implements RouteRepository r.path(routeDefinition.getPath()) .uri(routeDefinition.getUri()))); this.routeLocator = builder.build(); + // 触发 applicationContext.publishEvent(new RefreshRoutesEvent(new Object())); } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/NacosEventProcessor.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/NacosEventProcessor.java deleted file mode 100644 index ff8ab7a6..00000000 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/NacosEventProcessor.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.gitee.sop.gatewaycommon.manager; - -import com.alibaba.fastjson.JSON; -import com.alibaba.nacos.api.annotation.NacosInjected; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.listener.AbstractListener; -import com.alibaba.nacos.api.exception.NacosException; -import com.gitee.sop.gatewaycommon.bean.ChannelMsg; -import com.gitee.sop.gatewaycommon.bean.NacosConfigs; -import com.gitee.sop.gatewaycommon.secret.IsvManager; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; - -import javax.annotation.PostConstruct; - -/** - * 用不到了,这个类的作用是监听消息推送用的。由admin推送一条config配置,然后这里触发事件。 - * 现在改为直接由admin请求网关提供的接口进行配置修改。 - * 考虑 - * - * @author tanghc - */ -@Slf4j -@Deprecated -public class NacosEventProcessor { - - @NacosInjected - private ConfigService configService; - - @Autowired - private EnvGrayManager envGrayManager; - - @Autowired - private IPBlacklistManager ipBlacklistManager; - - @Autowired - private IsvManager isvManager; - - @Autowired - private IsvRoutePermissionManager isvRoutePermissionManager; - - @Autowired - private LimitConfigManager limitConfigManager; - - @Autowired - private RouteConfigManager routeConfigManager; - - @PostConstruct - public void after() throws NacosException { - log.debug("初始化nacos事件监听"); - initEnvGray(); - initIPBlack(); - initIsv(); - initIsvRoutePermission(); - initLimitConfig(); - initRouteConfig(); - } - - private void initEnvGray() throws NacosException { - configService.addListener(NacosConfigs.DATA_ID_GRAY, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { - @Override - public void receiveConfigInfo(String configInfo) { - ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); - envGrayManager.process(channelMsg); - } - }); - } - - private void initIPBlack() throws NacosException { - configService.addListener(NacosConfigs.DATA_ID_IP_BLACKLIST, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { - @Override - public void receiveConfigInfo(String configInfo) { - ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); - ipBlacklistManager.process(channelMsg); - } - }); - } - - private void initIsv() throws NacosException { - configService.addListener(NacosConfigs.DATA_ID_ISV, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { - @Override - public void receiveConfigInfo(String configInfo) { - ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); - isvManager.process(channelMsg); - } - }); - } - - private void initIsvRoutePermission() throws NacosException { - configService.addListener(NacosConfigs.DATA_ID_ROUTE_PERMISSION, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { - @Override - public void receiveConfigInfo(String configInfo) { - ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); - isvRoutePermissionManager.process(channelMsg); - } - }); - } - - private void initLimitConfig() throws NacosException { - configService.addListener(NacosConfigs.DATA_ID_LIMIT_CONFIG, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { - @Override - public void receiveConfigInfo(String configInfo) { - ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); - limitConfigManager.process(channelMsg); - } - }); - } - - private void initRouteConfig() throws NacosException { - configService.addListener(NacosConfigs.DATA_ID_ROUTE_CONFIG, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { - @Override - public void receiveConfigInfo(String configInfo) { - ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); - routeConfigManager.process(channelMsg); - } - }); - } - -} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java deleted file mode 100644 index e825925f..00000000 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.gitee.sop.gatewaycommon.manager; - -import com.alibaba.fastjson.JSON; -import com.alibaba.nacos.api.annotation.NacosInjected; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.api.naming.pojo.ServiceInfo; -import com.gitee.sop.gatewaycommon.bean.NacosConfigs; -import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; -import com.gitee.sop.gatewaycommon.bean.SopConstants; -import com.gitee.sop.gatewaycommon.bean.TargetRoute; -import com.gitee.sop.gatewaycommon.route.RegistryMetadata; -import com.gitee.sop.gatewaycommon.route.RegistryListener; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties; -import org.springframework.context.ApplicationEvent; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.CollectionUtils; -import org.springframework.util.DigestUtils; -import org.springframework.web.client.DefaultResponseErrorHandler; -import org.springframework.web.client.RestTemplate; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * 发现新服务,更新路由信息 - * - * @author tanghc - * - * @deprecated - * @see RegistryListener - */ -@Deprecated -@Slf4j -public class ServiceRoutesLoader implements RegistryMetadata { - - private static final String SOP_ROUTES_PATH = "/sop/routes"; - - private static final String SECRET = "a3d9sf!1@odl90zd>fkASwq"; - - private static final int FIVE_SECONDS = 1000 * 5; - - private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path"; - - @Autowired - private NacosDiscoveryProperties nacosDiscoveryProperties; - - @NacosInjected - private ConfigService configService; - - @Autowired - private BaseRouteCache baseRouteCache; - - private RestTemplate restTemplate = new RestTemplate(); - - private Map updateTimeMap = new HashMap<>(16); - - public ServiceRoutesLoader() { - // 解决statusCode不等于200,就抛异常问题 - restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { - @Override - protected boolean hasError(HttpStatus statusCode) { - return statusCode == null; - } - }); - } - - public synchronized void load(ApplicationEvent event) { - NamingService namingService = nacosDiscoveryProperties.namingServiceInstance(); - List subscribes = null; - try { - subscribes = namingService.getSubscribeServices(); - } catch (NacosException e) { - log.error("namingService.getSubscribeServices()错误", e); - } - if (CollectionUtils.isEmpty(subscribes)) { - return; - } - // subscribe - String thisServiceId = nacosDiscoveryProperties.getService(); - for (ServiceInfo serviceInfo : subscribes) { - String serviceName = serviceInfo.getName(); - // 如果是本机服务,跳过 - if (Objects.equals(thisServiceId, serviceName)) { - continue; - } - // nacos会不停的触发事件,这里做了一层拦截 - // 同一个serviceId5秒内允许访问一次 - Long lastUpdateTime = updateTimeMap.getOrDefault(serviceName, 0L); - long now = System.currentTimeMillis(); - if (now - lastUpdateTime < FIVE_SECONDS) { - continue; - } - updateTimeMap.put(serviceName, now); - try { - String dataId = NacosConfigs.getRouteDataId(serviceName); - String groupId = NacosConfigs.GROUP_ROUTE; - List allInstances = namingService.getAllInstances(serviceName); - if (CollectionUtils.isEmpty(allInstances)) { - // 如果没有服务列表,则删除所有路由信息 - log.info("服务下线,删除路由配置,serviceId: {}", serviceName); - baseRouteCache.remove(serviceName); - configService.removeConfig(dataId, groupId); - } else { - for (Instance instance : allInstances) { - String url = getRouteRequestUrl(instance); - log.info("拉取路由配置,serviceId: {}, url: {}", serviceName, url); - ResponseEntity responseEntity = restTemplate.getForEntity(url, String.class); - if (responseEntity.getStatusCode() == HttpStatus.OK) { - String body = responseEntity.getBody(); - ServiceRouteInfo serviceRouteInfo = JSON.parseObject(body, ServiceRouteInfo.class); - baseRouteCache.load(serviceRouteInfo, callback -> { - try { - log.info("推送路由配置到nacos,dataId: {}, groupId: {}", dataId, groupId); - configService.publishConfig(dataId, groupId, body); - } catch (NacosException e) { - log.error("nacos推送失败,serviceId: {}, instance: {}", serviceName, instance); - } - }); - } else { - log.error("拉取路由配置异常,url: {}, status: {}, body: {}", url, responseEntity.getStatusCodeValue(), responseEntity.getBody()); - } - } - } - } catch (Exception e) { - log.error("选择服务实例失败,serviceName: {}", serviceName, e); - } - } - } - - /** - * 拉取路由请求url - * @param instance 服务实例 - * @return 返回最终url - */ - private String getRouteRequestUrl(Instance instance) { - Map metadata = instance.getMetadata(); - String customPath = metadata.get(METADATA_SOP_ROUTES_PATH); - String homeUrl; - String servletPath; - // 如果metadata中指定了获取路由的url - if (StringUtils.isNotBlank(customPath)) { - // 自定义完整的url - if (customPath.startsWith("http")) { - homeUrl = customPath; - servletPath = ""; - } else { - homeUrl = getHomeUrl(instance); - servletPath = customPath; - } - } else { - // 默认处理 - homeUrl = getHomeUrl(instance); - String contextPath = this.getContextPath(metadata); - servletPath = contextPath + SOP_ROUTES_PATH; - } - if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { - servletPath = '/' + servletPath; - } - String query = buildQuery(SECRET); - return homeUrl + servletPath + query; - } - - private static String getHomeUrl(Instance instance) { - return "http://" + instance.getIp() + ":" + instance.getPort(); - } - - private static String buildQuery(String secret) { - String time = String.valueOf(System.currentTimeMillis()); - String source = secret + time + secret; - String sign = DigestUtils.md5DigestAsHex(source.getBytes()); - return "?time=" + time + "&sign=" + sign; - } - -} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java index 39ef7da9..2e7128b5 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java @@ -27,6 +27,7 @@ public abstract class BaseRegistryListener implements RegistryListener { static { EXCLUDE_SERVICE_ID_LIST.add("sop-gateway"); EXCLUDE_SERVICE_ID_LIST.add("sop-website"); + EXCLUDE_SERVICE_ID_LIST.add("sop-admin"); EXCLUDE_SERVICE_ID_LIST.add("website-server"); } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/EurekaRegistryListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/EurekaRegistryListener.java index 55f71a3a..0e481a40 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/EurekaRegistryListener.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/EurekaRegistryListener.java @@ -4,8 +4,6 @@ import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.netflix.appinfo.InstanceInfo; import com.netflix.discovery.shared.Application; import com.netflix.discovery.shared.Applications; -import lombok.AllArgsConstructor; -import lombok.Data; import org.apache.commons.collections.CollectionUtils; import org.springframework.cloud.netflix.eureka.CloudEurekaClient; import org.springframework.context.ApplicationEvent; @@ -46,6 +44,7 @@ public class EurekaRegistryListener extends BaseRegistryListener { .collect(Collectors.toList()); final Set currentServices = new HashSet<>(serviceList); + // 删除现有的,剩下的就是新服务 currentServices.removeAll(cacheServices); // 如果有新的服务注册进来 if (currentServices.size() > 0) { @@ -115,10 +114,4 @@ public class EurekaRegistryListener extends BaseRegistryListener { deletedServices.forEach(this::removeRoutes); } - @Data - @AllArgsConstructor - private static class ServiceHolder { - private String serviceId; - private long lastUpdatedTimestamp; - } } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/NacosRegistryListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/NacosRegistryListener.java index 73c2494a..a514f1b1 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/NacosRegistryListener.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/NacosRegistryListener.java @@ -1,20 +1,24 @@ package com.gitee.sop.gatewaycommon.route; -import com.alibaba.nacos.api.annotation.NacosInjected; -import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.api.naming.pojo.ServiceInfo; +import com.alibaba.nacos.api.naming.pojo.ListView; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties; import org.springframework.context.ApplicationEvent; import org.springframework.util.CollectionUtils; +import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * 加载服务路由,nacos实现 @@ -24,48 +28,105 @@ import java.util.Objects; @Slf4j public class NacosRegistryListener extends BaseRegistryListener { + private volatile Set cacheServices = new HashSet<>(); + @Autowired private NacosDiscoveryProperties nacosDiscoveryProperties; - @NacosInjected - private ConfigService configService; + @Autowired(required = false) + private List registryEventList; @Override - public void onEvent(ApplicationEvent applicationEvent) { + public synchronized void onEvent(ApplicationEvent applicationEvent) { NamingService namingService = nacosDiscoveryProperties.namingServiceInstance(); - List subscribes = null; + ListView servicesOfServer = null; try { - subscribes = namingService.getSubscribeServices(); + servicesOfServer = namingService.getServicesOfServer(1, Integer.MAX_VALUE); } catch (NacosException e) { - log.error("namingService.getSubscribeServices()错误", e); + log.error("namingService.getServicesOfServer()错误", e); } - if (CollectionUtils.isEmpty(subscribes)) { + if (servicesOfServer == null || CollectionUtils.isEmpty(servicesOfServer.getData())) { return; } - subscribes.stream() - .filter(serviceInfo -> this.canOperator(serviceInfo.getName())) - .forEach(serviceInfo -> { - String serviceName = serviceInfo.getName(); + + Map instanceMap = servicesOfServer + .getData() + .stream() + .filter(this::canOperator) + .map(serviceName -> { try { List allInstances = namingService.getAllInstances(serviceName); if (CollectionUtils.isEmpty(allInstances)) { - // 如果没有服务列表,则删除所有路由信息 - removeRoutes(serviceName); - } else { - for (Instance instance : allInstances) { - InstanceDefinition instanceDefinition = new InstanceDefinition(); - instanceDefinition.setInstanceId(instance.getInstanceId()); - instanceDefinition.setServiceId(serviceName); - instanceDefinition.setIp(instance.getIp()); - instanceDefinition.setPort(instance.getPort()); - instanceDefinition.setMetadata(instance.getMetadata()); - pullRoutes(instanceDefinition); - } + return null; } - } catch (Exception e) { - log.error("选择服务实例失败,serviceName: {}", serviceName, e); + Instance instance = allInstances.stream() + .filter(Instance::isHealthy) + .findFirst() + .orElse(null); + return instance == null ? null : new InstanceInfo(serviceName, instance); + } catch (NacosException e) { + log.error("namingService.getAllInstances(serviceName)错误,serviceName:{}", serviceName, e); + return null; } - }); + }) + .filter(Objects::nonNull) + .collect(Collectors.toMap(InstanceInfo::getServiceName, InstanceInfo::getInstance)); + + + Set serviceNames = instanceMap.keySet(); + + final Set currentServices = new HashSet<>(serviceNames); + // 删除现有的,剩下的就是新服务 + currentServices.removeAll(cacheServices); + // 如果有新的服务注册进来 + if (currentServices.size() > 0) { + currentServices.forEach(serviceName -> { + Instance instance = instanceMap.get(serviceName); + InstanceDefinition instanceDefinition = new InstanceDefinition(); + instanceDefinition.setInstanceId(instance.getInstanceId()); + instanceDefinition.setServiceId(serviceName); + instanceDefinition.setIp(instance.getIp()); + instanceDefinition.setPort(instance.getPort()); + instanceDefinition.setMetadata(instance.getMetadata()); + pullRoutes(instanceDefinition); + if (registryEventList != null) { + registryEventList.forEach(registryEvent -> registryEvent.onRegistry(instanceDefinition)); + } + }); + } + + // 如果有服务删除 + Set removedServiceIdList = getRemovedServiceId(serviceNames); + if (removedServiceIdList.size() > 0) { + removedServiceIdList.forEach(serviceId->{ + this.removeRoutes(serviceId); + if (registryEventList != null) { + registryEventList.forEach(registryEvent -> registryEvent.onRemove(serviceId)); + } + }); + } + + cacheServices = new HashSet<>(serviceNames); + } + + /** + * 获取已经下线的serviceId + * + * @param serviceList 最新的serviceId集合 + * @return 返回已下线的serviceId + */ + private Set getRemovedServiceId(Set serviceList) { + Set cache = cacheServices; + // 删除最新的,剩下就是已经删除的 + cache.removeAll(serviceList); + return cache; + } + + @Data + @AllArgsConstructor + private static class InstanceInfo { + private String serviceName; + private Instance instance; } } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/RegistryEvent.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/RegistryEvent.java new file mode 100644 index 00000000..5baf8c42 --- /dev/null +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/RegistryEvent.java @@ -0,0 +1,23 @@ +package com.gitee.sop.gatewaycommon.route; + +import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; + +/** + * 新的实例注册事件 + * + * @author tanghc + */ +public interface RegistryEvent { + + /** + * 新实例注册进来时触发 + * @param instanceDefinition 实例信息 + */ + void onRegistry(InstanceDefinition instanceDefinition); + + /** + * 服务下线时触发 + * @param serviceId 服务id + */ + void onRemove(String serviceId); +} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceHolder.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceHolder.java new file mode 100644 index 00000000..1febf746 --- /dev/null +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceHolder.java @@ -0,0 +1,11 @@ +package com.gitee.sop.gatewaycommon.route; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ServiceHolder { + private String serviceId; + private long lastUpdatedTimestamp; +} \ No newline at end of file diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index dbf90e5a..20ca41a9 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -2,20 +2,19 @@ - 4.0.0 + com.gitee.sop - sop-common - 3.1.5-SNAPSHOT - ../pom.xml + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 sop-service-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT jar - sop-service-common - sop-service-common - 1.8 @@ -25,7 +24,16 @@ com.google.guava guava - 27.1-jre + + + + org.apache.commons + commons-lang3 + + + + commons-io + commons-io @@ -38,19 +46,16 @@ net.oschina.durcframework easyopen - 1.16.1 true io.springfox springfox-spring-web - 2.9.2 true io.swagger swagger-annotations - 1.5.21 true @@ -76,6 +81,17 @@ 3.0.0 test + + + org.projectlombok + lombok + provided + + + javax.servlet + javax.servlet-api + provided + diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/RedisApiMetaManager.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/RedisApiMetaManager.java deleted file mode 100644 index 27c792cb..00000000 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/RedisApiMetaManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.gitee.sop.servercommon.manager; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.servercommon.bean.ServiceApiInfo; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.redis.core.StringRedisTemplate; - -/** - * @author tanghc - */ -@Slf4j -public class RedisApiMetaManager implements ApiMetaManager { - public static final String API_STORE_KEY = "com.gitee.sop.api"; - public static final String API_CHANGE_CHANNEL = "channel.sop.api.change"; - - private StringRedisTemplate redisTemplate; - - public RedisApiMetaManager(StringRedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - - @Override - public void uploadApi(ServiceApiInfo serviceApiInfo) { - log.info("上传接口信息到Redis,serviceId:{}, 接口数量:{}", serviceApiInfo.getServiceId(), serviceApiInfo.getApis().size()); - String serviceApiInfoJson = JSON.toJSONString(serviceApiInfo); - redisTemplate.opsForHash().put(API_STORE_KEY, serviceApiInfo.getServiceId(), serviceApiInfoJson); - // 发送订阅事件 - redisTemplate.convertAndSend(API_CHANGE_CHANNEL, serviceApiInfoJson); - } -} diff --git a/sop-example/pom.xml b/sop-example/pom.xml index a3efa857..985954fc 100644 --- a/sop-example/pom.xml +++ b/sop-example/pom.xml @@ -2,16 +2,19 @@ + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml + + 4.0.0 - com.gitee.sop sop-example - 1.0.0-SNAPSHOT pom sop-story - sop-book - sop-easyopen sop-springmvc \ No newline at end of file diff --git a/sop-example/readme.md b/sop-example/readme.md index eeafbca8..f2dc17a7 100644 --- a/sop-example/readme.md +++ b/sop-example/readme.md @@ -1,7 +1,5 @@ # 服务示例 -- sop-story:微服务示例,story服务,同时作为Provider提供服务。本地文档:http://localhost:2222/doc.html -- sop-book:微服务示例,book服务,也是Consumer,调用story提供的服务 +- sop-story:微服务示例 - sop-auth:应用授权示例 - sop-springmvc:springmvc工程实例 -- sop-easyopen:整合easyopen示例 diff --git a/sop-example/sop-book/pom.xml b/sop-example/sop-book/pom.xml deleted file mode 100644 index 6a343033..00000000 --- a/sop-example/sop-book/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - 4.0.0 - com.gitee.sop - sop-book-parent - 1.0.0-SNAPSHOT - pom - - - sop-book-api - sop-book-web - - \ No newline at end of file diff --git a/sop-example/sop-book/sop-book-api/.gitignore b/sop-example/sop-book/sop-book-api/.gitignore deleted file mode 100644 index c456c4a3..00000000 --- a/sop-example/sop-book/sop-book-api/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ diff --git a/sop-example/sop-book/sop-book-api/pom.xml b/sop-example/sop-book/sop-book-api/pom.xml deleted file mode 100644 index c47d23c4..00000000 --- a/sop-example/sop-book/sop-book-api/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - - - com.gitee.sop - sop-book-api - 1.0-SNAPSHOT - - - 1.8 - Greenwich.RELEASE - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.projectlombok - lombok - 1.18.4 - provided - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - \ No newline at end of file diff --git a/sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/domain/Book.java b/sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/domain/Book.java deleted file mode 100644 index a286924a..00000000 --- a/sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/domain/Book.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.gitee.book.api.domain; - -import lombok.Data; - -/** - * @author tanghc - */ -@Data -public class Book { - private int id; - private String name; -} diff --git a/sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/service/BookService.java b/sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/service/BookService.java deleted file mode 100644 index 66d5d90e..00000000 --- a/sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/service/BookService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gitee.book.api.service; - -import com.gitee.book.api.domain.Book; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author tanghc - */ -@RequestMapping("/book") -public interface BookService { - @RequestMapping("/getBook") - Book getBook(@RequestParam("id") int id); -} diff --git a/sop-example/sop-book/sop-book-web/.gitignore b/sop-example/sop-book/sop-book-web/.gitignore deleted file mode 100644 index c456c4a3..00000000 --- a/sop-example/sop-book/sop-book-web/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml deleted file mode 100644 index 3fdcfb7c..00000000 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ /dev/null @@ -1,153 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - - - com.gitee.sop - sop-book-web - 0.0.1-SNAPSHOT - sop-book - Demo project for Spring Boot - - - 1.8 - 2.6.5 - Greenwich.RELEASE - - 0.9.0.RELEASE - - 1.1.3 - - - - - com.gitee.sop - sop-service-common - 3.1.5-SNAPSHOT - - - com.gitee.sop - sop-book-api - 1.0-SNAPSHOT - - - com.gitee.sop - sop-story-api - 1.0-SNAPSHOT - - - - - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - - com.alibaba.boot - dubbo-spring-boot-starter - 0.2.1.RELEASE - - - com.alibaba - dubbo - ${dubbo.version} - - - io.netty - netty-all - - - - - io.springfox - springfox-swagger2 - 2.9.2 - - - io.swagger - swagger-models - - - - - io.swagger - swagger-models - 1.5.21 - - - io.springfox - springfox-swagger-ui - 2.9.2 - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - 1.18.4 - compile - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/SopBookApplication.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/SopBookApplication.java deleted file mode 100644 index cfb16be7..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/SopBookApplication.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gitee.sop.bookweb; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -// 允许调用其他服务 -@EnableFeignClients -// 服务注册 -@EnableDiscoveryClient -@SpringBootApplication -public class SopBookApplication { - - public static void main(String[] args) { - SpringApplication.run(SopBookApplication.class, args); - } - -} - diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java deleted file mode 100644 index a84ddea8..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.gitee.sop.bookweb.config; - -import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration; -import com.gitee.sop.servercommon.swagger.SwaggerSupport; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -/** - * 使用支付宝开放平台功能 - * @author tanghc - */ -@Configuration -public class OpenServiceConfig extends AlipayServiceConfiguration { - - // 开启文档 - @Configuration - @EnableSwagger2 - public static class Swagger2 extends SwaggerSupport { - @Override - protected String getDocTitle() { - return "图书API"; - } - } -} - -/** - * 使用淘宝开放平台功能 - * @author tanghc - */ -//@Configuration -//public class OpenServiceConfig extends TaobaoServiceConfiguration { -// -//} diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/consumer/StoryServiceConsumer.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/consumer/StoryServiceConsumer.java deleted file mode 100644 index cce5945b..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/consumer/StoryServiceConsumer.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gitee.sop.bookweb.consumer; - -import com.gitee.sop.story.api.service.StoryService; -import org.springframework.cloud.openfeign.FeignClient; - -/** - * 调用story服务 - * - * @author tanghc - */ -// value对应的spring.application.name -@FeignClient("story-service") -public interface StoryServiceConsumer extends StoryService { -} diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/AlipayBookController.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/AlipayBookController.java deleted file mode 100644 index eff28c56..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/AlipayBookController.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.gitee.sop.bookweb.controller; - -import com.gitee.book.api.domain.Book; -import com.gitee.sop.bookweb.consumer.StoryServiceConsumer; -import com.gitee.sop.bookweb.param.BookParam; -import com.gitee.sop.bookweb.vo.BookVO; -import com.gitee.sop.servercommon.annotation.ApiMapping; -import com.gitee.sop.story.api.domain.Story; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Arrays; - -/** - * 这里演示如何接受业务参数。 - * @author tanghc - */ -@Api(tags = "图书接口") -@RestController -public class AlipayBookController { - - @Autowired - StoryServiceConsumer storyServiceConsumer; - - @ApiOperation(value="查询书本信息", notes = "可以根据ISBN查询书本信息") - @ApiMapping(value = "book.search") - public BookVO searchBook(BookParam param) { - BookVO bookVO = new BookVO(); - bookVO.setId(1); - bookVO.setName("白雪公主,ISBN:" + param.getIsbn()); - bookVO.setIsbn("ABCSSSSDDD"); - return bookVO; - } - - @ApiMapping(value = "alipay.book.get") - public Book getBook() { - Book story = new Book(); - story.setId(1); - story.setName("白雪公主(alipay.book.get)"); - return story; - } - - // 通过Feign调用story服务 - @ApiMapping(value = "alipay.book.story.get") - public Object getBook2() { - Story story = new Story(); - story.setId(1); - story.setName("白雪公主(alipay.book.story.get)"); - Story story2 = storyServiceConsumer.getStory(1); - return Arrays.asList(story, story2); - } - -} diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/ApiResult.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/ApiResult.java deleted file mode 100644 index a102dfa8..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/ApiResult.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.gitee.sop.bookweb.controller; - -import lombok.Data; - -/** - * 默认的结果封装类. - *
- *
- * xml返回结果:
- * 
- *     50
- *     Remote service error
- *     isv.invalid-parameter
- *     非法参数
- * 
- * 成功情况:
- * 
- *     0
- *     成功消息
- *     
- *         ...返回内容
- *     
- * 
- *
- * json返回格式:
- * {
- *  "code":"50",
- * 	"msg":"Remote service error",
- * 	"sub_code":"isv.invalid-parameter",
- * 	"sub_msg":"非法参数"
- * }
- * 成功情况:
- * {
- *  "code":"0",
- * 	"msg":"成功消息内容。。。",
- * 	"data":{
- * 	    ...返回内容
- *    }
- * }
- * 
- *

- * 字段说明: - * code:网关异常码
- * msg:网关异常信息
- * sub_code:业务异常码
- * sub_msg:业务异常信息
- * - * @author tanghc - */ -@Data -public class ApiResult { - - /** - * 网关异常信息 - */ - private String msg; - - /** - * 业务异常码 - */ - private String sub_msg; - - /** - * 业务异常信息 - */ - private String sub_code; - - /** - * 返回结果 - */ - private Object data; -} diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/BookController.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/BookController.java deleted file mode 100644 index 710db1a5..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/BookController.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.gitee.sop.bookweb.controller; - -import com.gitee.book.api.domain.Book; -import com.gitee.sop.bookweb.consumer.StoryServiceConsumer; -import com.gitee.sop.bookweb.param.BookParam; -import com.gitee.sop.story.api.domain.Story; -import com.gitee.book.api.service.BookService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Arrays; - -/** - * book服务 - * - * @author tanghc - */ -@RestController -public class BookController implements BookService { - - @Autowired - StoryServiceConsumer storyServiceConsumer; - - @Override - public Book getBook(int id) { - Book book = new Book(); - book.setId(id); - book.setName("汪汪队"); - return book; - } - - @RequestMapping("listBookAndStory") - public Object listBookAndStory(int id) { - Book book = new Book(); - book.setId(id); - book.setName("汪汪队"); - - // 调用story服务 - Story story = storyServiceConsumer.getStory(id); - - return Arrays.asList(book, story); - } - - @RequestMapping("getBook2") - public Object getBookError(int id) { - if (id == 0) { - throw new RuntimeException("id不能为空"); - } - Book book = new Book(); - book.setId(id); - book.setName("汪汪队"); - return Arrays.asList(book); - } - - - - @RequestMapping("getBook3") - public Object getBook3(@RequestBody BookParam param) { - if (param.getId() == 0) { - throw new RuntimeException("id不能为空"); - } - Book book = new Book(); - book.setId(param.getId()); - book.setName("小马宝莉"); - - ApiResult apiResult = new ApiResult(); - apiResult.setData(book); - return apiResult; - } - -} diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java deleted file mode 100644 index 431c0a81..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.gitee.sop.bookweb.controller; - -import com.alibaba.dubbo.config.annotation.Reference; -import com.gitee.sop.servercommon.annotation.ApiMapping; -import com.gitee.sop.story.api.domain.Story; -import com.gitee.sop.story.api.param.DemoParam; -import com.gitee.sop.story.api.result.DemoResult; -import com.gitee.sop.story.api.service.DemoService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.RestController; - -/** - * 调用dubbo服务,provider是story,见DefaultDemoService.java - * dubbo配置方式参见:https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md - *

- * 对比SpringCloud提供的Feign,dubbo会方便很多。 - *

- * Feign的使用方式参见:com.gitee.sop.bookweb.controller.AlipayBookController#getBook2() - */ -@RestController -@Slf4j -public class DubboConsumerController { - - @Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") - private DemoService demoService; - - // 作为开放接口 - @ApiMapping(value = "dubbo.story.get") - public Story openApi(DemoParam demoParam) { - log.info("dubbo consumer, param: {}", demoParam); - // 通过dubbo调用story提供的服务 - DemoResult dubboStory = demoService.getStory(demoParam); - Story story = new Story(); - story.setId(dubboStory.getId()); - story.setName(dubboStory.getName()); - return story; - } - - -} \ No newline at end of file diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/param/BookParam.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/param/BookParam.java deleted file mode 100644 index 14841d9d..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/param/BookParam.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gitee.sop.bookweb.param; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -/** - * @author tanghc - */ -@Data -public class BookParam { - @ApiModelProperty(value = "图书id", example = "1") - private int id; - - @ApiModelProperty(value = "图书ISBN", example = "xxxx") - private String isbn; -} diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/vo/BookVO.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/vo/BookVO.java deleted file mode 100644 index 8ae601b5..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/vo/BookVO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gitee.sop.bookweb.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -@Data -public class BookVO { - @ApiModelProperty(value = "图书id", example = "1") - private int id; - - @ApiModelProperty(value = "图书名称", example = "白雪公主") - private String name; - - @ApiModelProperty(value = "isbn", example = "xxxxxx") - private String isbn; -} diff --git a/sop-example/sop-book/sop-book-web/src/main/resources/application-dev.properties b/sop-example/sop-book/sop-book-web/src/main/resources/application-dev.properties deleted file mode 100644 index 5d705fbc..00000000 --- a/sop-example/sop-book/sop-book-web/src/main/resources/application-dev.properties +++ /dev/null @@ -1,19 +0,0 @@ -server.port=3333 -spring.application.name=book-service - -# nacos注册中心 -#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 - -# eureka注册中心 -eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ - -# consumer不需要检查provider是否启动 -dubbo.consumer.check=false - -# zipkin服务跟踪 -#spring.zipkin.base-url=http://127.0.0.1:9411/ -## 设置sleuth收集信息的比率,默认0.1,最大是1,数字越大越耗性能 -#spring.sleuth.sampler.probability=1 -## dubbo使用zipkin过滤器 -#dubbo.provider.filter=tracing -#dubbo.consumer.filter=tracing diff --git a/sop-example/sop-book/sop-book-web/src/test/java/com/gitee/sop/bookweb/SopBookApplicationTests.java b/sop-example/sop-book/sop-book-web/src/test/java/com/gitee/sop/bookweb/SopBookApplicationTests.java deleted file mode 100644 index 6fa12ac2..00000000 --- a/sop-example/sop-book/sop-book-web/src/test/java/com/gitee/sop/bookweb/SopBookApplicationTests.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gitee.sop.bookweb; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SopBookApplicationTests { - - @Test - public void contextLoads() { - } - -} - diff --git a/sop-example/sop-easyopen/.gitignore b/sop-example/sop-easyopen/.gitignore deleted file mode 100644 index 18ccf36e..00000000 --- a/sop-example/sop-easyopen/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ -/local-config/ diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml deleted file mode 100644 index 55c705f1..00000000 --- a/sop-example/sop-easyopen/pom.xml +++ /dev/null @@ -1,132 +0,0 @@ - - - 4.0.0 - com.gitee.sop - sop-easyopen - 1.0.0-SNAPSHOT - jar - - easyopen-server - easyopen Demo project for Spring Boot - - - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - - - - - UTF-8 - UTF-8 - Greenwich.RELEASE - 1.8 - - - - - - com.gitee.sop - sop-service-common - 3.1.5-SNAPSHOT - - - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - - net.oschina.durcframework - easyopen - 1.16.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.springframework.boot - spring-boot-devtools - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - - - diff --git a/sop-example/sop-easyopen/readme.md b/sop-example/sop-easyopen/readme.md deleted file mode 100644 index 20cb4998..00000000 --- a/sop-example/sop-easyopen/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -# easyopen-server - -接口服务器空项目,可在此基础上做开发。 - -入口类:IndexController - -业务类在api下,重点关注这里即可。 - -``` -└─com.gitee.easyopen.server - │ EmptySpringbootApplication.java // springboot启动类 - │ IndexController.java // easyopen入口类 - │ - ├─api // 存放接口 - │ │ GoodsApi.java // 示例接口 - │ │ - │ ├─param // 存放接口参数类 - │ │ GoodsParam.java - │ │ - │ └─result // 存放放回接口类 - │ Goods.java - │ - ├─config // spring配置 - │ CorsConfig.java - │ - ├─interceptor // easyopen拦截器 - │ LogInterceptor.java - │ - └─message // 错误处理 - CommonErrors.java -``` \ No newline at end of file diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/IndexController.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/IndexController.java deleted file mode 100644 index aec16dd7..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/IndexController.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gitee.easyopen.server; - -import com.gitee.easyopen.ApiConfig; -import com.gitee.easyopen.support.ApiController; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -import java.util.HashMap; -import java.util.Map; - -/** - * 文档地址:http://localhost:8080/api/doc - */ -@Controller -@RequestMapping("api") -public class IndexController extends ApiController { - @Override - protected void initApiConfig(ApiConfig apiConfig) { - apiConfig.setShowDoc(true); // 显示文档页面 - // 配置国际化消息 - Map appSecretStore = new HashMap(); - appSecretStore.put("test", "123456"); - apiConfig.addAppSecret(appSecretStore); - } -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/SopEasyopenApplication.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/SopEasyopenApplication.java deleted file mode 100644 index f42762f5..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/SopEasyopenApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gitee.easyopen.server; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; - -@EnableDiscoveryClient -@SpringBootApplication -public class SopEasyopenApplication { - - public static void main(String[] args) { - SpringApplication.run(SopEasyopenApplication.class, args); - } -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/Goods2Api.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/Goods2Api.java deleted file mode 100644 index b41676cf..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/Goods2Api.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gitee.easyopen.server.api; - -import com.gitee.easyopen.annotation.Api; -import com.gitee.easyopen.annotation.ApiService; -import com.gitee.easyopen.doc.annotation.ApiDoc; -import com.gitee.easyopen.doc.annotation.ApiDocMethod; -import com.gitee.easyopen.server.api.param.GoodsParam; -import com.gitee.easyopen.server.api.result.Goods; - -import java.math.BigDecimal; - -/** - * 业务类 - * - * @author tanghc - */ -@ApiService -@ApiDoc("库存接口") -public class Goods2Api { - - @Api(name = "store.get") - @ApiDocMethod(description = "获取库存") - Goods getGoods(GoodsParam param) { - Goods goods = new Goods(); - goods.setId(1L); - goods.setGoods_name("苹果iPhoneX"); - goods.setPrice(new BigDecimal(8000)); - return goods; - } - -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/GoodsApi.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/GoodsApi.java deleted file mode 100644 index bd848d3f..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/GoodsApi.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gitee.easyopen.server.api; - -import com.gitee.easyopen.annotation.Api; -import com.gitee.easyopen.annotation.ApiService; -import com.gitee.easyopen.doc.annotation.ApiDoc; -import com.gitee.easyopen.doc.annotation.ApiDocMethod; -import com.gitee.easyopen.server.api.param.GoodsParam; -import com.gitee.easyopen.server.api.result.Goods; - -import java.math.BigDecimal; - -/** - * 业务类 - * - * @author tanghc - */ -@ApiService -@ApiDoc("商品接口") -public class GoodsApi { - - @Api(name = "easyopen.goods.get") - @ApiDocMethod(description = "获取商品") - Goods getGoods(GoodsParam param) { - Goods goods = new Goods(); - goods.setId(1L); - goods.setGoods_name("苹果iPhoneX"); - goods.setPrice(new BigDecimal(8000)); - return goods; - } - -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/param/GoodsParam.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/param/GoodsParam.java deleted file mode 100644 index c3f500c1..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/param/GoodsParam.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.gitee.easyopen.server.api.param; - -import com.gitee.easyopen.doc.annotation.ApiDocField; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotEmpty; - -public class GoodsParam { - - @ApiDocField(description = "商品名称", required = true, example = "iphoneX") - @NotEmpty(message = "商品名称不能为空") - @Length(min = 3, max = 20, message = "{goods.name.length}=3,20") - private String goods_name; - - public String getGoods_name() { - return goods_name; - } - - public void setGoods_name(String goods_name) { - this.goods_name = goods_name; - } - -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/result/Goods.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/result/Goods.java deleted file mode 100644 index 7ad6e9a9..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/result/Goods.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.gitee.easyopen.server.api.result; - -import com.gitee.easyopen.doc.DataType; -import com.gitee.easyopen.doc.annotation.ApiDocField; - -import java.math.BigDecimal; - -public class Goods { - - @ApiDocField(description = "id") - private Long id; - @ApiDocField(description = "商品名称") - private String goods_name; - @ApiDocField(description = "价格", dataType = DataType.FLOAT) - private BigDecimal price; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getGoods_name() { - return goods_name; - } - - public void setGoods_name(String goods_name) { - this.goods_name = goods_name; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(BigDecimal price) { - this.price = price; - } - - @Override - public String toString() { - return "Goods [id=" + id + ", goods_name=" + goods_name + ", price=" + price + "]"; - } - -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/CorsConfig.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/CorsConfig.java deleted file mode 100644 index 9c3c8d60..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/CorsConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.gitee.easyopen.server.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; - -/** - * 解决js跨域 - * @author tanghc - */ -@Configuration -public class CorsConfig { - - /** - * 跨域过滤器 - * - * @return - */ - @Bean - public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", buildConfig()); // 4 - return new CorsFilter(source); - } - - private CorsConfiguration buildConfig() { - CorsConfiguration corsConfiguration = new CorsConfiguration(); - corsConfiguration.addAllowedOrigin("*"); - corsConfiguration.addAllowedHeader("*"); - corsConfiguration.addAllowedMethod("*"); - return corsConfiguration; - } - - -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/SopConfig.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/SopConfig.java deleted file mode 100644 index 4228df21..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/SopConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.gitee.easyopen.server.config; - -import com.gitee.sop.servercommon.configuration.EasyopenDocSupportController; -import com.gitee.sop.servercommon.easyopen.EasyopenServiceConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Controller; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; - -/** - * @author tanghc - */ -@Configuration -public class SopConfig extends EasyopenServiceConfiguration { - - @Controller - public static class SopDocController extends EasyopenDocSupportController { - @Override - public String getDocTitle() { - return "商品API"; - } - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - //配置映射关系 - registry.addResourceHandler("/opendoc/**").addResourceLocations("classpath:/META-INF/resources/opendoc/"); - } -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/interceptor/LogInterceptor.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/interceptor/LogInterceptor.java deleted file mode 100644 index 87e74910..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/interceptor/LogInterceptor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.gitee.easyopen.server.interceptor; - -import com.gitee.easyopen.ApiContext; -import com.gitee.easyopen.interceptor.ApiInterceptorAdapter; -import com.gitee.easyopen.util.RequestUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.net.URLDecoder; - -public class LogInterceptor extends ApiInterceptorAdapter { - - Logger logger = LoggerFactory.getLogger(getClass()); - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object serviceObj, Object argu) - throws Exception { - logger.info("收到客户端请求,ip={},参数={}", RequestUtil.getClientIP(request), URLDecoder.decode(ApiContext.getApiParam().toJSONString(), "UTF-8")); - return true; - } -} diff --git a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/message/CommonErrors.java b/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/message/CommonErrors.java deleted file mode 100644 index ecee0784..00000000 --- a/sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/message/CommonErrors.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gitee.easyopen.server.message; - -import com.gitee.easyopen.message.ErrorMeta; - -/** - * 错误码放在这里 - * - * 使用方式:throw CommonErrors.NUll_ERROR.getException(); - */ -public interface CommonErrors { - String isvModule = "isv.error_"; // error_zh_CN2.properties内容前缀 - - ErrorMeta NUll_ERROR = new ErrorMeta(isvModule, "200", "不能为空"); - - -} diff --git a/sop-example/sop-easyopen/src/main/resources/application-dev.properties b/sop-example/sop-easyopen/src/main/resources/application-dev.properties deleted file mode 100644 index f6f62ae7..00000000 --- a/sop-example/sop-easyopen/src/main/resources/application-dev.properties +++ /dev/null @@ -1,7 +0,0 @@ -server.port=2121 -spring.application.name=easyopen-service - -# eureka注册中心 -eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ - -easyopen.prefix-path=/api diff --git a/sop-example/sop-easyopen/src/main/resources/application.properties b/sop-example/sop-easyopen/src/main/resources/application.properties deleted file mode 100644 index 257b3064..00000000 --- a/sop-example/sop-easyopen/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.profiles.active=dev \ No newline at end of file diff --git a/sop-example/sop-easyopen/src/main/resources/i18n/isv/error_zh_CN.properties b/sop-example/sop-easyopen/src/main/resources/i18n/isv/error_zh_CN.properties deleted file mode 100644 index 17981dd1..00000000 --- a/sop-example/sop-easyopen/src/main/resources/i18n/isv/error_zh_CN.properties +++ /dev/null @@ -1,2 +0,0 @@ -# common errors here -isv.error_200=\u4E0D\u80FD\u4E3A\u7A7A diff --git a/sop-example/sop-easyopen/src/test/java/com/gitee/sop/adminserver/SopEasyopenApplicationApplicationTests.java b/sop-example/sop-easyopen/src/test/java/com/gitee/sop/adminserver/SopEasyopenApplicationApplicationTests.java deleted file mode 100644 index 08b53786..00000000 --- a/sop-example/sop-easyopen/src/test/java/com/gitee/sop/adminserver/SopEasyopenApplicationApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gitee.sop.adminserver; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SopEasyopenApplicationApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/sop-example/sop-springmvc/pom.xml b/sop-example/sop-springmvc/pom.xml index d0b2022a..43efd3c4 100644 --- a/sop-example/sop-springmvc/pom.xml +++ b/sop-example/sop-springmvc/pom.xml @@ -1,12 +1,18 @@ + + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 - com.gitee.sop sop-springmvc sop-springmvc war - 1.0.0-SNAPSHOT 1.8 @@ -20,7 +26,7 @@ com.gitee.sop sop-service-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT @@ -43,6 +49,11 @@ ${org.springframework-version} + + org.hibernate.validator + hibernate-validator + + com.fasterxml.jackson.core diff --git a/sop-example/sop-story/pom.xml b/sop-example/sop-story/pom.xml index b2da4384..5fdc63bd 100644 --- a/sop-example/sop-story/pom.xml +++ b/sop-example/sop-story/pom.xml @@ -1,15 +1,93 @@ - + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 - com.gitee.sop-story - sop-story-parent - 1.0.0-SNAPSHOT - pom - - - sop-story-api - sop-story-web - - \ No newline at end of file + sop-story + + + 1.8 + + + + + com.gitee.sop + sop-service-common + 3.2.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + com.github.xiaoymin + swagger-bootstrap-ui + 1.9.5 + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + 1.18.4 + provided + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + diff --git a/sop-example/sop-story/sop-story-api/.gitignore b/sop-example/sop-story/sop-story-api/.gitignore deleted file mode 100644 index c456c4a3..00000000 --- a/sop-example/sop-story/sop-story-api/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ diff --git a/sop-example/sop-story/sop-story-api/pom.xml b/sop-example/sop-story/sop-story-api/pom.xml deleted file mode 100644 index 103848c1..00000000 --- a/sop-example/sop-story/sop-story-api/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - - - com.gitee.sop - sop-story-api - 1.0-SNAPSHOT - - - 1.8 - Greenwich.RELEASE - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.projectlombok - lombok - 1.18.4 - provided - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - \ No newline at end of file diff --git a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/domain/Story.java b/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/domain/Story.java deleted file mode 100644 index d2cfbae0..00000000 --- a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/domain/Story.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.gitee.sop.story.api.domain; - -import lombok.Data; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotBlank; - -/** - * @author tanghc - */ -@Data -public class Story { - private int id; - - @NotBlank(message = "name不能为空") - @Length(max = 20, message = "name长度不能超过20") - private String name; -} diff --git a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/param/DemoParam.java b/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/param/DemoParam.java deleted file mode 100644 index 36a0ce3c..00000000 --- a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/param/DemoParam.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gitee.sop.story.api.param; - -import lombok.Data; - -import java.io.Serializable; - -/** - * dubbo 参数 - * @author tanghc - */ -@Data -public class DemoParam implements Serializable { - private int id; -} diff --git a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/result/DemoResult.java b/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/result/DemoResult.java deleted file mode 100644 index 3be828f5..00000000 --- a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/result/DemoResult.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.gitee.sop.story.api.result; - -import lombok.Data; - -import java.io.Serializable; - -/** - * dubbo返回结果 - * @author tanghc - */ -@Data -public class DemoResult implements Serializable { - private int id; - private String name; -} diff --git a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/DemoService.java b/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/DemoService.java deleted file mode 100644 index 67c382d7..00000000 --- a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/DemoService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gitee.sop.story.api.service; - -import com.gitee.sop.story.api.param.DemoParam; -import com.gitee.sop.story.api.result.DemoResult; - -public interface DemoService { - - String sayHello(String name); - - /** - * 获取故事名称 - * @param param - * @return - */ - DemoResult getStory(DemoParam param); - -} \ No newline at end of file diff --git a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/StoryService.java b/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/StoryService.java deleted file mode 100644 index 0b3c9794..00000000 --- a/sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/StoryService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.gitee.sop.story.api.service; - -import com.gitee.sop.story.api.domain.Story; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author tanghc - */ -@RequestMapping("/story") -public interface StoryService { - @RequestMapping("/getStory") - Story getStory(@RequestParam("id")/* 必须指定@RequestParam,且value不能少 */ - int id); -} diff --git a/sop-example/sop-story/sop-story-web/.gitignore b/sop-example/sop-story/sop-story-web/.gitignore deleted file mode 100644 index c456c4a3..00000000 --- a/sop-example/sop-story/sop-story-web/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml deleted file mode 100644 index 41946680..00000000 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - - - com.gitee.sop - sop-story-web - 0.0.1-SNAPSHOT - sop-story - Demo project for Spring Boot - - - 1.8 - 2.6.5 - Greenwich.RELEASE - - 0.9.0.RELEASE - - 1.1.3 - - - - - com.gitee.sop - sop-service-common - 3.1.5-SNAPSHOT - - - com.gitee.sop - sop-story-api - 1.0-SNAPSHOT - - - - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - - com.alibaba.boot - dubbo-spring-boot-starter - 0.2.1.RELEASE - - - com.alibaba - dubbo - ${dubbo.version} - - - io.netty - netty-all - - - - - io.springfox - springfox-swagger2 - 2.9.2 - - - com.github.xiaoymin - swagger-bootstrap-ui - 1.9.5 - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - 1.18.4 - provided - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - true - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java deleted file mode 100644 index e7ed7976..00000000 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.gitee.sop.storyweb.controller; - -import com.gitee.sop.story.api.domain.Story; -import com.gitee.sop.story.api.service.StoryService; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author tanghc - */ -@RestController -public class StoryController implements StoryService { - - // 提供给Feign的服务 - @Override - public Story getStory(int id) { - Story story = new Story(); - story.setId(id); - story.setName("海底小纵队(Feign)"); - return story; - } - - -} diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryDemoController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryDemoController.java deleted file mode 100644 index b07e61fc..00000000 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryDemoController.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.gitee.sop.storyweb.controller; - -import com.gitee.sop.servercommon.annotation.ApiMapping; -import com.gitee.sop.story.api.domain.Story; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author tanghc - */ -@RestController -public class StoryDemoController { - - @ApiMapping(value = "story.demo.get") - public Story getStory() { - Story story = new Story(); - story.setId(1); - story.setName("白雪公主"); - return story; - } - -} diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java deleted file mode 100644 index 2929f9ed..00000000 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.gitee.sop.storyweb.service; - -import com.alibaba.dubbo.config.annotation.Service; -import com.gitee.sop.story.api.param.DemoParam; -import com.gitee.sop.story.api.result.DemoResult; -import com.gitee.sop.story.api.service.DemoService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; - -@Service(version = "1.0.0") -@Slf4j -public class DefaultDemoService implements DemoService { - - /** - * The default value of ${dubbo.application.name} is ${spring.application.name} - */ - @Value("${dubbo.application.name}") - private String serviceName; - - public String sayHello(String name) { - return String.format("[%s] : Hello, %s", serviceName, name); - } - - @Override - public DemoResult getStory(DemoParam param) { - log.info("dubbo provider, param: {}", param); - DemoResult demoResult = new DemoResult(); - demoResult.setId(param.getId()); - demoResult.setName("dubbo 白雪公主, param=" + param); - return demoResult; - } -} \ No newline at end of file diff --git a/sop-example/sop-story/sop-story-web/src/main/resources/application.properties b/sop-example/sop-story/sop-story-web/src/main/resources/application.properties deleted file mode 100644 index 257b3064..00000000 --- a/sop-example/sop-story/sop-story-web/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.profiles.active=dev \ No newline at end of file diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/SopStoryApplication.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/SopStoryApplication.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/SopStoryApplication.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/SopStoryApplication.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/config/OpenServiceConfig.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/config/OpenServiceConfig.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/config/OpenServiceConfig.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/config/OpenServiceConfig.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java similarity index 95% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java index f7510610..8614540e 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java +++ b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java @@ -6,7 +6,6 @@ import com.gitee.sop.servercommon.annotation.ApiAbility; import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.bean.OpenContext; import com.gitee.sop.servercommon.bean.ServiceContext; -import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.storyweb.controller.param.CategoryParam; import com.gitee.sop.storyweb.controller.param.StoryParam; import com.gitee.sop.storyweb.controller.result.CategoryResult; @@ -291,17 +290,6 @@ public class AlipayController { return new TreeResult(); } - // 测试参数绑定,http://localhost:2222/story/getStory4?biz_content=%7b%22id%22%3a1%2c%22name%22%3a%22aaaa%22%7d - @ApiAbility - @GetMapping("getStory4") - public StoryResult getStory4(Story param, P p2) { - System.out.println(param + ", p2=" + p2); - StoryResult result = new StoryResult(); - result.setId(1L); - result.setName("海底小纵队(默认版本号)" + param + ", p2=" + p2); - return result; - } - @Data public static class P { private String name; diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController2.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController2.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController2.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController2.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/DownloadController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/DownloadController.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/DownloadController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/DownloadController.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java similarity index 94% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java index ca830362..86321f14 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java +++ b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java @@ -1,7 +1,6 @@ package com.gitee.sop.storyweb.controller; import com.gitee.sop.servercommon.annotation.ApiMapping; -import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.storyweb.controller.result.StoryResult; import org.springframework.web.bind.annotation.RestController; diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java similarity index 63% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java index 25ac667e..9ef28264 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java +++ b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java @@ -1,9 +1,8 @@ package com.gitee.sop.storyweb.controller; import com.gitee.sop.servercommon.annotation.ApiMapping; -import com.gitee.sop.servercommon.bean.ServiceContext; import com.gitee.sop.servercommon.bean.OpenContext; -import com.gitee.sop.story.api.domain.Story; +import com.gitee.sop.servercommon.bean.ServiceContext; import com.gitee.sop.storyweb.controller.param.StoryParam; import com.gitee.sop.storyweb.controller.result.StoryResult; import org.apache.commons.lang3.StringUtils; @@ -39,25 +38,4 @@ public class PostJsonController { return result; } - /** - * 演示客户端使用json方式请求(application/json) - * @param param - * @return - */ - @ApiMapping(value = "demo.post.json", version = "1.2") - public Story postJson2(StoryParam param) { - // 获取开放平台请求参数 - OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); - List params = Arrays.asList( - openContext.getAppId(), - openContext.getMethod(), - openContext.getVersion() - ); - Story story = new Story(); - story.setId(1); - story.setName("1.2 参数:" + param.getName() + ", openParams:" + StringUtils.join(params)); - return story; - } - - } diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/ThrowExceptionDemoController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/ThrowExceptionDemoController.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/ThrowExceptionDemoController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/ThrowExceptionDemoController.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TokenController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/TokenController.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TokenController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/TokenController.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/CategoryParam.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/CategoryParam.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/CategoryParam.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/CategoryParam.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam2.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam2.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam2.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/FileUploadParam2.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsUpdateParam.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsUpdateParam.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsUpdateParam.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsUpdateParam.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/StoryParam.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/StoryParam.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/StoryParam.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/StoryParam.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/CategoryResult.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/CategoryResult.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/CategoryResult.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/CategoryResult.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/FileUploadResult.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/FileUploadResult.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/FileUploadResult.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/FileUploadResult.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/StoryResult.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/StoryResult.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/StoryResult.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/StoryResult.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/message/GoodsErrorEnum.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/message/GoodsErrorEnum.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/message/GoodsErrorEnum.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/message/GoodsErrorEnum.java diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/message/StoryErrorEnum.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/message/StoryErrorEnum.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/message/StoryErrorEnum.java rename to sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/message/StoryErrorEnum.java diff --git a/sop-example/sop-story/sop-story-web/src/main/resources/application-dev.properties b/sop-example/sop-story/src/main/resources/application-dev.properties similarity index 65% rename from sop-example/sop-story/sop-story-web/src/main/resources/application-dev.properties rename to sop-example/sop-story/src/main/resources/application-dev.properties index ea928967..a6277955 100644 --- a/sop-example/sop-story/sop-story-web/src/main/resources/application-dev.properties +++ b/sop-example/sop-story/src/main/resources/application-dev.properties @@ -4,16 +4,7 @@ spring.application.name=story-service # 如果有context-path,必须配下面这句 #spring.cloud.nacos.discovery.metadata.server.servlet.context-path=${server.servlet.context-path} # nacos注册中心 -#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 - -# eureka注册中心 -eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ - -# dubbo配置 -dubbo.protocol.name=dubbo -dubbo.protocol.port=12345 -dubbo.registry.address=N/A -dubbo.scan.base-packages=com.gitee.sop.storyweb.service +spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 # zipkin服务跟踪 #spring.zipkin.base-url=http://127.0.0.1:9411/ diff --git a/sop-example/sop-book/sop-book-web/src/main/resources/application.properties b/sop-example/sop-story/src/main/resources/application.properties similarity index 100% rename from sop-example/sop-book/sop-book-web/src/main/resources/application.properties rename to sop-example/sop-story/src/main/resources/application.properties diff --git a/sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/bizerror_en.properties b/sop-example/sop-story/src/main/resources/i18n/isp/bizerror_en.properties similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/bizerror_en.properties rename to sop-example/sop-story/src/main/resources/i18n/isp/bizerror_en.properties diff --git a/sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/bizerror_zh_CN.properties b/sop-example/sop-story/src/main/resources/i18n/isp/bizerror_zh_CN.properties similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/bizerror_zh_CN.properties rename to sop-example/sop-story/src/main/resources/i18n/isp/bizerror_zh_CN.properties diff --git a/sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/goods_error_en.properties b/sop-example/sop-story/src/main/resources/i18n/isp/goods_error_en.properties similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/goods_error_en.properties rename to sop-example/sop-story/src/main/resources/i18n/isp/goods_error_en.properties diff --git a/sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/goods_error_zh_CN.properties b/sop-example/sop-story/src/main/resources/i18n/isp/goods_error_zh_CN.properties similarity index 100% rename from sop-example/sop-story/sop-story-web/src/main/resources/i18n/isp/goods_error_zh_CN.properties rename to sop-example/sop-story/src/main/resources/i18n/isp/goods_error_zh_CN.properties diff --git a/sop-example/sop-story/sop-story-web/src/test/java/com/gitee/sop/storyweb/SopStoryApplicationTests.java b/sop-example/sop-story/src/test/java/com/gitee/sop/storyweb/SopStoryApplicationTests.java similarity index 100% rename from sop-example/sop-story/sop-story-web/src/test/java/com/gitee/sop/storyweb/SopStoryApplicationTests.java rename to sop-example/sop-story/src/test/java/com/gitee/sop/storyweb/SopStoryApplicationTests.java diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 1b1d779e..cd7f9651 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -1,28 +1,18 @@ - 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml - com.gitee.sop + + 4.0.0 sop-gateway - 1.0.0-SNAPSHOT - sop-gateway - Demo project for Spring Boot 1.8 - Greenwich.RELEASE - - 0.9.0.RELEASE - - 1.1.3 - - 0.2.3 @@ -34,13 +24,27 @@ com.gitee.sop sop-bridge-gateway - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT + + + + + io.projectreactor.netty + reactor-netty + 0.9.4.RELEASE + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery net.oschina.durcframework fastmybatis-spring-boot-starter - 1.8.6.1 mysql @@ -48,11 +52,6 @@ runtime - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - org.springframework.boot @@ -74,17 +73,6 @@ - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigServiceRoute.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigServiceRoute.java index dbed6fa8..855fbfa7 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigServiceRoute.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigServiceRoute.java @@ -46,8 +46,8 @@ public class ConfigServiceRoute { /** uri后面跟的path, 数据库字段:path */ private String path; - /** 路由执行的顺序, 数据库字段:order */ - private Integer order; + /** 路由执行的顺序, 数据库字段:order_index */ + private Integer orderIndex; /** 是否忽略验证,业务参数验证除外, 数据库字段:ignore_validate */ private Byte ignoreValidate; diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbEnvGrayManager.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbEnvGrayManager.java index c44c5ec5..4bf774d9 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbEnvGrayManager.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbEnvGrayManager.java @@ -6,8 +6,10 @@ import com.gitee.sop.gateway.entity.ConfigGrayInstance; import com.gitee.sop.gateway.mapper.ConfigGrayInstanceMapper; import com.gitee.sop.gateway.mapper.ConfigGrayMapper; import com.gitee.sop.gatewaycommon.bean.ChannelMsg; +import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.gitee.sop.gatewaycommon.bean.ServiceGrayDefinition; import com.gitee.sop.gatewaycommon.manager.DefaultEnvGrayManager; +import com.gitee.sop.gatewaycommon.route.RegistryEvent; import com.gitee.sop.gatewaycommon.zuul.loadbalancer.ServiceGrayConfig; import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; @@ -30,7 +32,7 @@ import java.util.stream.Stream; */ @Slf4j @Service -public class DbEnvGrayManager extends DefaultEnvGrayManager { +public class DbEnvGrayManager extends DefaultEnvGrayManager implements RegistryEvent { private static final int STATUS_ENABLE = 1; @@ -44,19 +46,26 @@ public class DbEnvGrayManager extends DefaultEnvGrayManager { private ConfigGrayInstanceMapper configGrayInstanceMapper; @Override - public void load() { + public void onRegistry(InstanceDefinition instanceDefinition) { + String instanceId = instanceDefinition.getInstanceId(); + ConfigGrayInstance grayInstance = configGrayInstanceMapper.getByColumn("instance_id", instanceId); + if (grayInstance != null && grayInstance.getStatus() == STATUS_ENABLE) { + log.info("实例[{}]开启灰度发布", grayInstance.getInstanceId()); + this.openGray(grayInstance.getInstanceId(), grayInstance.getServiceId()); + } + } + @Override + public void onRemove(String serviceId) { + + } + + @Override + public void load() { List list = configGrayMapper.list(new Query()); for (ConfigGray configGray : list) { this.setServiceGrayConfig(configGray); } - - Query query = new Query(); - query.eq("status", STATUS_ENABLE); - List grayInstanceList = configGrayInstanceMapper.list(query); - for (ConfigGrayInstance configGrayInstance : grayInstanceList) { - this.openGray(configGrayInstance.getInstanceId(), configGrayInstance.getServiceId()); - } } /** diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbRoutesProcessor.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbRoutesProcessor.java index ca0a21be..6740f2d8 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbRoutesProcessor.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbRoutesProcessor.java @@ -59,7 +59,7 @@ public class DbRoutesProcessor implements RoutesProcessor { configServiceRoute.setMergeResult((byte) routeDefinition.getMergeResult()); configServiceRoute.setStatus((byte) routeDefinition.getStatus()); configServiceRoute.setPermission((byte) routeDefinition.getPermission()); - configServiceRoute.setOrder(routeDefinition.getOrder()); + configServiceRoute.setOrderIndex(routeDefinition.getOrder()); configServiceRoute.setNeedToken((byte)routeDefinition.getNeedToken()); configServiceRoute.setServiceId(serviceId); return configServiceRoute; diff --git a/sop-mysql5.6以下版本.sql b/sop-mysql5.6以下版本.sql index 7d0cd7fa..d56a288c 100644 --- a/sop-mysql5.6以下版本.sql +++ b/sop-mysql5.6以下版本.sql @@ -222,7 +222,7 @@ CREATE TABLE `config_service_route` ( `filters` VARCHAR(256) DEFAULT NULL COMMENT '路由过滤器(SpringCloudGateway专用)', `uri` VARCHAR(128) NOT NULL DEFAULT '' COMMENT '路由规则转发的目标uri', `path` VARCHAR(128) NOT NULL DEFAULT '' COMMENT 'uri后面跟的path', - `order` INT(11) NOT NULL DEFAULT '0' COMMENT '路由执行的顺序', + `order_index` INT(11) NOT NULL DEFAULT '0' COMMENT '路由执行的顺序', `ignore_validate` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否忽略验证,业务参数验证除外', `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '状态,0:待审核,1:启用,2:禁用', `merge_result` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否合并结果', diff --git a/sop-sdk/pom.xml b/sop-sdk/pom.xml index 14908be5..8ddf5b87 100644 --- a/sop-sdk/pom.xml +++ b/sop-sdk/pom.xml @@ -2,8 +2,15 @@ + + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml + + 4.0.0 - com.gitee.sop sop-sdk 1.0.0-SNAPSHOT pom diff --git a/sop-sdk/sdk-java/pom.xml b/sop-sdk/sdk-java/pom.xml index d7f37743..28fe5475 100644 --- a/sop-sdk/sdk-java/pom.xml +++ b/sop-sdk/sdk-java/pom.xml @@ -1,7 +1,14 @@ + + + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 - com.gitee.sop sdk-java 1.0.0-SNAPSHOT @@ -17,20 +24,17 @@ com.squareup.okhttp3 okhttp - 3.14.0 com.alibaba fastjson - 1.2.62 commons-logging commons-logging - 1.2 diff --git a/sop-test/pom.xml b/sop-test/pom.xml index c6e167f5..14da7a43 100644 --- a/sop-test/pom.xml +++ b/sop-test/pom.xml @@ -3,16 +3,15 @@ - sop-parent com.gitee.sop + sop-parent 1.0.0-SNAPSHOT + ../pom.xml - 4.0.0 + 4.0.0 sop-test - sop-test - UTF-8 1.8 @@ -22,24 +21,19 @@ com.squareup.okhttp3 okhttp - 3.14.0 - compile commons-io commons-io - 2.5 com.alibaba fastjson - 1.2.62 + commons-codec commons-codec - 1.11 - compile org.projectlombok @@ -56,40 +50,4 @@ - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - true - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - UTF-8 - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - diff --git a/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java index fa3c93e2..08d062b2 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java @@ -1,7 +1,6 @@ package com.gitee.sop.test; import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipayApiException; import com.gitee.sop.test.alipay.AlipaySignature; import org.junit.Test; @@ -37,6 +36,8 @@ public class AlipayClientPostTest extends TestBase { @Test public void testGet() throws Exception { + // 接口实现见:com.gitee.sop.storyweb.controller.AlipayController.getStory + // 公共请求参数 Map params = new HashMap(); params.put("app_id", appId); @@ -71,231 +72,4 @@ public class AlipayClientPostTest extends TestBase { } - // 这个请求会路由到book服务 - @Test - public void testPostBook() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "alipay.book.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "1"); - bizContent.put("name", "葫芦娃"); -// bizContent.put("name", "葫芦娃1234567890葫芦娃1234567890"); // 超出长度 - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - // 这个请求会路由到book服务,然后再调用story服务 - // gateway -> book-service -> story-service - @Test - public void testPostBook2() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "alipay.book.story.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "1"); - bizContent.put("name", "葫芦娃"); -// bizContent.put("name", "葫芦娃1234567890葫芦娃1234567890"); // 超出长度 - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - // 测试dubbo服务,book会调用story提供的服务。参见:DemoConsumerController.java - @Test - public void testDubboDemo() throws Exception { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "dubbo.story.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "222"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - // 忽略验证,不校验签名,只需传接口名、版本号、业务参数 - @Test - public void testIgnore() { - // 公共请求参数 - Map params = new HashMap(); - params.put("method", "story.get"); - params.put("version", "2.1"); - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "222"); - bizContent.put("name", "忽略验证name"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - @Test - public void testStoryget() throws AlipayApiException { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "story.get"); - params.put("version", "2.2"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "222"); - bizContent.put("name", "忽略验证22"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - @Test - public void testGetStory2() throws AlipayApiException { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "getStory2"); - params.put("version", "1.0"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("name", "Jim"); - bizContent.put("age", "2"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = get(url, params);// 发送请求 - System.out.println(responseData); - } - - @Test - public void testGetJson() throws AlipayApiException { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "getJson"); - params.put("version", "1.0"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("name", "Jim"); - bizContent.put("age", "2"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = get(url, params);// 发送请求 - System.out.println(responseData); - } - } diff --git a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java index a34f26de..0f8e157a 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java @@ -83,33 +83,6 @@ public class AllInOneTest extends TestBase { client.execute(requestBuilder); } - /** - * 测试feign。gateway -> book-service(consumer) -> story-service(provider) - */ - public void testFeign() { - Client.RequestBuilder requestBuilder = new Client.RequestBuilder() - .method("alipay.book.story.get") - .version("1.0") - .bizContent(new BizContent()) - .httpMethod(HttpTool.HTTPMethod.GET); - - client.execute(requestBuilder); - } - - /** - * 测试dubbo服务,book会调用story提供的服务。参见:DemoConsumerController.java - */ - public void testDubbo() { - Client.RequestBuilder requestBuilder = new Client.RequestBuilder() - .method("dubbo.story.get") - .version("1.0") - .bizContent(new BizContent().add("id", "222")) - .httpMethod(HttpTool.HTTPMethod.GET); - - client.execute(requestBuilder); - - } - /** * 忽略验证,不校验签名,只需传接口名、版本号、业务参数 */ diff --git a/sop-test/src/test/java/com/gitee/sop/test/DubboDemoTest.java b/sop-test/src/test/java/com/gitee/sop/test/DubboDemoTest.java deleted file mode 100644 index 2abf2947..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/DubboDemoTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipaySignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * 测试dubbo服务调用,需要启动book服务 - * @author tanghc - */ -public class DubboDemoTest extends TestBase { - - String url = "http://localhost:8081"; - String appId = "2019032617262200001"; - // 平台提供的私钥 - String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; - - // 测试dubbo服务,book会调用story提供的服务。参见:DemoConsumerController.java - @Test - public void testDemo() throws Exception { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "dubbo.story.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "222"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/EasyopenClientPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/EasyopenClientPostTest.java deleted file mode 100644 index 7846c23f..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/EasyopenClientPostTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import org.apache.commons.codec.digest.DigestUtils; -import org.junit.Test; - -import java.io.IOException; -import java.net.URLEncoder; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author tanghc - */ -public class EasyopenClientPostTest extends TestBase { - - String url = "http://localhost:8081"; - String appKey = "easyopen_test"; - String secret = "G9w0BAQEFAAOCAQ8AMIIBCgKCA"; - - @Test - public void testPost() throws IOException { - // 业务参数 - Map bizParams = new HashMap(); - bizParams.put("goods_name", "iphoneX"); - - String json = JSON.toJSONString(bizParams); - json = URLEncoder.encode(json, "utf-8"); - - // 系统参数 - Map params = new HashMap<>(); - params.put("name", "easyopen.goods.get"); - params.put("app_key", appKey); - params.put("data", json); - params.put("timestamp", getTime()); - params.put("version", ""); - - String sign = buildSign(params, secret); - - params.put("sign", sign); - - System.out.println("=====请求数据====="); - System.out.println(JSON.toJSONString(params)); - System.out.println("=====返回结果====="); - String resp = post(url, params); - System.out.println(resp); - } - - /** - * 构建签名串 - * @param paramsMap 请求参数 - * @param secret 秘钥 - * @return - * @throws IOException - */ - public String buildSign(Map paramsMap, String secret) throws IOException { - Set keySet = paramsMap.keySet(); - List paramNames = new ArrayList(keySet); - - Collections.sort(paramNames); - - StringBuilder paramNameValue = new StringBuilder(); - - for (String paramName : paramNames) { - paramNameValue.append(paramName).append(paramsMap.get(paramName)); - } - - String source = secret + paramNameValue.toString() + secret; - - return md5(source); - } - - /** - * 生成md5,全部大写。 - * - * @param source - * @return - */ - public static String md5(String source) { - return DigestUtils.md5Hex(source).toUpperCase(); - } - - public String getTime() { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); - } -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/PostFormTest.java b/sop-test/src/test/java/com/gitee/sop/test/PostFormTest.java deleted file mode 100644 index a56a3013..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/PostFormTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipaySignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * post请求,模拟表单提交(application/x-www-form-urlencoded) - */ -public class PostFormTest extends TestBase { - - String url = "http://localhost:8081"; - String appId = "2019032617262200001"; - // 平台提供的私钥 - String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; - - @Test - public void testPostForm() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "demo.post.json"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("name", "葫芦娃"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java b/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java deleted file mode 100644 index c091c162..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipaySignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * 以json方式请求(application/json) - */ -public class PostJsonTest extends TestBase { - - String url = "http://localhost:8081"; - String appId = "2019032617262200001"; - // 平台提供的私钥 - String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; - - @Test - public void testPostJson() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "demo.post.json"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("name", "葫芦娃"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = postJson(url, params);// 发送请求 - System.out.println(responseData); - } - - @Test - public void testPostJson2() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "demo.post.json"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.2"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("name", "葫芦娃"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = postJson(url, params);// 发送请求 - System.out.println(responseData); - } - -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/RestUrlTest.java b/sop-test/src/test/java/com/gitee/sop/test/RestUrlTest.java deleted file mode 100644 index 03f859c6..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/RestUrlTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipaySignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * @author tanghc - */ -public class RestUrlTest extends TestBase { - - String appId = "2019032617262200001"; - // 平台提供的私钥 - String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; - - /** - * 演示将接口名版本号跟在url后面,规则:http://host:port/{method}/{version}/ - * @throws Exception - */ - @Test - public void testDemo() throws Exception { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - // 参数中的接口名和版本转移到了url中 -// params.put("method", "story.demo.get"); -// params.put("version", "1.0"); - // 注意这里的url - String url = "http://localhost:8081/story.demo.get/1.0/"; - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - - // 业务参数 - Map bizContent = new HashMap<>(); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/SpringCloudGatewayClientPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/SpringCloudGatewayClientPostTest.java deleted file mode 100644 index fee40b44..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/SpringCloudGatewayClientPostTest.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipaySignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * 模仿支付宝客户端请求接口 - */ -public class SpringCloudGatewayClientPostTest extends TestBase { - - String url = "http://localhost:8081"; // spring cloud gateway - String appId = "2019032617262200001"; - // 平台提供的私钥 - String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; - - /* - 参数 类型 是否必填 最大长度 描述 示例值 -app_id String 是 32 支付宝分配给开发者的应用ID 2014072300007148 -method String 是 128 接口名称 alipay.trade.fastpay.refund.query -format String 否 40 仅支持JSON JSON -charset String 是 10 请求使用的编码格式,如utf-8,gbk,gb2312等 utf-8 -sign_type String 是 10 商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2 RSA2 -sign String 是 344 商户请求参数的签名串,详见签名 详见示例 -timestamp String 是 19 发送请求的时间,格式"yyyy-MM-dd HH:mm:ss" 2014-07-24 03:07:50 -version String 是 3 调用的接口版本,固定为:1.0 1.0 -app_auth_token String 否 40 详见应用授权概述 -biz_content String 是 请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档 - */ - // 这个请求会路由到story服务 - @Test - public void testPost() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "alipay.story.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "1"); - bizContent.put("name", "葫芦娃"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - // 这个请求会路由到book服务 - @Test - public void testPostBook() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "alipay.book.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "1"); - bizContent.put("name", "葫芦娃"); -// bizContent.put("name", "葫芦娃1234567890葫芦娃1234567890"); // 超出长度 - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - // 这个请求会路由到book服务,然后再调用story服务 - // gateway -> book-service -> story-service - @Test - public void testPostBook2() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "alipay.book.story.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("id", "1"); - bizContent.put("name", "葫芦娃"); -// bizContent.put("name", "葫芦娃1234567890葫芦娃1234567890"); // 超出长度 - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - public void testPost2() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "alipay.category.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("categoryName", "啊啊啊"); - Map storyParam = new HashMap<>(); - storyParam.put("id", "1"); - storyParam.put("name", "葫芦娃啊啊啊"); - bizContent.put("storyParam", storyParam); - - - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/StoryDemoTest.java b/sop-test/src/test/java/com/gitee/sop/test/StoryDemoTest.java deleted file mode 100644 index 40a3ab6b..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/StoryDemoTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.gitee.sop.test; - -import com.alibaba.fastjson.JSON; -import com.gitee.sop.test.alipay.AlipaySignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * @author tanghc - */ -public class StoryDemoTest extends TestBase { - - String url = "http://localhost:8081"; - String appId = "2019032617262200001"; - // 平台提供的私钥 - String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; - - @Test - public void testDemo() throws Exception { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "story.demo.get"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - - @Test - public void testGoodsAdd() throws Exception { - // 公共请求参数 - Map params = new HashMap(); - params.put("app_id", appId); - params.put("method", "goods.add"); - params.put("format", "json"); - params.put("charset", "utf-8"); - params.put("sign_type", "RSA2"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("version", "1.0"); - - // 业务参数 - Map bizContent = new HashMap<>(); - bizContent.put("goods_name", "iphone6"); - - params.put("biz_content", JSON.toJSONString(bizContent)); - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + privateKey); - String content = AlipaySignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - -} diff --git a/sop-test/src/test/java/com/gitee/sop/test/TaobaoClientPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/TaobaoClientPostTest.java deleted file mode 100644 index f1f9e4b2..00000000 --- a/sop-test/src/test/java/com/gitee/sop/test/TaobaoClientPostTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.gitee.sop.test; - -import com.gitee.sop.test.taobao.TaobaoSignature; -import org.junit.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * 模仿淘宝客户端请求接口 - */ -public class TaobaoClientPostTest extends TestBase { - - - String url = "http://localhost:8081"; - String appId = "taobao_test"; - // 淘宝私钥 - String secret = "G9w0BAQEFAAOCAQ8AMIIBCgKCA"; - - /* -参数名称 参数类型 是否必须 参数描述 -method String 是 API接口名称。 -app_key String 是 TOP分配给应用的AppKey。这里要注意正式环境和沙箱环境的AppKey是不同的(包括AppSecret),使用时要注意区分;进入开放平台控制台“应用管理-概览” 和 “应用管理-沙箱环境管理”可分别查看正式环境及沙箱环境的AppKey、AppSecret -session String 否 用户登录授权成功后,TOP颁发给应用的授权信息,详细介绍请点击这里。当此API文档的标签上注明:“需要授权”,则此参数必传;“不需要授权”,则此参数不需要传;“可选授权”,则此参数为可选。 -timestamp String 是 时间戳,格式为yyyy-MM-dd HH:mm:ss,时区为GMT+8,例如:2016-01-01 12:00:00。淘宝API服务端允许客户端请求最大时间误差为10分钟。 -format String 否 响应格式。默认为xml格式,可选值:xml,json。 -v String 是 API协议版本,可选值:2.0。 -partner_id String 否 合作伙伴身份标识。 -target_app_key String 否 被调用的目标AppKey,仅当被调用的API为第三方ISV提供时有效。 -simplify Boolean 否 是否采用精简JSON返回格式,仅当format=json时有效,默认值为:false。 -sign_method String 是 签名的摘要算法,可选值为:hmac,md5。 -sign String 是 API输入参数签名结果,签名算法参照下面的介绍。 - */ - @Test - public void testPost() throws Exception { - - // 公共请求参数 - Map params = new HashMap(); - params.put("app_key", appId); - params.put("method", "alipay.story.get"); - params.put("format", "json"); - params.put("sign_method", "md5"); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - params.put("v", ""); - - // 业务参数 - params.put("id", "1"); - params.put("name", "葫芦娃"); -// bizContent.put("name", "葫芦娃1234567890葫芦娃1234567890"); // 超出长度 - - System.out.println("----------- 请求信息 -----------"); - System.out.println("请求参数:" + buildParamQuery(params)); - System.out.println("商户秘钥:" + secret); - String content = TaobaoSignature.getSignContent(params); - System.out.println("待签名内容:" + content); - String sign = TaobaoSignature.doSign(content, secret, "md5"); - System.out.println("签名(sign):" + sign); - - params.put("sign", sign); - - System.out.println("----------- 返回结果 -----------"); - String responseData = post(url, params);// 发送请求 - System.out.println(responseData); - } - -} diff --git a/sop-website/pom.xml b/sop-website/pom.xml index a8944ea5..c299458c 100644 --- a/sop-website/pom.xml +++ b/sop-website/pom.xml @@ -1,46 +1,31 @@ - 4.0.0 + - org.springframework.boot - spring-boot-starter-parent - 2.1.2.RELEASE - + com.gitee.sop + sop-parent + 1.0.0-SNAPSHOT + ../pom.xml - com.gitee.sop + + 4.0.0 sop-website - 1.0.0-SNAPSHOT - sop-website - sop-website 1.8 - Greenwich.RELEASE - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - com.gitee.sop sop-gateway-common - 3.1.5-SNAPSHOT + 3.2.0-SNAPSHOT - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery @@ -49,28 +34,21 @@ - commons-lang - commons-lang - 2.6 - compile + org.apache.commons + commons-lang3 com.squareup.okhttp3 okhttp - 3.14.0 - compile com.alibaba fastjson - 1.2.62 - compile org.apache.httpcomponents httpclient - 4.5.6 diff --git a/sop.sql b/sop.sql index 4df5d424..a9f95d31 100644 --- a/sop.sql +++ b/sop.sql @@ -224,7 +224,7 @@ CREATE TABLE `config_service_route` ( `filters` varchar(256) DEFAULT NULL COMMENT '路由过滤器(SpringCloudGateway专用)', `uri` varchar(128) NOT NULL DEFAULT '' COMMENT '路由规则转发的目标uri', `path` varchar(128) NOT NULL DEFAULT '' COMMENT 'uri后面跟的path', - `order` int(11) NOT NULL DEFAULT '0' COMMENT '路由执行的顺序', + `order_index` int(11) NOT NULL DEFAULT '0' COMMENT '路由执行的顺序', `ignore_validate` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否忽略验证,业务参数验证除外', `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态,0:待审核,1:启用,2:禁用', `merge_result` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否合并结果',