Unverified Commit 2b69527d authored by changyang liu's avatar changyang liu Committed by GitHub
Browse files

阿里云发送短信优化,在返回错误后记录日志以及返回发送失败状态 (#429)


Co-authored-by: default avataryang <477915244yang@gmail.com>
parent 83711ec2
...@@ -8,6 +8,7 @@ import com.aliyuncs.exceptions.ClientException; ...@@ -8,6 +8,7 @@ import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType; import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.DefaultProfile;
import com.qcloud.cos.utils.Jackson;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.JacksonUtil; import org.linlinjava.litemall.core.util.JacksonUtil;
...@@ -26,6 +27,8 @@ public class AliyunSmsSender implements SmsSender { ...@@ -26,6 +27,8 @@ public class AliyunSmsSender implements SmsSender {
private String accessKeySecret; private String accessKeySecret;
private String sign; private String sign;
private final String okCode = "OK";
public String getRegionId() { public String getRegionId() {
return regionId; return regionId;
} }
...@@ -106,8 +109,15 @@ public class AliyunSmsSender implements SmsSender { ...@@ -106,8 +109,15 @@ public class AliyunSmsSender implements SmsSender {
try { try {
CommonResponse response = client.getCommonResponse(request); CommonResponse response = client.getCommonResponse(request);
SmsResult smsResult = new SmsResult(); SmsResult smsResult = new SmsResult();
smsResult.setSuccessful(true);
smsResult.setResult(response); smsResult.setResult(response);
String code = Jackson.jsonNodeOf(response.getData()).get("Code").asText();
if (response.getHttpResponse().isSuccess() && okCode.equals(code) ){
smsResult.setSuccessful(true);
}else {
smsResult.setSuccessful(false);
logger.error("短信发送失败:"+response.getData());
}
return smsResult; return smsResult;
} catch (ServerException e) { } catch (ServerException e) {
e.printStackTrace(); e.printStackTrace();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment