TP 5-Minute integrated Alipay interface (with source code)

Source: Internet
Author: User
Tags php class

Alipay's Merchant Registration method

Hello, in order to better help you solve the problem, please contact the Merchant Customer Service Consulting can. Click link http://help.alipay.com/support/index_sh.htm Contact merchant's online customer service (working time: Monday to Sunday 9:0 0-22:00 Consulting or call the Merchant Service Hotline 0571-88158090 (working time: Monday to Friday 9:00-18:00, holidays excepted) Warm tip: If you want to contact merchants Online customer service, please close the current dialog box, and then find business Online customer service, click "Point this Consultation" Can enter the merchant online customer service consultation.


pangdan118 posted on 2011-12-18 19:30:31

Probably the idea is

1. The Payment Treasure official example code in the Lib folder under the name of all files, such as: service.class.php changed into service.php, the inside load file that sentence removed, 2, Create a new Alipay folder in the vendor directory of TP (no need to create a new directory page), and put the first step in the file.

3 Create a OrderAction.class.php,

Public Function _initialize () {<?php class Orderaction extends Action {public Function _initialize () {
                Vendor (' alipay.corefunction ');
                Vendor (' alipay.notify ');
                Vendor (' Alipay.service ');
                Vendor (' Alipay.submit ');

        Vendor (' Alipay.alipayconfig ');
                function Alipayto () {C (' token_on ', false);
                $aliapy _config = Alicofings (); $out _trade_no = ' GDS '. Date (' Ymdhis ', Time ()).

                Round (0, 100);

                $subject = $_post[' subject '];

                $body = $_post[' body '];

                $total _fee = $_post[' Total_fee '];

                $paymethod = ';

                $defaultbank = ';

                $anti _phishing_key = ';

                $exter _invoke_ip = ';

                $show _url = ' http://www.uvmonopoly.com ';

                $extra _common_param = ';
                $royalty _type = "";

    $royalty _parameters = "";            $parameter = Array ("service" => "Create_direct_pay_by_user", "Payment_type" => "1", "partner" => Trim ($aliapy _config[' partner ']), " _input_charset "=> Trim (strtolower ($aliapy _config[' Input_charset '))," Seller_email "=> trim ($aliapy _config[' Seller_email ']), "Return_url" => trim ($aliapy _config[' Return_url ']), "Notify_url" => trim ($aliapy _config[' Notify_url ']), "Out_trade_no" => $out _trade_no, "subject" => $subject, "body" => $body, "Total_fee" => $total _ Fee, "Paymethod" => $paymethod, "Defaultbank" => $defaultbank, "Anti_phishing_key" => $anti _phishing_key, " Exter_invoke_ip "=> $exter _invoke_ip," Show_url "=> $show _url," Extra_common_param "=> $extra _common_param,"
                Royalty_type "=> $royalty _type," royalty_parameters "=> $royalty _parameters);
                $d = d (' order ');
                $d->create (); $d->user_id = Cookie:: Get (' user_id ');
                $d->total_fee = $total _fee;
                $d->order_id = $out _trade_no;
                $d->creat_time=time ();
                $d->trde_status = 0;
                        if (False!== $d->add ()) {$alipayService = new Alipayservice ($aliapy _config);
                        $html _text = $alipayService->create_direct_pay_by_user ($parameter);
                        $this->assign (' Alipay ', $html _text);
                        $this->assign (' Total_fee ', $total _fee);

                $this->display ();

                else {$this->error (' system error temporarily cannot recharge, please contact online customer service! ');
                The Public Function ReturnUrl () {$aliapy _config = alicofings ();
                $alipayNotify = new Alipaynotify ($aliapy _config);
                $verify _result = $alipayNotify->verifyreturn ();

        if ($verify _result) {//validation successful                $out _trade_no = $_get[' out_trade_no ']; Get order number $trade _no = $_get[' trade_no ']; Get Alipay transaction number $total _fee = $_get[' Total_fee '];
                        Get the total price $d = d (' order ');
                        $result = $d->where ("order_id= '. $trade _no.")->select ();

                        $status = $result [0][' Trde_statuse '];

                                if ($_get[' trade_status '] = = ' trade_finished ' | | $_get[' trade_status '] = = ' trade_success ') {
                                        if ($status = = 0) {$d->create ();
                                        $d->trde_status = 1;
                                        $d->alipay_trade_no;

                                $d->total->fee = $total _fee;
                                } else {//echo "trade_status=". $_get[' Trade_status ']; $thiS->assign (' msg ', ' Recharge failed! ');
                        echo "Verify successful <br/>"; echo "trade_no=".

                $trade _no;
                else {$this->assign (' msg ', ' validation failed ');

        } $this->display ();
                The Public Function Notifyurl () {$aliapy _config = alicofings ();
                $alipayNotify = new Alipaynotify ($aliapy _config);

                $verify _result = $alipayNotify->verifynotify ();
                        if ($verify _result) {//verify success $out _trade_no = $_post[' out_trade_no '];//Get Order number $trade _no = $_post[' trade_no ']; Get Alipay transaction number $total _fee = $_post[' Total_fee ']; Get Total Price if ($_post[' trade_status '] = = ' trade_finished ' | | $_post[' trade_status '] = = ' Trade_succes

                              S ') {//transaction successfully concluded echo "success";//please do not modify or delete  Logresult ("Write the value of the code variable you want to debug, or other running result records"); else {echo "success";//other State judgments.

                                Ordinary instant to the account, other States do not have to judge, direct printing success.
                        For debugging purposes, write the text function to record whether the program is running normally//logresult ("write the value of the code variable you want to debug, or other running result records"); //--please write the program based on your business logic (the above code is for reference only)--//////////////////////////////////////
                        } else {

                        Validation failure echo "fail";
                For debugging purposes, write the text function to record whether the program is running normally//logresult ("write the value of the code variable you want to debug, or other running result records"); }}}?>

Payment Interface configuration file:

<?php
function alicofings () {
$aliapy _config[' partner ']      = ' 2088302763 ';

Security inspection code, with numbers and letters of 32-bit characters
$aliapy _config[' key ']          = ' m8ve6f5x1d90hjl5e95 ';

Signed Payment treasure account number or seller Alipay accounts
$aliapy _config[' seller_email '] = ' qiyunnetwork@vip.163.com ';

Page Jump Sync notification page path, to use the full path of the http://format, not allowed to add? id=123 such custom parameters
//return_url domain names cannot be written Http://localhost/create_direct_pay_ by_user_php_utf8/return_url.php, otherwise it will cause Return_url to execute invalid
$aliapy _config[' return_url ']   = ' http://www.x.com/ Order/returnurl.html ';

The server asynchronously notifies the page path, to use the full path of the http://format, and does not allow add? id=123 such custom parameters
$aliapy _config[' notify_url ']   = ' http:// Www.gudashi.com/order/notifyurl.html ';

↑↑↑↑↑↑↑↑↑↑ Please configure your basic information here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑


//signature method does not need to be modified
$aliapy _config[' sign_type ']    = ' MD5 ';

The character encoding format currently supports GBK or utf-8
$aliapy _config[' input_charset ']= ' utf-8 ';

Access mode, depending on whether your server supports SSL access, if support, please select HTTPS; if not supported please select HTTP
$aliapy _config[' transport ']    = ' http ';
return $aliapy _config
}
? >

Write so many, too lazy to type, I originate the code, I believe a look will be able to clear it, the advantage is that you can quickly integrate, 5 minutes can definitely fix the payment interface
If you can't handle it in 5 minutes, go home and take the kids. ^^ ^^ ^ a little joke ...

Alipay interface. zip

9.26 KB, download times: 576

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.