1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import json
- from alipay.aop.api.constant.ParamConstants import *
- from alipay.aop.api.domain.MessageContext import MessageContext
- class MessageTemplate(object):
- def __init__(self):
- self._context = None
- self._template_id = None
- @property
- def context(self):
- return self._context
- @context.setter
- def context(self, value):
- if isinstance(value, MessageContext):
- self._context = value
- else:
- self._context = MessageContext.from_alipay_dict(value)
- @property
- def template_id(self):
- return self._template_id
- @template_id.setter
- def template_id(self, value):
- self._template_id = value
- def to_alipay_dict(self):
- params = dict()
- if self.context:
- if hasattr(self.context, 'to_alipay_dict'):
- params['context'] = self.context.to_alipay_dict()
- else:
- params['context'] = self.context
- if self.template_id:
- if hasattr(self.template_id, 'to_alipay_dict'):
- params['template_id'] = self.template_id.to_alipay_dict()
- else:
- params['template_id'] = self.template_id
- return params
- @staticmethod
- def from_alipay_dict(d):
- if not d:
- return None
- o = MessageTemplate()
- if 'context' in d:
- o.context = d['context']
- if 'template_id' in d:
- o.template_id = d['template_id']
- return o
|