You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
12 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace ali\alipay\pay;
use Alipay\EasySDK\Kernel\Factory;
class AliPay extends \ali\alipay\Base
{
/**
* 支付宝手机APP支付接口名称alipay.trade.app.pay
* @param float $money 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]金额不能为0
* @param string $order_number 商户网站唯一订单号。由商家自定义64个字符以内仅支持字母、数字、下划线且需保证在商户端不重复。
* @param string $body 订单标题。注意:不可使用特殊字符,如 /=& 等。
* @param string $notify_url 支付宝服务器主动通知商户服务器里指定的页面http/https路径。
* @date 2021-10-25
*/
public function aliPay($money, $order_number, $body, $notify_url)
{
Factory::setOptions($this->getOptions($notify_url));
$result = Factory::payment()->app()->pay($body, $order_number, round($money, 2));
$result = $result->toMap();
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'body' => $body,
'order_number' => $order_number,
'money' => round($money, 2),
'notify_url' => $notify_url
], $result, 'alipaysdk_pay_app_alipay_uid_' . $uid);
return $result;
}
/**
* 支付宝小程序支付接口名称alipay.trade.create
* @param float $money 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]金额不能为0
* @param string $order_number 商户网站唯一订单号。由商家自定义64个字符以内仅支持字母、数字、下划线且需保证在商户端不重复。
* @param string $buyer_id 买家的支付宝唯一用户号2088开头的16位纯数字
* @param string $body 订单标题。注意:不可使用特殊字符,如 /=& 等。
* @param string $notify_url 支付宝服务器主动通知商户服务器里指定的页面http/https路径。
* @date 2021-10-25
*/
public function mpAliPay($money, $order_number, $buyer_id, $body, $notify_url)
{
Factory::setOptions($this->getOptions($notify_url));
$result = Factory::payment()->common()->create($body, $order_number, round($money, 2), $buyer_id);
$result = $result->toMap();
$result['http_body'] = json_decode($result['http_body'], true);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'body' => $body,
'order_number' => $order_number,
'money' => round($money, 2),
'buyer_id' => $buyer_id,
'notify_url' => $notify_url
], $result['http_body']['alipay_trade_create_response'], 'alipaysdk_pay_mp_alipay_uid_' . $uid);
return $result['http_body']['alipay_trade_create_response'];
}
/**
* 支付宝H5支付接口名称alipay.trade.wap.pay
* @param float $money 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]金额不能为0
* @param string $order_number 商户网站唯一订单号。由商家自定义64个字符以内仅支持字母、数字、下划线且需保证在商户端不重复。
* @param string $body 订单标题。注意:不可使用特殊字符,如 /=& 等。
* @param string $quit_url 用户付款中途退出返回商户网站的地址
* @param string $return_url 支付成功后同步跳转的页面是一个http/https开头的字符串
* @param string $notify_url 支付宝服务器主动通知商户服务器里指定的页面http/https路径。
* @date 2021-10-25
*/
public function h5AliPay($money, $order_number, $body, $quit_url, $return_url, $notify_url)
{
Factory::setOptions($this->getOptions($notify_url));
$result = Factory::payment()->wap()->pay($body, $order_number, round($money, 2), $quit_url, $return_url);
$result = $result->toMap();
// Factory::setOptions($this->getOptions($notify_url));
//
// $result = Factory::util()->generic()->sdkExecute('alipay.trade.wap.pay', [], [
// 'out_order_no' => $order_number,
// 'total_amount' => round($money, 2),
// 'subject' => $body,
// 'product_code' => 'QUICK_WAP_WAY', //销售产品码商家和支付宝签约的产品码。手机网站支付为QUICK_WAP_WAY
// 'quit_url' => $quit_url,
// ]);
//
// $result = $result->toMap();
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'body' => $body,
'order_number' => $order_number,
'money' => round($money, 2),
'notify_url' => $notify_url,
'quit_url' => $quit_url,
'return_url' => $return_url
], $result, 'alipaysdk_pay_h5_alipay_uid_' . $uid);
return $result;
}
/**
* 支付宝订单退款接口名称alipay.trade.refund
* @param string $order_number 原订单单号。
* @param string $refund_number 退款单号。商户网站唯一订单号。由商家自定义64个字符以内仅支持字母、数字、下划线且需保证在商户端不重复。
* @param float $refund_money 需要退款的金额,该金额不能大于订单金额,单位为元,支持两位小数
* @date 2021-10-28
*/
public function refund($order_number, $refund_number, $refund_money)
{
//20220126 支付退款,如果是部分退款必须要传递退款订单编号 原SDK存在BUG 采用通用接口传值
// Factory::setOptions($this->getOptions());
//
// $result = Factory::payment()->common()->refund($order_number, round($refund_money, 2));
//
// $result = objectToArray($result);
// $result['httpBody'] = objectToArray(json_decode($result['httpBody']));
//
// return $result;
Factory::setOptions($this->getOptions());
$result = Factory::util()->generic()->execute('alipay.trade.refund', [], [
'out_trade_no' => $order_number,
'refund_amount' => round($refund_money, 2),
'out_request_no' => $refund_number
]);
$result = $result->toMap();
$result['http_body'] = json_decode($result['http_body'], true);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'out_trade_no' => $order_number,
'refund_amount' => round($refund_money, 2),
'out_request_no' => $refund_number
], $result['http_body']['alipay_trade_refund_response'], 'alipaysdk_pay_refund_uid_' . $uid);
return $result['http_body']['alipay_trade_refund_response'];
}
/**
* 线上资金授权冻结窗口接口名称alipay.fund.auth.order.app.freeze
* @param float $money 需要冻结的金额,单位为:元(人民币),精确到小数点后两位。取值范围:[0.01,100000000.00]
* @param string $order_number 商户授权资金订单号。商家自定义需保证在商户端不重复。仅支持字母、数字、下划线。(商户本次资金操作的请求流水号,用于标示请求流水的唯一性。)
* @param string $body 订单标题。业务订单的简单描述,如商品名称等
* @param string $notify_url 支付宝服务器主动通知商户服务器里指定的页面http/https路径。
* @date 2021-10-25
*/
public function freeze($money, $order_number, $body, $notify_url)
{
Factory::setOptions($this->getOptions($notify_url));
$result = Factory::util()->generic()->sdkExecute('alipay.fund.auth.order.app.freeze', [], [
'out_order_no' => $order_number,
'out_request_no' => $order_number,
'order_title' => $body,
'amount' => round($money, 2),
'product_code' => 'PRE_AUTH_ONLINE', //销售产品码。支付宝预授权产品固定为 PRE_AUTH_ONLINE
'payee_logon_id' => $this->config['payee_logon_id'], //收款账户的支付宝登录号email或手机号。如果传入则会校验该登录号对应的账号是否具备当前商户收款权限如果商户希望用户能够使用花呗则用户号(payee_user_id)和登录号(payee_logon_id)两者必须传入其一
]);
$result = $result->toMap();
return $result;
}
/**
* 资金授权解冻接口接口名称alipay.fund.auth.order.unfreeze
* @param float $money 本次操作解冻的金额,单位为:元(人民币),精确到小数点后两位。 取值范围:[0.01,100000000.00]
* @param string $order_number 解冻请求流水号。如果是针对同一笔授权单不同的解冻请求如第一次解冻1元第二次解冻2元则解冻请求流水号必须不重复如果是针对同一笔解冻请求的多次发起则需要保证每次发起解冻请求流水号和解冻金额都相同
* @param string $auth_no 支付宝资金授权订单号。
* @param string $remark 商户对本次解冻操作的附言描述
* @date 2021-10-25
*/
public function unfreeze($money, $order_number, $auth_no, $remark)
{
Factory::setOptions($this->getOptions());
$result = Factory::util()->generic()->execute('alipay.fund.auth.order.unfreeze', [], [
'auth_no' => $auth_no,
'out_request_no' => $order_number,
'amount' => round($money, 2),
'remark' => $remark,
]);
$result = $result->toMap();
$result['http_body'] = json_decode($result['http_body'], true);
return $result['http_body']['alipay_fund_auth_order_unfreeze_response'];
}
/**
* 统一收单交易支付接口--预授权支付接口名称alipay.trade.pay
* @param float $money 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
* @param string $order_number 交易创建时传入的商户订单号
* @param string $body 订单标题。订单标题
* @param string $auth_code 支付授权码,即买家的付款码数字
* @param string $notify_url 可不填有同步返回结果。支付宝服务器主动通知商户服务器里指定的页面http/https路径。
* @date 2021-10-25
*/
public function freezePay($money, $order_number, $body, $auth_code, $notify_url = '')
{
Factory::setOptions($this->getOptions($notify_url));
$result = Factory::util()->generic()->execute('alipay.trade.pay', [], [
'out_trade_no' => $order_number,
'total_amount' => round($money, 2),
'subject' => $body,
'product_code' => 'PRE_AUTH_ONLINE',
'auth_no' => $auth_code
]);
$result = $result->toMap();
$result['http_body'] = json_decode($result['http_body'], true);
return $result['http_body']['alipay_trade_pay_response'];
}
/**
* 异步通知验签
* @param array $parameters 接收到的所有参数
* @date 2021-10-25
*/
public function verifyNotify($parameters)
{
Factory::setOptions($this->getOptions());
$result = Factory::payment()->common()->verifyNotify($parameters);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog($parameters, $result, 'alipaysdk_pay_check_sign_uid_' . $uid);
return $result;
}
/**
* 资金授权操作查询接口接口名称alipay.fund.auth.operation.detail.query
* @param string $order_number 商户的授权资金订单号。该值与资金冻结时 out_order_no一致。(同商户的授权资金操作流水号。)
* @date 2021-10-25
*/
public function freezeQuery($order_number)
{
Factory::setOptions($this->getOptions());
$result = Factory::util()->generic()->execute('alipay.fund.auth.operation.detail.query', [], [
'out_order_no' => $order_number,
'out_request_no' => $order_number,
]);
$result = $result->toMap();
$result['http_body'] = json_decode($result['http_body'], true);
return $result['http_body']['alipay_fund_auth_operation_detail_query_response'];
}
}