2 Star 9 Fork 5

ddCat / shop-cloud

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

开发说明

本文档需要有一定基础的人看,需要具备 SpringCloud + SringBoot 开发基础、Mysql基础、Mongodb基础、Redis基础.

本项目前后端完全分离,使用JSON数据进行前后端数据交互,接口文档使用Swagger2文档.

项目开发技术说明:

核心包: Spring Boot - 项目基于Spring Boot Start Web核心包,版本号: 2.3.1.RELEASE.

微服务架构基于: Spring Cloud,版本号: Hoxton.SR6

使用: Eureka + Spring Cloud Config + Open Feign + TX-LCN分布式事务 + Zipkin链路追踪

面向切面: 项目中面向切面(AOP)使用 SpringBoot 拦截器.

缓存: 前期使用单机架构Redis, 后期业务上数据量提高可做Redis集群.

数据库(DB): MYSQL - 版本号: 8.0.21

持久化框架: SpringBoot 集成 MyBatis - 版本号: 1.3.2

持久化数据分页框架: PageHelper - 版本号: 1.2.5

数据库连接池: Druid - 版本号: 1.1.22

接口文档: swagger : knife4j-spring-ui

分布式锁: 使用 Redisson

JSON解析器: 阿里JSON解析器fastjson - 版本号: 1.2.73

权限框架:

管理后台使用 Spring Security 安全认证
前端接口(APP/H5) 使用jwt

目录说明

等待完善。。。。。

微服务启动顺序

1. shop-eureka-server ---> ShopEurekaServerApplication 注册中心

    访问: http://127.0.0.1:11111 查看eureka服务注册情况

2. shop-config-server ---> ConfigApplication 配置中心

3. shop-tx ---> TxApplication 分布式事务控制中心

    需要创建 "shop_tx" 数据库(doc/sql/shop-tx/TX-LCN分布式事务-INIT.sql), 初始化sql.
    更改配置文件中tx-lcn mysql连接信息: shop-config/shop-tx/shop-tx-dev.properties, shop-config/shop-oms/shop-oms-dev.properties, shop-config/shop-pms/shop-pms-dev.properties
        
    访问:http://127.0.0.1:7970/admin/index.html#/login 进入管理后台
    
    默认密码是:codingapi

4. shop-pms ---> pms-server ---> PMSApplication 商品微服务

5. shop-oms ---> oms-server ---> OMSApplication 订单微服务

6. shop-gateway ---> GatewayApplication 统一网关 (使用 GateWay,因为gateway集成的SpringWebflux)
    
   访问: http://127.0.0.1:5555/order/order/orderInfo/13 

        通过 Gateway 网关请求订单微服务    

SpringCloud微服务架构图

Image text

Fegin 使用

Image text

接口规范:

1.协议

API与用户的通信协议,总是使用HTTPS协议,确保交互数据的传输安全。

2.安全

为了保证接口接收到的数据不是被篡改以及防止信息泄露造成损失,对敏感数据进行加密及签名。

数据加密
api接口请求参数一律采用RSA进行加解密,在客户端使用公钥对请求参数进行加密,在服务端使用对数私钥据进行解密,防止信息泄露。

签名
为了防止请求数据在网络传输过程中被恶意篡改,对所有非查询接口增加数字签名,签名原串为对请求参数进行自然排序,通过私钥加签后放入sign参数中。

时间戳
api接口中增加时间戳timestamp字段,作用:固定时间范围内,减少同一请求被暴力调用的次数。

3.API版本控制

API的版本号统一放入URL。
https://api.example.com/v{n}/ --- v{n}n代表版本号,分为整形和浮点型
整形版本号:大功能版本发布形式;具有当前版本状态下的所有API接口,例如:v1,v2
浮点型:为小版本号,只具备补充api的功能,其他api都默认调用大版本号的API,例如v1.1,v1.2

4.API路径规则

在RESTful架构中,每个网址代表一种资源(resource),所以网址中不能有动词,只能有名词。名词尽量与数据库表格名对应。

例子:

https://api.example.com/v1/products
https://api.example.com/v1/users
https://api.example.com/v1/employees

5.HTTP请求方式

对于资源的具体操作类型,由HTTP动词表示。
常用的HTTP动词由下面四个(括号里是对应的SQL命令)。
GET(SELECT):从服务器取出资源。
POST(CREATE):在服务器新建一个资源。
PUT(UPDATE):在服务器更新资源。
DELETE(DELETE):从服务器删除资源。

例子:

GET/product:列出所有商品
POST/product:新建一个商品
GET/product/ID:获取某个指定商品的信息
PUT/product/ID:更新某个指定商品的信息
DELETE/product/ID:删除某个商品
GET/product/ID/purchase:列出某个指定商品的所有投资者
GET/product/ID/purchase/ID:获取某个指定商品的指定投资者信息

6.请求数据

公共请求参数

POST 请求: 接受json格式请求参数 使用注册 @RequestBody ,需要单独封装dto,进行接受请求参数

    {
        "request": {
           "name": "ddcat",
           "age": 18
        }
    }

示例:

@ApiOperation("增加币种")
@AnonymousAccess
@GetMapping("/add")
AjaxResult add(@RequestBody CoinDTO coin){
    if(coin == null){
       return AjaxResult.error("币种信息不能为空!");
    }
    // 下面执行把dto转为实体类然后插入业务....
    return AjaxResult.success("新增成功");
}

GET 请求:以 key=value 接受请求参数 使用注解 @RequestParam 标注每个接口参数

    https://ip:port/api/v1/coin/info?id=129&value=wawd

示例:

@ApiOperation("查询币种详情")
@AnonymousAccess
@GetMapping("/info")
AjaxResult info(@RequestParam(value = "id", required = false) Long id){
    if(id == null){
        return AjaxResult.error("查询币种不能为空,请稍后重试!");
    }
    // 下面执行查询业务....
    Coin coin = new Coin();
    return AjaxResult.success(coin);
}
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

基于Spring Cloud构建的一个商城项目,包括前端,后端和h5应用,作为微服务架构的模板项目。基于SpringBoot2.x、SpringCloud Hoxton.SR6并采用前后端分离的企业级微服务敏捷开发系统架构。并引入组件化的思想实现高内聚低耦合,[ 微信 + 支付宝 + 百度 + 头条 ] 小程序 + APP + 公众号 + PC + H5 项目代码简洁注释丰富上手容易,适合学习和企业中使用。真正实现了基于oauth2的jwt和无状态统一权限认证的解决方案,面向互联网设计同时适合B端和C端用户,支持CI/CD多环境部署,提供应用管理方便第三方系统接入;同时还集合各种微服务治理功能和监控功能。模块包括: 企业级的认证系统、开发平台、应用监控、慢sql监控、统一日志、单点登录... 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/hengge666/shop-cloud.git
git@gitee.com:hengge666/shop-cloud.git
hengge666
shop-cloud
shop-cloud
develop

搜索帮助