code-lives/baidu-pay

百度小程序支付、订单查询、退款、支付回调、获取token

dev-main 2021-11-02 08:13 UTC

This package is auto-updated.

Last update: 2024-05-31 00:19:49 UTC


README

官方接口文档

说明(重要)

支付回调一定要保存userId 退款需要。

Config 参数

参数名字 类型 必须 说明
appid string 百度小程序appkey(退款必须)
appkey string 百度小程序appkey
payappKey string 百度小程序支付appkey
appSecret string 百度小程序aapSecret
dealId int 百度小程序支付凭证
rsaPriKeyStr string 私钥(只需要一行长串,不需要文件)
rsaPubKeyStr string 百度小程序支付的平台公钥(支付回调需要)

安装

   composer require code-lives/baidu-pay

Demo

    $config = [
    	'appid'=>'abcdef',
	'appkey' => 'abcdef',
	'payappKey' => "MMMMMMMM",
	'appSecret' => 'ABCDEF',
	'dealId' => 123456,
	'rsaPriKeyStr' => "ABCDEF",
	'rsaPubKeyStr' => 'ABCDEF',
    ];

初始化

    //use Baidu\Pay\Pays;
    $Baidu = new Pays($config);

获取token

    $Baidu = new Pays($config);
    $result = $Baidu->getToken();

支付参数配置

参数名字 类型 必须 说明
order string 平台订单号
money int 金额
desc string 订单描述

Demo

    $result = $Baidu->getOrderParm($order, $money, $desc);

订单查询参数配置

参数名字 类型 必须 说明
access_token string 根据上面的获取token
tpOrderId string 平台订单号
    $order = [
	'access_token' => 'abcde',
	'tpOrderId' => '123456',
    ];
    $result = $Baidu->findOrder($order);

退款参数配置

参数名字 类型 必须 说明
token string 根据上面的获取token
bizRefundBatchId int 百度平台的订单号
isSkipAudit int 默认为0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。
orderId int 百度平台的订单号
refundReason string 退款描述
refundType int 退款类型 1:用户发起退款;2:开发者业务方客服退款;3:开发者服务异常退款。百度小程序支付的平台公钥
tpOrderId string 自己平台订单号
userId int 用户uid(不是自己平台uid)

Demo

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

支付异步通知

    $Baidu->notifyCheck($_POST); //返回 true false