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); } }
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!