• 技术文章 >后端开发 >php教程

    php实现小程序退款完整版

    小云云小云云2018-03-21 13:26:13原创1867
    本文主要和大家分享php实现小程序退款完整版,功能前提:1. 使用 wx php sdk (小程序支付完整版) , 2. 配置证书时使用绝对路径希望能帮助到大家。

    1. 上代码:

        /**
         * 退款
         * @author:大脸猫脸大
         */
        public function refund()
        {
            import("Vendor.Wxpay.lib.WxPay#Api", "", ".php");
            $orderSn =  I("ordersn", "", "trim");
            $map = array('ordersn'=> $orderSn);
            $order = M("Order")->where($map)->find();
            if (!$order) {
                $result['code'] = 0;
                $result['msg'] = '未找到订单';
                $this->ajaxReturn($result);
            }
            $input = new \WxPayRefund();
            $input->SetTotal_fee($order['price']*100);
            $input->SetRefund_fee($order['price']*100);
            $input->SetOut_refund_no("R".$orderSn);
            $input->SetOut_trade_no("$orderSn");
            $input->SetOp_user_id(\WxPayConfig::MCHID);
            $refundOrder = \WxPayApi::refund($input);
            //file_put_contents(__DIR__."/refund.log", var_export($refundOrder, true). "\r\n" , FILE_APPEND);
            if ($refundOrder['result_code'] == 'SUCCESS' && $refundOrder['return_code'] == 'SUCCESS') {
                $result['code'] = 1;
                $result['data'] =  $refundOrder['transaction_id'];
                $this->ajaxReturn($result);
            }
            else {
                $result['code'] = 0;
                $result['msg'] =  $refundOrder['err_code'];
                $this->ajaxReturn($result);
            }
        }

    相关推荐:

    微信支付的退款功能开发

    PHP实现微信申请退款流程的方法

    PHP开发实现微信退款功能详解

    以上就是php实现小程序退款完整版的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:php 小程序 整版
    上一篇:PHP的基础知识简单介绍 下一篇:php如何写一个轻量级的容器
    20期PHP线上班

    相关文章推荐

    精选22门好课,价值3725元,开通VIP免费学习!• php7.2怎么连接oracle数据库?OCI8扩展的安装• php 验证码制作(网树注释思想)_PHP• 使用 PHP 5.0创建图形的巧妙方法_PHP• web开发中PHP MySQL分页显示示例分析_PHP• PHP 提示和技巧_PHP
    1/1

    PHP中文网