Yansongda、EasyWeChat对接支付宝、微信支付

最近在开发一个项目包含web端、H5端和App端,在开发支付功能时每个端的情况略有不同在这里做一下记录,支付宝支付使用Yangsongda,微信支付使用EasyWeChat,如有不对之处欢迎指正。

安装Yansongda

composer require yansongda/pay -vvv

安装EasyWeChat

composer require w7corp/easywechat

下面上代码,可以直接使用

use EasyWeChat\Factory;
use Yansongda\LaravelPay\Facades\Pay;

class PayController extends BaseController
{
    public function buyVip(Request $request)
    {
        $user_id = $this->getUserId();
        $type = $request->input('type', '');
        $id = (int)$request->input('id', 0);
        $device_type = $this->deviceType;
        if (!$type) {
            return $this->error('支付类型不能为空');
        }
        if (!$id) {
            return $this->error('商品ID不能为空');
        }

        $vip = Vip::where('id', $id)->first();
        if (!$vip) {
            return $this->error('充值金额不存在');
        }

        if ($type == 'wxpay') {

            $order = OrderService::createOrder($user_id, $vip, 'alipay');
            $config = config('wechat.payment.default');

            $app = Factory::payment($config);

            if ($device_type == 'app') {
                // APP支付
                $result = $app->order->unify([
                    'body' => $order['subject'],
                    'out_trade_no' => $order['order_sn'],
                    'total_fee' => $order['amount'] * 100,
                    //'notify_url' => 'https://pay.weixin.qq.com/wxpay/pay.action', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
                    'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
                ]);

            } else {

              
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值