crmeb标准版系统对接收银呗支付接口文档

收银呗隶属于武汉融商创银科技有限公司,融商创银是国内移动支付解决方案服务商,以支付为切点,涵盖商户收银、会员营销、财务管理、卡券核销、店铺运营分析和金融服务等功能,为商户开展数字化经营提供合理的移动支付解决方案和技术支持。
CRMEB开源商城系统是一款全开源可商用的系统,前后端分离开发,全部100%开源,在小程序、公众号、H5、APP、PC端都能用,使用方便,二开方便!
本章内容主要讲解crmeb接入收银呗支付平台的在线支付功能。收银呗支付可以完美解决crmeb在小程序、公众号、H5、APP、PC端上的支付服务。
以下以微信小程序的对接为例,代码如下:

namespace crmeb\services\pay\storage;

use app\services\pay\PayServices;
use crmeb\exceptions\AdminException;
use crmeb\exceptions\PayException;
use crmeb\services\pay\BasePay;
use crmeb\services\pay\PayInterface;
use crmeb\services\pay\extend\shouyinbeipay\ShouyinbeiPay as ShouyinbeiPayService;
use EasyWeChat\Payment\Order;
use think\facade\Event;
use think\facade\Log;

/**
 * 收银呗
 * Class ShouyinbeiPay
 * @author 模板之家
 * @V xu08290201
 * @date 2023/2/1
 * @package crmeb\services\pay\storage
 */
class ShouyinbeiPay extends BasePay implements PayInterface
{

    /**
     * @var ShouyinbeiPayService
     */
    protected $pay;

    /**
     * @param array $config
     * @return mixed|void
     * @author 模板之家
     * @V xu08290201
     * @date 2024-05-10
     */
    protected function initialize(array $config)
    {
        $this->pay = new ShouyinbeiPayService([
            'orgId' => sys_config('shouyinbei_orgId'),
            'appId' => sys_config('shouyinbei_appId'),
            'privateKey' => sys_config('shouyinbei_private_key'),
            'publicKey' => sys_config('shouyinbei_public_key'),
            'businessCode' => sys_config('shouyinbei_businessCode'),
            'subAppid' => sys_config('routine_appId'),
            'notifyUrl' => trim(sys_config('site_url')) . '/api/pay/notify/shouyinbei',
            'isBeta' => false,
        ]);
    }

    /**
     * 创建支付
     * @param string $orderId
     * @param string $totalFee
     * @param string $attach
     * @param string $body
     * @param string $detail
     * @param array $options
     * @return array|mixed
     * @author 模板之家
     * @V xu08290201
     * @date 2024-05-10
     */
    public function create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = [])
    {
        $this->authSetPayType();

        $options['returl'] = sys_config('site_url') . '/pages/index/index';
        if ($options['returl']) {
            $options['returl'] = str_replace('http://', 'https://', $options['returl']);
        }
        $options['appid'] = sys_config('routine_appId');

        switch ($this->payType) {
            case Order::APP:
                return $this->pay->appPay($totalFee, $orderId, $body, '', '', false, $attach);
            case Order::JSAPI:
                if (request()->isRoutine()) {
                    return $this->pay->miniproPay($totalFee, $orderId, $body, $attach, $options);
                } else {
                    return $this->pay->h5Pay($totalFee, $orderId, $body, $options['returl'] ?? '', $attach);
                }
            case Order::NATIVE:
                return $this->pay->pcPay($totalFee, $orderId, $body, $attach, !empty($options['wechat']));
            default:
                throw new PayException('收银呗:支付类型错误或者暂不支持此环境下支付');
        }
    }

    public function merchantPay(string $openid, string $orderId, string $amount, array $options = [])
    {
        throw new PayException('收银呗:暂不支持商家转账');
    }

    /**
     * 发起退款
     * @param string $outTradeNo
     * @param array $options
     * @return array|mixed
     * @author 模板之家
     * @V xu08290201
     * @date 2024-05-10
     */
    public function refund(string $outTradeNo, array $options = [])
    {
        $result = $this->pay->refund($options, $outTradeNo);

        if (isset($result) && $result['data']['status'] === 'REFUND_FAIL') {
            throw new AdminException('退款失败');
        }
    }

    public function queryRefund(string $outTradeNo, string $outRequestNo, array $other = [])
    {
        // TODO: Implement queryRefund() method.
    }

    /**
     * 异步回调
     * @return mixed|string
     * @author 模板之家
     * @V xu08290201
     * @date 2024-05-10
     */
    public function handleNotify()
    {
        return $this->pay->handleNotify(function ($notify) {

            if (isset($notify['data']['orderNumber'])) {

                $data = [
                    'attach' => $notify['data']['attach'],
                    'out_trade_no' => $notify['data']['mercOrderNo'],
                    'transaction_id' => $notify['data']['orderNumber'],
                    'mercCode' => $notify['data']['mercCode']
                ];

                return Event::until('NotifyListener', [$data, PayServices::SHOUYINBEI_PAY]);
            }
            return false;
        });
    }

    /**
     * 退款异步回调
     * @return mixed|string
     */
    public function refundNotify()
    {
        $params = request()->post();

        if (count($params) < 1) {
            //如果参数为空,则不进行处理
            return "error";
        }

        $params['data'] = json_decode($params['bizContent'], true);

        if (isset($params['code']) && $params['code'] === '0000' && $params['data']['status'] === 'REFUND_SUCCESS') {
            //验签成功
            return 'success';
        } else {
            return "error";
        }
    }
}

因开发内容较多,在这里就不帖出全部代码了,欢迎各位开发者加我(V:xu08290201)一起交流开发经验。收银呗支付对于退款接口等是有异步回调通知的,但crmeb本身只在支付交易中有异步通知,所以开发者需要自行再开发退款异步通知接口。好了,大概就写这些吧,大家在开发中有遇到问题,可以私信联系,一起共享交流。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

模板之家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值