NutzCN Logo
问答 静态方法 如何获取服务类的配置
发布于 1610天前 作者 JsckChin 1064 次浏览 复制 上一个帖子 下一个帖子
标签:

例如 静态方法 发送短信,accessKeyId,accessKeySecret 这几个变量可以在后台动态设置。没有思路

    /**
     * 通过模板发送短信
     * @param mobile    接受的手机号
     * @param tplId     模板ID
     * @param tplValue  模板变量值
     * @return          提交响应
     * @throws Exception
     */
    public static boolean tplSendSms(String mobile,String tplId, String tplValue) {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain(ALIYUN_SMS_DOMAIN);
        request.setVersion(ALIYUN_SMS_VERSION);
        request.setAction(ALIYUN_SMS_ACTION);

        /**
         *  SignName 短信签名
         *  PhoneNumbers  手机号
         *  TemplateCode  短信模板ID
         *  TemplateParam 短信模板变量替换JSON串
         */
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("PhoneNumbers", mobile);
        request.putQueryParameter("TemplateCode", tplId);
        request.putQueryParameter("TemplateParam", tplValue);
        try {
            // 发送短信
            CommonResponse response = client.getCommonResponse(request);
            String result  =response.getData();
            NutMap res = new NutMap(result);
            // 发送后记录短信日志
            String Code = res.getString("Code");
            if(SUCCESS_CODE.equals(Code)){
                return true;
            }else{
                return false;
            }
        } catch (ServerException e) {  // 服务端异常
            e.printStackTrace();
            return false;
        } catch (ClientException e) {  // 客户端异常
            e.printStackTrace();
            return false;
        }
    }
1 回复

把ioc的文档看一遍

添加回复
请先登陆
回到顶部