后端代码
php
public function test(){
$config = [
// 必要配置
'app_id' => 'app_id',
'mch_id' => 'mch_id',
'key' => 'key', // API v2 密钥 (注意: 是v2密钥 是v2密钥 是v2密钥)
// 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
'cert_path' => 'cert/apiclient_cert.pem', // XXX: 绝对路径!!!!
'key_path' => 'cert/apiclient_key.pem', // XXX: 绝对路径!!!!
'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它
];
$app = Factory::payment($config);
$now = time();
$outTradeNo = date('YmdHis', $now) . rand(1000, 9999);
$redpackData = [
'mch_billno' => '商户订单号',
'send_name' => '测试红包',
're_openid' => '用户openid',
'total_num' => 1, //固定为1,可不传
'total_amount' => 100, //单位为分,不小于100
'wishing' => '祝福语',
'act_name' => '测试活动',
'remark' => '测试备注',
];
$redpack = $app->redpack;
$result = $redpack->sendMiniprogramNormal($redpackData);
Log::info('===红包==='); // 打印日志
Log::info($result);
}
日志
php
[2024-11-01 20:37:06] local.INFO: ===红包===
[2024-11-01 20:37:06] local.INFO: array (
'return_code' => 'SUCCESS',
'return_msg' => '发放成功',
'result_code' => 'SUCCESS',
'err_code' => 'SUCCESS',
'err_code_des' => '发放成功',
'mch_billno' => '20241100000000000',
'mch_id' => '000000000',
'wxappid' => 'wx2a00000000000000',
're_openid' => 'oIBWo5Q2D_ei5H000000',
'total_amount' => '100',
'send_listid' => '1000041701202000000000000',
)