code-lives/baidu

百度小程序(支付、手机号解密、获取Token、支付异步通知、退款、订单查询、分账、模版消息)

1.0.0 2023-07-26 08:40 UTC

This package is auto-updated.

Last update: 2024-12-18 05:29:55 UTC


README

GitHub forks GitHub forks GitHub forks

安装

composer require code-lives/baidu 1.0.0

⚠️ 注意

金额单位分 100=1 元

返回结果 array 由开发者自行判断

预下单

<?php

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

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

百度小程序

Config

Token

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

Openid

$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;
}