Alipay integration requires three major steps:
1. Submit the information through the form, and the system will integrate the information and submit it to Alipay;
2. After the user pays, Alipay will notify the system to handle it in the background;
3. After the Alipay background notification is completed, the Alipay foreground jumps to the system return address;
Alipay PHP class
PHP class alipay_notify, whose main function is to notify the server during payment.
PHP class alipay_service, which generates Alipay address according to Alipay external service interface.
I put these two classes into a file alipay.class.inc, click here to view the source code for downloading the PHP Alipay class.
The following mainly explains the integration through Alipay's PHP class.
PHP AliPay integration
Step 1, establish the basic information for submitting recharge:
Zhifubao-Zhizhi PHP Alipay integration establishes and submits basic recharge information.
Step 2, verify whether the amount submitted by the user is correct. After the form is verified, Alipay link is generated through Alipay Alipay _ service class, and then jump to Alipay link.
Function index () {
$ total = intval($ _ POST[' total ']);
If (! Total USD) {
$ total = 1;
}
$ pay _ bank = trim($ _ POST[' pay _ bank ']);
$ account = $ _ POST[' _ account '];
$ base _ path =“”;
$ _ input _ charset = " UTF-8 ";
$ sign _ type = "MD5// signature method
$ transport =“”;
$ sign _ type = " MD5
$ _ input _ charset = ' UTF-8 ';
$ transport =“”;
$ sign _ type = " MD5
$ _ input _ charset = ' UTF-8 ';
$ transport = ' https
Requirements ("../libraries/payment/AliPay.class.inc");
$ AliPay = new AliPay _ notify($ partner,$security_code,$sign_type,$_input_charset,$ transport);
$ verify _ result = $ AliPay-> return _ verify();
$ order _ id = $ _ GET[' out _ trade _ no ']; //Get the order number
$ total _ fee =(int)$ _ GET[' total _ fee ']; //Get the total price
$txn_id = explode('-',$ order _ id);
$ real _ orderid = $ txn _ id[0]; //Get the real order
$ sid = $ txn _ id[ 1];
//Certified as qualified
If ($verify_result) {
$ output =' & lth2 & gt Congratulations, student ID. Sid $ TERM. Recharged to. $total_fee。 It worked! & lt/H2 & gt;' ;
$ student = MySQL _ query ("select uid, balance FROM {student} where sid = %d", $ sid);
$ output ='<p> Your current balance. $ student->; Balance. Yuan. & lt/p & gt; ;
$ output = l ('View Records',' User/'. $ student->; uid。 /deposit logs’);
Return $ output
}
Otherwise {
$ output =' & lth2 & gt There is something wrong with your order payment process! & lt/H2 & gt;' ;
$ output ='<p> Your transaction information is invalid. If you use the existing return information, then the transaction has been established. You can check my order history. & ltbr & gt If you are a hacker, I am a law-abiding citizen. I hope you can leave my shop alone. ;
$ output = ' & lt/p & gt; & ltp & gt& lta href = "/" & gt; Return to home page
Return $ output
}
}
If the user maliciously modifies the URL parameter, you will see:
If the user maliciously modifies the URL parameter, the callback fails.
If the user automatically jumps back through Alipay normally, you will see:
If the user automatically jumps back through Alipay normally, the callback returns successfully.
Ok, quickly apply the above methods and codes to your integral and account balance system!