123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace loyalsoft;
- /**
- * Description of ResponseVo
- * 服务端消息应答实体
- * @author jgao,gwang
- */
- class Resp extends Object_ext {
- /**
- * openId
- * @var String
- */
- public $uid;
- public $cmd;
- /**
- * 消息序列
- * @var int
- */
- public $msgid;
- /**
- * 错误码[成功为0]
- * @var int
- */
- public $err;
- /**
- * 执行结果
- * @var Object
- */
- public $result;
- /**
- * 时间戳
- * @var int
- */
- public $ts;
- /**
- * 标签[扩展用,保留]
- * @var object
- */
- public $tag;
- /**
- * 产生服务端应答
- * @param Req $req
- * @param assoc Array $ret
- * @return \ResponseVo
- */
- public static function ok($ret = null) {
- $resp = new Resp();
- $req = req();
- $resp->uid = $req->uid;
- $resp->cmd = $req->cmd;
- $resp->msgid = $req->msgid;
- $resp->err = ErrCode::ok;
- $resp->result = $ret;
- $resp->ts = time();
- $resp->tag = ObjectInit();
- return $resp;
- }
- /**
- *
- * @param Req $req
- * @param int $err
- * @param string $msg 【可选】附加信息
- * @return \ResponseVo
- */
- public static function err($err, $msg = "") {
- $resp = new Resp();
- $req = req();
- $resp->uid = $req->uid;
- $resp->cmd = $req->cmd;
- $resp->msgid = $req->msgid;
- $resp->err = $err;
- $resp->result = ObjectInit();
- $resp->ts = time();
- $resp->tag = ObjectInit();
- $resp->tag->errmsg = $msg;
- return $resp;
- }
- static $ext_tag = null;
- /**
- * 向返回值添加附加数据
- * @param string $name
- * @param any $value
- */
- public static function addTag($name, $value) {
- if (null == self::$ext_tag) {
- self::$ext_tag = ObjectInit();
- }
- self::$ext_tag->$name = $value;
- }
- }
|