1. Go to this page and download the library: Download itc/weixin-payment 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/ */
// execute the "pay/unifiedorder" command; the result is a Message instance
$result = $client->command('pay/unifiedorder')->execute([
'openid' => 'wx_9f8a98g9a8geag0',
'trade_type' => 'JSAPI',
'out_trade_no' => 'your-order-id',
'total_fee' => 1000,
]);
// authenticate the result
$authentic = $result->authenticate();
// if a prepay_id is in the Message, the payment is ready to execute
if ($authentic && $prepay_id = $result->get('prepay_id'))
{
// jsapize() returns a JsonSerializable object
$jsbridge_params = $client->jsapize(['prepay_id'=>$prepay_id]);
}
// create a Message instance with the "return_code" attribute
$message = $client->message(['return_code'=>'FAIL']);
// query a payment by wechat transaction id
$result = $client->command('pay/orderquery')->execute([
'transaction_id' => '1008450740201411110005820873'
]);
// or by domain order id ("out_trade_no")
$result = $client->command('pay/orderquery')->execute([
'out_trade_no' => 'domain-order-id'
]);