/** * response message entity */ public function setResponse(Entity $entity) { $body = $entity->getBody(); $body['ToUserName'] = $this['FromUserName']; $body['FromUserName'] = $this['ToUserName']; $body['MsgType'] = $entity->getType(); $body['CreateTime'] = time(); $response = new XmlResponse($body); $response->send(); }
/** * 构造方法 */ public function __construct(array $options = array()) { $required = array('ToUserName', 'FromUserName', 'CreateTime', 'Music'); $validator = new OptionValidator(); $validator->setDefined($required)->setRequired($required)->setAllowedTypes('Music', array('array')); $validtated = $validator->validate($options); parent::__construct($validtated); }
/** * 构造方法 */ public function __construct(array $options = array()) { $required = array('ToUserName', 'FromUserName', 'CreateTime', 'Video'); $validator = new OptionValidator(); $validator->setDefined($required)->setRequired($required)->setAllowedTypes('Video', array('array'))->setAllowedValues('Video', function ($value) { if (!array_key_exists('MediaId', $value)) { throw new \InvalidArgumentException('Undefined index: MediaId'); } return true; }); $validtated = $validator->validate($options); parent::__construct($validtated); }
/** * 构造方法 */ public function __construct(array $options = array()) { $required = array('ToUserName', 'FromUserName', 'CreateTime', 'ArticleCount', 'Articles'); $validator = new OptionValidator(); $validator->setDefined($required)->setRequired($required)->setAllowedTypes('Articles', array('array'))->setAllowedValues('Articles', function ($value) { if (!array_key_exists('item', $value)) { throw new \InvalidArgumentException('Undefined index: item'); } if (!is_array($value['item'])) { throw new \InvalidArgumentException('Articles item must be array'); } if (count($value['item']) > 10) { throw new \InvalidArgumentException('Articles item must be Less than 10'); } return true; })->setDefault('ArticleCount', function (Options $options) { return count($options['Articles']['item']); }); $validtated = $validator->validate($options); parent::__construct($validtated); }