本次尝试使用spring注入实例到静态类中,spring并不建议使用静态类,在语法上做了限制。虽然本次尝试可以成功注入,但并未真正使用。使用注解方法配制,以下是代码实现:
@Service
public class PushUtil {
@Autowired
private XingeApp xinge;
private static PushUtil pushService;
public void setUserInfo(XingeApp xinge)
{
this.xinge = xinge;
}
@PostConstruct
public void init()
{
pushService = this;
pushService.xinge = this.xinge;
}
// 单个设备下发透传消息
public static JSONObject pushSingleDeviceMessage(String token, Message message) {
return pushService.xinge.pushSingleDevice(token, message);
}
// 单个设备下发通知消息
public static JSONObject demoPushSingleDeviceNotification(String token, Message message) {
JSONObject ret = pushService.xinge.pushSingleDevice(token, message);
return (ret);
}
// 单个设备下发通知消息
public static JSONObject demoPushSingleDeviceIOS(String token, MessageIOS message) {
return pushService.xinge.pushSingleDevice(token, message, XingeApp.IOSENV_DEV);
}
// 单个设备下发通知Intent
// setIntent()的内容需要使用intent.toUri(Intent.URI_INTENT_SCHEME)方法来得到序列化后的Intent(自定义参数也包含在Intent内)
// 终端收到后可通过intent.parseUri()来反序列化得到Intent
public static JSONObject demoPushSingleDeviceNotificationIntent(String token, Message message) {
JSONObject ret = pushService.xinge.pushSingleDevice(token, message);
return (ret);
}
// 下发单个账号
public static JSONObject demoPushSingleAccount(int deviceType, String account, Message message) {
JSONObject ret = pushService.xinge.pushSingleAccount(deviceType, account, message);
return (ret);
}
// 下发多个账号
public static JSONObject demoPushAccountList(List<String> accountList, Message message) {
return pushService.xinge.pushAccountList(0, accountList, message);
}
}