Home  >  Article  >  php教程  >  ThinkPHP5.0 integrates Alipay mobile payment interface class

ThinkPHP5.0 integrates Alipay mobile payment interface class

PHP中文网
PHP中文网Original
2016-12-05 13:27:462077browse

thinkphp5.0 integrates Alipay payment, thinkphp5.0 integrates WeChat payment, mobile app payment
thinkphp5.0 integrates Alipay mobile payment code function implementation

When the app accesses Alipay payment, if the user’s mobile phone does not have the Alipay client installed, Alipay will be called Mobile payment h5 page.
If Alipay payment is installed, the Alipay client will be awakened for payment, and the best way for users to withdraw money.

Alipay document address:
https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7386797.0.0.Y4jDIe&treeId=59&articleId=103563&docType=1




All the data is there The server performs the combination and finally returns a processed string to the client.
The generated standard string is provided:

partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="Test"&body="Test Test"&total_fee="0.01"¬ ify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&sign="lBBK%2F0w5LOajrMrji7DUgEqNjIhQbidR13GovA5r3TgIbNqv231yC1NksLdw% 2Ba3JnfHXoXuet6XNNHtn7VE%2BeCoRO1O%2BR1KugLrQEZMtG5jmJIe2pbjm%2F3kb%2FuGkpG%2BwYQYI51%2BhA3YBbvZHVQBYveBqK%2Bh8mUyb7GM1HxWs9k4%3D"&sign_type="RSA "

ThinkPHP5.0 integrates Alipay mobile payment interface classThinkPHP5.0 integrates Alipay mobile payment interface classThinkPHP5.0 integrates Alipay mobile payment interface classThinkPHP5.0 integrates Alipay mobile payment interface class

Code part: //Alipay payment<br> function alipay_before(){<br> $mid = $ this- & gt; is_login (); <br> require_once extend_path.'alipay/alipaycore.php '; _ID = Input ("Request.order_id"); <br> IF ($ order_id == 0){<br>             ajaxmsg('illegal data', 0); <br>                                                                                                                                                               ajaxmsg( ; = 'Order payment '; //Product details <br>           $alipay_config = Config::get('alipay_config'); <br>                                                 out out over's ‐ ‐                  ‐   ‐ ‐ out‐‐‐ through out <br>                                    '], // The collaborator ID<br>' Seller_id '= & GT; $ Alipay_config [' Seller_id '], <br>' OUT_TRADE_NO '= & GT; t '= & gt;' order Payment ', // Commodity name <br>' body '= & gt; $ body, product details <br>' total_fee '= & gt; $ total_fee, <br>' notify_url '= &CONFIG [' NOTIFY _url '], // The server asynchronous The path of the notification page s 'service' = & gt; $ alipay_config ['service'], // interface name <br> 'payment_type' = & gt; $ alipay_config ['payment_type'], // payment type <br> '_Input_charset' = & gt; $ alipay_config ['input_charset'],//Parameter encoding character set <br> );<br>​​​​ //Concatenate all the elements of the array received by post into a string using the "&" character according to the "parameter = parameter value" pattern. <br>                                                                                                                             use   with use using   to be signed. log.txt in the log folder under the project directory. <br>                                                                                                                                                                                                          urlencode 'Private_key'])); <br><br> // Sect the signature and signature type sign_type behind the name string to be signed. <br>         $data = $data.'&sign='.'"'.$rsa_sign.'"'.'&sign_type='.'"'.$alipay_config['sign_type'].'"';<br><br>                                                                                                                                                                ​On the client side, it is recommended to use the public key corresponding to the private key to perform a signature verification to ensure that it was not transmitted by others. <br>        //echo $data;<br>        $list['form'] = $data;<br>        ajaxmsg('ok',1,$list);<br>    }<br>支付后通知接口:<br>    //支付宝支付通知<br>    public function alipay_notify_url () <br> {a $ alipay_config = config :: get ('alipay_config'); <br> // Calculate the notification verification results $ alipaynotify = new alipaynotify ($ alipay_config); $ alipaynotify- & gt; getResponse ($ _ post ['notify_id']))//After the judgment is successful, use the getResponse method to judge whether it is an asynchronous notification sent by Alipay. ({ if ($ alipaynotify-& gt; getSignVeryfy ($ _ pos, $ _post ['sign'])) {// Use Alipay Key Examination <br><br> // —— Please write the program based on your business logic (following Code is for reference only) - <br>                                                                                                                         using to ‐ to get notification return parameter from Alipay. <br>                // Alipay Transaction number <br>             $trade_no = $_POST['trade_no'];<br><br>                               If($_POST['trade_status'] == 'TRADE_FINISHED') { <br>                                                                                                                                                                         having Business procedures <br>                                                                             using using                                                      //After the refund date exceeds the refundable period (e.g., refundable within three months), the Alipay system will send a notification of the transaction status <br>                                                                                    // Please make sure that the total_fee, seller_id at the time of request are consistent with the total_fee, seller_id obtained at the time of notification <br>} s s else if ($ _post ['trade_status'] ==' trade_success') {<br> $ order_info = db :: name ("order")-& gt; where ("order_sn = '{$ OUT_TRA de_no} '")) -> find(); :name("order")->where("id= {$order_info['id']}")->save(<br>                                                                                                                                                                                                                                                                                  "pay_sn"=>$trade_no,<br> "pay_time"=>time(),<br> 'stauts'=>1<br>                                                                                                                   <br>                                                                                                                                                                                                                                                                                                      U Echo "Success"; // Please do not modify or delete}}}} else // Verify the signature failure {<br> echo "sign fail"; "response fail";<br>          }<br>      }<br>                                                                                                                     What I wrote is a standard ordering process, mainly <br> To wake up the Alipay client, waking up Alipay is the first step, indicating that the protocol, account number, and key method are all consistent. <br>The second step is to accept the notification from Alipay after the payment is successful and detail the database on your server. <br>Prevent repeated updates of orders and user fund accounts. <br><br>I have pasted the code. Just put the source code package I integrated directly into the extend directory and call it directly in the controller. <br>Be sure to write the configuration file correctly, especially how to generate the public key and private key, and upload it to the Alipay platform center. <br><br>Technical exchange group: <strong>495654168</strong><br>

ThinkPHP5.0 integrates Alipay mobile payment interface class Alipay.zip ( 140.02 KB Download: 24 times )

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn