统一下单返回前端jssdk调起支付需要的数据
适用于后台调起支付获取数据
@param InterfacePay $interface
@param null $redirect_uri
@return array|bool
@throws \Exception
331575
public function get_jssdk_parameters_current_wx_user(InterfacePay $interface,$redirect_uri = null){
        if (!$interface || !$redirect_uri) throw new \Exception('WeixinPayApi params exception');
        $config = $this->config;
        if (!isset($_GET['code'])) {
            /*获取订单号*/
            $out_trade_no=$_GET['out_trade_no'];
            if (!$out_trade_no) throw new \Exception('WeixinPayApi out_trade_no exception');
            /*校验订单是否能够支付*/
            $can_pay = $interface->check_can_pay();
            if (!$can_pay) {
                if ($this->business_interface) $this -> business_interface -> log("out_trade_no:$out_trade_no can not pay");
                return $can_pay;
            }

            $this->get_code($redirect_uri,$out_trade_no,'snsapi_base',self::PROCESS_REDIRECT);
        }else{
            /*如果有code参数；则表示获取到openid*/
            $code = $_GET['code'];

            /*校验订单是否能够支付*/
            $can_pay = $interface->check_can_pay();
            if (!$can_pay) {
                if ($this->business_interface) $this -> business_interface -> log("received wx_code out_trade_no:{$interface->get_out_trade_no()} can not pay");
                return $can_pay;
            }

            /*组合获取prepay_id的url*/
            $result = self::curl_auth_access_token($code);

            $openid = $result['openid'];

            /*封装统一下单数据*/
            $order = $interface -> create_unified_order_data($openid);

            /*统一下单 获取prepay_id*/
            $unified_order=$this->unified_order($order);

            /*组合jssdk需要用到的数据*/
            $time=time();
            $data = [
                'appId'=>$config['app_id'], /*appid*/
                'timeStamp'=>strval($time), /*时间戳*/
                'nonceStr'=>$unified_order['nonce_str'], /*随机字符串*/
                'package'=>'prepay_id='.$unified_order['prepay_id'],/* 预支付交易会话标识*/
                'signType'=>'MD5'//加密方式
            ];

            /*生成签名*/
            $data['paySign']=$this->make_sign($data);
            return $data;
        }
    }
136248
public function setRedirectUri($redirect_uri)
    {
        // $redirect_uri = trim(urldecode($redirect_uri));
        $redirect_uri = trim($redirect_uri);
        if (filter_var($redirect_uri, FILTER_VALIDATE_URL) === false) {
            throw new Exception('$redirect_uri无效');
        }
        $this->_redirect_uri = urlencode($redirect_uri);
    }
678595
protected function rewriteUriBySimpleMap( $requestUri, array $simpleMap )
	{
		$redirect = $this->buildRedirect( $requestUri, null );

		foreach ( $simpleMap as $pattern => $redirectData )
		{
			if ( $this->uriMatchesPattern( $requestUri, $pattern ) )
			{
				$this->guardRedirectUrlIsSetInMap( $redirectData );

				$redirectUrl  = preg_replace( $pattern, $redirectData[0], $requestUri );
				$redirectCode = isset($redirectData[1]) ? $redirectData[1] : null;

				$redirect = $this->buildRedirect( $redirectUrl, $redirectCode );
				break;
			}
		}

		return $redirect;
	}
503808
public function process(ServerRequestInterface $request, RequestHandlerInterface $next, ContainerInterface $container): ResponseInterface
    {
        $uri = $request->getUri();
        $scheme = $uri->getScheme();
        if ($scheme === 'https') {
            if ($request->getMethod() !== 'GET') {
                throw new SplashException('Only GET HTTP methods can be redirected to HTTP');
            }
            $uri = $uri->withScheme('http')->withPort($this->port);

            return new RedirectResponse($uri);
        }

        return $next->handle($request);
    }
939550
private function compareUris($redirect_uri, $clientRedirectUri)
    {
        if (!$redirect_uri || !$clientRedirectUri) {
            return false;
        }

        $wanted = array_fill_keys(['scheme', 'host', 'port', 'path'], true);

        // gets only scheme, host, port, path from uri
        $redirect_uri = array_intersect_key(parse_url($redirect_uri), $wanted);
        $clientRedirectUri = array_intersect_key(parse_url($clientRedirectUri), $wanted);

        return strcmp(implode($redirect_uri), implode($clientRedirectUri)) === 0;
    }
1342051
public function mpsRedirect($data = [], $resultIsUrl = FALSE)
    {
        try {
            $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($data));
            $movitelMps = new MovitelMps\MovitelMps($this->options);
            $movitelMps->setMovitelPublicKey($this->movitelPublicKey);
            $movitelMps->setMovitelPrivateKey($this->movitelPrivateKey);
            $movitelMps->setCpPublicKey($this->cpPublicKey);
            $movitelMps->setCpPrivateKey($this->cpPrivateKey);
            $dataToRequest = "SUB=" . $data['sub'] . "&REQ=" . $data['req'] . "&SOURCE=" . $data['source'] . "&SESS=" . $data['session_id'];
            $dataLink      = "PRO=" . $data['provider'] . "&CMD=" . $data['cmd_msisdn'] . "&SER=" . $data['service'] . "&SUB=" . $data['sub'] . "&DATA=";
            $this->debug->info(__FUNCTION__, '$dataToRequest: ' . json_encode($dataToRequest));
            $this->debug->info(__FUNCTION__, '$dataLink: ' . json_encode($dataLink));
            $dataRequest = $movitelMps->createDataRequestToMps($data, $dataToRequest);
            $this->debug->info(__FUNCTION__, '$dataRequest: ' . json_encode($dataRequest));
            if ($dataRequest !== NULL && is_array($dataRequest)) {
                $dataEncrypted = $dataRequest[0];
                $dataSignature = $dataRequest[1];
                // Link
                $movitelRedirectUrl = $data['link'] . self::MSISDN_METHOD . '?' . $dataLink . urlencode($dataEncrypted) . '&SIG=' . $dataSignature;
                $this->debug->info(__FUNCTION__, '$movitelRedirectUrl: ' . json_encode($movitelRedirectUrl));
                if ($resultIsUrl === TRUE) {
                    $this->debug->info(__FUNCTION__, 'Result is URL');

                    return [
                        'status' => 'url',
                        'link'   => $movitelRedirectUrl
                    ];
                } else {
                    $this->debug->info(__FUNCTION__, 'Result is Redirect');
                    // Redirect url
                    Utils::redirect($movitelRedirectUrl);
                }
            }
            $this->debug->info(__FUNCTION__, 'Invalid Redirect URL');
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return NULL;
        }

        return NULL;
    }
635330
protected URI createRedirectUri(String servletpath, UserGroupInformation ugi,
      DatanodeID host, HttpServletRequest request, NameNode nn) throws URISyntaxException {
    final String hostname = host instanceof DatanodeInfo?
        ((DatanodeInfo)host).getHostName(): host.getHost();
    final String scheme = request.getScheme();
    final int port = "https".equals(scheme)?
        (Integer)getServletContext().getAttribute("datanode.https.port")
        : host.getInfoPort();
    // Add namenode address to the URL params
    final String nnAddr = NetUtils.toIpPort(nn.getNameNodeAddress());
    final String filename = request.getPathInfo();
    return new URI(scheme, null, hostname, port, servletpath,
        "filename=" + filename + "&ugi=" + ugi +
        JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnAddr), null);
  }
960347
protected function getRefreshUri(RequestInterface $request, ResponseInterface $response)
    {
        if (preg_match(static::REFRESH_EXPRESSION, $response->getHeaderLine('Refresh'), $matches)) {
            return new Uri($matches[1]);
        }

        return $this->solveJavascriptChallenge($request, $response);
    }
1337754
protected function getUriFromCustomLinkDetails(array $redirectRecord, ?SiteInterface $site, array $linkDetails, array $queryParams): ?UriInterface
    {
        if (!isset($linkDetails['type'], $GLOBALS['TYPO3_CONF_VARS']['FE']['typolinkBuilder'][$linkDetails['type']])) {
            return null;
        }
        $controller = $this->bootFrontendController($site, $queryParams);
        /** @var AbstractTypolinkBuilder $linkBuilder */
        $linkBuilder = GeneralUtility::makeInstance(
            $GLOBALS['TYPO3_CONF_VARS']['FE']['typolinkBuilder'][$linkDetails['type']],
            $controller->cObj,
            $controller
        );
        try {
            $configuration = [
                'parameter' => (string)$redirectRecord['target'],
                'forceAbsoluteUrl' => true,
            ];
            if ($redirectRecord['force_https']) {
                $configuration['forceAbsoluteUrl.']['scheme'] = 'https';
            }
            if ($redirectRecord['keep_query_parameters']) {
                $configuration['additionalParams'] = HttpUtility::buildQueryString($queryParams, '&');
            }
            list($url) = $linkBuilder->build($linkDetails, '', '', $configuration);
            return new Uri($url);
        } catch (UnableToLinkException $e) {
            return null;
        }
    }
962907
protected function getRedirectResponse($type) {
    $sdk = $this->getSdk($type);

    if ($sdk instanceof RedirectResponse) {
      return $sdk;
    }

    $this->authManager->setSdk($sdk);
    $url = $this->authManager->getAuthenticationUrl($type);

    return new TrustedRedirectResponse($url);
  }
973328
public static function rewindEntityBody(RequestInterface $redirectRequest)
    {
        // Rewind the entity body of the request if needed
        if ($body = $redirectRequest->getBody()) {
            // Only rewind the body if some of it has been read already, and
            // throw an exception if the rewind fails
            if ($body->tell() && !$body->seek(0)) {
                throw new CouldNotRewindStreamException(
                    'Unable to rewind the non-seekable request body after redirecting',
                    $redirectRequest
                );
            }
        }
    }
1062102
public function getRedirect($url, $siteId)
    {
        if (empty($url)) {
            throw new InvalidArgumentException('No URL found to search by');
        }

        try {
            $result = $this->getQuery($siteId, $url)->getResult();
        } catch (NoResultException $e) {
            return null;
        }

        return array_pop($result);
    }
1209480
public static SamlEndpoint ofHttpRedirect(String uri) {
        requireNonNull(uri, "uri");
        try {
            return ofHttpRedirect(new URI(uri));
        } catch (URISyntaxException e) {
            return Exceptions.throwUnsafely(e);
        }
    }
712730
private function sendRequest(RequestInterface $request)
    {
        $request->getParams()->set('redirect.max', $this->getMaxRedirects());

        try {
            $response = $request->send();
        } catch (\Exception $e) {
            throw HttpAdapterException::cannotFetchUrl($request->getUrl(), $this->getName(), $e->getMessage());
        }

        return $this->createResponse(
            $response->getStatusCode(),
            $request->getUrl(),
            $response->getHeaders()->toArray(),
            $response->getBody(true),
            $response->getEffectiveUrl()
        );
    }
275837
public function h5Pay(array $args = [], $redirect_url = null) {
        $args['trade_type'] = 'MWEB';
        $data = $this->order($args);
        if ($data === false) {
            return false;
        }
        if (array_key_exists('mweb_url', $data)) {
            return $data['mweb_url'].'&redirect_url='.urlencode((string)$redirect_url);
        }
        throw new Exception('unkown');
    }
10941
public static void redirect(String url, boolean copyParameters, ServletRequest req, ServletResponse res)
	{
		if(url == null)
		{
			throw new IllegalArgumentException("URL cannot be null");
		}
		String redirectUrl = url;
		char separator = '?';
		if (redirectUrl.indexOf('?') != -1)
		{
			separator = '&';
		}
		if(copyParameters)
		{
			Enumeration e = req.getParameterNames();
			while (e.hasMoreElements())
			{
				String name = (String) e.nextElement();
				String value = req.getParameter(name);
				redirectUrl += separator + name + '=' + value;
				separator = '&';
			}
			e = req.getAttributeNames();
	/*		while (e.hasMoreElements())
			{
				String name = (String) e.nextElement();
				String value = req.getParameter(name);
				redirectUrl += separator + name + '=' + value;
				separator = '&';
			}  */
		}
		System.out.println(new LogEntry("about to redirect to " + redirectUrl));
		try
		{
			((HttpServletResponse)res).sendRedirect(redirectUrl);
		}
		catch(IOException ioe)
		{
			throw new ResourceException("redirect to '" + redirectUrl + "' failed with message: " +
			ioe.getMessage(), ioe);
		}
	}
1258268
public function mpsRedirect($data = [], $resultIsUrl = FALSE)
    {
        try {
            $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($data));
            $viettelMps = new ViettelMps\ViettelMps($this->options);
            $viettelMps->setViettelPublicKey($this->viettelPublicKey);
            $viettelMps->setViettelPrivateKey($this->viettelPrivateKey);
            $viettelMps->setCpPublicKey($this->cpPublicKey);
            $viettelMps->setCpPrivateKey($this->cpPrivateKey);
            $dataToRequest = "SUB=" . $data['sub'] . "&REQ=" . $data['req'] . "&SOURCE=" . $data['source'] . "&SESS=" . $data['session_id'];
            $dataLink      = "PRO=" . $data['provider'] . "&CMD=" . $data['cmd_msisdn'] . "&SER=" . $data['service'] . "&SUB=" . $data['sub'] . "&DATA=";
            $this->debug->info(__FUNCTION__, '$dataToRequest: ' . json_encode($dataToRequest));
            $this->debug->info(__FUNCTION__, '$dataLink: ' . json_encode($dataLink));
            $dataRequest = $viettelMps->createDataRequestToMps($data, $dataToRequest);
            $this->debug->info(__FUNCTION__, '$dataRequest: ' . json_encode($dataRequest));
            if ($dataRequest !== NULL && is_array($dataRequest)) {
                $dataEncrypted = $dataRequest[0];
                $dataSignature = $dataRequest[1];
                // Link
                $viettelRedirectUrl = $data['link'] . self::MSISDN_METHOD . '?' . $dataLink . urlencode($dataEncrypted) . '&SIG=' . $dataSignature;
                $this->debug->info(__FUNCTION__, '$viettelRedirectUrl: ' . json_encode($viettelRedirectUrl));
                if ($resultIsUrl === TRUE) {
                    $this->debug->info(__FUNCTION__, 'Result is URL');

                    return [
                        'status' => 'url',
                        'link'   => $viettelRedirectUrl
                    ];
                } else {
                    $this->debug->info(__FUNCTION__, 'Result is Redirect');
                    // Redirect url
                    Utils::redirect($viettelRedirectUrl);
                }
            }
            $this->debug->info(__FUNCTION__, 'Invalid Redirect URL');
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return NULL;
        }

        return NULL;
    }