|
|
<?php
|
|
|
|
|
|
namespace fubei\pay;
|
|
|
|
|
|
|
|
|
use fubei\Base;
|
|
|
|
|
|
class Pay extends Base
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 统一下单
|
|
|
* @param string $user_id 用户标识(微信openid,支付宝userid)
|
|
|
* @param float $money 订单总金额,单位为元,精确到0.01 ~ 10000000
|
|
|
* @param string $order_number 订单的唯一标识
|
|
|
* @param string $fubei_order_number 外部系统订单号(确保唯一,前后不允许带空格)
|
|
|
* @param string $body 商品描述
|
|
|
* @param string $notify_url 支付回调地址
|
|
|
* @param string $store_id 商户门店号(如果只有一家有效门店,可不传)
|
|
|
* @param string $user_agent 平台 mp_weixin--微信小程序 weixin--微信公众号 mp_alipay--支付宝小程序
|
|
|
* @date 2022-03-11
|
|
|
*/
|
|
|
public function pay($user_id, $money, $order_number, $fubei_order_number, $body = '', $notify_url = '', $store_id = '', $user_agent = 'weixin')
|
|
|
{
|
|
|
//公共参数
|
|
|
$common_data = [
|
|
|
'method' => 'fbpay.order.create',
|
|
|
];
|
|
|
|
|
|
//业务参数
|
|
|
$biz_content = [
|
|
|
'merchant_order_sn' => $fubei_order_number, //外部系统订单号(确保唯一,前后不允许带空格)
|
|
|
'total_amount' => (string)round($money, 2), //订单总金额,单位为元,精确到0.01 ~ 10000000
|
|
|
'store_id' => $store_id, //商户门店号(如果只有一家有效门店,可不传)
|
|
|
'user_id' => $user_id, //用户标识(微信openid,支付宝userid)
|
|
|
'notify_url' => $notify_url,
|
|
|
'attach' => json_encode([
|
|
|
'order_number' => $order_number
|
|
|
])
|
|
|
];
|
|
|
if ($user_agent == 'weixin' || $user_agent == 'mp_weixin') {
|
|
|
$biz_content['pay_type'] = 'wxpay'; //支付方式 wxpay--微信 aipay--支付宝
|
|
|
$biz_content['sub_appid'] = $this->config['sub_appid']; //公众号appid。当微信支付时,该字段必填(user_id需要保持一致,即为该公众号appid获取的)
|
|
|
} else if ($user_agent == 'mp_alipay') {
|
|
|
$biz_content['pay_type'] = 'alipay';
|
|
|
}
|
|
|
if (!empty($body)) {
|
|
|
$biz_content['body'] = $body;
|
|
|
}
|
|
|
|
|
|
$result = $this->actionApi($common_data, $biz_content);
|
|
|
|
|
|
// 记录日志
|
|
|
$uid = defined('UID') ? UID : '';
|
|
|
platformLog([
|
|
|
'common_data' => $common_data,
|
|
|
'biz_content' => $biz_content,
|
|
|
], $result, 'fubei_pay_uid_' . $uid);
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
} |