You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 5
Next »
前言
当开发者开发的插件想要用户付费购买的时候,需要在插件中加入付费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字段一致的,如果插件试用期已过,那么就会返回空的路径,导致这个插件的并不会起作用了,当然,也可以使用其他更多的方式进行购买提醒。
注意事项
Authorize注解只应该加在除extra-designer标签以外的接入点实现类上。