【仅供内部供应商使用,不提供对外解答和培训】

Page tree

【仅供内部供应商使用,不提供对外解答和培训】

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »

前言

当开发者开发的插件想要用户付费购买的时候,需要在插件中加入付费API,以便在试用期到期后会提供用户购买插件。

关键类

在接入点接口的实现类中,加上付费说明的注解(Annotation),注解的内容如下:

付费注解
package com.fr.stable.fun;

import com.fr.stable.StringUtils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Authorize {

    /**
     * 开发者根据插件id申请得到的验证码
     *
     * @return 验证码
     */
    String callSignKey() default StringUtils.EMPTY;

    /**
     * 验证码可以写在代码中,也可以写在文件中
     *
     * @return 存验证码的文件的路径
     */
    String callSignKeyPath() default StringUtils.EMPTY;
}

示例实现

我们以主题插件开发为示例:注解Authorize用来描述这是一个付费的插件,而代码

PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(Constants.PLUGIN_ID);
if (pluginLicense.isAvailable()) {
    // 做认证通过的事情
} else {
    // 做认证未通过的事情
} 

则用于处理认证通过和未通过时的不同逻辑。

主题示例实现
@Authorize(callSignKey = Constants.PLUING_ID)
public class ThemeGreen extends AbstractThemeVariousProvider {

    @Override
    public String name() {
        return "AcrossGreen";
    }

    @Override
    public String text() {
        return "横向目录";
    }

    @Override
    public String coverPath() {
        return "/com/fr/solution/theme/green/files/cover.png";
    }

    @Override
    public String scriptPath() {
        PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(MongoConstants.PLUGIN_ID);
        if (pluginLicense.isAvailable()) {
            return "/com/fr/solution/theme/green/files/theme.js";
        } else {
            return "";
        }
    }

    @Override
    public String stylePath() {
        PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(MongoConstants.PLUGIN_ID);
        if (pluginLicense.isAvailable()) {
            return "/com/fr/solution/theme/green/files/style.css";
        } else {
            return "";
        }
    }
}

上述示例中,callSignKey的值就是插件的ID,是需要和plugin.xml中的id字段一致的,如果插件试用期已过,那么就会返回空的路径,导致这个插件的并不会起作用了,当然,也可以使用其他更多的方式进行购买提醒。

注意事项

  1. 注解和授权控制代码并非要在一个类上;
  2. 一般是来说,同时含有设计器接口和非设计器接口的插件,Authorize注解只应该加在除extra-designer标签以外的接入点实现类上。

 

效果自测

报表注册插件lic试用期内设计器*1设计器中的服务器环境*2服务器环境*3
未注册无/有无限试用期正常正常正常
注册正常正常正常
注册过期过期过期
注册正常过期正常

*1:设计器是指包含有为设计器部分做的插件,比如设计器的菜单,对话框等;

*2:指的是包含有为服务器部分做的插件,在设计器中包含有的jetty服务器环境的运行情况;

*3:指的是包含有为服务器部分做的插件,在tomcat等其他独立java web容器中的运行情况;

 

  • No labels