English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Firstly, please apply for a real-time settlement account on Alipay, which requires submission of relevant materials. Then, according to the real-time settlement API documentation, proceed with the integration. The API documentation provides demo versions in various languages. Here, I have downloaded the PHP version demo and then made relevant modifications. You can also re-integrate the code from the demo version. Here, I temporarily do not perform code refactoring to ensure the real-time settlement recharge process works smoothly.
API Documentation:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7386797.0.0.eZb8FX&treeId=108&articleId=103950&docType=1
Front-end form submission
<form action="/pay/alipayapi.php" class="tm-panel-small uk-form uk-form-stacked" method="post" target="_blank"> <div class="element" style="margin-top:60px;"> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">订单序号:</label> <input class="uk-form-width-large" type="text" name="WIDout_trade_no" id="out_trade_no" value="<?php echo trim($_GET['orderid']);?>" > <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">商品名称:</label> <input class="uk-form-width-large" type="text" name="WIDsubject" value="<?php echo trim($_GET['orderid']);?>" > <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">付款金额:</label> <input class="uk-form-width-large" type="text" name="WIDtotal_fee" value="<?php echo trim($_GET['amt']);?>"> <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">商品描述:</label> <input class="uk-form-width-large" type="text" name="WIDbody" value="订单测试支付"> <br> </div> </div> <input type="hidden" name="uid" value="<?php echo $_GET['uid'];?>"> <input type="hidden" name="codes" value="<?php echo $_GET['code'];?>"> <input type="hidden" name="tags" value="<?php echo $_GET['tag'] ?>"> <div class="uk-form-row"> <input class="uk-button uk-button-primary uk-button-large uk-width-1-1" type="submit" class="alisubmit" value ="Confirm Payment"> </div> </div> </form>
Set the alipay.config.php configuration file, mainly configure the following parameters
$alipay_config['partner'] sets the signing account ID
$alipay_config['key'] sets MD5Verify key
$alipay_config['notify_url'] sets the asynchronous callback address
$alipay_config['return_url'] sets the callback return address
$alipay_config['transport'] sets the protocol type, default is http
$alipay_config['partner'] = 'xxxxxxxxxxxx'; //Receiving Alipay account, with2088Starting with16A string composed of pure digits, in general, the receiving account is the signing account $alipay_config['seller_id'] = $alipay_config['partner']; // MD5A key, security check code, composed of numbers and letters32A string of digits, see the address: https://b.alipay.com/order/pidAndKey.htm $alipay_config['key'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Asynchronous server notification page path requires http://The complete path in format, do not add?id=123These custom parameters must be accessible from the outside network $alipay_config['notify_url'] = "http://xx.xx.xx.xx/pay/"notify_url.php"; // Synchronous page jump notification page path requires http://The complete path in format, do not add?id=123These custom parameters must be accessible from the outside network $alipay_config['return_url'] = "http://xx.xx.xx.xx/pay/return_url.php"; //Signature method $alipay_config['sign_type'] = strtoupper('MD5); //Character encoding format, currently supports gbk or utf-8 $alipay_config['input_charset']= strtolower('utf-8); //CA certificate path address, used for ssl verification in curl //Please ensure that the cacert.pem file is in the current folder directory $alipay_config['cacert'] = getcwd().'\\cacert.pem'; //Access mode, choose https if your server supports ssl access; choose http if it does not support ssl $alipay_config['transport'] = 'http'; // Payment type, no need to modify $alipay_config['payment_type'] = "1"; // Product type, no need to modify $alipay_config['service'] = "create_direct_pay_by_user";
After the transaction is processed, the order information and transaction status will be sent to the return_url.php you specified. You can judge whether the transaction is successful by the order status returned to you. If successful, proceed to the next logic (your own order processing logic), otherwise return failure.
<?php /* * * Function: Alipay page jump synchronous notification page * Version:3.3 * Date:2012-07-23 * Note: * The following code is just a sample code provided for the convenience of merchants to test, and merchants can write according to their own website needs according to the technical documentation, and it is not necessary to use this code. * This code is provided for learning and research purposes only for Alipay interface usage, and is just for reference. *************************Page function description************************* * This page can be tested on the local computer * You can place HTML code for beautifying the page and merchant business logic program code here * This page can be debugged using PHP development tools or the logResult function, which is turned off by default, see the verifyReturn function in alipay_notify_class.php require_once("alipay.config.php"); require_once("lib/alipay_notify.class.php"); ?> <?php //计算得出通知验证结果 $alipayNotify = new AlipayNotify($alipay_config); $verify_result = $alipayNotify->verifyReturn(); if($verify_result) {//验证成功 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 //商户订单号^M $out_trade_no = $_GET['out_trade_no']; //支付宝交易号^M $trade_no = $_GET['trade_no']; //交易状态 $trade_status = $_GET['trade_status']; $total_fee = $_GET['total_fee']; //获取用户返回数据 $user_info = $_GET['extra_common_param']; $user_arr = explode('.',$user_info); $uid = $user_arr[0]; $code = $user_arr[1 $tags = $user_arr[2 if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') { $types = "alipay"; $user_url = "/user_obj/do_orderinfo.php"; die("<script>;window.location='{$user_url}&"63;uid={$uid}&code={$code}&tags={$tags}&payAmount={$total_fee}&order={$out_trade_no}&types={$types}';</script> //Determine whether this order has been processed in the merchant's website //If you have not done any processing, find the detailed information of this order (out_trade_no) in the order system of the merchant's website, and execute the business program of the merchant //If you have done any processing, do not execute the business program of the merchant } else { echo "trade_status=".$_GET['trade_status']; } var_dump($verify_result); echo "Verification successful<br />"; //——Please write the program according to your business logic (the above code is for reference only)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else { //Verification failed //If you want to debug, please see the verifyReturn function on the alipay_notify.php page echo "Verification failed"; } ?> <title>Alipay Instant Payment Transaction Interface</title> </head> <body> </body> </html>
The above is the introduction of the PHP Alipay Instant Payment function introduced by the editor to everyone, hoping it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. Here, I also thank everyone for supporting the Yanao tutorial website!
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not undergo manual editing, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email for reporting. Provide relevant evidence, and once verified, this site will immediately delete the suspected infringing content.)