Commit dc267ea5681e73aa6eac55d34da370c3735f0839

Authored by YunaiV
2 parents 8775472a 2f38261d

Merge branch 'develop' of https://gitee.com/scholarli/ruoyi-vue-pro_1 into develop

# Conflicts:
#	yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClient.java
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClient.java
... ... @@ -23,6 +23,8 @@ import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProp
23 23 import com.google.common.annotations.VisibleForTesting;
24 24 import lombok.extern.slf4j.Slf4j;
25 25  
  26 +import java.io.UnsupportedEncodingException;
  27 +import java.net.URLEncoder;
26 28 import java.util.*;
27 29 import java.util.stream.Collectors;
28 30  
... ... @@ -64,7 +66,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
64 66 queryParam.put("TemplateCode", apiTemplateId);
65 67 queryParam.put("TemplateParam", JsonUtils.toJsonString(MapUtils.convertMap(templateParams)));
66 68 queryParam.put("OutId", sendLogId);
67   - JSONObject response = request("sendSms", queryParam);
  69 + JSONObject response = request("SendSms", queryParam);
68 70  
69 71 // 2. 解析请求
70 72 return new SmsSendRespDTO()
... ... @@ -100,6 +102,8 @@ public class AliyunSmsClient extends AbstractSmsClient {
100 102 queryParam.put("TemplateCode", apiTemplateId);
101 103 JSONObject response = request("QuerySmsTemplate", queryParam);
102 104  
  105 + System.out.println("getSmsTemplate response is =====" + response.toString());
  106 +
103 107 // 2.1 请求失败
104 108 String code = response.getStr("Code");
105 109 if (ObjectUtil.notEqual(code, RESPONSE_CODE_SUCCESS)) {
... ... @@ -144,6 +148,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
144 148 headers.put("x-acs-action", apiName);
145 149 headers.put("x-acs-date", FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("GMT")).format(new Date()));
146 150 headers.put("x-acs-signature-nonce", IdUtil.randomUUID());
  151 +
147 152 // 2.2 构建签名 Header
148 153 StringBuilder canonicalHeaders = new StringBuilder(); // 构造请求头,多个规范化消息头,按照消息头名称(小写)的字符代码顺序以升序排列后拼接在一起
149 154 StringBuilder signedHeadersBuilder = new StringBuilder(); // 已签名消息头列表,多个请求头名称(小写)按首字母升序排列并以英文分号(;)分隔
... ... @@ -162,16 +167,18 @@ public class AliyunSmsClient extends AbstractSmsClient {
162 167 String hashedRequestBody = DigestUtil.sha256Hex(requestBody);
163 168  
164 169 // 4. 构建 Authorization 签名
165   - String hashedCanonicalRequest = DigestUtil.sha256Hex("POST" // httpMethod
166   - + "\n" + "/" // canonicalUri
167   - + "\n" + queryString + "\n" + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody);
  170 + String canonicalRequest = "POST" + "\n" + "/" + "\n" + queryString + "\n" + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody;
  171 + String hashedCanonicalRequest = DigestUtil.sha256Hex(canonicalRequest);
  172 +
168 173 String stringToSign = "ACS3-HMAC-SHA256" + "\n" + hashedCanonicalRequest;
169 174 String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign); // 计算签名
170 175 headers.put("Authorization", "ACS3-HMAC-SHA256" + " " + "Credential=" + properties.getApiKey()
171 176 + ", " + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature);
172 177  
173 178 // 5. 发起请求
174   - String urlWithParams = URL + "?" + URLUtil.buildQuery(queryParams, null);
  179 + String urlWithParams = URL + "?" + queryString;
  180 +
  181 + System.out.println("urlWithParams ======" + urlWithParams);
175 182 try (HttpResponse response = HttpRequest.post(urlWithParams).addHeaders(headers).body(requestBody).execute()) {
176 183 return JSONUtil.parseObj(response.body());
177 184 }
... ... @@ -183,12 +190,15 @@ public class AliyunSmsClient extends AbstractSmsClient {
183 190 * @param str 需要进行URL编码的字符串
184 191 * @return 编码后的字符串
185 192 */
186   - private static String percentCode(String str) {
187   - Assert.notNull(str, "str 不能为空");
188   - return URLUtil.encode(str)
189   - .replace("+", "%20") // 加号 "+" 被替换为 "%20"
190   - .replace("*", "%2A") // 星号 "*" 被替换为 "%2A"
191   - .replace("%7E", "~"); // 波浪号 "%7E" 被替换为 "~"
  193 + public static String percentCode(String str) {
  194 + if (str == null) {
  195 + throw new IllegalArgumentException("输入字符串不可为null");
  196 + }
  197 + try {
  198 + return URLEncoder.encode(str, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
  199 + } catch (UnsupportedEncodingException e) {
  200 + throw new RuntimeException("UTF-8编码不被支持", e);
  201 + }
192 202 }
193 203  
194 204 -}
  205 +}
195 206 \ No newline at end of file
... ...