PHP code example of huifurepo / dg-php-sdk

1. Go to this page and download the library: Download huifurepo/dg-php-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/ */

    

huifurepo / dg-php-sdk example snippets


    # 加载 SDK 初始化文件
    

    # 从文件导入商户系统参数
    BsPay::init(dirname(__FILE__). '/config/config_merch_default.json', false);
    
    # sdk也支持追加多套系统参数,并可以在调用接口时进行切换,适用于下辖多商户的系统接入
    BsPay::init(dirname(__FILE__). '/config/config_merch_2.json', false, "merchantKey2");
    BsPay::init(dirname(__FILE__). '/config/config_merch_3.json', false, "merchantKey3");
    ...
   

   # 导入初始化内容
   LE__). "/../BsPaySdk/request/V2MerchantBusiOpenRequest.php";
   

   # 创建请求Client对象,调用接口
    $client = new BsPayClient();
    $result = $client->postRequest($request);
   

   # 成功/失败应答的处理
   if (!$result || $result->isError()){  //失败处理
       var_dump($result -> getErrorInfo());
   } else {    //成功处理
       var_dump($result);
   }
   

   # 导入初始化内容
   LE__). "/../BsPaySdk/request/V2MerchantBusiOpenRequest.php";
   

    # 请求实例
    $request = new V2MerchantBusiOpenRequest();
    
    // 请求参数,不区分必填和可选,按照 api 文档 data 参数结构依次传入
    $param = array(
        "funcCode" => $request->getFunctionCode(),
        "params" => array(
            "req_seq_id" => date("YmdHis").mt_rand(),
            "req_date" => date("Ymd"),
            "huifu_id" => "6666000104778898",
            "upper_huifu_id" => "6666000003080000",
            "balance_pay_config" => json_encode(array(
                "fee_rate" =>"2",
                "fee_fix_amt" =>"1",
            ),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),
        ),
    );
   

   # 创建请求Client对象,调用接口
    $client = new BsPayClient();
    $result = $client->postRequest($param);
   

   # 成功/失败应答的处理
   if (!$result || $result->isError()){  //失败处理
       var_dump($result -> getErrorInfo());
   } else {    //成功处理
       var_dump($result);
   }
   

$data = array(
    'bank_code' =>'10000',
    'bank_message' =>'Success',
    'hf_seq_id' =>'002900TOP2B220511142822P984ac132ff400000',
    'huifu_id' =>'6666000108854952',
    'qr_code' =>'https://qr.alipay.com/bax04465kcijedllqhuq004b',
    'req_date' =>'20220511',
    'req_seq_id' =>'202205111428211506200',
    'resp_code' =>'00000100',
    'resp_desc' =>'下单成功',
    'trade_type' =>'A_NATIVE',
    'trans_amt' =>'1.00',
    'trans_stat' =>'P',
);
$sign = "OUotiU75VW7SdEwLIZX3gAqSgZk8hCjE7r01WQr8mDdm23B+zd58r8HNWvE9BWV+mTwZ2iAOSuht9SOGM+spSYFANa3VIqMZzGim3y4aZmptQTTptNcclocsWyocn78efdAuTcGvf5dhUc6/Ue1oYV+BVhphYPmkKUKfxpEvBEvw/vlpsCu0I0Dx/k7kN6IaxY6mODypFmDtnEaZbkGaxbh8yxH1lJDn5/91YfD6vpK+sRJXiVXLzDK13BPAjQ3RAlFUxHJ8LPJbWQQpABQ94Gd1TTc/bfOluqUwJJbofC7WZiIOW6MKsa9gL5Y6lmbqFcMBKfvexJ0SlRFLWvSkQg==";
$merConfig = BsPay::getConfig();
$result = BsPayTools::verifySign_sort($sign,$data,$merConfig->rsa_huifu_public_key);

$data = array(
    'bank_code' =>'10000',
    'bank_message' =>'Success',
    'hf_seq_id' =>'002900TOP2B220511142822P984ac132ff400000',
    'huifu_id' =>'6666000108854952',
    'qr_code' =>'https://qr.alipay.com/bax04465kcijedllqhuq004b',
    'req_date' =>'20220511',
    'req_seq_id' =>'202205111428211506200',
    'resp_code' =>'00000100',
    'resp_desc' =>'下单成功',
    'trade_type' =>'A_NATIVE',
    'trans_amt' =>'1.00',
    'trans_stat' =>'P',
);
$sign = 'dcc64089c44ea77cfde785de4cfa97ba';
$key = 'test_key';
$result = BsPayTools::verify_webhook_sign($sign,$data,$key);