|
|
@@ -0,0 +1,56 @@
|
|
|
+package com.seecoder.thirdParty;
|
|
|
+
|
|
|
+import com.aliyuncs.CommonRequest;
|
|
|
+import com.aliyuncs.CommonResponse;
|
|
|
+import com.aliyuncs.DefaultAcsClient;
|
|
|
+import com.aliyuncs.IAcsClient;
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
+import com.aliyuncs.http.MethodType;
|
|
|
+import com.aliyuncs.profile.DefaultProfile;
|
|
|
+import com.seecoder.config.property.AliProperties;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AliService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(AliService.class);
|
|
|
+
|
|
|
+ private final AliProperties.Profile aliProfile;
|
|
|
+ private final IAcsClient client;
|
|
|
+
|
|
|
+ public AliService(AliProperties aliProperties) {
|
|
|
+ this.aliProfile = aliProperties.getProfile();
|
|
|
+ DefaultProfile profile = DefaultProfile.getProfile(
|
|
|
+ aliProfile.getRegionId(),
|
|
|
+ aliProfile.getAccessKeyId(),
|
|
|
+ aliProfile.getAccessKeySecret());
|
|
|
+ client = new DefaultAcsClient(profile);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void sendMessage(String phone, String text) {
|
|
|
+ sendSms(phone, text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendSms(String phone, String code) {
|
|
|
+ CommonRequest request = new CommonRequest();
|
|
|
+ request.setSysMethod(MethodType.POST);
|
|
|
+ request.setSysDomain(aliProfile.getSysDomain());
|
|
|
+ request.setSysVersion(aliProfile.getSysVersion());
|
|
|
+ request.setSysAction("SendSms");
|
|
|
+ request.putQueryParameter("RegionId", aliProfile.getRegionId());
|
|
|
+ request.putQueryParameter("PhoneNumbers", phone);
|
|
|
+ request.putQueryParameter("SignName", aliProfile.getSignName());
|
|
|
+ request.putQueryParameter("TemplateCode", aliProfile.getTemplateCode());
|
|
|
+ request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
|
|
|
+ try {
|
|
|
+ CommonResponse response = client.getCommonResponse(request);
|
|
|
+ log.info(response.getData());
|
|
|
+ } catch (ClientException e) {
|
|
|
+ log.error("Send sms error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|