企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] 官方文档: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2 >注:需要“证书”才能进行订单退款 ## (一)【证书路径设置】 设置商户证书路径: 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载,API证书下载地址:`https://pay.weixin.qq.com/index.php/account/api_cert`,下载之前需要安装商户操作证书) 下载证书地址,如图: ![mark](http://qiniu.newthink.cc/blog/20170919-232049462.png) ![mark](http://qiniu.newthink.cc/blog/20170919-232419969.png) 我里我们在根目录下新建一个 `cert` 文件夹,把下载的文件放置到该路径下: ![mark](http://qiniu.newthink.cc/blog/20170919-233157934.png) ## (二)配置情况如下 ![mark](http://qiniu.newthink.cc/blog/20170919-234042543.png) ## (三)代码使用 ``` // 微信支付-退款(报错了,需要证书 public function refund() { wxpayRefund('4200000011201709193042132589','2017091910048541',100,10); } ``` ## (四)退款函数 ``` /** * 订单退款 * 需要配置中有 * 微信订单号和商户订单号选少填一个,微信订单号优先 * @param $transaction_id 微信订单号 * @param $out_trade_no 商户订单号 * @param $total_fee 订单总金额(分) * @param $refund_fee 退款金额(分) */ function wxpayRefund($transaction_id,$out_trade_no,$total_fee,$refund_fee) { //导入 WxPay.Api.php 类 import('WxpayAPI.lib.WxPay',EXTEND_PATH,'.Api.php'); //导入 WxPay.Data.php 类 import('WxpayAPI.lib.WxPay',EXTEND_PATH,'.Data.php'); $input = new WxPayRefund(); $input->SetTransaction_id($transaction_id); $input->SetOut_trade_no($out_trade_no); $input->SetTotal_fee($total_fee); $input->SetRefund_fee($refund_fee); $input->SetOut_refund_no(WxPayConfig::MCHID.date("YmdHis")); $input->SetOp_user_id(WxPayConfig::MCHID); dump(WxPayApi::refund($input)); } ``` ## (五)返回数据 ``` array(18) { ["appid"] => string(18) "wx92dedc49b3405e25" ["cash_fee"] => string(3) "100" ["cash_refund_fee"] => string(2) "10" ["coupon_refund_count"] => string(1) "0" ["coupon_refund_fee"] => string(1) "0" ["mch_id"] => string(10) "1404807102" ["nonce_str"] => string(16) "VrsDVJc3l6NRHf5s" ["out_refund_no"] => string(24) "140480710220170919233847" ["out_trade_no"] => string(16) "2017091910048541" ["refund_channel"] => array(0) { } ["refund_fee"] => string(2) "10" ["refund_id"] => string(29) "50000504262017091901789042036" ["result_code"] => string(7) "SUCCESS" ["return_code"] => string(7) "SUCCESS" ["return_msg"] => string(2) "OK" ["sign"] => string(32) "D185FD4E87F712A34B7B3A6C8754CE38" ["total_fee"] => string(3) "100" ["transaction_id"] => string(28) "4200000011201709193042132589" } ``` ## (六)手机微信退款通知 退款交易通知 ![mark](http://qiniu.newthink.cc/blog/20170919-234313931.png =300x500) 退款交易详情 ![mark](http://qiniu.newthink.cc/blog/20170919-234321913.png =300x500) ## (七)PC退款通知 退款交易通知 ![mark](http://qiniu.newthink.cc/blog/20170919-234609179.png ) 退款交易详情 ![mark](http://qiniu.newthink.cc/blog/20170919-235456198.png ) ## (八)手机微信已退款通知 已退款交易通知 ![mark](http://qiniu.newthink.cc/blog/20170920-102919883.png =300x500) 已退款交易详情 ![mark](http://qiniu.newthink.cc/blog/20170920-102926097.png =300x500) ## (九)官网参考 ![mark](http://qiniu.newthink.cc/blog/20170920-103230981.png)