1 files deleted
2 files added
5 files modified
| | |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | return headers; |
| | | } |
| | | |
| | | private static HttpHeaders get() { |
| | | private static HttpHeaders getMsg() { |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.set("accept", "*/*"); |
| | | headers.set("connection", "Keep-Alive"); |
| | | headers.set("user-agent", |
| | | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | List<MediaType> mediaTypes = new ArrayList<>(); |
| | | mediaTypes.add(MediaType.ALL); |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // 表单格式 |
| | | headers.setAccept(mediaTypes); |
| | | headers.setConnection("Keep-Alive"); |
| | | headers.set("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | return headers; |
| | | } |
| | | |
| | | /** |
| | | * 短信 |
| | | * http返回String xml |
| | | */ |
| | | public static String exchangeMsg(HttpMethod httpMethod, String url, MultiValueMap<String, String> map) { |
| | | HttpHeaders headers = getMsg(); |
| | | HttpEntity<Object> httpEntity = new HttpEntity<>(map, headers); |
| | | RestTemplate restTemplate = new RestTemplate(getFactory()); |
| | | return restTemplate.exchange(url, httpMethod, httpEntity, String.class).getBody(); |
| | | } |
| | | |
| | | /** |
| | | * http返回String |
| | | */ |
| | | public static String exchangeString(HttpMethod httpMethod, String url, Map<String, Object> map) { |
| | | HttpHeaders headers = get(); |
| | | HttpHeaders headers = getHeaders(); |
| | | HttpEntity<Object> httpEntity = new HttpEntity<>(map, headers); |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | return restTemplate.exchange(url, httpMethod, httpEntity, String.class).getBody(); |
| | |
| | | import com.oying.annotation.rest.AnonymousGetMapping; |
| | | import com.oying.utils.R; |
| | | import com.oying.utils.RedisUtils; |
| | | import com.oying.utils.SendMessageUtils; |
| | | import com.oying.utils.WinnerLookProperties; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private String key; |
| | | @Value("${sms.time}") |
| | | private Long time; |
| | | private final WinnerLookProperties properties; |
| | | |
| | | @AnonymousGetMapping |
| | | @ApiOperation("短信验证码") |
| | | public ResponseEntity<Object> toPayAsPc(@RequestParam String phone) { |
| | | public ResponseEntity<Object> verification(@RequestParam String phone) { |
| | | String uuid = key + IdUtil.simpleUUID(); |
| | | System.out.println(phone); |
| | | //创建验证码 |
| | | String verification = (int) ((Math.random() * 9 + 1) * 100000) + ""; |
| | | redisUtils.set(uuid, verification, time); |
| | | String message = "您的验证码为:" + verification + ",请勿泄露于他人!"; |
| | | SendMessageUtils.sendMsg(phone, message, properties); |
| | | return ResponseEntity.ok(R.success(uuid)); |
| | | } |
| | | } |
| | |
| | | endpoint: https://obs.cn-southwest-2.myhuaweicloud.com |
| | | |
| | | winner-look: |
| | | url: https://118.178.116.15:8443/ |
| | | url-send-msg: https://118.178.116.15:8443/winnerrxd/api/trigger/SendMsg |
| | | user-code: CQLYSXYJ |
| | | user-pass: lych1205! |
| | |
| | | endpoint: https://obs.cn-southwest-2.myhuaweicloud.com |
| | | |
| | | winner-look: |
| | | url: https://118.178.116.15:8443/ |
| | | url-send-msg: https://118.178.116.15:8443/winnerrxd/api/trigger/SendMsg |
| | | user-code: CQLYSXYJ |
| | | user-pass: lych1205! |
| | |
| | | package com.oying.utils; |
| | | |
| | | import com.oying.exception.BadRequestException; |
| | | import lombok.Data; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.http.HttpMethod; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.Map; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * @author xin |
| | | * @description |
| | | * @date 2025/6/4 01:10 |
| | | */ |
| | | @Slf4j |
| | | @Data |
| | | public class SendMessageUtils { |
| | | @Value("${winner-look.url}") |
| | | private String url; |
| | | @Value("${winner-look.user-code}") |
| | | private String userCode; |
| | | @Value("${winner-look.user-pass}") |
| | | private String userPass; |
| | | |
| | | public static void main(String[] args) { |
| | | String url = "https://118.178.116.15:8443/winnerrxd/api/trigger/SendMsg"; |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("userCode", "CQLYSXYJ"); |
| | | paramMap.put("userPass", "lych1205!"); |
| | | paramMap.put("DesNo", "15213186640"); |
| | | paramMap.put("Msg", "短信内容【立研】"); |
| | | paramMap.put("smsType", "101"); |
| | | System.out.println(HttpRequest.exchangeString(HttpMethod.POST, url, paramMap)); |
| | | public static void sendMsg(String phone, String message, WinnerLookProperties properties) { |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("userCode", properties.getUserCode()); |
| | | params.put("userPass", properties.getUserPass()); |
| | | params.put("DesNo", phone); |
| | | params.put("Msg", message + "【立研】"); |
| | | params.put("smsType", "101"); |
| | | String str = HttpRequest.exchangeMsg(HttpMethod.POST, properties.getUrlSendMsg(), convert(params)); |
| | | if (ObjectUtils.isEmpty(extractWithRegex(str))) { |
| | | log.error("短信调用异常 {}", str); |
| | | throw new BadRequestException("短信调用异常"); |
| | | } |
| | | int i = Integer.parseInt(str); |
| | | if (i < 0) { |
| | | throw new BadRequestException(WinnerLookEnum.find(i)); |
| | | } |
| | | } |
| | | |
| | | public static String extractWithRegex(String xml) { |
| | | Pattern pattern = Pattern.compile( |
| | | "<string[^>]*>([^<]*)</string>" |
| | | ); |
| | | Matcher matcher = pattern.matcher(xml); |
| | | return matcher.find() ? matcher.group(1) : null; |
| | | } |
| | | |
| | | /** |
| | | * Map转MultiValueMap |
| | | */ |
| | | public static <K, V> MultiValueMap<K, V> convert(Map<K, V> map) { |
| | | MultiValueMap<K, V> multiValueMap = new LinkedMultiValueMap<>(); |
| | | map.forEach(multiValueMap::add); |
| | | return multiValueMap; |
| | | } |
| | | } |
New file |
| | |
| | | package com.oying.utils; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum WinnerLookEnum { |
| | | ONE(-1, "应用程序错误"), |
| | | THREE(-3, "用户名或密码错误"), |
| | | FOUR(-4, "短信内容和备案的模板不一样"), |
| | | FIVE(-5, "签名不正确"), |
| | | SEVEN(-7, "余额不足"), |
| | | EIGHT(-8, "无可用通道或不在通道时间范围"), |
| | | NINE(-9, "无效号码"), |
| | | TEN(-10, "签名内容不符合长度"), |
| | | ELEVEN(-11, "用户有效期过期"), |
| | | TWELVE(-12, "黑名单"), |
| | | SIXTEEN(-16, "接口请求过于频繁,余额接口 5s 秒一次,其他接口适当调整"), |
| | | SEVENTEEN(-17, "非法 IP"), |
| | | EIGHTEEN(-18, "Msg 内容格式错误"), |
| | | NINETEEN(-19, "短信数量错误,小于 1 /大于 500(个性化)/大于 1000(群发)"), |
| | | TWENTY(-20, "号码错误或者黑名单"), |
| | | TWENTY_THREE(-23, "解密失败"), |
| | | TWENTY_FOUR(-24, "短信包含用户敏感信息"), |
| | | TWENTY_FIVE(-25, "用户被冻结"), |
| | | TWENTY_SIX(-26, "无效数据"), |
| | | TWENTY_SEVEN(-27, "请求参数错误"), |
| | | TWENTY_EIGHT(-28, "无效数据"), |
| | | FORTY_ONE(-41, "指定短信模板类型错误或短信类型参数错误"), |
| | | FORTY_FOUR(-44, "自定义扩展号不符合规则(1-16 位数字)"), |
| | | FORTY_SIX(-46, "用户黑名单"), |
| | | FORTY_SEVEN(-47, "系统黑名单"), |
| | | FORTY_EIGHT(-48, "号码超频拦截"), |
| | | FIFTY_ONE(-51, "超过设置的每月短信条数的限制"), |
| | | FIFTY_FIVE(-54, "短信包含系统敏感信息"), |
| | | ZERO(0, "未知错误"); |
| | | |
| | | private final int key; |
| | | private final String value; |
| | | |
| | | public static String find(Integer key) { |
| | | for (WinnerLookEnum value : WinnerLookEnum.values()) { |
| | | if (value.getKey() == key) { |
| | | return value.getValue(); |
| | | } |
| | | } |
| | | return ZERO.getValue(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.oying.utils; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | /** |
| | | * @author xin |
| | | * @description |
| | | * @date 2025/6/4 14:32 |
| | | */ |
| | | @Data |
| | | @Configuration |
| | | @ConfigurationProperties(prefix = "winner-look") |
| | | public class WinnerLookProperties { |
| | | |
| | | private String urlSendMsg; |
| | | private String userCode; |
| | | private String userPass; |
| | | } |