ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 微信退款 **位置:** Common\Lib\WechatLib.class.php **参数:** * @param $refund_params array 微信退款需要的参数数组 **调用:** * 组件文件外调用 $my_wx = new WechatLib(); // 实例化微信组件库类 $refund_params = array( 'out_trade_no' => '1OS2018122445', 'total_fee' => '200', 'refund_fee' => '50', 'refund_order_no' => 'fanfanfan' ); $res = $my_wx->wxRefund($refund_params); **返回:** 成功时返回 Array ( [appid] => wx63e9531e049c102c [cash_fee] => 200 [cash_refund_fee] => 50 [coupon_refund_count] => 0 [coupon_refund_fee] => 0 [mch_id] => 1338026401 [nonce_str] => hJbinYV2oEpMmFHv [out_refund_no] => fanfanfan [out_trade_no] => 1OS2018122445 [refund_channel] => Array ( ) [refund_fee] => 50 [refund_id] => 50000609162018122507684961139 [result_code] => SUCCESS [return_code] => SUCCESS [return_msg] => OK [sign] => 1ADD203674A7C7D3C22422970C7080825B834DDF091ED688BD1785B44FB74392 [total_fee] => 200 [transaction_id] => 4200000248201812241034543566 ) 失败时候返回 详见微信申请退款API文档 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4 **完整代码:** ~~~ /** * @param $refund_params退款参数数组 * 例: * $refund_params = array( * 'out_trade_no' => '1OS2018122445', * 'total_fee' => '200', * 'refund_fee' => '50', * 'refund_order_no' => 'fanfanfan' * ); * @return 成功时返回退款成功信息,不成功返回错误信息 */ public function wxRefund($refund_params) { require_once APP_PATH."Common/Plugins/Wxpay/lib/WxPay.Api.php"; require_once APP_PATH."Common/Plugins/Wxpay/example/WxPay.Config.php"; require_once APP_PATH."Common/Plugins/Wxpay/example/log.php"; if((isset($refund_params["transaction_id"]) && $refund_params["transaction_id"] != "" && !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $refund_params["transaction_id"], $matches)) || (isset($refund_params["out_trade_no"]) && $refund_params["out_trade_no"]!="" && !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $refund_params["out_trade_no"], $matches)) || (isset($refund_params["total_fee"]) && $refund_params["total_fee"] != "" && !preg_match("/^[0-9]{0,10}$/i", $refund_params["total_fee"], $matches)) || (isset($refund_params["refund_fee"]) && $refund_params["refund_fee"] != "" && !preg_match("/^[0-9]{0,10}$/i", $refund_params["refund_fee"], $matches))) { header('HTTP/1.1 404 Not Found'); exit(); } if(isset($refund_params["out_trade_no"]) && $refund_params["out_trade_no"] != ""){ $out_trade_no = $refund_params["out_trade_no"]; $total_fee = $refund_params["total_fee"]; $refund_fee = $refund_params["refund_fee"]; $refund_order_no = $refund_params["refund_order_no"]; $input = new \WxPayRefund(); $input->SetOut_trade_no($out_trade_no); $input->SetTotal_fee($total_fee); $input->SetRefund_fee($refund_fee); $config = new \WxPayConfig(); $input->SetOut_refund_no($refund_order_no); $input->SetOp_user_id($config->GetMerchantId()); $result = \WxPayApi::refund($config, $input); return $result; } } ~~~