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 "
Code part://Alipay payment
$ 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. ({
function alipay_before(){
$mid = $ this- & gt; is_login ();
require_once extend_path.'alipay/alipaycore.php '; _ID = Input ("Request.order_id");
IF ($ order_id == 0){
ajaxmsg('illegal data', 0);
ajaxmsg( ; = 'Order payment '; //Product details
$alipay_config = Config::get('alipay_config');
out out over's ‐ ‐ ‐ ‐ ‐ out‐‐‐ through out
'], // The collaborator ID
' Seller_id '= & GT; $ Alipay_config [' Seller_id '],
' OUT_TRADE_NO '= & GT; t '= & gt;' order Payment ', // Commodity name
' body '= & gt; $ body, product details
' total_fee '= & gt; $ total_fee,
' notify_url '= &CONFIG [' NOTIFY _url '], // The server asynchronous The path of the notification page s 'service' = & gt; $ alipay_config ['service'], // interface name
'payment_type' = & gt; $ alipay_config ['payment_type'], // payment type
'_Input_charset' = & gt; $ alipay_config ['input_charset'],//Parameter encoding character set
);
//Concatenate all the elements of the array received by post into a string using the "&" character according to the "parameter = parameter value" pattern.
use with use using to be signed. log.txt in the log folder under the project directory.
urlencode 'Private_key']));
// Sect the signature and signature type sign_type behind the name string to be signed.
$data = $data.'&sign='.'"'.$rsa_sign.'"'.'&sign_type='.'"'.$alipay_config['sign_type'].'"';
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.
//echo $data;
$list['form'] = $data;
ajaxmsg('ok',1,$list);
}
支付后通知接口:
//支付宝支付通知
public function alipay_notify_url ()
{a $ alipay_config = config :: get ('alipay_config');
// Calculate the notification verification resultsif ($ alipaynotify-& gt; getSignVeryfy ($ _ pos, $ _post ['sign'])) {// Use Alipay Key Examination
// —— Please write the program based on your business logic (following Code is for reference only) -
using to ‐ to get notification return parameter from Alipay.
// Alipay Transaction number
$trade_no = $_POST['trade_no'];
If($_POST['trade_status'] == 'TRADE_FINISHED') {
having Business procedures
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
// 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
} s s else if ($ _post ['trade_status'] ==' trade_success') {
$ order_info = db :: name ("order")-& gt; where ("order_sn = '{$ OUT_TRA de_no} '")) -> find(); :name("order")->where("id= {$order_info['id']}")->save(
"pay_sn"=>$trade_no,
"pay_time"=>time(),
'stauts'=>1
U Echo "Success"; // Please do not modify or delete}}}} else // Verify the signature failure {
echo "sign fail"; "response fail";
}
}
What I wrote is a standard ordering process, mainly
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.
The second step is to accept the notification from Alipay after the payment is successful and detail the database on your server.
Prevent repeated updates of orders and user fund accounts.
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.
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.
Technical exchange group: 495654168
Alipay.zip( 140.02 KB Download: 24 times )