wang-hao-jie
2022-01-07 0f2202dfcea3309c1b0e7515f6db5fbdc83d51d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//package cn.exrick.xboot.core.common.sms;
//
//import cn.exrick.xboot.core.common.constant.SettingConstant;
//import cn.exrick.xboot.core.common.exception.XbootException;
//import cn.exrick.xboot.core.entity.Setting;
//import cn.exrick.xboot.core.service.SettingService;
//import cn.exrick.xboot.core.vo.SmsSetting;
//import cn.hutool.core.util.StrUtil;
//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.google.gson.Gson;
//import com.google.gson.JsonObject;
//import com.google.gson.JsonParser;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
///**
// * @author exrick
// */
//@Slf4j
//@Component
//public class AliSms implements Sms {
//
//    @Autowired
//    private SettingService settingService;
//
//    @Override
//    public SmsSetting getSmsSetting() {
//
//        Setting setting = settingService.get(SettingConstant.ALI_SMS);
//        if (setting == null || StrUtil.isBlank(setting.getValue())) {
//            throw new XbootException("您还未配置阿里云短信服务");
//        }
//        return new Gson().fromJson(setting.getValue(), SmsSetting.class);
//    }
//
//    @Override
//    public void sendSms(String mobile, String params, String templateCode) {
//
//        SmsSetting s = getSmsSetting();
//
//        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", s.getAccessKey(), s.getSecretKey());
//        IAcsClient client = new DefaultAcsClient(profile);
//
//        CommonRequest request = new CommonRequest();
//        request.setSysMethod(MethodType.POST);
//        request.setSysDomain("dysmsapi.aliyuncs.com");
//        request.setSysVersion("2017-05-25");
//        request.setSysAction("SendSms");
//        request.putQueryParameter("RegionId", "cn-hangzhou");
//        // 支持对多个手机号码发送短信,手机号码之间以英文逗号(,)分隔,上限为1000个手机号码
//        request.putQueryParameter("PhoneNumbers", mobile);
//        request.putQueryParameter("SignName", s.getSignName());
//        request.putQueryParameter("TemplateCode", templateCode);
//        request.putQueryParameter("TemplateParam", params);
//
//        CommonResponse response;
//        try {
//            response = client.getCommonResponse(request);
//        } catch (ClientException e) {
//            log.error(e.getMessage());
//            throw new XbootException("请求发送短信验证码失败," + e.getErrMsg());
//        }
//        JsonObject result = JsonParser.parseString(response.getData()).getAsJsonObject();
//        String code = result.get("Code").getAsString();
//        String message = result.get("Message").getAsString();
//        if (!"OK".equals(code) && !"OK".equals(message)) {
//            throw new XbootException("请求发送验证码失败," + message);
//        }
//    }
//}