'/v3/pay/transactions/h5', 'app' => '/v3/pay/transactions/app', 'jsapi' => '/v3/pay/transactions/jsapi', 'native' => '/v3/pay/transactions/native', ]; if (empty($types[$type])) { throw new InvalidArgumentException("Payment {$type} not defined."); } else { // 创建预支付码 $result = $this->doRequest('POST', $types[$type], json_encode($data, JSON_UNESCAPED_UNICODE), true); if (empty($result['prepay_id'])) return $result; // 支付参数签名 $time = (string)time(); $appid = $this->config['appid']; $prepayId = $result['prepay_id']; $nonceStr = Tools::createNoncestr(); if ($type === 'app') { $sign = $this->signBuild(join("\n", [$appid, $time, $nonceStr, $prepayId])); return ['partnerId' => $this->config['mch_id'], 'prepayId' => $prepayId, 'package' => 'Sign=WXPay', 'nonceStr' => $nonceStr, 'timeStamp' => $time, 'sign' => $sign]; } elseif ($type === 'jsapi') { $sign = $this->signBuild(join("\n", [$appid, $time, $nonceStr, "prepay_id={$prepayId}"])); return ['appId' => $appid, 'timeStamp' => $time, 'nonceStr' => $nonceStr, 'package' => "prepay_id={$prepayId}", 'signType' => 'RSA', 'paySign' => $sign]; } else { return $result; } } } /** * 支付订单查询 * @param string $orderNo 订单单号 * @return array * @throws InvalidResponseException */ public function query($orderNo) { $pathinfo = "/v3/pay/transactions/out-trade-no/{$orderNo}"; return $this->doRequest('GET', "{$pathinfo}?mchid={$this->config['mch_id']}", '', true); } }