//退款
public function refund(Request $request)
{
$userInfo = parent::getAuthenticatedUser($msg);
if (isset($userInfo['user']) && !empty($userInfo['user'])) {
$request->offsetSet('id', $userInfo['user']['id']);
} else {
return $this->sendResponse($msg, 'error', '', 401);
}
$config = [
// 必要配置
'app_id' => env('WECHAT_MINI_PROGRAM_APPID'),
'mch_id' => env('WECHAT_MINI_PROGRAM_MCH_ID'),
'key' => env('WECHAT_MINI_PROGRAM_KEY'), // API 密钥
// 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
/* 'cert_path' => './wechat_pay/apiclient_cert.pem', // XXX: 绝对路径!!!!
'key_path' => './wechat_pay/apiclient_key.pem', // XXX: 绝对路径!!!!*/
'notify_url' => env('URL') . '/api/pay/wxnotify', // 你也可以在下单时单独设置来想覆盖它
];
$app = $payment = Factory::payment($config);
$data = $request->all();
$orders = app(WalletRepositoryEloquent::class)->createRefundOrder($data);
$data = [
'partner_trade_no' => $orders['partner_trade_no'], // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
'openid' => $orders['openid'],
'check_name' => 'FORCE_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
're_user_name' => $orders['re_user_name'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
'amount' => $orders['amount'], // 企业付款金额,单位为分
'desc' => $orders['desc'], // 企业付款操作说明信息。必填
];
$app->transfer->toBalance($data);
return $this->sendResponse(trans('admin.operate_succeeded'), 'succ');
}