要先下载证书放到服务器上
include_once("$config[webroot]/pay/module/payment/lib/WxPayPubHelper/WxPayPubHelper.php");
//商户订单号,此处仅作举例
$out_trade_no = $_POST["order_id"];
$refund_fee = $_POST["price"]*100;
//商户退款单号,商户自定义,此处仅作举例
$out_refund_no = "$out_trade_no".time();
//总金额需与订单号out_trade_no对应,demo中的所有订单的总金额为1分
$total_fee = $_POST["price"]*100;
//使用退款接口
$refund = new Refund_pub();
//设置必填参数
//appid已填,商户无需重复填写
//mch_id已填,商户无需重复填写
//noncestr已填,商户无需重复填写
//sign已填,商户无需重复填写
$refund->setParameter("out_trade_no","$out_trade_no");//商户订单号
$refund->setParameter("out_refund_no","$out_refund_no");//商户退款单号
$refund->setParameter("total_fee","$total_fee");//总金额
$refund->setParameter("refund_fee","$refund_fee");//退款金额
$refund->setParameter("op_user_id",WxPayConf_pub::MCHID);//操作员
//非必填参数,商户可根据实际情况选填
//$refund->setParameter("sub_mch_id","XXXX");//子商户号
//$refund->setParameter("device_info","XXXX");//设备号
//$refund->setParameter("transaction_id","XXXX");//微信订单号
//调用结果
$refundResult = $refund->getResult();
//商户根据实际情况设置相应的处理流程,此处仅作举例
if ($refundResult["return_code"] == "FAIL") {
echo "通信出错:".$refundResult['return_msg']."<br>";
}
else{
if($refundResult['result_code']=="SUCCESS"){
//处理业务代码
}
else{
echo "业务结果:".$refundResult['result_code']."<br>";
echo "错误代码:".$refundResult['err_code']."<br>";
echo "错误代码描述:".$refundResult['err_code_des']."<br>";
echo "公众账号ID:".$refundResult['appid']."<br>";
echo "商户号:".$refundResult['mch_id']."<br>";
echo "子商户号:".$refundResult['sub_mch_id']."<br>";
echo "设备号:".$refundResult['device_info']."<br>";
echo "签名:".$refundResult['sign']."<br>";
echo "微信订单号:".$refundResult['transaction_id']."<br>";
echo "商户订单号:".$refundResult['out_trade_no']."<br>";
echo "商户退款单号:".$refundResult['out_refund_no']."<br>";
echo "微信退款单号:".$refundResult['refund_idrefund_id']."<br>";
echo "退款渠道:".$refundResult['refund_channel']."<br>";
echo "退款金额:".$refundResult['refund_fee']."<br>";
echo "现金券退款金额:".$refundResult['coupon_refund_fee']."<br>";
}
}