ToUserName = $data['ToUserName']; $this->FromUserName = $data['FromUserName']; $this->CreateTime = $data['CreateTime']; $this->MsgType = $data['MsgType']; $this->Event = $data['Event']; $this->OpenId = $data['OpenId']; $this->OutTradeNo = $data['OutTradeNo']; $this->WeChatPayInfo = new WeChatPayInfo($data['WeChatPayInfo']); $this->Env = $data['Env']; $this->GoodsInfo = new GoodsInfo($data['GoodsInfo']); $this->RetryTimes = $data['RetryTimes']; } /** * 从 JSON 字符串创建对象 */ public static function fromJson(string $json): self { $data = json_decode($json, true); return new self($data); } }