支付宝支付和退款

commposer下载yansongda

支付

fastadmin后台下载epay插件

 $param = $this->request->param();
        $uid = $this->auth->id;
//        $openId = \db("third")->where(["user_id" => $uid])->value("openid");
        $row = db('api_order')->where('id',$param['id'])->find();
        if ($param['type'] == 'alipay'){
            $amount = [
                'amount'    => $row['pay_price'],
                'orderid'   => $row['order_no'],
                'type'      => $param['type'],
                'title'     => '网页支付',
                'notifyurl' => $this->request->domain() . '/addons/epay/index/notifyx/paytype/' .$param['type'] ,
                'returnurl' => $this->request->domain() . "/pages/order/myOrder",
                'method'    => 'web',
                'openid'    => "",
            ];
            $response = Service::submitOrder($amount);
            echo $response;
}

支付回调

需要验签

支付宝快速入门 | Pay

退款

$config = [
                            'app_id' => '2021004101620262',
                            'notify_url' => '',
                            'return_url' => '',
                            'ali_public_key' => '支付宝公钥',
                            'private_key' => '应用私钥',
                            'log' => [ // optional
                                'file' => './logs/alipay.log',
                                'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
                                'type' => 'single', // optional, 可选 daily.
                                'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
                            ],
                            'http' => [ // optional
                                'timeout' => 5.0,
                                'connect_timeout' => 5.0,
                                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
                            ],
                            // 'mode' => 'dev', // optional,设置此参数,将进入沙箱模式
                        ];
                        $order = [
                            'out_trade_no' => $find['order_no'],
                            'refund_amount' => $params['refund_price'],
                        ];
                        $result = Pay::alipay($config)->refund($order);
                        // 验证服务器数据
                        // 是的,验签就这么简单!
                        if ($result['code'] == '10000' && $result['msg'] == 'Success'){
                            $this->model->where(["order_no" => $find["order_no"]])->update(["status" => "refunded", 'refund_no' => $refundNo, "refund_time" => time()]);
                            db("api_order_refund")->insert([
                                "user_id" => $this->auth->id,
                                "refund_no" => $refundNo,
                                "order_no" => $find["order_no"],
                                "refund_time" => time(),
                                "status" => 1
                            ]);
                            $this->success("支付宝退款成功!");
                        }else{
                            $this->error($result['err_code_des']);
                        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值