发送验证码
This commit is contained in:
parent
1ab1d7f27d
commit
ff030bf22d
|
@ -1,7 +1,9 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Deprecation" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="RawUseOfParameterizedType" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ThrowablePrintStackTrace" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UNCHECKED_WARNING" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
|
@ -4,17 +4,25 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="修改不用的引用">
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/mapper/ProductDetailsMapper.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/mapper/ProductMapper.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/mapper/product/ProductDetailsMapper.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/mapper/product/ProductMapper.xml" afterDir="false" />
|
||||
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="商品详情">
|
||||
<change afterPath="$PROJECT_DIR$/spzx-common/common-util/src/main/java/cn/bunny/common/HttpUtils.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/User.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/config/RedisConfig.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/SmsService.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/SmsServiceImpl.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/application-dev.yml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/application.yml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/mapper/ProductSkuMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/mapper/ProductSkuMapper.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/service/ProductService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/service/ProductService.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-common/common-util/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-common/common-util/pom.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-server-gateway/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-server-gateway/src/main/resources/application-dev.yml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/config/RedisConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/config/RedisConfig.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/service/imp/ProductServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/service/imp/ProductServiceImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/mapper/product/ProductSkuMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/mapper/product/ProductSkuMapper.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/application-dev.yml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/pom.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/web/App.java" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -24,9 +32,9 @@
|
|||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
<option value="Interface" />
|
||||
<option value="mybatis-mapper" />
|
||||
<option value="Interface" />
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
@ -78,7 +86,7 @@
|
|||
"code.cleanup.on.save": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"jdk.selected.JAVA_MODULE": "21",
|
||||
"last_opened_file_path": "F:/File/Java/spzx-parent/spzx-service/service-product/src/main/java/cn/bunny/web/product",
|
||||
"last_opened_file_path": "F:/File/Java/spzx-parent/spzx-service/service-user/src/main/java/cn/bunny/user",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
|
@ -102,6 +110,8 @@
|
|||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="F:\File\Java\spzx-parent\spzx-service\service-user\src\main\java\cn\bunny\user" />
|
||||
<recent name="F:\File\Java\spzx-parent\spzx-service\service-user\src\main\resources" />
|
||||
<recent name="F:\File\Java\spzx-parent\spzx-service\service-product\src\main\java\cn\bunny\web\product" />
|
||||
<recent name="F:\File\Java\spzx-parent\spzx-server-gateway\src\main\resources" />
|
||||
<recent name="F:\File\Java\spzx-parent\spzx-service\service-product\src\main\resources" />
|
||||
|
@ -119,7 +129,7 @@
|
|||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager" selected="Spring Boot.ProductApplication">
|
||||
<component name="RunManager" selected="Spring Boot.User">
|
||||
<configuration name="MangerApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
|
||||
<module name="spzx-manager" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="cn.bunny.MangerApplication" />
|
||||
|
@ -146,10 +156,38 @@
|
|||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="ServerGetWayApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
|
||||
<module name="spzx-server-gateway" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="cn.bunny.getway.ServerGetWayApplication" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="cn.bunny.getway.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="User" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
|
||||
<module name="service-user" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="cn.bunny.user.User" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="cn.bunny.user.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Spring Boot.ProductApplication" />
|
||||
<item itemvalue="Spring Boot.User" />
|
||||
<item itemvalue="Spring Boot.ServerGetWayApplication" />
|
||||
<item itemvalue="Spring Boot.MangerApplication" />
|
||||
<item itemvalue="Spring Boot.ProductApplication" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
|
@ -163,7 +201,7 @@
|
|||
<updated>1703487755445</updated>
|
||||
<workItem from="1703487757122" duration="903000" />
|
||||
<workItem from="1703488670206" duration="5932000" />
|
||||
<workItem from="1703549556395" duration="13968000" />
|
||||
<workItem from="1703549556395" duration="20239000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="前端接口初始化;显示商品页面">
|
||||
<option name="closed" value="true" />
|
||||
|
@ -221,7 +259,15 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1703559306235</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="8" />
|
||||
<task id="LOCAL-00008" summary="商品详情">
|
||||
<option name="closed" value="true" />
|
||||
<created>1703567148967</created>
|
||||
<option name="number" value="00008" />
|
||||
<option name="presentableId" value="LOCAL-00008" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1703567148967</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="9" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
|
@ -234,18 +280,10 @@
|
|||
<MESSAGE value="将首页数据存放在redis中作为缓存" />
|
||||
<MESSAGE value="根据品牌进行查询" />
|
||||
<MESSAGE value="修改不用的引用" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="修改不用的引用" />
|
||||
<MESSAGE value="商品详情" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="商品详情" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<url>file://$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/config/RedisConfig.java</url>
|
||||
<line>33</line>
|
||||
<option name="timeStamp" value="15" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
<pin-to-top-manager>
|
||||
<pinned-members>
|
||||
<PinnedItemInfo parentTag="java.lang.String" memberName="value" />
|
||||
|
|
|
@ -13,11 +13,19 @@ public class Knife4jConfig {
|
|||
@Bean
|
||||
public GroupedOpenApi adminApi() {// 创建API分组
|
||||
return GroupedOpenApi.builder()
|
||||
.group("admin-api111")
|
||||
.group("后端接口")
|
||||
.pathsToMatch("/admin/**")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi UserApi() {// 创建API分组
|
||||
return GroupedOpenApi.builder()
|
||||
.group("前端用户")
|
||||
.pathsToMatch("/api/**")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OpenAPI customerOpenApi() {
|
||||
return new OpenAPI().info(new Info().title("接口文档").version("1.0").contact(new Contact()
|
||||
|
|
|
@ -41,5 +41,32 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>9.3.7.v20160115</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,238 @@
|
|||
package cn.bunny.common;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpUtils {
|
||||
public static HttpResponse doGet(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
Map<String, String> bodys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (bodys != null) {
|
||||
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||
|
||||
for (String key : bodys.keySet()) {
|
||||
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||
}
|
||||
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||
request.setEntity(formEntity);
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
String body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
byte[] body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPut(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
String body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPut(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
byte[] body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doDelete(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||
StringBuilder sbUrl = new StringBuilder();
|
||||
sbUrl.append(host);
|
||||
if (!StringUtils.isBlank(path)) {
|
||||
sbUrl.append(path);
|
||||
}
|
||||
if (null != querys) {
|
||||
StringBuilder sbQuery = new StringBuilder();
|
||||
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||
if (0 < sbQuery.length()) {
|
||||
sbQuery.append("&");
|
||||
}
|
||||
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append(query.getValue());
|
||||
}
|
||||
if (!StringUtils.isBlank(query.getKey())) {
|
||||
sbQuery.append(query.getKey());
|
||||
if (!StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append("=");
|
||||
sbQuery.append(URLEncoder.encode(query.getValue(), StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0 < sbQuery.length()) {
|
||||
sbUrl.append("?").append(sbQuery);
|
||||
}
|
||||
}
|
||||
|
||||
return sbUrl.toString();
|
||||
}
|
||||
|
||||
private static HttpClient wrapClient(String host) {
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
if (host.startsWith("https://")) {
|
||||
sslClient(httpClient);
|
||||
}
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
private static void sslClient(HttpClient httpClient) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[]{tm}, null);
|
||||
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||
registry.register(new Scheme("https", 443, ssf));
|
||||
} catch (KeyManagementException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,10 @@ spring:
|
|||
uri: lb://service-product
|
||||
predicates:
|
||||
- Path=/*/product/**
|
||||
- id: service-user
|
||||
uri: lb://service-user
|
||||
predicates:
|
||||
- Path=/*/user/**
|
||||
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
|
|
|
@ -34,14 +34,13 @@ public class RedisConfig {
|
|||
@Bean
|
||||
public CacheManager cacheManager(LettuceConnectionFactory connectionFactory) {
|
||||
|
||||
//定义序列化器
|
||||
// 定义序列化器
|
||||
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
|
||||
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
|
||||
//过期时间600秒
|
||||
.entryTtl(Duration.ofSeconds(600))
|
||||
// 过期时间600秒
|
||||
.entryTtl(Duration.ofSeconds(604800))
|
||||
// 配置序列化
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(stringRedisSerializer))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(genericJackson2JsonRedisSerializer));
|
||||
|
|
|
@ -23,10 +23,8 @@ import java.util.*;
|
|||
public class ProductServiceImpl implements ProductService {
|
||||
@Resource
|
||||
private ProductSkuMapper productSkuMapper;
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Resource
|
||||
private ProductDetailsMapper productDetailsMapper;
|
||||
@Resource
|
||||
|
@ -35,8 +33,8 @@ public class ProductServiceImpl implements ProductService {
|
|||
@Cacheable(value = "productSku", key = "'one'")
|
||||
@Override
|
||||
public List<ProductSku> selectProductSkuBySal() {
|
||||
/* // 1. 查询redis是否有一级分类
|
||||
Object productSkuJson = redisTemplate.opsForValue().get("productSku:one");
|
||||
// 1. 查询redis是否有一级分类
|
||||
Object productSkuJson = redisTemplate.opsForValue().get("productSku::one");
|
||||
String productSkuJsonString = JSON.toJSONString(productSkuJson);
|
||||
|
||||
// 2. 如果存在一级分类直接返回即可
|
||||
|
@ -44,15 +42,10 @@ public class ProductServiceImpl implements ProductService {
|
|||
return JSON.parseArray(productSkuJsonString);
|
||||
}
|
||||
// 3. 如果redis没有一级分类,查询数据库,把数据库内容返回,并且查询放到redis中
|
||||
List<ProductSku> productSkuList = productSkuMapper.selectProductSkuBySale();
|
||||
redisTemplate.opsForValue()
|
||||
.set("productSku:one", JSON.toJSON(productSkuList), 7, TimeUnit.DAYS);
|
||||
return productSkuList; */
|
||||
Object productSkuJson = redisTemplate.opsForValue().get("productSku:one");
|
||||
String productSkuJsonString = JSON.toJSONString(productSkuJson);
|
||||
if (!Objects.equals(productSkuJsonString, "null")) {
|
||||
return JSON.parseArray(productSkuJsonString);
|
||||
}
|
||||
// List<ProductSku> productSkuList = productSkuMapper.selectProductSkuBySale();
|
||||
// redisTemplate.opsForValue()
|
||||
// .set("productSku::one", JSON.toJSON(productSkuList), 7, TimeUnit.DAYS);
|
||||
// return productSkuList;
|
||||
return productSkuMapper.selectProductSkuBySale();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.2.156:8848
|
||||
|
||||
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>spzx-service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package cn.bunny.user;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"cn.bunny"})
|
||||
public class User {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(User.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package cn.bunny.user.config;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||
|
||||
// 设置key序列化为String
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// 设置value序列化方式为JSON,使用GenericJackson2JsonRedisSerializer替换为默认序列化
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager(LettuceConnectionFactory connectionFactory) {
|
||||
|
||||
// 定义序列化器
|
||||
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
|
||||
// 过期时间600秒
|
||||
.entryTtl(Duration.ofSeconds(600))
|
||||
// 配置序列化
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(stringRedisSerializer))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(genericJackson2JsonRedisSerializer));
|
||||
|
||||
return RedisCacheManager.builder(connectionFactory)
|
||||
.cacheDefaults(config)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.bunny.user.controller;
|
||||
|
||||
import cn.bunny.common.spzx.model.vo.common.Result;
|
||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||
import cn.bunny.user.service.SmsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/user/sms")
|
||||
public class SmsController {
|
||||
@Resource
|
||||
private SmsService smsService;
|
||||
|
||||
@GetMapping(value = "/sendCode/{phone}")
|
||||
@Operation(summary = "短信验证码", operationId = "发送短信验证码")
|
||||
public Result sendValidateCode(@PathVariable("phone") String phone) {
|
||||
return Result.build(smsService.sendCode(phone), ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package cn.bunny.user.service;
|
||||
|
||||
public interface SmsService {
|
||||
// 短信验证码
|
||||
Object sendCode(String phone);
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package cn.bunny.user.service.impl;
|
||||
|
||||
import cn.bunny.common.HttpUtils;
|
||||
import cn.bunny.user.service.SmsService;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class SmsServiceImpl implements SmsService {
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
// 短信验证码
|
||||
@Override
|
||||
public Object sendCode(String phone) {
|
||||
Object code = redisTemplate.opsForValue().get(phone);
|
||||
if (StringUtils.hasText((String) code)) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// 1.生成短信验证码
|
||||
code = RandomStringUtils.randomNumeric(4);
|
||||
// 2.放入Redis中,设置过期时间
|
||||
redisTemplate.opsForValue().set(phone, code, 5, TimeUnit.MINUTES);
|
||||
// 3. 向手机号发送短信验证码
|
||||
sendMessage(phone, (String) code);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
private void sendMessage(String phone, String code) {
|
||||
String host = "https://dfsns.market.alicloudapi.com";
|
||||
String path = "/data/send_sms";
|
||||
String method = "POST";
|
||||
String appcode = "5a4cb12374904a7fa2975ec5a1a9d50f";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
// 根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
bodys.put("content", "code:" + code);
|
||||
bodys.put("template_id", "CST_ptdie100"); // 该模板为调试接口专用,短信下发有受限制,调试成功后请联系客服报备专属模板
|
||||
bodys.put("phone_number", phone);
|
||||
|
||||
|
||||
try {
|
||||
HttpResponse httpResponse = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
System.out.println(httpResponse.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package cn.bunny.web;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
server:
|
||||
port: 8512
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: service-user
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.2.156:8848
|
||||
|
||||
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://60.204.230.80:3306/db_spzx?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: "02120212"
|
||||
data:
|
||||
redis:
|
||||
port: 6379
|
||||
host: 192.168.2.156
|
|
@ -0,0 +1,3 @@
|
|||
spring:
|
||||
profiles:
|
||||
active: dev
|
Loading…
Reference in New Issue