500, 'message' => '充值金额不能小于0.']); } $this->money = $money; $this->orderNo = $orderNo; $this->data['openid'] = $openId; return http::post($this->createPayUrl(), $this->builder(), function ($result, $body) use ($_this) { $data = $_this->toArray($result); if(isset($data['sign'])){ $sign = $data['sign']; unset($data['sign']); $_sign = $_this->sign($data); } $return = []; if (!isset($sign) || $sign != $_sign) { $return['code'] = -1; $return['message'] = $data['return_msg'] ?? '返回数据签名验证失败'; } else { if ($data['return_code'] == 'FAIL') { $return['code'] = -1; $return['message'] = $data['return_msg']; } else { $return['code'] = 0; $return['data'] = $data; $return['data']['postBody'] = $body; } } return $return; }, ['Content-Type' => 'text/xml'] ); } /** * @return string */ protected function builder() { $data = [ 'appid' => $this->app_id, 'mch_id' => $this->mch_id, 'nonce_str' => $this->random(32), 'body' => $this->body, 'out_trade_no' => $this->orderNo, 'total_fee' => $this->money, 'sign_type' => $this->sign_type, 'spbill_create_ip' => $_SERVER['REMOTE_ADDR'], 'notify_url' => $this->notify_url, 'trade_type' => $this->trade_type, ]; $data = array_merge($data, $this->data); $data['sign'] = $this->sign($data); return $this->toXml($data); } private function createPayUrl() { return $this->mch_host . '/pay/unifiedorder'; } }