66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Facades\WechatPayService;
|
|
use App\Http\Response\ResponseJson;
|
|
use Exception;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Log;
|
|
use TypeError;
|
|
|
|
class WechatPayController extends Controller
|
|
{
|
|
use ResponseJson;
|
|
function mchTransfer(Request $request)
|
|
{
|
|
$rules = [
|
|
"trade_no" => "required|string",
|
|
"scene_id" => "string",
|
|
"openid" => "required|string",
|
|
"amount" => "required|integer",
|
|
"remark" => "required|string",
|
|
"notify_url" => "required|url"
|
|
];
|
|
$input = $request->all();
|
|
$validator = Validator::make($input, $rules, $messages = [
|
|
'required' => 'The :attribute field is required.',
|
|
]);
|
|
|
|
foreach ($validator->errors()->all() as $message) {
|
|
return $this->failure($message);
|
|
}
|
|
|
|
|
|
$trade_no = $request->trade_no;
|
|
$scene_id = $request->scene_id;
|
|
if (empty($scene_id)) {
|
|
$scene_id = config("wechatpay.screen.commission");
|
|
}
|
|
$openid = $request->openid;
|
|
$amount = $request->amount;
|
|
$remark = $request->remark;
|
|
$notify_url = $request->notify_url;
|
|
$res = WechatPayService::mchTransfer($trade_no, $scene_id, $openid, $amount, $remark, $notify_url, []);
|
|
|
|
return $this->success("ok", $res);
|
|
}
|
|
|
|
function mchTransferCallback(Request $request)
|
|
{
|
|
$headers = [
|
|
'wechatpay-timestamp' => $_SERVER['HTTP_WECHATPAY_TIMESTAMP'] ?? '',
|
|
'wechatpay-nonce' => $_SERVER['HTTP_WECHATPAY_NONCE'] ?? '',
|
|
'wechatpay-signature' => $_SERVER['HTTP_WECHATPAY_SIGNATURE'] ?? '',
|
|
'wechatpay-serial' => $_SERVER['HTTP_WECHATPAY_SERIAL'] ?? '',
|
|
];
|
|
$body = $request->getContent();
|
|
Log::info("请求头", ["headers" => $headers]);
|
|
Log::info("请求体", ["body" => $body]);
|
|
$res = WechatPayService::mchTransferCallback($headers, $body);
|
|
Log::info("解密数据", ["data" => $res]);
|
|
return $this->success("ok", $res);
|
|
}
|
|
}
|