From f2eb15ce11fba7d1d34b800e08d1555ab3e89550 Mon Sep 17 00:00:00 2001 From: pengshiyu <1940607002@qq.com> Date: Sun, 12 Jun 2022 22:23:12 +0800 Subject: [PATCH] fix --- _sidebar.md | 3 +- blog/elasticsearch/index.md | 5 + blog/elasticsearch/install.md | 19 +- blog/pay/create-project.md | 426 ++++++++++++++++++++++++++++++++ blog/pay/security.md | 79 ++++++ blog/pay/start.md | 42 ++++ blog/pay/weixin-pay.md | 16 ++ blog/php-mysql/index.md | 4 +- blog/php-mysql/sql-variables.md | 2 +- doc/index.md | 2 + doc/javascript.md | 14 +- 11 files changed, 606 insertions(+), 6 deletions(-) create mode 100644 blog/pay/create-project.md create mode 100644 blog/pay/security.md create mode 100644 blog/pay/start.md create mode 100644 blog/pay/weixin-pay.md diff --git a/_sidebar.md b/_sidebar.md index 53f3083..471e558 100644 --- a/_sidebar.md +++ b/_sidebar.md @@ -34,4 +34,5 @@ - 其他 - [其他](doc/index.md) - - [chrome](doc/chrome.md) \ No newline at end of file + - [chrome](doc/chrome.md) + - [微信支付](blog/pay/weixin-pay.md) \ No newline at end of file diff --git a/blog/elasticsearch/index.md b/blog/elasticsearch/index.md index 7a69fd2..85439a5 100644 --- a/blog/elasticsearch/index.md +++ b/blog/elasticsearch/index.md @@ -40,3 +40,8 @@ Elastic Stack [聚合查询 aggregation](blog/elasticsearch/aggregation.md) +[核心概念] + +[搜索和查询] + +https://www.bilibili.com/video/BV1LY4y167n5?p=20&vd_source=efbb4dc944fa761b6e016ce2ca5933da \ No newline at end of file diff --git a/blog/elasticsearch/install.md b/blog/elasticsearch/install.md index 54bda61..b313d69 100644 --- a/blog/elasticsearch/install.md +++ b/blog/elasticsearch/install.md @@ -313,6 +313,24 @@ http.cors.allow-origin: "*" 备用地址:[https://github.com/mouday/ElasticSearch-Head.crx](https://github.com/mouday/ElasticSearch-Head.crx) +## 集群健康检查 + +- green 集群健康 +- yellow 至少一个数据可用 +- red 数据不完整,集群不可用 + +查看健康值 +```bash +# 返回简要 +GET _cat/health + +# 返回带有标题的数据 +GET _cat/health?v + +# 返回json数据 +GET _cluster/health +``` + ## 5、不同编程语言的客户端 https://www.elastic.co/guide/en/elasticsearch/client/index.html @@ -364,5 +382,4 @@ server { } } ``` - https://www.bilibili.com/video/BV1LY4y167n5?p=5&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da \ No newline at end of file diff --git a/blog/pay/create-project.md b/blog/pay/create-project.md new file mode 100644 index 0000000..501c15b --- /dev/null +++ b/blog/pay/create-project.md @@ -0,0 +1,426 @@ +# 创建项目 + +- SpringBoot java SpringMVC RESTful json +- Swagger 接口文档和测试页面生成工具 +- 定义统一的结果 让前后端数据通信更规范 +- MySQL +- MyBatis-Plus +- Vue.js + +## 创建项目 + +阿里云脚手架:https://start.aliyun.com/ + +版本:SpringBoot 2.3.7 + +依赖 + +```xml + + + + org.springframework.boot + + spring-boot-starter-web + +``` + +配置文件 + +application.properties 重命名为 application.yml + +```yaml +# application.yml + +server: + port: 8090 + +sprint: + applicaiotn: + # 应用名称 + name: payment-demo + +``` + +定义测试接口 + +```java +package com.mouday.paymentdemo.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/product") +public class ProductController { + + @GetMapping("/test") + public String test(){ + return "Hello"; + } +} + +``` + + +访问测试 + +http://localhost:8090/api/product/test + + +## 引入 swagger + +```xml + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + + io.springfox + springfox-swagger-ui + 2.9.2 + +``` + +配置文件 + +```java +package com.mouday.paymentdemo.config; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + + @Bean + public Docket docket() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(new ApiInfoBuilder().title("微信支付文档").build()); + } +} + +``` + +完善接口配置 +```java +package com.mouday.paymentdemo.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "商品管理") +@RestController +@RequestMapping("/api/product") +public class ProductController { + + @ApiOperation("测试接口") + @GetMapping("/test") + public String test(){ + return "Hello"; + } +} + +``` + +查看地址:http://localhost:8090/swagger-ui.html + + +## 引入lombok + +```xml + + + org.projectlombok + lombok + +``` + +## 定义统一的返回格式 + +```java +package com.mouday.paymentdemo.vo; + +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + + +@Data +public class Result { + + // 响应码 + private Integer code; + + //响应消息 + private String message; + + //响应数据 + private Map data = new HashMap<>(); + + public static Result success() { + Result result = new Result(); + result.setCode(0); + result.setMessage("成功"); + return result; + } + + public static Result error() { + Result result = new Result(); + result.setCode(-1); + result.setMessage("失败"); + return result; + } + + public Result data(String key, Object value) { + this.data.put(key, value); + return this; + } +} + +``` + +使用 +```java +package com.mouday.paymentdemo.controller; + +import com.mouday.paymentdemo.vo.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Date; + +@Api(tags = "商品管理") +@RestController +@RequestMapping("/api/product") +public class ProductController { + + @ApiOperation("测试接口") + @GetMapping("/test") + public Result test(){ + return Result.success().data("now", new Date()); + } +} + +``` + +返回结果 +```json +{ + "code": 0, + "message": "成功", + "data": { + "now": "2022-06-12T02:59:15.447+00:00" + } +} +``` + +## 引入数据库依赖 + +```xml + + + mysql + mysql-connector-java + 8.0.15 + + + + + com.baomidou + mybatis-plus-boot-starter + 3.3.2 + +``` + +创建数据库 + +```bash +mysql -uroot -p + +create database db_payment_demo; +``` +数据库信息配置 + +```yaml +# application.yml +sprint: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + # 设置连接的时区和字符编码 + url: jdbc:mysql://localhost:3306/db_payment_demo?serverTimezone=Asia/Shanghai&characterEncoding=utf-8 + username: root + password: 123456 + +``` + +实现以下类 + +```bash +entity + BaseEntity.java +mapper + /xml +service + /impl +``` + +扫描mapper类 + +```java +package com.mouday.paymentdemo.config; + + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@MapperScan("com.mouday.paymentdemo.mapper") +// 启用事务管理 +@EnableTransactionManagement +public class MyBatisPlusConfig { + +} + +``` + +打包xml文件 + +```xml + + + + + src/main/java + + **/*.xml + + false + + + +``` + + +```yaml +# 配置 mybatis-plus +mybatis-plus: + configuratin: + # sql日志 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath:com/mouday/paymentdemo/mapper/xml/*.xml +``` + +## 前端项目 + +安装Node.js +``` +node -v +14.18.0 +``` + +编辑工具:vscode + +插件: Volar vue-helper + +vue.js: https://cn.vuejs.org/index.html + +```bash +# 设置淘宝镜像 +npm config set registry https://registry.npm.taobao.org + +# 全局安装vue-cli +npm install @vue/cli -g + +# 创建vue2项目 +vue create vue-demo + +# 运行项目 +npm run serve -- --port 8001 + +# 清屏 +ctrl + l +``` + +浏览器开发工具:vue.js devtools + +数据绑定 +```vue + + +
{{name}}
+ + + + + + +
+ + +``` + +内容 + +1. 引入支付参数 +2. 加载商户私钥 +3. 获取平台证书和验证签名 +4. 获取HttpClient对象 +5. API字典和接口规则 +6. 内网穿透 +7. API v3 + +```xml + + + org.springframework.boot + spring-boot-configuration-processor + true + +``` + + +```xml + + + com.google.code.gson + gson + +``` + diff --git a/blog/pay/security.md b/blog/pay/security.md new file mode 100644 index 0000000..5cb37d4 --- /dev/null +++ b/blog/pay/security.md @@ -0,0 +1,79 @@ + +# 加密 + +术语: +``` +明文 plain text +密文 cipher text +秘钥 key +加密 encrypt +解密 decrtpt +加密算法 +``` + +## 对称加密 + +加密解密的秘钥是同一个 +``` +明文 秘钥加密 密文 秘钥解密 明文 +``` + +eg: AES + +## 非对称加密 + +加密解密的秘钥不是同一个 + +``` +明文 公钥加密 密文 私钥解密 明文 +``` + +eg: RSA + +|加密分类 | 优点 | 缺点 +|- | - | - +|对称加密 | 速度快 | 消息容易被破解 +|非对称加密 | 速度慢 | 消息不容易被破解 + + +## 身份认证 + +- 加密信息:公钥加密 -> 私钥解密 +- 身份认证:私钥加密 -> 公钥解密 + +## 摘要算法 + +摘要算法(Digest Algorithm)即:散列函数、哈希函数(Hash Function) + +作用:保证数据完整性 + +``` +固定长度字符串 = Hash(任意长度字符串) +``` + +好的摘要算法: + +- 不可逆 +- 难题友好性 +- 发散性 +- 抗碰撞性 + +常见算法:MD5、SHA1、SHA2(SHA224、SHA256、SHA384) + +## 数字签名 + +``` +发送方: +原文 -> hash -> 签名 -> private key -> 密文 + +接收方: +密文 -> public key -> 明文 -> hash -> 签名 +``` + +## 数字证书 + +- 公钥 +- 所有者 +- 颁发者 + +使用场景:https diff --git a/blog/pay/start.md b/blog/pay/start.md new file mode 100644 index 0000000..dbe1017 --- /dev/null +++ b/blog/pay/start.md @@ -0,0 +1,42 @@ +# 接入指引 + +1. 申请APPID + - 公众号: https://mp.weixin.qq.com/ + - 小程序:https://mp.weixin.qq.com/ + - APP 开放平台:https://open.weixin.qq.com/ + +2. 申请mchid(商户号) + - 微信商户平台:https://pay.weixin.qq.com/ + +3. API v3密钥 + - 微信商户平台:https://pay.weixin.qq.com/ + +4. 商户证书 + - 微信商户平台:https://pay.weixin.qq.com/ + +5. 微信平台证书 + - Java命令行下载工具: https://github.com/wechatpay-apiv3/CertificateDownloader + - php命令行下载工具:[https://github.com/wechatpay-apiv3/wechatpay-php/blob/main/bin/README.md](https://github.com/wechatpay-apiv3/wechatpay-php/blob/main/bin/README.md) + +> 商户和微信平台进行通信,所以双方都需要有一套证书 + +## SDK + +Java: https://github.com/wechatpay-apiv3/wechatpay-apache-httpclient + +```xml + + com.github.wechatpay-apiv3 + wechatpay-apache-httpclient + 0.4.7 + +``` + +PHP:https://github.com/wechatpay-apiv3/wechatpay-php + +- Guzzle 7.0,PHP >= 7.2.5 +- Guzzle 6.5,PHP >= 7.1.2 + +```bash +composer require wechatpay/wechatpay +``` \ No newline at end of file diff --git a/blog/pay/weixin-pay.md b/blog/pay/weixin-pay.md new file mode 100644 index 0000000..72c0581 --- /dev/null +++ b/blog/pay/weixin-pay.md @@ -0,0 +1,16 @@ + +【尚硅谷】微信支付&支付宝支付,一套搞定Java在线支付开发教程 +https://www.bilibili.com/video/BV1US4y1D77m + + +## 微信支付 + +https://pay.weixin.qq.com + +[接入指引](blog/pay/start.md) + +[支付安全](blog/pay/security.md) + +[创建项目](blog/pay/create-project.md) + +https://www.bilibili.com/video/BV1US4y1D77m?p=51 \ No newline at end of file diff --git a/blog/php-mysql/index.md b/blog/php-mysql/index.md index c302059..30a03e8 100644 --- a/blog/php-mysql/index.md +++ b/blog/php-mysql/index.md @@ -54,9 +54,9 @@ 26. [视图 view](blog/php-mysql/sql-view.md) -[事务安全 transaction](blog/php-mysql/sql-transaction.md) +27. [事务安全 transaction](blog/php-mysql/sql-transaction.md) -[变量 variables](blog/php-mysql/sql-variables.md) +28. [变量 variables](blog/php-mysql/sql-variables.md) [流程结构 if while](blog/php-mysql/sql-if-while.md) diff --git a/blog/php-mysql/sql-variables.md b/blog/php-mysql/sql-variables.md index bc7c4d4..ad95ec1 100644 --- a/blog/php-mysql/sql-variables.md +++ b/blog/php-mysql/sql-variables.md @@ -1,4 +1,4 @@ -# 变量 +# 变量 variables MySQL本质是一种编程语言 diff --git a/doc/index.md b/doc/index.md index fdd6dad..aa5adbf 100644 --- a/doc/index.md +++ b/doc/index.md @@ -75,6 +75,8 @@ Logo:https://www.logoly.pro/ [Snipaste](https://zh.snipaste.com/index.html) 截图 + 贴图,提高您的工作效率 +[ngrok](https://ngrok.com/) 内网穿透工具 + ## 学习资料: 2022 黑马程序员 Java 学习路线图 diff --git a/doc/javascript.md b/doc/javascript.md index a8d4e8c..9531868 100644 --- a/doc/javascript.md +++ b/doc/javascript.md @@ -2,7 +2,10 @@ ## 第三方库 -[vue.js](https://cn.vuejs.org/v2/guide/) +vue.js: 渐进式 JavaScript 框架 + +- [vue2.js](https://cn.vuejs.org/v2/guide/): https://cn.vuejs.org/ +- [vue3.js](https://staging-cn.vuejs.org/guide/introduction.html): https://staging-cn.vuejs.org/ - [element-ui](https://element.eleme.cn/#/zh-CN/component/installation): 一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库 - [vColorPicker](http://vue-color-picker.rxshc.com/): 基于 Vue 的颜色选择器插件 @@ -68,6 +71,15 @@ [preactjs](https://preactjs.com/)Fast 3kB alternative to React with the same modern API. +[node-qrcode](https://github.com/soldair/node-qrcode) QR code/2d barcode generator. + +[QRCode.js](https://github.com/davidshimjs/qrcodejs): Cross-browser QRCode generator for javascript + +[vue-qriously](https://github.com/theomessin/vue-qriously):A Vue.js 2 component to draw QR codes on an HTML Canvas using qrious. + +[qrious](https://github.com/neocotic/qrious): Pure JavaScript library for QR code generation using canvas + + ## CDN [BootCDN](https://www.bootcdn.cn/): 稳定、快速、免费的前端开源项目 CDN 加速服务 -- GitLab