下单:
public function charge(Request $request)
{
$config = [
'app_id' => 'appID',
'mch_id' => '商户号',
'key' => '秘钥',
'notify_url' => 'http://lp.llons.com/api/chargeBack',
];
$app = Factory::payment($config);
$result = $app->order->unify([
'body' => '套餐充值',
'out_trade_no' => '订单号',
'total_fee' => '价钱',
'trade_type' => 'JSAPI',
'openid' => '',
]);
$jssdk = $app->jssdk;
$pay = $jssdk->sdkConfig($result['prepay_id']);
return success([
'result' =>$pay
]);
}
支付回调:就是一个非常纯粹的POST请求接口
public function chargeBack()
{
$config = [
'app_id' => 'appID',
'mch_id' => '商户号',
'key' => '秘钥',
];
$app = Factory::payment($config);
$response = $app->handlePaidNotify(function($message, $fail){
if ($message['return_code'] === 'SUCCESS' &&
$message['result_code'] === 'SUCCESS') {
} else {
return $fail('通信失败,请稍后再通知我');
}
return true;
});
$response->send();
}
退款回调
public function wecharRefundBack()
{
$config = [
'app_id' => 'appID',
'mch_id' => '商户号',
'key' => '秘钥',
'cert_path' => '',
'key_path' => '',
'notify_url' => ''
];
$app = Factory::payment($config);
$response = $app->handleRefundedNotify(function ($message, $reqInfo, $fail) {
if ($message['return_code'] === 'SUCCESS' && $reqInfo['refund_status'] === 'SUCCESS') {
$this->focusSend($order['class_id'], $order['student_id']);
} else {
return $fail('通信失败,请稍后在通知我');
}
return true;
});
$response->send();
}
退款:可以根据订单号或者支付单号退款。这里自根据支付单号
public function wechatRefund($transactionId, $totalFee, $refundFee)
{
$config = [
'app_id' => 'appID',
'mch_id' => '商户号',
'key' => '秘钥',
'cert_path' => '',
'key_path' => '',
'notify_url' => ''
];
$app = Factory::payment($config);
$a = get_refund_num();
$result = $app->refund->byTransactionId($transactionId, $a, $totalFee * 100, $refundFee * 100, [
'refund_desc' => '班级退课',
'notify_url' => ''
]);
}
(做的笔记,自己看的)
|