The example in this article describes the method for receiving Alipay values after the URL hides the entry file in thinkphp. Share to everyone for your reference. The specific methods are as follows:
Now the requirements of the company project are changeable, the project uses the Thinkphp2.0, and the url_model=2 set in the conf.php, in order to be compatible. htaccess and hide index.php, but when using some third-party interfaces (such as Alipay or MSN open Platform) , the parameters they return often contain a number, and when url_model=2, TP automatically converts the URL containing the.
Before conversion: Http://www.xxx.com/index.php/alipay/callback/?is_success/T/sign_type/MD5/notify_id/RqPnCoPT3K9/vwbh3I
After conversion: Http://www.xxx.com/alipay/callback/is_success/T/sign_type/MD5/notify_id/RqPnCoPT3K9/vwbh3I
The converted URL will not be accessible, and before the conversion of the URL can be accessed, then need to temporarily target Alipay this controller, url_model=1, but in the Controller C (' Url_model ', 1) is not used, because TP will be in the entry file App::run () is 404 straight.
Think of a lot of ways, first modify its configuration file conf.php, the result found that will generate cache file ~app.php, so must delete this cache file, so I have index.php import file modified (in fact, put in any app::run () before all can, You can encapsulate it yourself).
PHP Instance code:
Copy Code code as follows:
<?php
Define thinkphp Framework Path
Define (' Think_path ', ' Don't tell you my TP folder name/');
Delete the cached profile if such a form exists in the URL and create an identity
if (strstr ($_server[' Request_uri '), ' alipay/callback/') | | Strstr ($_server[' Request_uri ', ' Order.return_pay ')) {
Unlink ('./home/runtime/~app.php ');
Create a cache file as an identity
$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 project name and path
Define (' app_name ', ' home ');
Define (' App_path ', ' home ');
Load Frame Entry file
Require (Think_path.) Thinkphp.php ");
Instantiate an instance of a Web site application
App::run ();
?>
The project's configuration file conf.php make a judgment based on your own situation.
PHP Instance Source code:
Copy Code code as follows:
Compatible Alipay Quick login? request
if (strstr ($_server[' Request_uri '), ' alipay/callback/') | | Strstr ($_server[' Request_uri ', ' Order.return_pay ')) {
$my _array[' Url_model '] = 1;
}
return $my _array;
In this way, when you visit a page of any Alipay controller such as www.xxx.com or www.xxx.com/shipin/, the site is still using Url_model = second to hide the index.php, making the URL friendly.
I hope this article will help you with the PHP program design based on thinkphp framework.