PHP implements the full version of mini program refund

小云云
Release: 2023-03-21 20:50:01
Original
3163 people have browsed it

This article mainly shares with you the full version of php to implement mini program refund. Functional premise: 1. Use wx php sdk (full version of mini program payment), 2. Use absolute path when configuring the certificate. I hope it can help everyone. .

1. Up code:

    /**
     * 退款
     * @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);
        }
    }
Copy after login

Related recommendations:

WeChat payment refund function development

PHP method to implement WeChat refund application process

Detailed explanation of PHP development to implement WeChat refund function

The above is the detailed content of PHP implements the full version of mini program refund. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template