PHP code example of code-lives / baidu

1. Go to this page and download the library: Download code-lives/baidu 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/ */

    

code-lives / baidu example snippets


composer 



//引入命名空间
use Applet\Assemble\Baidu;

$pay= Baidu::init($config)->set("订单号","金额","描述","描述")->getParam();


$data= Baidu::init($config)->getToken();

$code="";
$data= Baidu::init($config)->getOpenid($code);

$data= Baidu::init($config)->decryptPhone($session_key, $iv, $ciphertext);
echo $phone['mobile'];

$Baidu = Baidu::init($config);
$order = [
        'tpOrderId' => '',//订单号
        'access_token' => $Baidu->getToken()['access_token'],
    ];
$data = $Baidu->findOrder($order);

$order = [
'token' => 'abcd',
'bizRefundBatchId' => 123456,//百度平台订单号
'isSkipAudit' => 1,
'orderId' => 123456,
'refundReason' => '测试退款',
'refundType' => 2,//
'tpOrderId' => '123',//自己平台订单号
'userId' => 123,
];
$data= Baidu::init($config)->applyOrderRefund($order);

$data = [
    "touser_openId" => "",
    "template_id" => "",
    "page" => "pages/index/index",
    "subscribe_id" => '百度from组件subscribe-id 一致',
    "data" => json_encode([
        'keyword1' => ['value' => "第一个参数"],
        'keyword2' => ['value' => "第二个参数"],
        'keyword3' =>  ['value' => "第三个参数"],
    ])
];
$data= Baidu::init($config)->sendMsg($data,$token);
$data=[
   "errno" => 0,
    "msg" => "success",
    "data" => array=> [
    "msg_key" => 1663314134696897
  ]
]

$pay = Baidu::init($config);
$status = $pay->notifyCheck();//验证
if($status){
    $order = $pay->getNotifyOrder();
    //$order['tpOrderId']
    //$order['orderId']
    //$order['userId']
    echo 'success';exit;
}