EeasyWechat 微信app支付

EeasyWechat 微信app支付

用的是easywechat3.x版本 + php

use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order;
public function appPay()
    {
        if ($this->request->isPost()) {
            $post = $this->request->post();
           $result = [
                'body' => '商品名称',
                'out_trade_no' => ‘订单编号’,
                'total_fee' => 10 * 100, // 金额
                'spbill_create_ip' => '', // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
                'notify_url' => '/notify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
                'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
            ];
            $appOrder = new Order($result);
            $appPayment = self::appPayment(); // 微信app配置信息 new Application(self::options);
            $rest = $appPayment->payment->prepare($appOrder);
            if ($rest->return_code != 'SUCCESS' || $rest->result_code != 'SUCCESS') {
                $this->error('获取支付订单失败');
            }         
                if ($rest->return_code == 'SUCCESS' && $rest->result_code == 'SUCCESS') {
                    $prepayId = $rest['prepay_id'];
                    $json = $appPayment->payment->configForAppPayment($prepayId);
                    $this->success('支付成功',$json);
                } else {
                    $this->error('调起支付失败,稍后再试~');
                }
        }
        $this->error('请求错误');
    }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值