Home Backend Development PHP Tutorial ThinkPHP中url隐藏入口文件后接收alipay传值的方法_PHP

ThinkPHP中url隐藏入口文件后接收alipay传值的方法_PHP

May 31, 2016 pm 06:15 PM
thinkphp url hide

本文实例讲述了ThinkPHP中url隐藏入口文件后接收alipay传值的方法。分享给大家供大家参考。具体方法如下:

现在公司项目的需求变化多端,项目使用的是Thinkphp2.0,而conf.php中设置的URL_MODEL=2,为了兼容.htaccess和隐藏index.php,但在使用一些第三方接口时(例如支付宝或MSN开放平台),他们返回的参数往往含有一个?号,而URL_MODEL=2时,TP会自动将含有?的URL进行转换.

转换前:http://www.xxx.com/index.php/alipay/callback/?is_success/T/sign_type/MD5/notify_id/RqPnCoPT3K9/vwbh3I

转换后:http://www.xxx.com/alipay/callback/is_success/T/sign_type/MD5/notify_id/RqPnCoPT3K9/vwbh3I

转换后的网址将无法访问,而转换前的网址是可以访问的,这时需要临时针对alipay这个控制器,URL_MODEL=1,但在该控制器里C('URL_MODEL',1)是没有用的,因为TP会在入口文件App::run()时直接404了.

想了很多方法,先是修改它的配置文件Conf.php,结果发现会生成缓存文件~app.php,所以必须根据情况删除这个缓存文件,于是我对index.php入口文件进行了修改(事实上,放在任何App::run()之前都可以,你可以自行封装).

PHP实例代码:

代码如下:

// 定义ThinkPHP框架路径 
define('THINK_PATH', '不告诉你我的TP文件夹名/'); 
//如果网址中存在这样的形式就删除缓存配置文件,并创建一个标识 
if(strstr($_SERVER['REQUEST_URI'],'alipay/callback/')||strstr($_SERVER['REQUEST_URI'],'order.return_pay')){ 
    unlink('./home/Runtime/~app.php'); 
    //创建一个缓存文件做为标识 
    $fn= fopen('./home/Runtime/re_url_model.php','wb'); 
    fclose($fn); 
}elseif(file_exists('./home/Runtime/re_url_model.php')){ 
    unlink('./home/Runtime/re_url_model.php'); 
    unlink('./home/Runtime/~app.php'); 

 
//定义项目名称和路径 
define('APP_NAME', 'home'); 
 
define('APP_PATH', 'home'); 
 
// 加载框架入口文件 
 
require(THINK_PATH."ThinkPHP.php"); 
 
//实例化一个网站应用实例 
App::run(); 
?>


项目的配置文件Conf.php根据你自己的情况做一个判断即可.

PHP实例源码:

代码如下:

//兼容支付宝快捷登录的?请求 
if(strstr($_SERVER['REQUEST_URI'],'alipay/callback/')||strstr($_SERVER['REQUEST_URI'],'order.return_pay')){ 
    $my_array['URL_MODEL'] = 1; 

return $my_array;


这样,访问www.xxx.com或www.xxx.com/shipin/等任何非alipay控制器的页面时,网站依然是使用url_model = 2来隐藏index.php,使得URL友好.

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Win11 input method floating window hidden settings Win11 input method floating window hidden settings Dec 30, 2023 pm 11:24 PM

Some friends are not used to the floating window function of win11 input method, and it always feels strange to use, so they want to turn off this floating window function. Now I will introduce to you the correct operation method of closing the floating window in win11 system. Follow along. Win11 hides the input method floating window 1. Open the settings key of the computer, and then select "Time and Language". After entering, click "Enter" 2. Find "Switch Input Method" in "Advanced Keyboard Settings", and then change "Desktop Language" Click the check mark in front of "Bar", and then enter "Language Bar Options" 3. After opening, we click "Hide" here to close the language floating window.

How to hide Windows 11 taskbar icons? How to hide Windows 11 taskbar icons? Jan 06, 2024 am 08:38 AM

In the win11 system, if we find the icons in the taskbar troublesome, we can choose to hide them in the taskbar corner overflow interface. However, the icons in the taskbar of the application opened below cannot be hidden. Let’s follow the editor below. Let’s look at the specific situation. How to hide the win11 taskbar icon: 1. Center the icon 1. First, if we want to hide the icon in the taskbar below, we can right-click to select it and click "Unpin from taskbar" 2. But if we open this application and are in the process Use it and that's impossible to hide. 2. Icon in the lower right corner 1. If you want to hide the application icon in the lower right corner, first open the system settings. 2. Then click "Personalization" on the left sidebar, as shown in the picture. 3. Then click to enter the taskbar on the right

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

How to hide WeChat friends without blocking or deleting them? How to hide WeChat friends without blocking or deleting them How to hide WeChat friends without blocking or deleting them? How to hide WeChat friends without blocking or deleting them Mar 13, 2024 pm 07:19 PM

How to hide WeChat friends without blocking or deleting them? Many users want to hide some friends but don’t know how to do it. Let this site carefully introduce to users how to hide WeChat friends without blocking or deleting them. Methods to hide WeChat friends without blocking or deleting Method 1: 1. First open the WeChat software, find the address book on the WeChat page, and click "My". 2. Then we enter the settings page. 3. Find the “Privacy” option and click on it. 4. Then click "Don't let him see". 5. Go to the Do Not Let Her View page and click "+" to check the friends you want to hide.

Why NameResolutionError(self.host, self, e) from e and how to solve it Why NameResolutionError(self.host, self, e) from e and how to solve it Mar 01, 2024 pm 01:20 PM

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to hide works in Douyin short videos How to hide personal video works How to hide works in Douyin short videos How to hide personal video works Mar 12, 2024 pm 12:49 PM

There are many short video works provided in the Douyin short video app software. You can watch them as you like, and they are all permanently provided free of charge. Different types of live video channels are open, and all video content is original, with Give everyone the most satisfying way to watch. Enter your account to log in online, and a variety of exciting short videos will be pushed, which are accurately recommended based on what everyone watches every day. You can also enter the live broadcast room to interact and chat with the anchor, making you feel more happy. Works uploaded by individuals can also be hidden. It is very simple to set up with one click. You can see wherever you swipe. Swipe up and down to see the real-time comments of countless netizens. You can also share daily life dynamics. Now the editor has detailed online Douyin short videos. Users push for ways to hide personal video works. First open Douyin short video

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

See all articles