It is very simple to integrate the interface of Alipay. There are currently about 3 types, such as instant account, dual-function, and guaranteed transactions. Only one guaranteed transaction is required. Others, such as instant account integration, are easy, and there are several guaranteed transactions, such as: whether payment is successful, whether the seller ships the goods, and the buyer confirms the harvest. There is only one type of instant account, that is, whether the payment has been made! At most, there is a refund function. Generally not used.
Through the previous project: the funding allocation platform, it has a prepaid function, and uses Alipay's dual-function collection, which actually provides two payment methods, instant account arrival and guarantee transactions. Generally, buyers will choose to guarantee with caution.
The following is the specific integration process. First: download the corresponding integration interface package, such as downloading the instant account when you arrive immediately, and guaranteeing the guarantee. It is very unlikely that you will modify the instant account to a guarantee or vice versa. The dual-function interface file I downloaded in the case, the utf8-php interface.
The files downloaded are similar, and the instant account arrival and guaranteed files are not much different. Anyway, it is certain that as long as you configure the guaranteed Alipay interface, you can configure the instant account arrival.
The files we need to modify are as follows: [Configuration file, which is only used to modify the configuration interface developer id and key]
[The main adjustment file, hand over the post data to be sent to the file, and then be responsible for jumping to the payment page]
[The demo page can be modified without modification, but the parameter name passed in it needs to be understood]
notify_url.php Returns the data page, where the transaction status will be returned. With more status, we can change the database order information, and the file is accepted through post.
return_url.php returns the data page, where the transaction status will be returned. With more state, we can change the database order information, and the file is GET.
Specific process:
The first step is to modify the configuration information:
$alipay_config['partner'] = 'xxx8511073xxxxxxxx';
//Safety inspection code, 32-bit characters composed of numbers and letters
$alipay_config['key'] ='xxxxxxxxnow07oajbflskxxxxxxxxxx';
Second: Spoke post data, generally only need to modify the request parameters
/********************************* Request parameters***************************/
//Payment type
$payment_type = "1";
//Required, cannot be modified
//The path of the server asynchronous notification page
$notify_url = "http://your domain name/alipay/notify_url.php";
//The complete path of http://format is required, and custom parameters such as ?id=123 cannot be added
//Page jump synchronous notification page path
$return_url = "http://your domain name/alipay/return_url.php";
//The complete path of http://format is required. You cannot add custom parameters like ?id=123 and cannot be written ashttp://localhost/
//Seller's Alipay account
$seller_email = $_POST['WIDseller_email'];//demo[] sent by
//Required
//Merchant order number
$out_trade_no = $_POST['WIDout_trade_no'];//Sent from
//The only order number in the merchant website order system, required
//Order name
$subject = $_POST['WIDsubject'];//Same as above
//Required
//Payment amount
$price = $_POST['WIDprice'];//What is passed is the value filled in in your form
//Required
//Quantity of products
$quantity = "1";
//Required, it is recommended to default to 1, and do not change the value. A transaction is regarded as placing an order instead of buying a product
//Logistics fees
$logistics_fee = "0.00";
//Required, that is, shipping
//Logistics Type
$logistics_type = "EXPRESS";
//Required, three values are available: EXPRESS (express), POST (price mail), EMS (EMS)
//Logistics payment method
$logistics_payment = "SELLER_PAY";
//Required, two values are available: SELLER_PAY (seller bears freight), BUYER_PAY (buyer bears freight)
//Order description
$body = $_POST['WIDbody'];
//Product display address
$show_url = $_POST['WIDshow_url'];
//The complete path that needs to start with http:// is required, such as:
//The consignee's name
$receive_name = 'fire';
//For example: Zhang San
//Consignee's address
$receive_address = $_POST['WIDreceive_address'];
//For example: No. XXXX Unit XXXX Building XXX Community, XXX District, XXX District, XXX City, XXX Province
//The consignee's postal code
$receive_zip = $_POST['WIDreceive_zip'];
//For example: 123456
//Tel number of the consignee
$receive_phone = $_POST['WIDreceive_phone'];
//For example: 0571-88158090
//Consignee's mobile phone number
$receive_mobile = $_POST['WIDreceive_mobile'];
//For example: 13312341234
Third: After the data construction is completed, you can pay on the page to test whether the payment page can be opened correctly. If it can be opened, you can make payment at this time, but we cannot know the status of the buyer's payment, such as whether the payment has been successful, whether the seller has shipped the goods, etc. Then start the business logic processing of the return state.
Open the return_url.php file, modify it according to the prompts, and deal with the correct cause.
//—Please write the program according to your business logic (the following code is for reference only)—
//Get the notification return parameters of Alipay, refer to the page jump to the synchronous notification parameter list in the technical document
//Merchant order number $out_trade_no = $_GET['out_trade_no'];
//Alipay transaction number $trade_no = $_GET['trade_no'];
//Trading status
$trade_status = $_GET['trade_status'];
if($_GET['trade_status'] == 'WAIT_SELLER_SEND_GOODS') {//Status is successful
//Deal with the business logic of your own website
if(!$order['status']){//Judge whether the order in the local database has been processed
db_update("stx_recharge",array("status"=>1),array("oid"=>$_GET
['out_trade_no']));//If it is not processed, change the status to have been processed.
//Increase of money
$zd = db_line("stx_terminal",array("id"=>$order['ztid']));
db_update("stx_terminal",array("money"=>$zd['money']+$order
['money']),array("id"=>$order['ztid']));//Increase the balance to the user's account.
}
}
else if($_GET['trade_status'] == 'TRADE_FINISHED') {
//Judge whether the order has been processed on the merchant website
//If there has not been any processing, the order system on the merchant website is based on the order number (out_trade_no)
The details of the order were found in and the merchant’s business procedures were executed
//If there has been any processing, the merchant’s business procedures will not be executed
}
else {
echo "trade_status=".$_GET['trade_status'];
}
echo "Verification successful<br />";
echo "trade_no=".$trade_no;
The same is true for notify_url.php, write the corresponding code according to the status! There should be more status in the notify_url.php file.
//—Please write the program according to your business logic (the following code is for reference only)—
//Get the notification return parameters of Alipay, refer to the technical document asynchronous notification parameter list
//Merchant order number
$out_trade_no = $_POST['out_trade_no'];
//Alipay transaction number
$trade_no = $_POST['trade_no'];
//Trading status
$trade_status = $_POST['trade_status'];
if($_POST['trade_status'] == 'WAIT_BUYER_PAY') {
//This judgment indicates that the buyer has generated a transaction record in Alipay transaction management, but has not paid
//Judge whether the order has been processed on the merchant website
//If there has not been any processing, find the details of the order in the order system of the merchant website according to the order number (out_trade_no), and execute the merchant's business procedures.
//If there has been any processing, the merchant’s business procedures will not be executed
echo "success"; //Please do not modify or delete
//For debugging, write text functions to record whether the program runs normally
//logResult("Write the code variable value you want to debug here, or record of other running result");
}
else if($_POST['trade_status'] == 'WAIT_SELLER_SEND_GOODS') {
//This judgment indicates that the buyer has generated a transaction record in Alipay transaction management and the payment is successful, but the seller has not shipped the goods.
if(!$order['status']){
db_update("stx_recharge",array("status"=>1),array("oid"=>$_POST['out_trade_no']));
//Increase of money
$zd = db_line("stx_terminal",array("id"=>$order['ztid']));
db_update("stx_terminal",array("money"=>$zd['money']+$order['money']),array("id"=>$order['ztid']));
}
echo "success"; //Please do not modify or delete
//For debugging, write text functions to record whether the program runs normally
//logResult("Write the code variable value you want to debug here, or record of other running result");
}
else if($_POST['trade_status'] =='WAIT_BUYER_CONFIRM_GOODS') {
//This judgment means that the seller has shipped the goods, but the buyer has not done any operation to confirm the receipt.
if(!$order['status']){
db_update("stx_recharge",array("status"=>1),array("oid"=>$_POST['out_trade_no']));
//Increase of money
$zd = db_line("stx_terminal",array("id"=>$order['ztid']));
db_update("stx_terminal",array("money"=>$zd['money']+$order['money']),array("id"=>$order['ztid']));
}
echo "success"; //Please do not modify or delete
//For debugging, write text functions to record whether the program runs normally
//logResult("Write the code variable value you want to debug here, or record of other running result");
}
else if($_POST['trade_status'] == 'TRADE_FINISHED') {
//This judgment means that the buyer has confirmed the receipt and the transaction is completed
//Judge whether the order has been processed on the merchant website
//If there has not been any processing, find the details of the order in the order system of the merchant website according to the order number (out_trade_no), and execute the merchant's business procedures.
//If there has been any processing, the merchant’s business procedures will not be executed
echo "success"; //Please do not modify or delete
//For debugging, write text functions to record whether the program runs normally
//logResult("Write the code variable value you want to debug here, or record of other running result");
}
Since I basically did not use the subsequent delivery process, it was not processed in this state. If your website is a shopping website, it needs to be processed in seconds, such as the update status value is shipped, or unpaid, confirmed, etc. It is convenient to see the transaction process. At the same time, the order id of Alipay will be generated in the paid order, which can be recorded in your own order at the same time.
The above is all about Alipay interface in this article. I hope it will be helpful for everyone to master the secondary development of Alipay interface payment.