From 6f6c6a480d02b7c91e72821e29a937d5927e38cc Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期三, 19 六月 2024 17:48:21 +0800
Subject: [PATCH] 2024-06-19 朱宝民 迁移4个微信小程序接口
---
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml | 4
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/WXDataSourceNameSetFilter.java | 41 ++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/RandomCode.java | 2
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeVerifyDTO.java | 2
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java | 2
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeLoginDTO.java | 20 +
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/AliyunSmsSv.java | 2
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/RestTemplateUtil.java | 115 ++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java | 52 ---
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientCtrl.java | 220 +++++++++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/result/WechatResultCode.java | 16 +
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java | 194 -------------
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java | 18 -
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application.yml | 7
pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml | 2
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientSv.java | 76 +++++
pipIrr-platform/pipIrr-global/src/main/resources/application-database-ym.yml | 4
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/config/WebFilterConfiguration.java | 35 --
18 files changed, 520 insertions(+), 292 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/WXDataSourceNameSetFilter.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/WXDataSourceNameSetFilter.java
new file mode 100644
index 0000000..3b127ad
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webFilter/WXDataSourceNameSetFilter.java
@@ -0,0 +1,41 @@
+package com.dy.common.webFilter;
+
+import com.dy.common.multiDataSource.DataSourceContext;
+import jakarta.servlet.*;
+import jakarta.servlet.http.HttpServletRequest;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-19 11:02
+ * @LastEditTime 2024-06-19 11:02
+ * @Description
+ */
+
+@Slf4j
+public class WXDataSourceNameSetFilter implements Filter {
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+ String wxDataSourceName = httpRequest.getHeader("tag");
+ if(wxDataSourceName != null && wxDataSourceName.trim().length() > 0){
+ log.info("寰俊寮�鍙戯紝璁剧疆鏁版嵁婧愬悕绉颁负:" + wxDataSourceName);
+ //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
+ DataSourceContext.set(wxDataSourceName);
+ } else {
+ log.info("鐢ㄦ埛鏈�夋嫨鏁版嵁婧�");
+ }
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ @Override
+ public void destroy() {
+ }
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/application-database-ym.yml b/pipIrr-platform/pipIrr-global/src/main/resources/application-database-ym.yml
index 29fac5c..700142f 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/application-database-ym.yml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/application-database-ym.yml
@@ -5,8 +5,8 @@
#name: ym
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
-# url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
- url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
+ url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
+# url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username: root
password: dysql,;.abc!@#
druid:
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml b/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml
index 9fd4b6a..01b83ee 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/application-global.yml
@@ -72,7 +72,7 @@
pipIrr:
global:
- dev: true #鏄惁寮�鍙戦樁娈碉紝true鎴杅alse
+ dev: false #鏄惁寮�鍙戦樁娈碉紝true鎴杅alse
dsName: ym #寮�鍙戦樁娈碉紝璁剧疆涓存椂鐨勬暟鎹簱鍚嶇О
mw:
webPort: 8070
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml
index c487a86..fcd9d78 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml
@@ -3,8 +3,8 @@
datasource: #閰嶇疆鏁版嵁婧�
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
-# url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
- url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
+ url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
+# url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username: root
password: dysql,;.abc!@#
druid:
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
index 196f207..35b198e 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -1,8 +1,5 @@
package com.dy.pipIrrSell.client;
-import com.alibaba.fastjson2.JSONObject;
-import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
-import com.aliyuncs.exceptions.ClientException;
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
@@ -10,14 +7,7 @@
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoBa.BaClient;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
-import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify;
-import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
import com.dy.pipIrrGlobal.voSe.VoClient;
-import com.dy.pipIrrGlobal.voSe.VoClientWechat;
-import com.dy.pipIrrSell.client.dto.CodeVerifyDTO;
-import com.dy.pipIrrSell.result.SellResultCode;
-import com.dy.pipIrrSell.sms.AliyunSmsSv;
-import com.dy.pipIrrSell.sms.RandomCode;
import com.dy.pipIrrSell.util.RestTemplateUtil;
import com.dy.pipIrrSell.wechatpay.PayInfo;
import io.swagger.v3.oas.annotations.Operation;
@@ -35,7 +25,6 @@
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
-import java.io.IOException;
import java.util.*;
/**
@@ -52,7 +41,6 @@
@RequiredArgsConstructor
public class ClientCtrl {
private final ClientSv clientSv;
- private final AliyunSmsSv aliyunSmsSv;
//private final RedisUtils redisUtils;
private final RestTemplateUtil restTemplateUtil;
@@ -401,186 +389,4 @@
map.put("projectNo",projectNo3);
return BaseResponseUtils.buildSuccess(map);
}
-
- /**
- * 鍙戦�侀獙璇佺爜
- * @param phoneNumber
- * @return
- */
- @Operation(summary = "鍙戦�侀獙璇佺爜", description = "鍙戦�侀獙璇佺爜")
- @ApiResponses(value = {
- @ApiResponse(
- responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- schema = @Schema(implementation = Boolean.class))}
- )
- })
- @PostMapping(path = "send_sms")
- @SsoAop()
- public BaseResponse<Boolean> sendSms(@RequestParam(name = "phoneNumber", required = true) String phoneNumber) throws ClientException {
- if(phoneNumber == null || phoneNumber.length() <= 0) {
- return BaseResponseUtils.buildFail(SellResultCode.PHONE_NUMBER_CANNOT_BE_NULL.getMessage());
- }
-
- // 鐢熸垚6浣嶉獙璇佺爜骞惰浆涓篔son鏍煎紡
- String securityCode = String.valueOf(RandomCode.genCode());
- JSONObject param = new JSONObject();
- param.put("code", securityCode);
- String templateParam = param.toJSONString();
-
- //redisUtils.set(phoneNumber, securityCode, 60);
-
- // 鑾峰彇褰撳墠鏃堕棿鎴冲苟寤跺悗3鍒嗛挓
- Long timestamp = System.currentTimeMillis();
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(timestamp);
- calendar.add(Calendar.SECOND, 180);
- Long expires = calendar.getTimeInMillis();
-
- SeCodeVerify codeVerify = new SeCodeVerify();
- codeVerify.setPhoneNumber(phoneNumber);
- codeVerify.setSecurityCode(securityCode);
- codeVerify.setExpires(expires);
- clientSv.addCodeVerify(codeVerify);
-
- SendSmsResponse response = aliyunSmsSv.sendSms(phoneNumber, templateParam);
- if (response.getCode().equals("OK")) {
- // 鍙戦�佹垚鍔熷鐞嗛�昏緫
- return BaseResponseUtils.buildSuccess(true) ;
- } else {
- // 鍙戦�佸け璐ュ鐞嗛�昏緫
- return BaseResponseUtils.buildFail(SellResultCode.SECURITY_CODE_SEND_FAIL.getMessage()) ;
- }
- }
-
- /**
- * 鏍¢獙楠岃瘉鐮�
- * @param po
- * @param bindingResult
- * @return
- * @throws IOException
- */
- @Operation(summary = "鏍¢獙楠岃瘉鐮�", description = "鏍¢獙楠岃瘉鐮�")
- @ApiResponses(value = {
- @ApiResponse(
- responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- schema = @Schema(implementation = Boolean.class))}
- )
- })
- @PostMapping(path = "verify", consumes = MediaType.APPLICATION_JSON_VALUE)
- @Transactional(rollbackFor = Exception.class)
- @SsoAop()
- public BaseResponse<Boolean> verify(@RequestBody @Valid CodeVerifyDTO po, BindingResult bindingResult) throws IOException {
- if(bindingResult != null && bindingResult.hasErrors()){
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
-
- String phoneNumber = po.getPhoneNumber();
- String securityCode = po.getSecurityCode();
- String code = po.getCode();
-
- // 杩涜鎵嬫満鍙枫�侀獙璇佺爜銆佽繃鏈熸椂闂存牎楠�
- SeCodeVerify codeVerify = clientSv.getCodeVerify(phoneNumber);
- if(codeVerify == null) {
- return BaseResponseUtils.buildFail(SellResultCode.NO_SECURITY_CODE_FOR_PHONE.getMessage());
- }
-
- if(!codeVerify.getSecurityCode().equals(securityCode)) {
- return BaseResponseUtils.buildFail(SellResultCode.SECURITY_CODE_ERROR.getMessage());
- }
-
- Long currentTimestamp = System.currentTimeMillis();
- if(currentTimestamp > codeVerify.getExpires() ) {
- return BaseResponseUtils.buildFail(SellResultCode.VALIDATION_TIMEOUT.getMessage());
- }
-
- // 鏍¢獙閫氳繃锛岃繘琛岀櫥褰曞嚟璇佹牎楠�
- Map<String, Object> queryParams = new HashMap<>();
- queryParams.put("appid", appid);
- queryParams.put("secret", secret);
- queryParams.put("js_code", code);
- queryParams.put("grant_type", grantType);
- Map<String, String> headerParams = new HashMap<>();
- JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
-
- if(job.getLong("errcode") != null && job.getLong("errcode") >= -1) {
- return BaseResponseUtils.buildFail("鐧诲綍鍑瘉鏍¢獙澶辫触");
- }
- String openid = job.getString("openid");
- String sessionKey = job.getString("session_key");
-
- Long clientId = clientSv.getClientIdByPhone(phoneNumber);
- String SessionId = "";
- if(clientId != null) {
- // 娣诲姞寰俊鐢ㄦ埛璐︽埛璁板綍
- SeOpenId seOpenId = new SeOpenId();
- seOpenId.setClientId(clientId);
- seOpenId.setOpenId(openid);
- seOpenId.setSessionKey(sessionKey);
- seOpenId.setCreateTime(new Date());
- //Long SessionId = clientSv.addOpenId(seOpenId);
- Long rec = clientSv.addOpenId(seOpenId);
- if(rec != null) {
- SessionId = String.valueOf(rec);
- }
- return BaseResponseUtils.buildSuccess(SessionId);
-
- } else {
- return BaseResponseUtils.buildError(SellResultCode.PHONE_NUMBER_IS_ERROR.getMessage());
- }
- }
-
- /**
- * 鑾峰彇鍐滄埛鍩烘湰淇℃伅锛屽皬绋嬪簭棣栭〉浣跨敤
- * @param sessionId
- * @return
- */
- @GetMapping(path = "/simple_info")
- @SsoAop()
- public BaseResponse<VoClientWechat> getSimpleClientInfo(@RequestParam Long sessionId){
- try {
- VoClientWechat res = clientSv.getSimpleClientInfo(sessionId, null);
- return BaseResponseUtils.buildSuccess(res);
- } catch (Exception e) {
- log.error("鏌ヨ鍐滄埛寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage()) ;
- }
- }
-
- /**
- * 鐧诲綍鍑瘉鐧诲綍
- * @param code 涓存椂鐧诲綍鍑瘉
- * @return
- */
- @GetMapping(path = "/code_login")
- @SsoAop()
- public BaseResponse<VoClientWechat> codeLogin(@RequestParam String code) throws IOException {
-
- // 鐧诲綍鍑瘉鏍¢獙
- Map<String, Object> queryParams = new HashMap<>();
- queryParams.put("appid", appid);
- queryParams.put("secret", secret);
- queryParams.put("js_code", code);
- queryParams.put("grant_type", grantType);
- Map<String, String> headerParams = new HashMap<>();
- JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
-
- String openId = job.getString("openid");
- if(openId == null) {
- return BaseResponseUtils.buildFail(SellResultCode.LOGIN_FAIL.getMessage());
- }
-
- try {
- VoClientWechat res = clientSv.getSimpleClientInfo(null, openId);
- return BaseResponseUtils.buildSuccess(res);
- } catch (Exception e) {
- log.error("鏌ヨ鍐滄埛寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage()) ;
- }
- }
-
-
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java
index 1753ae1..0ae07c7 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java
@@ -4,13 +4,10 @@
import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper;
import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
import com.dy.pipIrrGlobal.daoSe.SeClientMapper;
-import com.dy.pipIrrGlobal.daoSe.SeCodeVerifyMapper;
import com.dy.pipIrrGlobal.daoSe.SeOpenIdMapper;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
-import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify;
import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
import com.dy.pipIrrGlobal.voSe.VoClient;
-import com.dy.pipIrrGlobal.voSe.VoClientWechat;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,13 +33,10 @@
private BaDistrictMapper baDistrictMapper;
@Autowired
- private SeCodeVerifyMapper seCodeVerifyMapper;
+ private BaSettingsMapper baSettingsMapper;
@Autowired
private SeOpenIdMapper seOpenIdMapper;
-
- @Autowired
- private BaSettingsMapper baSettingsMapper;
/**
* 鏍规嵁鎸囧畾鏉′欢鑾峰彇鍐滄埛鏁版嵁
@@ -82,23 +76,6 @@
return seClientMapper.insertSelective(po);
}
- /**
- * 娣诲姞楠岃瘉鐮佽褰�
- * @param po
- * @return
- */
- public Integer addCodeVerify(SeCodeVerify po) {
- return seCodeVerifyMapper.insert(po);
- }
-
- /**
- * 鏍规嵁鎵嬫満鍙疯幏鍙栭獙璇佺爜楠岃瘉瀵硅薄
- * @param phoneNumber
- * @return
- */
- public SeCodeVerify getCodeVerify(String phoneNumber) {
- return seCodeVerifyMapper.getCodeVerify(phoneNumber);
- }
/**
* 鏍规嵁6浣嶅尯鍒掍覆妯$硦鏌ヨ鍐滄埛缂栧彿
* @param district6
@@ -159,6 +136,15 @@
}
/**
+ * 鏍规嵁閰嶇疆椤硅幏鍙栭厤缃」鍊�
+ * @param itemName
+ * @return
+ */
+ public String getItemValue(String itemName) {
+ return baSettingsMapper.getItemValue(itemName);
+ }
+
+ /**
* 鏍规嵁鐢佃瘽鍙风爜鑾峰彇鍐滄埛ID
* @param phoneNumber
* @return
@@ -176,23 +162,5 @@
seOpenIdMapper.insert(po);
//return po.getClientId();
return po.getId();
- }
-
- /**
- * 鏍规嵁閰嶇疆椤硅幏鍙栭厤缃」鍊�
- * @param itemName
- * @return
- */
- public String getItemValue(String itemName) {
- return baSettingsMapper.getItemValue(itemName);
- }
-
- /**
- * 鑾峰彇鍐滄埛鍩烘湰淇℃伅锛屽皬绋嬪簭棣栭〉浣跨敤
- * @param sessionId
- * @return
- */
- public VoClientWechat getSimpleClientInfo(Long sessionId, String openId) {
- return seClientMapper.getSimpleClientInfo(sessionId, openId);
}
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java
index f991269..cbd7e67 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/result/SellResultCode.java
@@ -124,23 +124,7 @@
No_TRADE_SUMMARIES(100001, "娌℃湁绗﹀悎鏉′欢鐨勪氦鏄撴眹鎬昏褰�"),
No_TRADE_DETAILS(100001, "娌℃湁绗﹀悎鏉′欢鐨勪氦鏄撴槑缁�"),
- /**
- * 寰俊鐢ㄦ埛
- */
- PHONE_NUMBER_CANNOT_BE_NULL(20001, "鎵嬫満鍙蜂笉鑳戒负绌�"),
- SECURITY_CODE_SEND_FAIL(20001, "楠岃瘉鐮佸彂閫佸け璐�"),
- VERIFY_PARAMS_INCOMPLETE(20001, "楠岃瘉鍙傛暟涓嶅畬鏁�"),
- CODE_VERIFY_FAIL(20001, "楠岃瘉鐮佹牎楠屽け璐�"),
-
- NO_SECURITY_CODE_FOR_PHONE(20002, "璇ユ墜鏈哄彿鏈彂閫侀獙璇佺爜"),
- SECURITY_CODE_ERROR(20003, "楠岃瘉鐮侀敊璇�"),
- VALIDATION_TIMEOUT(20004, "楠岃瘉瓒呮椂"),
- PHONE_NUMBER_IS_ERROR(20004, "鎵嬫満鍙烽敊璇紝闈炴敞鍐屽啘鎴�"),
-
- /**
- * 灏忕▼搴�
- */
- LOGIN_FAIL(20004, "鐧诲綍澶辫触");
+ PHONE_NUMBER_IS_ERROR(20004, "鎵嬫満鍙烽敊璇紝闈炴敞鍐屽啘鎴�");
private final Integer code;
private final String message;
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientCtrl.java
new file mode 100644
index 0000000..89aa7c8
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientCtrl.java
@@ -0,0 +1,220 @@
+package com.dy.pipIrrWechat.client;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify;
+import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
+import com.dy.pipIrrGlobal.voSe.VoClientWechat;
+import com.dy.pipIrrSell.wechatpay.PayInfo;
+import com.dy.pipIrrWechat.client.dto.CodeLoginDTO;
+import com.dy.pipIrrWechat.client.dto.CodeVerifyDTO;
+import com.dy.pipIrrWechat.result.WechatResultCode;
+import com.dy.pipIrrWechat.sms.AliyunSmsSv;
+import com.dy.pipIrrWechat.sms.RandomCode;
+import com.dy.pipIrrWechat.util.RestTemplateUtil;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.MediaType;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-19 14:21
+ * @LastEditTime 2024-06-19 14:21
+ * @Description
+ */
+
+@Slf4j
+@Tag(name = "鍐滄埛鏁版嵁鎿嶄綔", description = "鍐滄埛鏁版嵁鎿嶄綔")
+@RestController
+@RequestMapping(path="client")
+@RequiredArgsConstructor
+public class ClientCtrl {
+ private final ClientSv clientSv;
+ private final AliyunSmsSv aliyunSmsSv;
+ private final RestTemplateUtil restTemplateUtil;
+ private final String privateCertFileName = PayInfo.privateCertFileName;
+ private final String appid = PayInfo.appid;
+ private final String secret = PayInfo.secret;
+ private final String mchid = PayInfo.mchid;
+ private final String schema = PayInfo.schema;
+ private final String signType = PayInfo.signType;
+ private final String description = PayInfo.description;
+ private final String loginUrl = PayInfo.loginUrl;
+ private final String notifyUrl = PayInfo.notifyUrl;
+ private final String grantType = PayInfo.grantType;
+
+ /**
+ * 鐧诲綍鍑瘉鐧诲綍
+ * @param po
+ * @param bindingResult
+ * @return
+ * @throws IOException
+ */
+ @PostMapping(path = "code_login", consumes = MediaType.APPLICATION_JSON_VALUE)
+ public BaseResponse<VoClientWechat> codeLogin(@RequestBody @Valid CodeLoginDTO po, BindingResult bindingResult) throws IOException {
+ if(bindingResult != null && bindingResult.hasErrors()){
+ return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+ String code = po.getCode();
+
+ // 鐧诲綍鍑瘉鏍¢獙
+ Map<String, Object> queryParams = new HashMap<>();
+ queryParams.put("appid", appid);
+ queryParams.put("secret", secret);
+ queryParams.put("js_code", code);
+ queryParams.put("grant_type", grantType);
+ Map<String, String> headerParams = new HashMap<>();
+ JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
+
+ String openId = job.getString("openid");
+ if(openId == null) {
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.LOGIN_FAIL.getMessage());
+ }
+
+ try {
+ VoClientWechat res = clientSv.getSimpleClientInfo(null, openId);
+ return BaseResponseUtils.buildSuccess(res);
+ } catch (Exception e) {
+ log.error("鏌ヨ鍐滄埛寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+
+ /**
+ * 鍙戦�侀獙璇佺爜
+ * @param phoneNumber
+ * @return
+ */
+ @PostMapping(path = "send_sms")
+ public BaseResponse<Boolean> sendSms(@RequestParam(name = "phoneNumber", required = true) String phoneNumber) throws ClientException {
+ if(phoneNumber == null || phoneNumber.length() <= 0) {
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.PHONE_NUMBER_CANNOT_BE_NULL.getMessage());
+ }
+
+ // 鐢熸垚6浣嶉獙璇佺爜骞惰浆涓篔son鏍煎紡
+ String securityCode = String.valueOf(RandomCode.genCode());
+ JSONObject param = new JSONObject();
+ param.put("code", securityCode);
+ String templateParam = param.toJSONString();
+
+ //redisUtils.set(phoneNumber, securityCode, 60);
+
+ // 鑾峰彇褰撳墠鏃堕棿鎴冲苟寤跺悗3鍒嗛挓
+ Long timestamp = System.currentTimeMillis();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(timestamp);
+ calendar.add(Calendar.SECOND, 180);
+ Long expires = calendar.getTimeInMillis();
+
+ SeCodeVerify codeVerify = new SeCodeVerify();
+ codeVerify.setPhoneNumber(phoneNumber);
+ codeVerify.setSecurityCode(securityCode);
+ codeVerify.setExpires(expires);
+ clientSv.addCodeVerify(codeVerify);
+
+ SendSmsResponse response = aliyunSmsSv.sendSms(phoneNumber, templateParam);
+ if (response.getCode().equals("OK")) {
+ // 鍙戦�佹垚鍔熷鐞嗛�昏緫
+ return BaseResponseUtils.buildSuccess(true) ;
+ } else {
+ // 鍙戦�佸け璐ュ鐞嗛�昏緫
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.SECURITY_CODE_SEND_FAIL.getMessage()) ;
+ }
+ }
+
+ /**
+ * 鏍¢獙楠岃瘉鐮�
+ * @param po
+ * @param bindingResult
+ * @return
+ * @throws IOException
+ */
+ @PostMapping(path = "verify", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @Transactional(rollbackFor = Exception.class)
+ public BaseResponse<Boolean> verify(@RequestBody @Valid CodeVerifyDTO po, BindingResult bindingResult) throws IOException {
+ if(bindingResult != null && bindingResult.hasErrors()){
+ return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+
+ String phoneNumber = po.getPhoneNumber();
+ String securityCode = po.getSecurityCode();
+ String code = po.getCode();
+
+ // 杩涜鎵嬫満鍙枫�侀獙璇佺爜銆佽繃鏈熸椂闂存牎楠�
+ SeCodeVerify codeVerify = clientSv.getCodeVerify(phoneNumber);
+ if(codeVerify == null) {
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.NO_SECURITY_CODE_FOR_PHONE.getMessage());
+ }
+
+ if(!codeVerify.getSecurityCode().equals(securityCode)) {
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.SECURITY_CODE_ERROR.getMessage());
+ }
+
+ Long currentTimestamp = System.currentTimeMillis();
+ if(currentTimestamp > codeVerify.getExpires() ) {
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.VALIDATION_TIMEOUT.getMessage());
+ }
+
+ // 鏍¢獙閫氳繃锛岃繘琛岀櫥褰曞嚟璇佹牎楠�
+ Map<String, Object> queryParams = new HashMap<>();
+ queryParams.put("appid", appid);
+ queryParams.put("secret", secret);
+ queryParams.put("js_code", code);
+ queryParams.put("grant_type", grantType);
+ Map<String, String> headerParams = new HashMap<>();
+ JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
+
+ if(job.getLong("errcode") != null && job.getLong("errcode") >= -1) {
+ return BaseResponseUtils.buildErrorMsg("鐧诲綍鍑瘉鏍¢獙澶辫触");
+ }
+ String openid = job.getString("openid");
+ String sessionKey = job.getString("session_key");
+
+ Long clientId = clientSv.getClientIdByPhone(phoneNumber);
+ String SessionId = "";
+ if(clientId != null) {
+ // 娣诲姞寰俊鐢ㄦ埛璐︽埛璁板綍
+ SeOpenId seOpenId = new SeOpenId();
+ seOpenId.setClientId(clientId);
+ seOpenId.setOpenId(openid);
+ seOpenId.setSessionKey(sessionKey);
+ seOpenId.setCreateTime(new Date());
+ //Long SessionId = clientSv.addOpenId(seOpenId);
+ Long rec = clientSv.addOpenId(seOpenId);
+ if(rec != null) {
+ SessionId = String.valueOf(rec);
+ }
+ return BaseResponseUtils.buildSuccess(SessionId);
+
+ } else {
+ return BaseResponseUtils.buildErrorMsg(WechatResultCode.PHONE_NUMBER_IS_ERROR.getMessage());
+ }
+ }
+
+ /**
+ * 鑾峰彇鍐滄埛鍩烘湰淇℃伅锛屽皬绋嬪簭棣栭〉浣跨敤
+ * @param sessionId
+ * @return
+ */
+ @GetMapping(path = "/simple_info")
+ public BaseResponse<VoClientWechat> getSimpleClientInfo(@RequestParam Long sessionId){
+ try {
+ VoClientWechat res = clientSv.getSimpleClientInfo(sessionId, null);
+ return BaseResponseUtils.buildSuccess(res);
+ } catch (Exception e) {
+ log.error("鏌ヨ鍐滄埛寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientSv.java
new file mode 100644
index 0000000..fbe5234
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/ClientSv.java
@@ -0,0 +1,76 @@
+package com.dy.pipIrrWechat.client;
+
+import com.dy.pipIrrGlobal.daoSe.SeClientMapper;
+import com.dy.pipIrrGlobal.daoSe.SeCodeVerifyMapper;
+import com.dy.pipIrrGlobal.daoSe.SeOpenIdMapper;
+import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify;
+import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
+import com.dy.pipIrrGlobal.voSe.VoClientWechat;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-19 14:25
+ * @LastEditTime 2024-06-19 14:25
+ * @Description
+ */
+
+@Slf4j
+@Service
+public class ClientSv {
+ @Autowired
+ private SeClientMapper seClientMapper;
+ @Autowired
+ private SeCodeVerifyMapper seCodeVerifyMapper;
+ @Autowired
+ private SeOpenIdMapper seOpenIdMapper;
+
+ /**
+ * 鏍规嵁鐢佃瘽鍙风爜鑾峰彇鍐滄埛ID
+ * @param phoneNumber
+ * @return
+ */
+ public Long getClientIdByPhone(String phoneNumber) {
+ return seClientMapper.getClientIdByPhone(phoneNumber);
+ }
+
+ /**
+ * 娣诲姞寰俊鐢ㄦ埛璐︽埛璁板綍
+ * @param po
+ * @return
+ */
+ public Long addOpenId(SeOpenId po) {
+ seOpenIdMapper.insert(po);
+ //return po.getClientId();
+ return po.getId();
+ }
+
+ /**
+ * 娣诲姞楠岃瘉鐮佽褰�
+ * @param po
+ * @return
+ */
+ public Integer addCodeVerify(SeCodeVerify po) {
+ return seCodeVerifyMapper.insert(po);
+ }
+
+ /**
+ * 鏍规嵁鎵嬫満鍙疯幏鍙栭獙璇佺爜楠岃瘉瀵硅薄
+ * @param phoneNumber
+ * @return
+ */
+ public SeCodeVerify getCodeVerify(String phoneNumber) {
+ return seCodeVerifyMapper.getCodeVerify(phoneNumber);
+ }
+
+ /**
+ * 鑾峰彇鍐滄埛鍩烘湰淇℃伅锛屽皬绋嬪簭棣栭〉浣跨敤
+ * @param sessionId
+ * @return
+ */
+ public VoClientWechat getSimpleClientInfo(Long sessionId, String openId) {
+ return seClientMapper.getSimpleClientInfo(sessionId, openId);
+ }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeLoginDTO.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeLoginDTO.java
new file mode 100644
index 0000000..9eb554a
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeLoginDTO.java
@@ -0,0 +1,20 @@
+package com.dy.pipIrrWechat.client.dto;
+
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-19 15:57
+ * @LastEditTime 2024-06-19 15:57
+ * @Description
+ */
+
+@Data
+public class CodeLoginDTO {
+ /**
+ * 涓存椂鐧诲綍鍑瘉
+ */
+ @NotBlank(message = "涓存椂鐧诲綍鍑瘉涓嶈兘涓虹┖")
+ private String code;
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/dto/CodeVerifyDTO.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeVerifyDTO.java
similarity index 93%
rename from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/dto/CodeVerifyDTO.java
rename to pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeVerifyDTO.java
index fa660bf..603073a 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/dto/CodeVerifyDTO.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/client/dto/CodeVerifyDTO.java
@@ -1,4 +1,4 @@
-package com.dy.pipIrrSell.client.dto;
+package com.dy.pipIrrWechat.client.dto;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
index d881f14..d3fc309 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
@@ -476,7 +476,7 @@
* @return
*/
@GetMapping(path = "/get")
- @SsoAop()
+ //@SsoAop()
public BaseResponse<List<VoUnclosedValve>> getUnclosedValves(@RequestParam Long operator){
try {
List<VoUnclosedValve> res = commandSv.getUnclosedValves(operator);
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/config/WebFilterConfiguration.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/config/WebFilterConfiguration.java
index c724dae..b0f0226 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/config/WebFilterConfiguration.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/config/WebFilterConfiguration.java
@@ -1,9 +1,7 @@
package com.dy.pipIrrWechat.config;
-import com.dy.common.webFilter.DevOfDataSourceNameSetFilter;
-import com.dy.common.webFilter.UserTokenFilter;
+import com.dy.common.webFilter.WXDataSourceNameSetFilter;
import jakarta.servlet.Filter;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -16,35 +14,14 @@
*/
@Configuration
public class WebFilterConfiguration {
-
- @Value("${pipIrr.global.dev}")
- public String isDevStage ;//鏄惁涓哄紑鍙戦樁娈�
- @Value("${pipIrr.global.dsName}")
- public String dsName ;//寮�鍙戦樁娈电殑鏁版嵁婧愬悕绉�
-
- /**
- * DevOfDataSourceNameSetFilter涓嶶serTokenFilter鍙兘涓�涓閰嶇疆涓婏紝
- * 鎵�浠ヤ粬浠殑order閮芥槸1
- */
- private static final int order_UserTokenFilter = 1 ;//涓庝笅闈�
- private static final int order_DevOfDataSourceNameSetFilter = 1 ;
-
-
@Bean
public FilterRegistrationBean<? extends Filter> RegFilter() {
FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
- if(this.isDevStage != null && !this.isDevStage.trim().equals("") && this.isDevStage.trim().equalsIgnoreCase("true")){
- filterRegistrationBean.setFilter(new DevOfDataSourceNameSetFilter());
- filterRegistrationBean.addUrlPatterns("/*");//閰嶇疆杩囨护瑙勫垯
- filterRegistrationBean.addInitParameter("dataSourceName",dsName);//璁剧疆init鍙傛暟
- filterRegistrationBean.setName("DevOfDataSourceNameSetFilter");//璁剧疆杩囨护鍣ㄥ悕绉�
- filterRegistrationBean.setOrder(order_DevOfDataSourceNameSetFilter);//鎵ц娆″簭
- }else{
- filterRegistrationBean.setFilter(new UserTokenFilter());
- filterRegistrationBean.addUrlPatterns("/*");//閰嶇疆杩囨护瑙勫垯
- filterRegistrationBean.setName("UserTokenFilter");//璁剧疆杩囨护鍣ㄥ悕绉�
- filterRegistrationBean.setOrder(order_UserTokenFilter);//鎵ц娆″簭
- }
+ filterRegistrationBean.setFilter(new WXDataSourceNameSetFilter());
+ filterRegistrationBean.addUrlPatterns("/*");//閰嶇疆杩囨护瑙勫垯
+ filterRegistrationBean.setName("WXDataSourceNameSetFilter");//璁剧疆杩囨护鍣ㄥ悕绉�
+ filterRegistrationBean.setOrder(1);//鎵ц娆″簭
+
return filterRegistrationBean;
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/result/WechatResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/result/WechatResultCode.java
index 7c23a12..da81d38 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/result/WechatResultCode.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/result/WechatResultCode.java
@@ -25,9 +25,23 @@
/**
* RTU
*/
- RTU_NOT_EXIST(20001, "闃�鎺у櫒涓嶅瓨鍦�");
+ RTU_NOT_EXIST(20001, "闃�鎺у櫒涓嶅瓨鍦�"),
//RTU_ADDR_CANNOT_BE_NULL(20002, "闃�鎺у櫒鍦板潃涓嶈兘涓虹┖");
+ /**
+ * 寰俊鐢ㄦ埛
+ */
+ PHONE_NUMBER_CANNOT_BE_NULL(20001, "鎵嬫満鍙蜂笉鑳戒负绌�"),
+ SECURITY_CODE_SEND_FAIL(20001, "楠岃瘉鐮佸彂閫佸け璐�"),
+ VERIFY_PARAMS_INCOMPLETE(20001, "楠岃瘉鍙傛暟涓嶅畬鏁�"),
+ CODE_VERIFY_FAIL(20001, "楠岃瘉鐮佹牎楠屽け璐�"),
+
+ NO_SECURITY_CODE_FOR_PHONE(20002, "璇ユ墜鏈哄彿鏈彂閫侀獙璇佺爜"),
+ SECURITY_CODE_ERROR(20003, "楠岃瘉鐮侀敊璇�"),
+ VALIDATION_TIMEOUT(20004, "楠岃瘉瓒呮椂"),
+ PHONE_NUMBER_IS_ERROR(20004, "鎵嬫満鍙烽敊璇紝闈炴敞鍐屽啘鎴�"),
+ LOGIN_FAIL(20004, "鐧诲綍澶辫触");
+
private final Integer code;
private final String message;
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/AliyunSmsSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/AliyunSmsSv.java
similarity index 97%
rename from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/AliyunSmsSv.java
rename to pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/AliyunSmsSv.java
index 6012b0b..a0de838 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/AliyunSmsSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/AliyunSmsSv.java
@@ -1,4 +1,4 @@
-package com.dy.pipIrrSell.sms;
+package com.dy.pipIrrWechat.sms;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/RandomCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/RandomCode.java
similarity index 89%
rename from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/RandomCode.java
rename to pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/RandomCode.java
index f2049c8..7cc3f9b 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/RandomCode.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/sms/RandomCode.java
@@ -1,4 +1,4 @@
-package com.dy.pipIrrSell.sms;
+package com.dy.pipIrrWechat.sms;
/**
* @author ZhuBaoMin
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/RestTemplateUtil.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/RestTemplateUtil.java
new file mode 100644
index 0000000..04710fd
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/RestTemplateUtil.java
@@ -0,0 +1,115 @@
+package com.dy.pipIrrWechat.util;
+
+import com.alibaba.fastjson2.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.*;
+import org.springframework.stereotype.Component;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-03-06 13:47
+ * @LastEditTime 2024-03-06 13:47
+ * @Description
+ */
+
+@Component
+public class RestTemplateUtil {
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ //@Qualifier("RestTemplateWithCert")
+ //@Resource
+ //private RestTemplate restTemplate;
+
+ public JSONObject get(String url, Map<String, Object> queryParams) throws IOException {
+ return get(url, queryParams, new HashMap<>(1));
+ }
+
+ public JSONObject get(String url, Map<String, Object> queryParams, Map<String, String> headerParams) throws IOException {
+ String tempUrl = setParamsByAppendUrl(queryParams, url);
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(null, headers);
+ ResponseEntity<String> response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class);
+ return JSONObject.parseObject(response.getBody());
+ }
+
+ public JSONObject getHeaders(String url, Map<String, Object> queryParams, Map<String, String> headerParams) throws IOException {
+ String tempUrl = setParamsByAppendUrl(queryParams, url);
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(null, headers);
+ ResponseEntity<String> response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class);
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("headers", response.getHeaders());
+ jsonObject.put("body", response.getBody());
+ return jsonObject;
+ }
+
+ public JSONObject get2(String url, Map<String, Object> queryParams, Map<String, String> headerParams) throws IOException {
+ String tempUrl = setParamsByPath(queryParams, url);
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(null, headers);
+ ResponseEntity<String> response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class, queryParams);
+ return JSONObject.parseObject(response.getBody());
+ }
+
+ public JSONObject post(String url, String json, Map<String, String> headerParams) {
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ headers.add("Accept", MediaType.APPLICATION_JSON.toString());
+ HttpEntity<String> httpEntity = new HttpEntity<>(json, headers);
+ ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+ return JSONObject.parseObject(response.getBody());
+ }
+
+ private String setParamsByPath(Map<String, Object> queryParams, String url) {
+ // url?id={id}&name={name}
+ if (queryParams == null || queryParams.isEmpty()) {
+ return url;
+ }
+ StringBuilder sb = new StringBuilder();
+ try {
+ for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
+ sb.append("&").append(entry.getKey()).append("=").append("{").append(entry.getKey()).append("}");
+ }
+ if (!url.contains("?")) {
+ sb.deleteCharAt(0).insert(0, "?");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return url + sb;
+ }
+
+ private String setParamsByAppendUrl(Map<String, Object> queryParams, String url) {
+ // url?id=1&name=zzc
+ if (queryParams == null || queryParams.isEmpty()) {
+ return url;
+ }
+ StringBuilder sb = new StringBuilder();
+ try {
+ for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
+ sb.append("&").append(entry.getKey()).append("=");
+ sb.append(entry.getValue());
+ }
+ if (!url.contains("?")) {
+ sb.deleteCharAt(0).insert(0, "?");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return url + sb;
+ }
+
+}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application.yml b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application.yml
index f36e52a..a591cdf 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application.yml
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application.yml
@@ -16,3 +16,10 @@
idSuffix: ${pipIrr.wechat.idSuffix}
#ConfigListener涓簲鐢�
#configFileNames: config-global.xml,config-demo.xml
+#闃块噷鐭俊鏈嶅姟
+aliyun:
+ sms:
+ sms-access-key-id: LTAI5tPCmHqfyJ9YnoPorEwt
+ sms-access-key-secret: sU2CoLdNgcjnf5uPPU2dY7NNGNvOIX
+ sms-template-code: SMS_460776024
+ sms-sign-name: 澶х鑺傛按
\ No newline at end of file
--
Gitblit v1.8.0