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.

63 lines
2.5 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 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;
}
}