PHP code example of itc / weixin-payment

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/ */

    

itc / weixin-payment example snippets


$client = \ITC\Weixin\Payment\Client::instance([
    'app_id' => 'your appid',
    'secret' => 'your signing secret',
    'mch_id' => 'your merchant id',
    'public_key_path' => '/path/to/public_key',
    'private_key_path' => '/path/to/private_key',
]);

// 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']);

$message->set('foo', 1);
$message->set('bar', 'two');

// this adds a "sign" attribute to the Mesage instance
$message->sign();

$message->get('sign');
>>> "2C2B2A1D626E750FCFD0ED661E80E3AA"

$result = $client->command('pay/unifiedorder')->execute([/* ... */]);
$kosher = $result->authenticate();

    $result = $client->command('pay/unifiedorder')->execute([
        'openid' => 'wx_9f8a98g9a8geag0',
        'trade_type' => 'JSAPI',
        'out_trade_no' => 'domain-order-id',
        'total_fee' => 1000,
    ]);
    

    // 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'
    ]);
    

    $result = $client->command('pay/closeorder')->execute([/* ... */]);
    

    $result = $client->command('secapi/refund')->execute([/* ... */]);
    

    $result = $client->command('pay/refundquery')->execute([/* ... */]);
    

    $result = $client->command('pay/downloadbill')->execute([/* ... */]);
    

    $result = $client->command('payitil/report')->execute([/* ... */]);
    

    $result = $client->command('tools/shorturl')->execute([/* ... */]);
    

    $result = $client->command('mmpaymkttransfers/sendredpack')->execute([
        'mch_billno' => '10000098201411111234567890',
        'send_name' => '天虹百货',
        're_openid' => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
        'total_amount' => 1000,
        'total_num' => 1,
        'client_ip' => '192.168.0.1',
        'wishing' => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
        'act_name' => '猜灯谜抢红包活动',
        'remark' => '猜越多得越多,快来抢!',
    ]);
   

    $result = $client->command('mmpaymkttransfers/gethbinfo')->execute([
        'mch_billno' => '10000098201411111234567890',
        'bill_type' => 'MCHT',
    ]);
    

$client = App::make('ITC\Weixin\Payment\Contracts\Client');
javascript
var jsbridge_params =  echo json_encode($jsbridge_params)