sms服务替换

master
yixian 4 years ago
parent 064b45639a
commit 8214e507e6

@ -15,16 +15,13 @@ import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
import au.com.royalpay.payment.manage.merchants.beans.BankAccountInfo; import au.com.royalpay.payment.manage.merchants.beans.BankAccountInfo;
import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo; import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo;
import au.com.royalpay.payment.manage.merchants.beans.ClientRegisterInfo; import au.com.royalpay.payment.manage.merchants.beans.ClientRegisterInfo;
import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.notice.core.MailService; import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.product.beans.ProductBean; import au.com.royalpay.payment.manage.product.beans.ProductBean;
import au.com.royalpay.payment.manage.product.core.ClientProduct; import au.com.royalpay.payment.manage.product.core.ClientProduct;
import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.ManagerAccountsService;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.support.sms.SmsSender; import au.com.royalpay.payment.manage.support.sms.SmsSenderQcloudImpl;
import au.com.royalpay.payment.tools.device.DeviceSupport;
import au.com.royalpay.payment.tools.device.ManageDeviceSupport; import au.com.royalpay.payment.tools.device.ManageDeviceSupport;
import au.com.royalpay.payment.tools.device.support.DeviceRegister; import au.com.royalpay.payment.tools.device.support.DeviceRegister;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
@ -37,7 +34,6 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
@ -91,7 +87,7 @@ public class ManageAppServiceImp implements ManageAppService {
@Resource @Resource
private SpringTemplateEngine thymeleaf; private SpringTemplateEngine thymeleaf;
@Resource @Resource
private SmsSender smsSender; private SmsSenderQcloudImpl smsSender;
private final String BIND_MANAGE_EMAIL_PREFIX = "BIND_MANAGE_EMAIL"; private final String BIND_MANAGE_EMAIL_PREFIX = "BIND_MANAGE_EMAIL";
private final String BIND_MANAGE_PHONE_PREFIX = "BIND_MANAGE_PHONE"; private final String BIND_MANAGE_PHONE_PREFIX = "BIND_MANAGE_PHONE";
private final int BIND_PHONE_TEMPLID = 126978; private final int BIND_PHONE_TEMPLID = 126978;

@ -46,7 +46,7 @@ import au.com.royalpay.payment.manage.riskbusiness.enums.RiskResultTypeEnum;
import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl; import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl;
import au.com.royalpay.payment.manage.support.sms.SmsSender; import au.com.royalpay.payment.manage.support.sms.SmsSenderQcloudImpl;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery; import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
import au.com.royalpay.payment.manage.tradelog.core.TradeLogService; import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
import au.com.royalpay.payment.manage.tradelog.refund.RefundService; import au.com.royalpay.payment.manage.tradelog.refund.RefundService;
@ -234,7 +234,7 @@ public class RetailAppServiceImp implements RetailAppService {
private final String IMG_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2020/04/08/1586313342533_41vI3w9R8OHrhAVYWvdv7S2IyQra4z.pdf"; private final String IMG_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2020/04/08/1586313342533_41vI3w9R8OHrhAVYWvdv7S2IyQra4z.pdf";
@Resource @Resource
private SmsSender smsSender; private SmsSenderQcloudImpl smsSender;
private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL"; private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL";
private final String BIND_ACCOUNT_PHONE_PREFIX = "BIND_ACCOUNT_PHONE"; private final String BIND_ACCOUNT_PHONE_PREFIX = "BIND_ACCOUNT_PHONE";
private final String UNBIND_ACCOUNT_PHONE_PREFIX = "UHBIND_ACCOUNT_PHONE"; private final String UNBIND_ACCOUNT_PHONE_PREFIX = "UHBIND_ACCOUNT_PHONE";

@ -14,6 +14,8 @@ import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.signin.beans.LoginInfo; import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.support.sms.SmsSender; import au.com.royalpay.payment.manage.support.sms.SmsSender;
import au.com.royalpay.payment.manage.support.sms.msg.OpenMessage;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import au.com.royalpay.payment.manage.system.core.MailGunService; import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
@ -55,6 +57,7 @@ import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -86,7 +89,7 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private SignInAccountService signInAccountService; private SignInAccountService signInAccountService;
@Resource @Resource
private SimpleClientApplyService simpleClientApplyService; private SimpleClientApplyService simpleClientApplyService;
private Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
@Resource @Resource
private ClientAccountMapper clientAccountMapper; private ClientAccountMapper clientAccountMapper;
@Resource @Resource
@ -117,8 +120,6 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private SmsSender smsSender; private SmsSender smsSender;
@Resource @Resource
private StringRedisTemplate stringRedisTemplate; private StringRedisTemplate stringRedisTemplate;
private final int REGISTER_CLIENT_TEMPLID = 126978;
private final int REGISTER_CLIENT_TEMPLID_ENGLISH = 346078;
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT"; private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS"; private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL"; private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
@ -159,34 +160,18 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
if (StringUtils.isNotEmpty(value)) { if (StringUtils.isNotEmpty(value)) {
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes."); throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes.");
} }
ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, false, true); String registerClientCode = RandomStringUtils.random(6, false, true);
param.add("RoyalPay"); int expireMin = 3;
param.add(registerClientCode); logger.debug("send {} sms code : {} ",phoneNumber, registerClientCode);
String expireMin = "3"; smsSender.sendAuthCodeMessage(nationCode.trim(),phoneNumber,request.getLocales().nextElement(),new AuthCodeMessage("RoyalPay", registerClientCode,expireMin));
param.add(expireMin); stringRedisTemplate.boundValueOps(getRegisterClientRedisKey(phoneNumber)).set(registerClientCode, Duration.ofMinutes(expireMin));
logger.debug("send sms code : {} ", registerClientCode);
try {
if(request.getLocales().nextElement().equals(Locale.CHINESE)|| request.getLocales().nextElement().equals(Locale.SIMPLIFIED_CHINESE)){
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID, param, "RoyalPay", "", "");
}else{
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID_ENGLISH, param, "RoyalPay", "", "");
}
} catch (Exception e) {
e.printStackTrace();
throw new ServerErrorException("Phone number is wrong Please try again");
}
stringRedisTemplate.boundValueOps(getRegisterClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
return registerClientCode; return registerClientCode;
} }
@Override @Override
public void sendOpenSms(String phoneNumber, String nationCode) { public void sendOpenSms(String phoneNumber, String nationCode) {
ArrayList<String> param = new ArrayList<>();
String phone_Number = phoneNumber.substring(0, 3) + "****" + phoneNumber.substring(7, phoneNumber.length());
param.add(phone_Number);
try { try {
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, 462770, param, "RoyalPay", "", ""); smsSender.sendOpenMessage(nationCode.trim(), phoneNumber, Locale.CHINESE, new OpenMessage(phoneNumber));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new ServerErrorException("Phone number is wrong Please try again"); throw new ServerErrorException("Phone number is wrong Please try again");
@ -857,24 +842,11 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
if (StringUtils.isNotEmpty(value)) { if (StringUtils.isNotEmpty(value)) {
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 1 minutes."); throw new BadRequestException("SMS has been sentPlease check your messages or try again in 1 minutes.");
} }
ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, false, true); String registerClientCode = RandomStringUtils.random(6, false, true);
param.add("RoyalPay");
param.add(registerClientCode);
String expireMin = "1";
logger.debug("{} phone sms send code :{}",phoneNumber,registerClientCode); logger.debug("{} phone sms send code :{}",phoneNumber,registerClientCode);
param.add(expireMin); int expireMin = 1;
try { smsSender.sendAuthCodeMessage(nationCode.trim(),phoneNumber,request.getLocales().nextElement(),new AuthCodeMessage("RoyalPay", registerClientCode,expireMin));
if(request.getLocales().nextElement().equals(Locale.CHINESE)|| request.getLocales().nextElement().equals(Locale.SIMPLIFIED_CHINESE)){ stringRedisTemplate.boundValueOps(getLoginClientRedisKey(phoneNumber)).set(registerClientCode, Duration.ofMinutes(expireMin));
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID, param, "RoyalPay", "", "");
}else{
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID_ENGLISH, param, "RoyalPay", "", "");
}
} catch (Exception e) {
e.printStackTrace();
throw new ServerErrorException("Phone number is wrong Please try again");
}
stringRedisTemplate.boundValueOps(getLoginClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
} }
@Override @Override

@ -74,6 +74,7 @@ import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.support.serverless.ServerlessFunctionTrigger; import au.com.royalpay.payment.manage.support.serverless.ServerlessFunctionTrigger;
import au.com.royalpay.payment.manage.support.sms.SmsSender; import au.com.royalpay.payment.manage.support.sms.SmsSender;
import au.com.royalpay.payment.manage.support.sms.msg.RefuseMessage;
import au.com.royalpay.payment.manage.system.core.ClientContractService; import au.com.royalpay.payment.manage.system.core.ClientContractService;
import au.com.royalpay.payment.manage.system.core.MailGunService; import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery; import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
@ -205,9 +206,6 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
private ClientComplianceApply clientComplianceApply; private ClientComplianceApply clientComplianceApply;
@Resource @Resource
private ClientIncrementalMapper clientIncrementalMapper; private ClientIncrementalMapper clientIncrementalMapper;
@Value("${client_card.account_reserve}")
private String cardAccountReserve;
@Value("${client_card.annual_rate}") @Value("${client_card.annual_rate}")
private String cardAnnualRate; private String cardAnnualRate;
@ -364,7 +362,6 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Resource @Resource
private MpWechatApiProvider mpWechatApiProvider; private MpWechatApiProvider mpWechatApiProvider;
private final int REFUSE_CLIENT_TEMPLID = 166108;
@Resource @Resource
private PaymentChannelMccGoodMapper paymentChannelMccGoodMapper; private PaymentChannelMccGoodMapper paymentChannelMccGoodMapper;
@ -4968,13 +4965,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
if (client.getIntValue("source") == 4) { if (client.getIntValue("source") == 4) {
String contactPhone = client.getString("contact_phone"); String contactPhone = client.getString("contact_phone");
if (contactPhone.startsWith("+61")) { if (contactPhone.startsWith("+61")) {
ArrayList<String> param = new ArrayList<>(); smsSender.sendRefuseMessage("61", contactPhone, Locale.CHINESE, new RefuseMessage(refuseRemark));
param.add(refuseRemark);
try {
smsSender.getSender().sendWithParam("61", contactPhone.replace("+61", ""), REFUSE_CLIENT_TEMPLID, param, "RoyalPay", "", "");
} catch (Exception ignore) {
throw new ServerErrorException("Phone number is wrong :" + contactPhone);
}
} }
} }
if (client.getIntValue("source") == 5) { if (client.getIntValue("source") == 5) {
@ -5015,13 +5006,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
if (client.getIntValue("source") == 4) { if (client.getIntValue("source") == 4) {
String contactPhone = client.getString("contact_phone"); String contactPhone = client.getString("contact_phone");
if (contactPhone.startsWith("+61")) { if (contactPhone.startsWith("+61")) {
ArrayList<String> param = new ArrayList<>(); smsSender.sendRefuseMessage("61", contactPhone, Locale.CHINESE, new RefuseMessage(refuseRemark));
param.add(refuseRemark);
try {
smsSender.getSender().sendWithParam("61", contactPhone.replace("+61", ""), REFUSE_CLIENT_TEMPLID, param, "RoyalPay", "", "");
} catch (Exception ignore) {
throw new ServerErrorException("Phone number is wrong :" + contactPhone);
}
} }
} }
if (client.getIntValue("source") == 5) { if (client.getIntValue("source") == 5) {

@ -15,12 +15,12 @@ import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent; import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent;
import au.com.royalpay.payment.manage.signin.events.ManagerLoginEvent; import au.com.royalpay.payment.manage.signin.events.ManagerLoginEvent;
import au.com.royalpay.payment.manage.support.sms.SmsSender; import au.com.royalpay.payment.manage.support.sms.SmsSender;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import au.com.royalpay.payment.manage.system.core.PermissionClientModulesService; import au.com.royalpay.payment.manage.system.core.PermissionClientModulesService;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.env.RequestEnvironment; import au.com.royalpay.payment.tools.env.RequestEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.locale.LocaleSupport; import au.com.royalpay.payment.tools.locale.LocaleSupport;
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
@ -44,10 +44,7 @@ import org.thymeleaf.spring5.SpringTemplateEngine;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -105,7 +102,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
private final String[] KYC_FILE_KEYS = {"client_bank_file", "kyc_utility_bill_file", "client_id_file"}; private final String[] KYC_FILE_KEYS = {"client_bank_file", "kyc_utility_bill_file", "client_id_file"};
private final String[] KYC_PUT_KEYS = {"file_bank_info", "utility_bill_info", "file_id_info"}; private final String[] KYC_PUT_KEYS = {"file_bank_info", "utility_bill_info", "file_id_info"};
private final String[] KYC_FILE_NAMES = {"* ASIC File", "Utility Bill Files", "* ID"}; private final String[] KYC_FILE_NAMES = {"* ASIC File", "Utility Bill Files", "* ID"};
private final int RESET_PASSWORD_TEMPLID = 126978;
private ApplicationEventPublisher publisher; private ApplicationEventPublisher publisher;
private static final List<String> tags = new ArrayList<>(); private static final List<String> tags = new ArrayList<>();
@ -574,17 +571,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
}); });
break; break;
case "phone": case "phone":
ArrayList<String> param = new ArrayList<>(); smsSender.sendAuthCodeMessage(account.getString("nation_code").trim(), account.getString("contact_phone"), Locale.ENGLISH, new AuthCodeMessage("密码重置服务", codeKeyValue, 5));
param.add("密码重置服务");
param.add(codeKeyValue);
String expireMin = "5";
param.add(expireMin);
try {
smsSender.getSender().sendWithParam(account.getString("nation_code").trim(), account.getString("contact_phone"), RESET_PASSWORD_TEMPLID, param, "RoyalPay", "", "");
} catch (Exception e) {
e.printStackTrace();
throw new ServerErrorException("Phone number is wrong.Please try again.");
}
break; break;
} }
stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).set(codeKeyValue, 5, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).set(codeKeyValue, 5, TimeUnit.MINUTES);
@ -620,17 +607,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
}); });
break; break;
case "phone": case "phone":
ArrayList<String> param = new ArrayList<>(); smsSender.sendAuthCodeMessage(account.getString("nation_code").trim(), account.getString("phone"), Locale.CHINESE, new AuthCodeMessage("密码重置服务",codeKeyValue,5));
param.add("密码重置服务");
param.add(codeKeyValue);
String expireMin = "5";
param.add(expireMin);
try {
smsSender.getSender().sendWithParam(account.getString("nation_code").trim(), account.getString("phone"), RESET_PASSWORD_TEMPLID, param, "RoyalPay", "", "");
} catch (Exception e) {
e.printStackTrace();
throw new ServerErrorException("Phone number is wrong.Please try again.");
}
break; break;
} }
stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).set(codeKeyValue, 5, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).set(codeKeyValue, 5, TimeUnit.MINUTES);

@ -1,33 +1,15 @@
package au.com.royalpay.payment.manage.support.sms; package au.com.royalpay.payment.manage.support.sms;
import com.github.qcloudsms.SmsSingleSender; import au.com.royalpay.payment.manage.support.sms.msg.OpenMessage;
import au.com.royalpay.payment.manage.support.sms.msg.RefuseMessage;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import org.springframework.beans.factory.annotation.Value; import java.util.Locale;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; public interface SmsSender {
void sendOpenMessage(String nationCode, String mobile, Locale locale, OpenMessage msg);
/** void sendAuthCodeMessage(String nationCode, String mobile, Locale locale, AuthCodeMessage register);
* @author kira
* @date 2018/8/1
*/
@Component
public class SmsSender {
@Value("${royalpay.sms.appid:1400094878}")
private int appId;
@Value("${royalpay.sms.appkey:43390d81e20c5191c278fbf4cd275be2}")
private String appKey;
private SmsSingleSender sender = null;
@PostConstruct
public void init() {
sender = new SmsSingleSender(appId, appKey);
}
public SmsSingleSender getSender(){
return sender;
}
void sendRefuseMessage(String nationCode, String mobile, Locale locale, RefuseMessage refuse);
} }

@ -0,0 +1,130 @@
package au.com.royalpay.payment.manage.support.sms;
import au.com.royalpay.payment.manage.support.sms.daas.DaasMessageTemplate;
import au.com.royalpay.payment.manage.support.sms.daas.OpenMessageTemplate;
import au.com.royalpay.payment.manage.support.sms.daas.RefuseMessageTemplate;
import au.com.royalpay.payment.manage.support.sms.daas.AuthCodeMessageTemplate;
import au.com.royalpay.payment.manage.support.sms.msg.OpenMessage;
import au.com.royalpay.payment.manage.support.sms.msg.RefuseMessage;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.apache.commons.codec.binary.Base64;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestClientResponseException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.server.ServerErrorException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import java.util.Optional;
@Service
@ConditionalOnProperty(value = "royalpay.sms.daas.enable", havingValue = "true")
public class SmsSenderDaasImpl implements SmsSender {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String serectId;
private final String secretKey;
private final RestTemplate restTemplate;
private static final String URL = "https://service-rzq04n9p-1255701024.sh.apigw.tencentcs.com/release/superapi/super/sms/internation/single";
public SmsSenderDaasImpl(@Value("${royalpay.sms.daas.secret-id}") String serectId, @Value("${royalpay.sms.daas.secret-key}") String secretKey) {
this.serectId = serectId;
this.secretKey = secretKey;
this.restTemplate = new RestTemplateBuilder().messageConverters(new FormHttpMessageConverter(),
new StringHttpMessageConverter(StandardCharsets.UTF_8),
new FastJsonHttpMessageConverter())
.build();
}
@Override
public void sendOpenMessage(String nationCode, String mobile, Locale locale, OpenMessage msg) {
sendSms(nationCode, mobile, new OpenMessageTemplate(msg));
}
@Override
public void sendAuthCodeMessage(String nationCode, String mobile, Locale locale, AuthCodeMessage register) {
sendSms(nationCode, mobile, new AuthCodeMessageTemplate(locale, register));
}
@Override
public void sendRefuseMessage(String nationCode, String mobile, Locale locale, RefuseMessage refuse) {
sendSms(nationCode, mobile, new RefuseMessageTemplate(refuse));
}
private void sendSms(String nationCode, String mobile, DaasMessageTemplate tpl) {
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("mobile", nationCode + mobile.replaceAll("^(\\+61)(61)", ""));
body.add("msg", "[RoyalPay]" + tpl.getMessage());
RequestEntity<MultiValueMap<String, String>> request = RequestEntity.post(URI.create(URL))
.headers(signature()).contentType(MediaType.APPLICATION_FORM_URLENCODED)
.body(body);
try {
ResponseEntity<JSONObject> resp = restTemplate.exchange(request, JSONObject.class);
JSONObject respBody = resp.getBody();
logger.debug("daas sms response:{}", respBody);
Optional.ofNullable(respBody)
.map(resBody -> resBody.getJSONArray("data"))
.filter(arr -> !arr.isEmpty())
.map(dataArr -> dataArr.getJSONObject(0))
.ifPresent(data -> {
JSONObject record0 = data.getJSONArray("record").getJSONObject(0);
logger.info("send sms success:[{}]{}, messageNum:{}", record0.getString("resCode"), record0.getString("resDesc"), data.getString("recordNum"));
});
} catch (RestClientResponseException e) {
logger.error("request sms service failed:[{}]{}", e.getRawStatusCode(), e.getResponseBodyAsString(), e);
} catch (RestClientException e) {
logger.error("request sms service failed", e);
}
}
private HttpHeaders signature() {
String source = "market";
String datetime = DateTime.now().withZone(DateTimeZone.UTC).toString("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH);
try {
String auth = calcAuthorization(source, serectId, secretKey, datetime);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("X-Source", source);
headers.add("X-Date", datetime);
headers.add("Authorization", auth);
return new HttpHeaders(headers);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
throw new ServerErrorException("Signature failed", e);
}
}
public static String calcAuthorization(String source, String secretId, String secretKey, String datetime)
throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
String signStr = "x-date: " + datetime + "\n" + "x-source: " + source;
Mac mac = Mac.getInstance("HmacSHA1");
Key sKey = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), mac.getAlgorithm());
mac.init(sKey);
byte[] hash = mac.doFinal(signStr.getBytes(StandardCharsets.UTF_8));
String sig = Base64.encodeBase64String(hash);
return "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"" + sig + "\"";
}
}

@ -0,0 +1,65 @@
package au.com.royalpay.payment.manage.support.sms;
import au.com.royalpay.payment.manage.support.sms.msg.OpenMessage;
import au.com.royalpay.payment.manage.support.sms.msg.RefuseMessage;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import com.github.qcloudsms.SmsSingleSender;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import java.util.Locale;
/**
* @author kira
* @date 2018/8/1
*/
@Component
@ConditionalOnProperty(value = "royalpay.sms.qcloud.enable", havingValue = "true")
public class SmsSenderQcloudImpl implements SmsSender {
private static final int OPEN_MESSAGE_ID = 462770;
private static final int REGISTER_CLIENT_TEMPLID_ZH = 126978;
private static final int REGISTER_CLIENT_TEMPLID_EN = 346078;
private static final int REFUSE_CLIENT_TEMPLID = 166108;
private static final int RESET_PASSWORD_TEMPLID = 126978;
private final SmsSingleSender sender;
private final String sign;
public SmsSenderQcloudImpl(@Value("${royalpay.sms.qcloud.appid}") int appId, @Value("${royalpay.sms.qcloud.appkey}") String appKey) {
sender = new SmsSingleSender(appId, appKey);
sign = "RoyalPay";
}
public SmsSingleSender getSender() {
return sender;
}
@Override
public void sendOpenMessage(String nationCode, String mobile, Locale locale, OpenMessage msg) {
sendMessage(nationCode, mobile, OPEN_MESSAGE_ID, msg.getMaskedPhoneNumber());
}
private void sendMessage(String nationCode, String mobile, int tplId, String... param) {
try {
sender.sendWithParam(nationCode, mobile.replace("+61", ""), tplId, param, sign, "", "");
} catch (Exception e) {
throw new ServerErrorException("Phone number is wrong :" + mobile, e);
}
}
@Override
public void sendAuthCodeMessage(String nationCode, String mobile, Locale locale, AuthCodeMessage register) {
if (locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE)) {
sendMessage(nationCode, mobile, REGISTER_CLIENT_TEMPLID_ZH, register.getBiz(), register.getCode(), register.getExpireMin() + "");
} else {
sendMessage(nationCode, mobile, REGISTER_CLIENT_TEMPLID_EN, register.getBiz(), register.getCode(), register.getExpireMin() + "");
}
}
@Override
public void sendRefuseMessage(String nationCode, String mobile, Locale locale, RefuseMessage refuse) {
sendMessage(nationCode, mobile, REFUSE_CLIENT_TEMPLID, refuse.getReason());
}
}

@ -0,0 +1,27 @@
package au.com.royalpay.payment.manage.support.sms.daas;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import java.util.Locale;
public class AuthCodeMessageTemplate implements DaasMessageTemplate {
private static final String CN_TPL = "您正在申请%s验证码为%s%s分钟内有效请勿向任何人提供此验证码";
private static final String EN_TPL = "Your %s secret code is %svalid for %s minutes). Do not provide this to anyone.";
private final Locale locale;
private final AuthCodeMessage register;
public AuthCodeMessageTemplate(Locale locale, AuthCodeMessage register) {
this.locale = locale;
this.register = register;
}
@Override
public String getMessage() {
String tpl = EN_TPL;
if (locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE)) {
tpl = CN_TPL;
}
return String.format(tpl, register.getBiz(), register.getCode(), register.getExpireMin());
}
}

@ -0,0 +1,9 @@
package au.com.royalpay.payment.manage.support.sms.daas;
import org.springframework.util.MultiValueMap;
public interface DaasMessageTemplate {
String getMessage();
}

@ -0,0 +1,19 @@
package au.com.royalpay.payment.manage.support.sms.daas;
import au.com.royalpay.payment.manage.support.sms.msg.OpenMessage;
public class OpenMessageTemplate implements DaasMessageTemplate {
private static final String TEMPLATE = "尊敬的商户,恭喜您注册成功,请使用您的(%s账户登录网址(https://mpay.royalpay.com.au/)或者使用RoyalPay手机App。您可以使用RoyalPay所有的功能包括接受客户的付款在您激活账号之前RoyalPay将不执行清算操作。因此请您尽快提交合规材料若有任何疑问请联系我们客服。";
private final OpenMessage openMessage;
public OpenMessageTemplate(OpenMessage openMessage) {
this.openMessage = openMessage;
}
@Override
public String getMessage() {
return String.format(TEMPLATE, openMessage.getMaskedPhoneNumber());
}
}

@ -0,0 +1,17 @@
package au.com.royalpay.payment.manage.support.sms.daas;
import au.com.royalpay.payment.manage.support.sms.msg.RefuseMessage;
public class RefuseMessageTemplate implements DaasMessageTemplate{
private static final String TPL = "尊敬的RoyalPay商户您提交的商户资料审核不通过原因%s,请登录系统后台修改后,重新提交审核。[RoyalPay合规部]";
private final RefuseMessage refuseMessage;
public RefuseMessageTemplate(RefuseMessage refuseMessage) {
this.refuseMessage = refuseMessage;
}
@Override
public String getMessage() {
return String.format(TPL,refuseMessage.getReason());
}
}

@ -0,0 +1,25 @@
package au.com.royalpay.payment.manage.support.sms.msg;
public class AuthCodeMessage {
private final String biz;
private final String code;
private final int expireMin;
public AuthCodeMessage(String biz, String code, int expireMin) {
this.biz = biz;
this.code = code;
this.expireMin = expireMin;
}
public String getBiz() {
return biz;
}
public String getCode() {
return code;
}
public int getExpireMin() {
return expireMin;
}
}

@ -0,0 +1,14 @@
package au.com.royalpay.payment.manage.support.sms.msg;
public class OpenMessage {
private final String phoneNumber;
public OpenMessage(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getMaskedPhoneNumber(){
return new StringBuilder(phoneNumber).replace(3,7,"****").toString();
}
}

@ -0,0 +1,13 @@
package au.com.royalpay.payment.manage.support.sms.msg;
public class RefuseMessage {
private final String reason;
public RefuseMessage(String reason) {
this.reason = reason;
}
public String getReason() {
return reason;
}
}

@ -0,0 +1,4 @@
package au.com.royalpay.payment.manage.support.sms.qcloud;
public interface QCloudMessageTemplate {
}

@ -120,8 +120,14 @@ qcloud:
secret-key: YswoQDsIZfWEqEAEvMXS8Yic84lFn9Jp secret-key: YswoQDsIZfWEqEAEvMXS8Yic84lFn9Jp
royalpay: royalpay:
sms: sms:
qcloud:
appid: 1400094878 appid: 1400094878
appkey: 43390d81e20c5191c278fbf4cd275be2 appkey: 43390d81e20c5191c278fbf4cd275be2
enable: false
daas:
secret-id: AKIDKR8WAXdaRcfbZysCU41K6ViGMwL2XG49zdDE
secret-key: 15ug40UL3X74v7705tKqb2u0bmqyOr873Yyyn41C
enable: true
settle: settle:
abafile: abafile:
bank: bank:

Loading…
Cancel
Save