How to receive the value passed by alipay after hiding the entry file in url in ThinkPHP, _PHP tutorial

WBOY
Release: 2016-07-13 10:12:06
Original
828 people have browsed it

How to receive the value passed by alipay after hiding the entry file in url in ThinkPHP,

The example in this article describes the method of receiving the value from alipay after hiding the entry file in the url in ThinkPHP. Share it with everyone for your reference. The specific method is as follows:

Nowadays, the needs of company projects are ever-changing. The project uses Thinkphp2.0, and the URL_MODEL=2 set in conf.php is for compatibility with .htaccess and hiding 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 will automatically convert URLs containing ?.

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 be inaccessible, but the pre-converted URL is accessible. At this time, you need to temporarily target the alipay controller, URL_MODEL=1, but in this controller C('URL_MODEL',1) is It's useless, because TP will directly issue 404 when entering the entry file App::run().

I thought of many ways, first I modified its configuration file Conf.php, and found that a cache file ~app.php would be generated, so I had to delete this cache file according to the situation, so I modified the index.php entry file ( In fact, it can be placed before any App::run(), you can encapsulate it yourself).

PHP example code:

Copy code The code is as follows:
// Define ThinkPHP framework path
define('THINK_PATH', 'I won't tell you my TP folder name/');
//If such a form exists in the URL, delete the cache configuration file and create an identifier
if(strstr($_SERVER['REQUEST_URI'],'alipay/callback/')||strstr($_SERVER['REQUEST_URI'],'order.return_pay')){
Unlink('./home/Runtime/~app.php');
//Create a cache file as a logo
$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 framework entry file

require(THINK_PATH."ThinkPHP.php");

//Instantiate a website application instance
App::run();
?>

The project configuration file Conf.php can be judged based on your own situation.

PHP example source code:

Copy code The code is as follows:
//Compatible with 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 visiting any non-alipay controller pages such as www.xxx.com or www.xxx.com/shipin/, the website still uses url_model = 2 to hide index.php, making the URL friendly.

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/924544.htmlTechArticleThe method of receiving the value from alipay after the url hidden entry file in ThinkPHP. This article describes the example of the url hidden entry file in ThinkPHP Then receive the value passed by alipay. Share it with everyone for your reference...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template