decode(); } /** * @var NotifyModel */ public NotifyModel $notifyModel; /** * @return void * @throws Exception */ public function decode(): void { $data = $this->decryptToString($this->resource); if ($data === false) { throw new Exception('消息体格式错误, 解码失败.'); } $data = json_decode($data, true); $this->notifyModel = new NotifyModel(); $this->notifyModel->amount = $data['amount']; $this->notifyModel->payer = $data['payer']; $this->notifyModel->scene_info = $data['payer']; $this->notifyModel->appid = $data['appid']; $this->notifyModel->mchid = $data['mchid']; $this->notifyModel->out_trade_no = $data['out_trade_no']; $this->notifyModel->transaction_id = $data['transaction_id']; $this->notifyModel->trade_type = $data['trade_type']; $this->notifyModel->trade_state = $data['trade_state']; $this->notifyModel->trade_state_desc = $data['trade_state_desc']; $this->notifyModel->bank_type = $data['bank_type']; $this->notifyModel->attach = $data['attach']; $this->notifyModel->success_time = $data['success_time']; $this->notifyModel->promotion_detail = []; foreach ($data['promotion_detail'] as $datum) { $detail = new PromotionDetail(); $detail->amount = $datum['amount']; $detail->wechatpay_contribute = $datum['wechatpay_contribute']; $detail->coupon_id = $datum['coupon_id']; $detail->scope = $datum['scope']; $detail->merchant_contribute = $datum['merchant_contribute']; $detail->name = $datum['name']; $detail->other_contribute = $datum['other_contribute']; $detail->currency = $datum['currency']; $detail->stock_id = $datum['stock_id']; $detail->goods_detail = []; foreach ($datum['goods_detail'] as $value) { $detail->goods_detail[] = new GoodsDetail($value); } $this->notifyModel->promotion_detail[] = $detail; } } }