xiaoyong931011
2022-09-23 f9a7691e2175281dd972ae2ad2beb73bc3fd0650
20220902
3 files modified
125 ■■■■■ changed files
pom.xml 5 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/common/utils/ZzSmsSend.java 84 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/controller/CommonController.java 36 ●●●●● patch | view | raw | blame | history
pom.xml
@@ -29,6 +29,11 @@
    <dependencies>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>dysmsapi20170525</artifactId>
            <version>2.0.18</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
            <version>${aliyun-oss.version}</version>
src/main/java/cc/mrbird/febs/common/utils/ZzSmsSend.java
@@ -6,7 +6,11 @@
import cn.hutool.core.util.XmlUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import com.aliyun.tea.*;
import java.util.Date;
import java.util.HashMap;
@@ -18,6 +22,60 @@
 **/
@Slf4j
public class ZzSmsSend {
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
    private static final String SIGNNAME = "汇达农业";
    private static final String TEMPLATECODE = "SMS_251041117";
    public static boolean sendALiYun(String phone,String TemplateParam){
        com.aliyun.dysmsapi20170525.Client client = null;
        try {
            client = createClient("LTAI4GBuydqbJ5bTsDP97Lpd", "vbCjQtPxABWjqtUlQfzjlA0qAY96fh");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
//                .setSignName("阿里云短信测试")
                .setSignName(SIGNNAME)
//                .setTemplateCode("SMS_154950909")
                .setTemplateCode(TEMPLATECODE)
//                .setPhoneNumbers("15274802129")
                .setPhoneNumbers(phone)
//                .setTemplateParam("{\"code\":\"1234\"}");
                .setTemplateParam("{\"code\":\""+TemplateParam+"\"}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
            log.info("短信发送:{}", sendSmsResponse);
            JSONObject jsonObject = JSONUtil.parseObj(sendSmsResponse);
            System.out.print(jsonObject);
            if(200 == sendSmsResponse.getStatusCode()) {
                return true;
            }else{
                return false;
            }
        } catch (TeaException error) {
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
        return false;
    }
    private static final String URL = "http://zzsms365.com/v2sms.aspx?action=send";
@@ -52,17 +110,19 @@
    }
    public static void main(String[] args) {
        Map<String, Object> data = new HashMap<>();
        Long time = System.currentTimeMillis();
        data.put("userid", USER_ID);
        data.put("timestamp", time);
        data.put("mobile", "15773002834");
        String signStr = ACCOUNT + PWD + time;
        String sign = SecureUtil.md5(signStr);
        data.put("sign", sign);
        data.put("content", "【HiBit】尊敬的用户,恭喜您于2010-03-25有一笔充值已成功到账,充值数量为10。");
        String post = HttpUtil.post(URL, data);
        System.out.println(post);
//        Map<String, Object> data = new HashMap<>();
//        Long time = System.currentTimeMillis();
//        data.put("userid", USER_ID);
//        data.put("timestamp", time);
//        data.put("mobile", "15773002834");
//        String signStr = ACCOUNT + PWD + time;
//        String sign = SecureUtil.md5(signStr);
//        data.put("sign", sign);
//        data.put("content", "【HiBit】尊敬的用户,恭喜您于2010-03-25有一笔充值已成功到账,充值数量为10。");
//
//        String post = HttpUtil.post(URL, data);
//        System.out.println(post);
        boolean b = sendALiYun( "15274802129", "123456");
        System.out.println(b);
    }
}
src/main/java/cc/mrbird/febs/mall/controller/CommonController.java
@@ -76,6 +76,42 @@
        return new FebsResponse().fail().message("验证码发送失败");
    }
    @ApiOperation(value = "获取阿里云验证码接口", notes = "获取阿里云验证码接口")
    @GetMapping(value = "/aliVerifyCode")
    public FebsResponse aliVerifyCode(@ApiParam(name = "account", value = "手机号", required = true) @RequestParam(value = "account") String account,
                                   @ApiParam(name = "type", value = "类型1-手机号", required = true) @RequestParam("type") String type) {
        log.info("#账号:{}, 类型:{}#", account, type);
        Integer code = (int) ((Math.random() * 9 + 1) * 100000);
        if (StrUtil.isNotBlank(redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + account))) {
            throw new FebsException("验证码已发送");
        }
        // 发送手机验证码
        if (AppContants.ACCOUNT_TYPE_MOBILE.equals(type)) {
            boolean result = ZzSmsSend.sendALiYun(account, code.toString());
            if (result) {
                Map<String, Object> map = new HashMap<>();
                boolean flag = redisUtils.set(AppContants.VERIFY_CODE_PREFIX + account, code, 120);
                map.put("code", flag);
                return new FebsResponse().success().message("验证码发送成功");
            }
            // 发送邮件验证码
        } else if (AppContants.ACCOUNT_TYPE_EMAIL.equals(type)) {
            boolean flag = SubMailSend.sendMail(account, code.toString());
            if (flag) {
                redisUtils.set(AppContants.VERIFY_CODE_PREFIX + account, code, 120);
                return new FebsResponse().success().message("验证码发送成功");
            } else {
                return new FebsResponse().fail().message("验证码发送失败");
            }
        } else {
            log.info("未定义账号类型");
            throw new FebsException("未定义账号类型");
        }
        return new FebsResponse().fail().message("验证码发送失败");
    }
    /**
     *  图片上传
     * @return