How to access mobile websites and App Lite Alipay payment functions PHP version

Alipay ready to work :( access on the account can be an individual merchant accounts can also be a business but must have a business license)

1. Log ants gold dress 2. Create an open platform application, application category pages and mobile applications. Applications submitted for review after review by Appid to get permission to call the appropriate interfaces

3. Add function: scan code generally have to pay, computer website payment, mobile payment site, APP pay. See what you need. Mobile Application Selection APP scan code is paid or paid, and web applications are divided into mobile terminal and PC terminal.

4. The contract requires merchants to submit relevant information usually require you to provide your website address and APP packets and other requirements in accordance with contract requirements related to Alipay payment functions

5. Configure your application development configuration (once very critical configuration errors can not afford the transfer Alipay)

a. Gateway Alipay Alipay has not filled out move

b. Fill the application gateway here is the domain name of your back-office systems such as https://www.ios.events.com must be accessible 

c. Authorization to get the callback callback address is the address used when the user asked to fill out a pre-authorization as such can have no fixed

d. endorsement manner is generally recommended RSA (SHA256) where the key points of the first through the https://docs.open.alipay.com/291/105971 download window this link to download the Windows system-generated business applications public and private business applications it must be a key match

And then copied to here so Alipay public key will be generated automatically. Please keep in the text

6. Application of this configuration of course, if you want to test sandbox for testing is also required to configure a sandbox environment and online course is the same but the payment gateway is a treasure https://openapi.alipaydev.com/gateway.do but if APP is a paid unless the IOS, Andrews language pay the sandbox environment is of no use

Complete signing on to add functionality, application configuration is complete then start developing payment function modules of the front and back

Background development

1. First configure your background Alipay environment and if you are using the official SDK would be best placed to expand its SDK library below

'Alipay' => [ 

            // line APP_ID    
 
            'APP_ID' => "2,016,092,300,576,028", // online application private key 
            'merchant_private_key' => "en4wG3L", // online asynchronous notification address 
            'notify_url' => "https : //www.ios.events.com/index.php/Order/notify ", // the line synchronization notification address 
            'return_url' =>" https://www.ios.events.com/index.php/Order / return_url ", // encoding format 
            'charset' =>" UTF-. 8 ", // signature method 
            'sign_type' =>" RSA2 ", // online payment gateway Po 
            'gatewayUrl' =>" https://openapi.alipay.com/gateway.do ", // sandbox Alipay Gateway

            


            


            


            


            


            


            

            // 'GatewayUrl' => "https://openapi.alipaydev.com/gateway.do", 

            // line Alipay public
 
            'alipay_public_key' => "", // use the public key 
            'wap_public_key' => "" , 
        ]

            

PHP 2. Download the ants gold dress open platform payment SDK TP Framework SDK introduction of important files on ThinkPHP / Library / Vendor / Alipay_wap at public libraries Vendor

The file you need to change .class.php because we need to introduce and to use them as a class and their namespace Vendor / Alipay_wap

After a good step 2 above, we have built a good payment environment. Here to go to the actual development can hope to understand the reference to open the document. I also watched the development of the document (Alipay have to say a very detailed development documents) while development

3. (mobile site payment) step is generally good reception to create a payment order passed to the next page (above Alipay or micro-channel payment type and amount of course there are other things) Click the button to call back pay payment interface such as written Pay

1. call Alipay single interface to 

$ config = C ( "Alipay"); // Alipay interface configuration data 

        IF (! Empty ( $ _POST [ 'WIDout_trade_no']) && TRIM ( $ _POST [ 'WIDout_trade_no']) = "! " ) { 

            // merchant order number, merchant website order system unique order number, required 

            $ out_trade_no = $ _POST [ 'WIDout_trade_no' ]; 

            // order name, required 

            $ Subject = $ _POST [ 'WIDsubject' ]; 

            / / payment amount, required 

            $ TOTAL_AMOUNT = $ _POST [ 'WIDtotal_amount' ];

            // Description of goods can be empty 

            $ body =$_POST['WIDbody'];

            //超时时间

            $timeout_express = "9m";

            $payRequestBuilder = new AlipayWapPay();

            $payRequestBuilder->setBody($body);

            $payRequestBuilder->setSubject($subject);

            $payRequestBuilder->setOutTradeNo($out_trade_no);

            $payRequestBuilder->setTotalAmount($total_amount);

            $payRequestBuilder->setTimeExpress($timeout_express);

            $payResponse = new AlipayService($config);

            $result=$payResponse->wapPay($payRequestBuilder,$config['return_url'],$config['notify_url']);

        }

Of course, you can add your own parameters into it unnecessary to fill (which I'll bugger)

The results will be sent to pay the payment result notification via asynchronous transfer mode 4. After starting pay us also known as asynchronous notification

 Time $ = Time ();
         $ orderModel = M ( 'Order' );
         $ config = C ( "Alipay"); // Alipay interface configuration data 
        $ ARR = $ _POST ;
         / * actual verification process is recommended to add the following merchant check . 
        1, the merchant needs to verify whether the notification data out_trade_no merchant system order number is created, 
        2, determines whether indeed total_amount order for the actual amount (i.e. the amount of time order to create business), 
        3, the check notification seller_id (or SELLER_EMAIL) whether the corresponding operation side out_trade_no this document (sometimes, a merchant may have a plurality of seller_id / SELLER_EMAIL) 
        . 4, for merchants to verify whether app_id itself. 
        * / 
        // inspection process to sign 
        $ alipaySevice = new new AlipayService ( $ config );
         $ alipaySevice-> writeLog ( var_export ( $ _POST , to true ));
         $ Result = $ alipaySevice -> Check ( $ ARR );
         IF ( $ Result ) { // verification succeeds 
            // verify 
            IF ( $ ARR ) {
                 $ ordersn = _POST $ [ 'out_trade_no']; // order number 
                $ TOTAL_AMOUNT = $ _POST [ 'TOTAL_AMOUNT']; // order total 
                $ APP_ID = $ _POST [ 'APP_ID']; // application ID 
                $ Data = M('weiz_order')->where('ordersn='.$ordersn)->find();
                if(empty($data)||$total_amount!==$data['total']||$app_id!==$config['app_id']){
                    return false;
                } 

            }else{
                return false;
            }
            if($_POST['trade_status'] == 'TRADE_SUCCESS') {
                $orderModel->startTrans();//事务开始
                if(!empty($ordersn)){
                    $data['paytime'] = $time;//支付时间
                    $data['payment'] = 2;
                    $data['paystatus'] = 1;
                     $res=$orderModel->where('ordersn='.$ordersn)->save($data);
                    $orderData = M('order')->where('ordersn='.$ordersn)->find();
                    $orderId = $orderData['id'];

Here is the code for this Baidu do not upload code 

The steps are: accept Alipay asynchronous notification return parameters for the return of the signature to verify the signature will not go wrong if carried out, if the payment is successful and verify order number generated in our database

Whether the order number are the same, whether the order amount is consistent, app_id are the same. If you are going to modify the same payment status of the order has been modified to determine whether the treatment is not, it will be carried out if there is no database

If the transaction will not be rolled back. Modified successfully commit the transaction is carried out do not forget the most important step echo success else Alipay once in a while asynchronous notification has been sent.

Of course, there may be some extreme cases, if the asynchronous notification does not modify the order to pay state or asynchronous notification is not received successfully but the user supposed to pay for success, failure to pay users do not have control.

This is necessary in the field through our database to record our asynchronous notification of the payment transaction serial number. Transactions to query whether the serial number order pay payment success if it is their own success again

Modify the order to pay the state.

Of course, if we do not receive asynchronous notification of words (such accidents rarely happen but sent), so it is important to inform synchronization

5. Sync notice first order number to get behind our back-office systems to determine whether the state of the state is to pay unpaid if not then exit the program if it is then you can modify the order payment status.

Well paid mobile site PHP version then ended up here is to record and share my personal experience it all work together!

Guess you like

Origin www.cnblogs.com/lbw-share/p/11291669.html