PHP code example of abbotton / alipay-sdk

1. Go to this page and download the library: Download abbotton/alipay-sdk 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/ */

    

abbotton / alipay-sdk example snippets


   // 通过密钥文件创建(推荐)
    $keyPair = \Alipay\Key\AlipayKeyPair::create(
        __DIR__ . '/private.pem',
        __DIR__ . '/public.pem'
    );
   
   // 通过密钥字符串创建
   $privateKey = '-----BEGIN RSA PRIVATE KEY-----
   // ......
   kXTZhB4nQqZXWFu8R+RdqC6gTh9k2dDz0NlibYSW9xApWRN572M9/n737110Yxa2
   JZX27eBHLqR8aCZcXkADRpe9+yAL9SqErEOMh26nWFtwP5ZugHRf
    -----END RSA PRIVATE KEY-----';
   $publicKey = '-----BEGIN PUBLIC KEY-----
   // ......
    C9ykBV6BfujeeVQ2wUdpxFtI4gW8A4rgqecMvbL/KngU+aChG+W6SGXD8QY0fC4d
    4QIDAQAB
    -----END PUBLIC KEY-----';
   $keyPair = \Alipay\Key\AlipayKeyPair::create($privateKey, $publicKey);
    

    $aop = new \Alipay\AopClient('APP_ID', $keyPair);
    

   $bizContent = [
        'start_time' => '2021-08-01 00:00:00',
        'end_time' => '2021-08-31 23:59:59',
        'type' => 'TRANSFER',
        'page_no' => 1
   ];
   
   // 通过工厂类创建
    $request = (new \Alipay\AlipayRequestFactory)->create('alipay.data.bill.transfer.query', [
        'biz_content' => $bizContent,
        // ...
    ]);
   
   // 直接创建
   $request = (new \Alipay\Request\AlipayRequest())
        ->setApiMethodName('alipay.data.bill.transfer.query')
        ->setBizContent($bizContent);
    

    $result = $aop->execute($request)->getData();