1. Go to this page and download the library: Download ccob/omnipay-wechatpay 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/ */
ccob / omnipay-wechatpay example snippets
use Omnipay\Omnipay;
$gateway = Omnipay::create( 'WechatPay' );
$gateway->setAppId( 'Your appid here.' );
$gateway->setMchId( 'Your mch_id here.' );
$gateway->setKey( 'Your key for WeChat payment here.' );
$gateway->setTradeType( 'JSAPI' );
$gateway->setAttach( 'test' );
$gateway->setBody( 'test' );
$gateway->setGoodsTag( 'test' );
$gateway->setOutTradeNo( 'Unique order id in your site.' );
$gateway->setTotalFee( 1 );
$gateway->setSpbillCreateIP( Request::ip() );
$gateway->setNotifyUrl( 'http://test.com/pay/notify' );
$response = $gateway->createUnifiedOrder()->send(); // Get prepay_id, code_url etc.
$package = $response->createWebPaymentPackage(); // Get payment parameters for web
use Omnipay\Omnipay;
$request_content = file_get_contents('php://input');
$gateway = Omnipay::create( 'WechatPay' );
$gateway->setKey( 'Your key for WeChat payment here.' );
$complete_request = $gateway->completeOrder( $request_content ); // Auto convert xml string to array
$complete_response = $complete_request->send();
$complete_response->isResultSuccessful();
$complete_response->isResponseSuccessful();
/**
* Would get xml string followed while function 'isResultSuccessful' return Boolean true:
* <xml><return_code><![CDATA[SUCCESS]]></return_code></xml>
* Or string followed while false
* <xml><return_code><![CDATA[FAIL]]></return_code></xml>
*/
$complete_response->getResponseText();