From b16109c89467f5dbcb43fb1d7ef2d48e147e8cdd Mon Sep 17 00:00:00 2001 From: liushaodong Date: Thu, 7 Nov 2019 09:29:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/common/utils/SendSmsgCode.java | 114 +++++++----------- .../resources/properties/emailconf-dev.yml | 8 +- .../resources/properties/imjgconf-dev.yml | 8 +- .../main/resources/properties/smsconf-dev.yml | 20 +-- 4 files changed, 64 insertions(+), 86 deletions(-) diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/utils/SendSmsgCode.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/utils/SendSmsgCode.java index 1b55a85..2f1bf81 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/utils/SendSmsgCode.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/utils/SendSmsgCode.java @@ -1,30 +1,28 @@ package com.blockchain.server.user.common.utils; -import com.aliyuncs.CommonRequest; -import com.aliyuncs.CommonResponse; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.http.MethodType; -import com.aliyuncs.profile.DefaultProfile; import lombok.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import java.util.Arrays; +import java.util.List; + /** - * 短信API服务调用 - 阿里云短信 + * 短信API服务调用 **/ @Data @Configuration @Component -@ConfigurationProperties(prefix = "aliyunsms") +@ConfigurationProperties(prefix = "feigesms") public class SendSmsgCode { @Autowired private RestTemplate restTemplate; @@ -34,93 +32,69 @@ public class SendSmsgCode { private boolean closed;//是否开启 private long timeout;//超时时间,单位:分钟 - //阿里云 - private String ACCESS_KEY_ID; - private String ACCESS_SECRET; - private String ENGLISH_MSG; - private String BIG5_MSG; - private String SginName; - private String TemplateCode; + //参数 + private String URL; + private String Account; + private String Pwd; + private String TemplateId_ZH_CN; + private String SignId_ZH_CN; - private String MSG_CODE_PLACEHOLDER = "${code}"; private String CHINA_CODE = "86"; - private String BIG5_CODE = "852,853,886"; + //参数 + private String TemplateId_ZH_HK; + private String TemplateId_EN_US; + private String SignId_EN_US; + private String SignId_ZH_HK; + + private List BIG5_CODE = Arrays.asList(new String[]{"852", "853", "886"}); /** - * 请求阿里云短信接口,发送短信验证码 + * 请求短信接口,发送短信验证码 * - * @param mobile 手机号 - * @param smsCode 短信验证码 - * @param templateId 模板ID + * @param mobile 手机号 + * @param smsCode 短信验证码 * @return */ @Async - public void sendSmsg(String mobile, String smsCode, String internationalCode, String templateId) { + public void sendSmsg(String mobile, String smsCode, String internationalCode) { if (closed) {//如果没有开启短信,则不发送短信 return; } - DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", ACCESS_KEY_ID, ACCESS_SECRET); - IAcsClient client = new DefaultAcsClient(profile); - CommonRequest request = new CommonRequest(); - request.setMethod(MethodType.POST); - //域名,请勿修改 - request.setDomain("dysmsapi.ap-southeast-1.aliyuncs.com"); - //API版本号,请勿修改 - request.setVersion("2018-05-01"); - //接收号码,格式为:国际码+号码,必填 - request.putQueryParameter("To", internationalCode + mobile); - - //国际代码 + MultiValueMap requestEntity = new LinkedMultiValueMap<>(); + requestEntity.add("Account", Account); + requestEntity.add("Pwd", Pwd); + requestEntity.add("Content", smsCode); + //国内手机 if (CHINA_CODE.equals(internationalCode)) { - //请求国内服务器发送短信 - sendTelCode(mobile, smsCode, internationalCode, templateId); + requestEntity.add("Mobile", mobile); + requestEntity.add("TemplateId", TemplateId_ZH_CN); + requestEntity.add("SignId", SignId_ZH_CN); -// //API名称 -// request.setAction("SendMessageWithTemplate"); -// -// request.putQueryParameter("From", SginName); -// request.putQueryParameter("TemplateCode", TemplateCode); -// request.putQueryParameter("TemplateParam", "{\"code\":\"" + smsCode + "\"}"); + try { + ResponseEntity res = restTemplate.postForEntity(URL, requestEntity, String.class); + LOG.info("===send sms end==== : {} ", res); + } catch (Exception e) { + e.printStackTrace(); + } } else { - //API名称 - request.setAction("SendMessageToGlobe"); - //短信内容,必填 + //国际代码 if (BIG5_CODE.contains(internationalCode)) { - //香港,用繁体 - request.putQueryParameter("Message", BIG5_MSG.replace(MSG_CODE_PLACEHOLDER, smsCode)); + requestEntity.add("SignId", SignId_ZH_HK); + requestEntity.add("TemplateId", TemplateId_ZH_HK); } else { - //其他,用英文 - request.putQueryParameter("Message", ENGLISH_MSG.replace(MSG_CODE_PLACEHOLDER, smsCode)); + requestEntity.add("SignId", SignId_EN_US); + requestEntity.add("TemplateId", TemplateId_EN_US); } try { - CommonResponse response = client.getCommonResponse(request); - LOG.info("===send sms end==== : {} ", response.getData()); + ResponseEntity res = restTemplate.postForEntity(URL, requestEntity, String.class); + LOG.info("===send sms end==== : {} ", res); } catch (Exception e) { e.printStackTrace(); } - } } - /** - * 请求国内服务器发送短信 - */ - private void sendTelCode(String mobile, String smsCode, String internationalCode, String templateId) { - String url = "http://47.112.194.145:9220/sendsms"; - MultiValueMap multiValueMap = new LinkedMultiValueMap<>(); - multiValueMap.add("mobile", mobile); - multiValueMap.add("smsCode", smsCode); - multiValueMap.add("internationalCode", internationalCode); - multiValueMap.add("templateId", templateId); - try { - String res = restTemplate.postForEntity(url, multiValueMap, String.class).getBody(); - LOG.info("===send sms end==== : {} ", res); - } catch (Exception e) { - e.printStackTrace(); - } - } - } \ No newline at end of file diff --git a/spring-cloud/spring-cloud-config/src/main/resources/properties/emailconf-dev.yml b/spring-cloud/spring-cloud-config/src/main/resources/properties/emailconf-dev.yml index 5235036..c001aa3 100644 --- a/spring-cloud/spring-cloud-config/src/main/resources/properties/emailconf-dev.yml +++ b/spring-cloud/spring-cloud-config/src/main/resources/properties/emailconf-dev.yml @@ -1,12 +1,12 @@ #邮件发送方的email email: - fromAccount: flamex333@gmail.com + fromAccount: zhixinchain@163.com #主机名 126邮箱为smtp.126.com,163邮箱为163.smtp.com,QQ为smtp.qq.com - hostName: smtp.gmail.com + hostName: 163.smtp.com #邮件发送方的授权码 - authCode: yanhuo888@99 + authCode: zxc2019 #邮件发送方的用户名 - userName: FLAMEX + userName: ZHIXINLIAN #过期时间,单位:分钟,默认30分钟 timeout: 30 #是否关闭邮箱 关闭(true) | 开启(false) diff --git a/spring-cloud/spring-cloud-config/src/main/resources/properties/imjgconf-dev.yml b/spring-cloud/spring-cloud-config/src/main/resources/properties/imjgconf-dev.yml index 66a3f12..6b51417 100644 --- a/spring-cloud/spring-cloud-config/src/main/resources/properties/imjgconf-dev.yml +++ b/spring-cloud/spring-cloud-config/src/main/resources/properties/imjgconf-dev.yml @@ -1,10 +1,10 @@ #极光配置信息 JiGuang: - p_type: yanhuo - appkey: d8496dd94124ee33209f3fc4 - secret: 7f728916dfb2a81e734c59c4 + p_type: zhixinlian + appkey: f701f93f8bd22f5aedb4fb08 + secret: ea9d66b884aa962579b2c03a #随机数,随便填 - random_str: d8496dd94124ee33209f3fc42019 + random_str: d8496dd94124ee33209f3fc41106 api: address: https://api.im.jpush.cn address_v2: https://report.im.jpush.cn/v2 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-config/src/main/resources/properties/smsconf-dev.yml b/spring-cloud/spring-cloud-config/src/main/resources/properties/smsconf-dev.yml index 052586a..440af77 100644 --- a/spring-cloud/spring-cloud-config/src/main/resources/properties/smsconf-dev.yml +++ b/spring-cloud/spring-cloud-config/src/main/resources/properties/smsconf-dev.yml @@ -1,9 +1,13 @@ -aliyunsms: - closed: true +feigesms: + closed: false timeout: 5 - SginName: 焰火网 - TemplateCode: SMS_10505006 - ACCESS_KEY_ID: LTAI46NrbdbBtAdS - ACCESS_SECRET: oG4lZDX0dyH98CQNjSQ9gfTYdc5tj5 - ENGLISH_MSG: "【FLAME】Your verification code is: ${code}, which is valid within 5 minutes. Please do not disclose it to others." - BIG5_MSG: 【焰火網】您的驗證碼為:${code},該驗證碼5分鐘內有效,請勿泄漏於他人。 \ No newline at end of file + #国内短信接口 + URL: http://api.feige.ee/SmsService/Inter + Account: 18818574533 + Pwd: zxc2019 + TemplateId_ZH_CN: 38129 + SignId_ZH_CN: 38944 + TemplateId_ZH_HK: 38120 + TemplateId_EN_US: 38138 + SignId_ZH_HK: 38944 + SignId_EN_US: 38944