With the popularity of mobile payment, WeChat payment, as the most popular third-party payment method on the market, has become more and more common in our daily lives. Especially in the field of e-commerce, the usage rate of WeChat payment has increased significantly and it has become an indispensable payment method for many merchants. This article will introduce the basic process and technical principles of WeChat payment to help PHP developers better understand and apply WeChat payment. Let’s first take a look at the basic process of WeChat payment.
Basic process of WeChat payment
The basic process of WeChat payment can be divided into the user placing an order on the merchant APP or H5 page, the merchant calling the WeChat payment API to pay, WeChat returning the transaction results, and the merchant receiving the payment. Notice the four steps.
Specifically, when a user places an order on a merchant APP or H5 page, the merchant needs to pass the order information to the WeChat payment platform, and after the payment processing of the WeChat payment platform, the payment result is returned. When the payment result is returned, the merchant performs corresponding business processing based on the transaction result and displays the transaction result to the user.
WeChat payment flow chart:
WeChat payment technology principle
WeChat payment technology principle mainly consists of three parts: WeChat payment API, WeChat payment platform, and merchant system. Let’s take a look at the WeChat payment API first.
WeChat Payment API
When the merchant system initiates a payment request through WeChat Pay, it needs to send the payment request to the WeChat Payment platform through the WeChat Payment API. The WeChat payment API is a set of RESTful interfaces that are highly readable and easy to use. It mainly includes interfaces such as unified order placing, order query, order closing, refund application, and refund inquiry. Below we mainly introduce the use of the unified ordering interface.
Steps for using the unified ordering interface
Unified order interface calling example:
<?php require_once "WxPay.Api.php"; $input = new WxPayUnifiedOrder(); $input->SetBody("test"); $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis")); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url("http://www.example.com/wxpay/notify.php"); $input->SetTrade_type("APP"); $order = WxPayApi::unifiedOrder($input); print_r($order); ?>
Unified order interface calling example:
$parameters = [ 'appid' => $app_id, 'partnerid' => $mch_id, 'prepayid' => $prepay_id, 'package' => 'Sign=WXPay', 'noncestr' => $nonce_str, 'timestamp' => $timestamp, ]; ksort($parameters); $string = ''; foreach ($parameters as $key => $value) { $string .= $key . '=' . $value . '&'; } $string .= 'key=' . $key; $parameters['sign'] = strtoupper(md5($string));
WeChat payment platform
WeChat payment platform is a payment service platform of WeChat, which mainly consists of payment, settlement and clearing composed of other modules. The payment module is responsible for receiving and processing payment requests issued by merchants, and receiving and processing payment result notifications; the settlement module is responsible for merchant settlement, including merchant settlement inquiries, settlement strategy configuration, and generation of settlement lists; the liquidation module is responsible for regular liquidation and management Financial affairs of each functional module of the WeChat payment platform.
Merchant System
The merchant system is the client of WeChat payment and is responsible for receiving and processing various payment requests initiated by the WeChat payment platform and performing corresponding payment operations. The merchant system mentioned in this article mainly refers to the PHP merchant system, which transfers order information, obtains prepayment order numbers, obtains payment parameters and other basic payment operations by calling the WeChat payment API.
Summary
With the popularity and promotion of WeChat Pay in the domestic market, its technical principles and usage methods have become more and more mature. Developers need to understand the basic principles and usage of WeChat Pay in order to better apply WeChat Pay technology to meet users' payment needs. This article mainly introduces the basic process and technical principles of WeChat payment, hoping to be helpful to PHP developers.
The above is the detailed content of PHP WeChat payment flow chart idea analysis. For more information, please follow other related articles on the PHP Chinese website!