1. Go to this page and download the library: Download labs7in0/omnipay-wechat library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
labs7in0 / omnipay-wechat example snippets
$omnipay = Omnipay::create('WeChat_Express');
$omnipay->setAppId('app_id'); // App ID of your WeChat MP account
$omnipay->setAppKey('app_key'); // App Key of your WeChat MP account
$omnipay->setMchId('partner_id'); // Partner ID of your WeChat merchandiser (WeChat Pay) account
$params = array(
'out_trade_no' => time() . rand(100, 999), // billing id in your system
'notify_url' => $notify_url, // URL for asynchronous notify
'body' => $billing_desc, // A simple description
'total_fee' => 0.01, // Amount with less than 2 decimals places
'fee_type' => 'CNY', // Currency name from ISO4217, Optional, default as CNY
);
$response = $omnipay->purchase($params)->send();
$qrCode = new Endroid\QrCode\QrCode(); // Use Endroid\QrCode to generate the QR code
$qrCode
->setText($response->getRedirectUrl())
->setSize(120)
->setPadding(0)
->render();
$omnipay = Omnipay::create('WeChat_Express');
$omnipay->setAppId('app_id'); // App ID of your WeChat MP account
$omnipay->setAppKey('app_key'); // App Key of your WeChat MP account
$omnipay->setMchId('partner_id'); // Partner ID of your WeChat merchandiser (WeChat Pay) account
$params = array(
'out_trade_no' => $billing_id, // billing id in your system
//or you can use 'transaction_id', the trade number from WeChat
);
$response = $omnipay->completePurchase($params)->send();
if ($response->isSuccessful() && $response->isTradeStatusOk()) {
$responseData = $response->getData();
// Do something here
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.